Skip to content

Commit c842240

Browse files
committed
Auto merge of #96108 - Dylan-DPC:rollup-t5f2fc9, r=Dylan-DPC
Rollup of 9 pull requests Successful merges: - #93969 (Only add codegen backend to dep info if -Zbinary-dep-depinfo is used) - #94605 (Add missing links in platform support docs) - #95372 (make unaligned_references lint deny-by-default) - #95859 (Improve diagnostics for unterminated nested block comment) - #95961 (implement SIMD gather/scatter via vector getelementptr) - #96004 (Consider lifetimes when comparing types for equality in MIR validator) - #96050 (Remove some now-dead code that was only relevant before deaggregation.) - #96070 ([test] Add test cases for untested functions for BTreeMap) - #96099 (MaybeUninit array cleanup) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 07bb916 + f559cf9 commit c842240

37 files changed

+797
-92
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,27 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
18391839
simd_neg: Int => neg, Float => fneg;
18401840
}
18411841

1842+
if name == sym::simd_arith_offset {
1843+
// This also checks that the first operand is a ptr type.
1844+
let pointee = in_elem.builtin_deref(true).unwrap_or_else(|| {
1845+
span_bug!(span, "must be called with a vector of pointer types as first argument")
1846+
});
1847+
let layout = bx.layout_of(pointee.ty);
1848+
let ptrs = args[0].immediate();
1849+
// The second argument must be a ptr-sized integer.
1850+
// (We don't care about the signedness, this is wrapping anyway.)
1851+
let (_offsets_len, offsets_elem) = arg_tys[1].simd_size_and_type(bx.tcx());
1852+
if !matches!(offsets_elem.kind(), ty::Int(ty::IntTy::Isize) | ty::Uint(ty::UintTy::Usize)) {
1853+
span_bug!(
1854+
span,
1855+
"must be called with a vector of pointer-sized integers as second argument"
1856+
);
1857+
}
1858+
let offsets = args[1].immediate();
1859+
1860+
return Ok(bx.gep(bx.backend_type(layout), ptrs, &[offsets]));
1861+
}
1862+
18421863
if name == sym::simd_saturating_add || name == sym::simd_saturating_sub {
18431864
let lhs = args[0].immediate();
18441865
let rhs = args[1].immediate();

compiler/rustc_const_eval/src/interpret/step.rs

+3-19
Original file line numberDiff line numberDiff line change
@@ -196,27 +196,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
196196
self.write_immediate(*val, &dest)?;
197197
}
198198

199-
Aggregate(ref kind, ref operands) => {
200-
// active_field_index is for union initialization.
201-
let (dest, active_field_index) = match **kind {
202-
mir::AggregateKind::Adt(adt_did, variant_index, _, _, active_field_index) => {
203-
self.write_discriminant(variant_index, &dest)?;
204-
if self.tcx.adt_def(adt_did).is_enum() {
205-
assert!(active_field_index.is_none());
206-
(self.place_downcast(&dest, variant_index)?, None)
207-
} else {
208-
if active_field_index.is_some() {
209-
assert_eq!(operands.len(), 1);
210-
}
211-
(dest, active_field_index)
212-
}
213-
}
214-
_ => (dest, None),
215-
};
199+
Aggregate(box ref kind, ref operands) => {
200+
assert!(matches!(kind, mir::AggregateKind::Array(..)));
216201

217-
for (i, operand) in operands.iter().enumerate() {
202+
for (field_index, operand) in operands.iter().enumerate() {
218203
let op = self.eval_operand(operand, None)?;
219-
let field_index = active_field_index.unwrap_or(i);
220204
let field_dest = self.place_field(&dest, field_index)?;
221205
self.copy_op(&op, &field_dest)?;
222206
}

compiler/rustc_const_eval/src/transform/validate.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
315315
| ty::FnPtr(..)
316316
)
317317
}
318-
// None of the possible types have lifetimes, so we can just compare
319-
// directly
320-
if a != b {
318+
// The function pointer types can have lifetimes
319+
if !self.mir_assign_valid_types(a, b) {
321320
self.fail(
322321
location,
323322
format!("Cannot compare unequal types {:?} and {:?}", a, b),
@@ -464,7 +463,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
464463
};
465464
// since CopyNonOverlapping is parametrized by 1 type,
466465
// we only need to check that they are equal and not keep an extra parameter.
467-
if op_src_ty != op_dst_ty {
466+
if !self.mir_assign_valid_types(op_src_ty, op_dst_ty) {
468467
self.fail(location, format!("bad arg ({:?} != {:?})", op_src_ty, op_dst_ty));
469468
}
470469

compiler/rustc_data_structures/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#![feature(thread_id_value)]
2828
#![feature(vec_into_raw_parts)]
2929
#![allow(rustc::default_hash_types)]
30-
#![deny(unaligned_references)]
3130
#![allow(rustc::potential_query_instability)]
3231

3332
#[macro_use]

compiler/rustc_interface/src/passes.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,15 @@ fn write_out_deps(
629629
});
630630
files.extend(extra_tracked_files);
631631

632-
if let Some(ref backend) = sess.opts.debugging_opts.codegen_backend {
633-
files.push(backend.to_string());
634-
}
635-
636632
if sess.binary_dep_depinfo() {
633+
if let Some(ref backend) = sess.opts.debugging_opts.codegen_backend {
634+
if backend.contains('.') {
635+
// If the backend name contain a `.`, it is the path to an external dynamic
636+
// library. If not, it is not a path.
637+
files.push(backend.to_string());
638+
}
639+
}
640+
637641
boxed_resolver.borrow_mut().access(|resolver| {
638642
for cnum in resolver.cstore().crates_untracked() {
639643
let source = resolver.cstore().crate_source_untracked(cnum);

compiler/rustc_lint_defs/src/builtin.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,6 @@ declare_lint! {
11101110
/// ### Example
11111111
///
11121112
/// ```rust,compile_fail
1113-
/// #![deny(unaligned_references)]
1114-
///
11151113
/// #[repr(packed)]
11161114
/// pub struct Foo {
11171115
/// field1: u64,
@@ -1139,10 +1137,11 @@ declare_lint! {
11391137
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
11401138
/// [issue #82523]: https://github.com/rust-lang/rust/issues/82523
11411139
pub UNALIGNED_REFERENCES,
1142-
Warn,
1140+
Deny,
11431141
"detects unaligned references to fields of packed structs",
11441142
@future_incompatible = FutureIncompatibleInfo {
11451143
reference: "issue #82523 <https://github.com/rust-lang/rust/issues/82523>",
1144+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
11461145
};
11471146
report_in_external_macro
11481147
}

compiler/rustc_middle/src/mir/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2518,7 +2518,8 @@ pub enum Rvalue<'tcx> {
25182518
/// * `Offset` has the same semantics as [`offset`](pointer::offset), except that the second
25192519
/// parameter may be a `usize` as well.
25202520
/// * The comparison operations accept `bool`s, `char`s, signed or unsigned integers, floats,
2521-
/// raw pointers, or function pointers of matching types and return a `bool`.
2521+
/// raw pointers, or function pointers and return a `bool`. The types of the operands must be
2522+
/// matching, up to the usual caveat of the lifetimes in function pointers.
25222523
/// * Left and right shift operations accept signed or unsigned integers not necessarily of the
25232524
/// same type and return a value of the same type as their LHS. Like in Rust, the RHS is
25242525
/// truncated as needed.

compiler/rustc_parse/src/lexer/mod.rs

+50-10
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,7 @@ impl<'a> StringReader<'a> {
182182
}
183183
rustc_lexer::TokenKind::BlockComment { doc_style, terminated } => {
184184
if !terminated {
185-
let msg = match doc_style {
186-
Some(_) => "unterminated block doc-comment",
187-
None => "unterminated block comment",
188-
};
189-
let last_bpos = self.pos;
190-
self.sess.span_diagnostic.span_fatal_with_code(
191-
self.mk_sp(start, last_bpos),
192-
msg,
193-
error_code!(E0758),
194-
);
185+
self.report_unterminated_block_comment(start, doc_style);
195186
}
196187

197188
// Skip non-doc comments
@@ -553,6 +544,55 @@ impl<'a> StringReader<'a> {
553544
err.emit()
554545
}
555546

547+
fn report_unterminated_block_comment(&self, start: BytePos, doc_style: Option<DocStyle>) {
548+
let msg = match doc_style {
549+
Some(_) => "unterminated block doc-comment",
550+
None => "unterminated block comment",
551+
};
552+
let last_bpos = self.pos;
553+
let mut err = self.sess.span_diagnostic.struct_span_fatal_with_code(
554+
self.mk_sp(start, last_bpos),
555+
msg,
556+
error_code!(E0758),
557+
);
558+
let mut nested_block_comment_open_idxs = vec![];
559+
let mut last_nested_block_comment_idxs = None;
560+
let mut content_chars = self.str_from(start).char_indices().peekable();
561+
562+
while let Some((idx, current_char)) = content_chars.next() {
563+
match content_chars.peek() {
564+
Some((_, '*')) if current_char == '/' => {
565+
nested_block_comment_open_idxs.push(idx);
566+
}
567+
Some((_, '/')) if current_char == '*' => {
568+
last_nested_block_comment_idxs =
569+
nested_block_comment_open_idxs.pop().map(|open_idx| (open_idx, idx));
570+
}
571+
_ => {}
572+
};
573+
}
574+
575+
if let Some((nested_open_idx, nested_close_idx)) = last_nested_block_comment_idxs {
576+
err.span_label(self.mk_sp(start, start + BytePos(2)), msg)
577+
.span_label(
578+
self.mk_sp(
579+
start + BytePos(nested_open_idx as u32),
580+
start + BytePos(nested_open_idx as u32 + 2),
581+
),
582+
"...as last nested comment starts here, maybe you want to close this instead?",
583+
)
584+
.span_label(
585+
self.mk_sp(
586+
start + BytePos(nested_close_idx as u32),
587+
start + BytePos(nested_close_idx as u32 + 2),
588+
),
589+
"...and last nested comment terminates here.",
590+
);
591+
}
592+
593+
err.emit();
594+
}
595+
556596
// RFC 3101 introduced the idea of (reserved) prefixes. As of Rust 2021,
557597
// using a (unknown) prefix is an error. In earlier editions, however, they
558598
// only result in a (allowed by default) lint, and are treated as regular

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,7 @@ symbols! {
12471247
simd,
12481248
simd_add,
12491249
simd_and,
1250+
simd_arith_offset,
12501251
simd_as,
12511252
simd_bitmask,
12521253
simd_cast,

compiler/rustc_typeck/src/check/intrinsic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
437437
| sym::simd_fpow
438438
| sym::simd_saturating_add
439439
| sym::simd_saturating_sub => (1, vec![param(0), param(0)], param(0)),
440+
sym::simd_arith_offset => (2, vec![param(0), param(1)], param(0)),
440441
sym::simd_neg
441442
| sym::simd_fsqrt
442443
| sym::simd_fsin

library/alloc/src/collections/btree/map/tests.rs

+105
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,96 @@ fn test_first_last_entry() {
18781878
a.check();
18791879
}
18801880

1881+
#[test]
1882+
fn test_pop_first_last() {
1883+
let mut map = BTreeMap::new();
1884+
assert_eq!(map.pop_first(), None);
1885+
assert_eq!(map.pop_last(), None);
1886+
1887+
map.insert(1, 10);
1888+
map.insert(2, 20);
1889+
map.insert(3, 30);
1890+
map.insert(4, 40);
1891+
1892+
assert_eq!(map.len(), 4);
1893+
1894+
let (key, val) = map.pop_first().unwrap();
1895+
assert_eq!(key, 1);
1896+
assert_eq!(val, 10);
1897+
assert_eq!(map.len(), 3);
1898+
1899+
let (key, val) = map.pop_first().unwrap();
1900+
assert_eq!(key, 2);
1901+
assert_eq!(val, 20);
1902+
assert_eq!(map.len(), 2);
1903+
let (key, val) = map.pop_last().unwrap();
1904+
assert_eq!(key, 4);
1905+
assert_eq!(val, 40);
1906+
assert_eq!(map.len(), 1);
1907+
1908+
map.insert(5, 50);
1909+
map.insert(6, 60);
1910+
assert_eq!(map.len(), 3);
1911+
1912+
let (key, val) = map.pop_first().unwrap();
1913+
assert_eq!(key, 3);
1914+
assert_eq!(val, 30);
1915+
assert_eq!(map.len(), 2);
1916+
1917+
let (key, val) = map.pop_last().unwrap();
1918+
assert_eq!(key, 6);
1919+
assert_eq!(val, 60);
1920+
assert_eq!(map.len(), 1);
1921+
1922+
let (key, val) = map.pop_last().unwrap();
1923+
assert_eq!(key, 5);
1924+
assert_eq!(val, 50);
1925+
assert_eq!(map.len(), 0);
1926+
1927+
assert_eq!(map.pop_first(), None);
1928+
assert_eq!(map.pop_last(), None);
1929+
1930+
map.insert(7, 70);
1931+
map.insert(8, 80);
1932+
1933+
let (key, val) = map.pop_last().unwrap();
1934+
assert_eq!(key, 8);
1935+
assert_eq!(val, 80);
1936+
assert_eq!(map.len(), 1);
1937+
1938+
let (key, val) = map.pop_last().unwrap();
1939+
assert_eq!(key, 7);
1940+
assert_eq!(val, 70);
1941+
assert_eq!(map.len(), 0);
1942+
1943+
assert_eq!(map.pop_first(), None);
1944+
assert_eq!(map.pop_last(), None);
1945+
}
1946+
1947+
#[test]
1948+
fn test_get_key_value() {
1949+
let mut map = BTreeMap::new();
1950+
1951+
assert!(map.is_empty());
1952+
assert_eq!(map.get_key_value(&1), None);
1953+
assert_eq!(map.get_key_value(&2), None);
1954+
1955+
map.insert(1, 10);
1956+
map.insert(2, 20);
1957+
map.insert(3, 30);
1958+
1959+
assert_eq!(map.len(), 3);
1960+
assert_eq!(map.get_key_value(&1), Some((&1, &10)));
1961+
assert_eq!(map.get_key_value(&3), Some((&3, &30)));
1962+
assert_eq!(map.get_key_value(&4), None);
1963+
1964+
map.remove(&3);
1965+
1966+
assert_eq!(map.len(), 2);
1967+
assert_eq!(map.get_key_value(&3), None);
1968+
assert_eq!(map.get_key_value(&2), Some((&2, &20)));
1969+
}
1970+
18811971
#[test]
18821972
fn test_insert_into_full_height_0() {
18831973
let size = node::CAPACITY;
@@ -1904,6 +1994,21 @@ fn test_insert_into_full_height_1() {
19041994
}
19051995
}
19061996

1997+
#[test]
1998+
fn test_try_insert() {
1999+
let mut map = BTreeMap::new();
2000+
2001+
assert!(map.is_empty());
2002+
2003+
assert_eq!(map.try_insert(1, 10).unwrap(), &10);
2004+
assert_eq!(map.try_insert(2, 20).unwrap(), &20);
2005+
2006+
let err = map.try_insert(2, 200).unwrap_err();
2007+
assert_eq!(err.entry.key(), &2);
2008+
assert_eq!(err.entry.get(), &20);
2009+
assert_eq!(err.value, 200);
2010+
}
2011+
19072012
macro_rules! create_append_test {
19082013
($name:ident, $len:expr) => {
19092014
#[test]

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
#![feature(const_intrinsic_copy)]
118118
#![feature(const_intrinsic_forget)]
119119
#![feature(const_likely)]
120+
#![feature(const_maybe_uninit_uninit_array)]
120121
#![feature(const_maybe_uninit_as_mut_ptr)]
121122
#![feature(const_maybe_uninit_assume_init)]
122123
#![feature(const_num_from_num)]

0 commit comments

Comments
 (0)