Skip to content

Commit 381d699

Browse files
committed
Auto merge of rust-lang#121549 - matthiaskrgr:rollup-1hvu3lb, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#121435 (Account for RPITIT in E0310 explicit lifetime constraint suggestion) - rust-lang#121490 (Rustdoc: include crate name in links for local primitives) - rust-lang#121520 (delay cloning of iterator items) - rust-lang#121522 (check that simd_insert/extract indices are in-bounds) - rust-lang#121531 (Ignore less tests in debug builds) - rust-lang#121539 (compiler/rustc_target/src/spec/base/apple/tests.rs: Avoid unnecessary large move) - rust-lang#121542 (update stdarch) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6bdb8a4 + ee23b78 commit 381d699

File tree

76 files changed

+190
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+190
-153
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+34-19
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
10791079
.map(|(arg_idx, val)| {
10801080
let idx = val.unwrap_leaf().try_to_i32().unwrap();
10811081
if idx >= i32::try_from(total_len).unwrap() {
1082-
bx.sess().dcx().emit_err(InvalidMonomorphization::ShuffleIndexOutOfBounds {
1082+
bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds {
10831083
span,
10841084
name,
10851085
arg_idx: arg_idx as u64,
@@ -1138,24 +1138,15 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
11381138
let val = bx.const_get_elt(vector, i as u64);
11391139
match bx.const_to_opt_u128(val, true) {
11401140
None => {
1141-
bx.sess().dcx().emit_err(
1142-
InvalidMonomorphization::ShuffleIndexNotConstant {
1143-
span,
1144-
name,
1145-
arg_idx,
1146-
},
1147-
);
1148-
None
1141+
bug!("typeck should have already ensured that these are const")
11491142
}
11501143
Some(idx) if idx >= total_len => {
1151-
bx.sess().dcx().emit_err(
1152-
InvalidMonomorphization::ShuffleIndexOutOfBounds {
1153-
span,
1154-
name,
1155-
arg_idx,
1156-
total_len,
1157-
},
1158-
);
1144+
bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds {
1145+
span,
1146+
name,
1147+
arg_idx,
1148+
total_len,
1149+
});
11591150
None
11601151
}
11611152
Some(idx) => Some(bx.const_i32(idx as i32)),
@@ -1184,18 +1175,42 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
11841175
out_ty: arg_tys[2]
11851176
}
11861177
);
1178+
let idx = bx
1179+
.const_to_opt_u128(args[1].immediate(), false)
1180+
.expect("typeck should have ensure that this is a const");
1181+
if idx >= in_len.into() {
1182+
bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds {
1183+
span,
1184+
name,
1185+
arg_idx: 1,
1186+
total_len: in_len.into(),
1187+
});
1188+
return Ok(bx.const_null(llret_ty));
1189+
}
11871190
return Ok(bx.insert_element(
11881191
args[0].immediate(),
11891192
args[2].immediate(),
1190-
args[1].immediate(),
1193+
bx.const_i32(idx as i32),
11911194
));
11921195
}
11931196
if name == sym::simd_extract {
11941197
require!(
11951198
ret_ty == in_elem,
11961199
InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
11971200
);
1198-
return Ok(bx.extract_element(args[0].immediate(), args[1].immediate()));
1201+
let idx = bx
1202+
.const_to_opt_u128(args[1].immediate(), false)
1203+
.expect("typeck should have ensure that this is a const");
1204+
if idx >= in_len.into() {
1205+
bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds {
1206+
span,
1207+
name,
1208+
arg_idx: 1,
1209+
total_len: in_len.into(),
1210+
});
1211+
return Ok(bx.const_null(llret_ty));
1212+
}
1213+
return Ok(bx.extract_element(args[0].immediate(), bx.const_i32(idx as i32)));
11991214
}
12001215

12011216
if name == sym::simd_select {

compiler/rustc_codegen_ssa/messages.ftl

+2-4
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,12 @@ codegen_ssa_invalid_monomorphization_return_type = invalid monomorphization of `
106106
107107
codegen_ssa_invalid_monomorphization_second_argument_length = invalid monomorphization of `{$name}` intrinsic: expected second argument with length {$in_len} (same as input type `{$in_ty}`), found `{$arg_ty}` with length {$out_len}
108108
109-
codegen_ssa_invalid_monomorphization_shuffle_index_not_constant = invalid monomorphization of `{$name}` intrinsic: shuffle index #{$arg_idx} is not a constant
110-
111-
codegen_ssa_invalid_monomorphization_shuffle_index_out_of_bounds = invalid monomorphization of `{$name}` intrinsic: shuffle index #{$arg_idx} is out of bounds (limit {$total_len})
112-
113109
codegen_ssa_invalid_monomorphization_simd_argument = invalid monomorphization of `{$name}` intrinsic: expected SIMD argument type, found non-SIMD `{$ty}`
114110
115111
codegen_ssa_invalid_monomorphization_simd_first = invalid monomorphization of `{$name}` intrinsic: expected SIMD first type, found non-SIMD `{$ty}`
116112
113+
codegen_ssa_invalid_monomorphization_simd_index_out_of_bounds = invalid monomorphization of `{$name}` intrinsic: SIMD index #{$arg_idx} is out of bounds (limit {$total_len})
114+
117115
codegen_ssa_invalid_monomorphization_simd_input = invalid monomorphization of `{$name}` intrinsic: expected SIMD input type, found non-SIMD `{$ty}`
118116
119117
codegen_ssa_invalid_monomorphization_simd_return = invalid monomorphization of `{$name}` intrinsic: expected SIMD return type, found non-SIMD `{$ty}`

compiler/rustc_codegen_ssa/src/errors.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -797,16 +797,8 @@ pub enum InvalidMonomorphization<'tcx> {
797797
out_ty: Ty<'tcx>,
798798
},
799799

800-
#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_not_constant, code = E0511)]
801-
ShuffleIndexNotConstant {
802-
#[primary_span]
803-
span: Span,
804-
name: Symbol,
805-
arg_idx: u64,
806-
},
807-
808-
#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_out_of_bounds, code = E0511)]
809-
ShuffleIndexOutOfBounds {
800+
#[diag(codegen_ssa_invalid_monomorphization_simd_index_out_of_bounds, code = E0511)]
801+
SimdIndexOutOfBounds {
810802
#[primary_span]
811803
span: Span,
812804
name: Symbol,

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
379379
let (input, input_len) = self.operand_to_simd(&args[0])?;
380380
let (dest, dest_len) = self.place_to_simd(dest)?;
381381
assert_eq!(input_len, dest_len, "Return vector length must match input length");
382-
assert!(
383-
index < dest_len,
384-
"Index `{index}` must be in bounds of vector with length {dest_len}"
385-
);
382+
// Bounds are not checked by typeck so we have to do it ourselves.
383+
if index >= input_len {
384+
throw_ub_format!(
385+
"`simd_insert` index {index} is out-of-bounds of vector with length {input_len}"
386+
);
387+
}
386388

387389
for i in 0..dest_len {
388390
let place = self.project_index(&dest, i)?;
@@ -397,10 +399,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
397399
sym::simd_extract => {
398400
let index = u64::from(self.read_scalar(&args[1])?.to_u32()?);
399401
let (input, input_len) = self.operand_to_simd(&args[0])?;
400-
assert!(
401-
index < input_len,
402-
"index `{index}` must be in bounds of vector with length {input_len}"
403-
);
402+
// Bounds are not checked by typeck so we have to do it ourselves.
403+
if index >= input_len {
404+
throw_ub_format!(
405+
"`simd_extract` index {index} is out-of-bounds of vector with length {input_len}"
406+
);
407+
}
404408
self.copy_op(&self.project_index(&input, index)?, dest)?;
405409
}
406410
sym::likely | sym::unlikely | sym::black_box => {

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2437,6 +2437,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
24372437
let suggestion =
24382438
if has_lifetimes { format!(" + {lt_name}") } else { format!(": {lt_name}") };
24392439
suggs.push((sp, suggestion))
2440+
} else if let GenericKind::Alias(ref p) = bound_kind
2441+
&& let ty::Projection = p.kind(self.tcx)
2442+
&& let DefKind::AssocTy = self.tcx.def_kind(p.def_id)
2443+
&& let Some(ty::ImplTraitInTraitData::Trait { .. }) =
2444+
self.tcx.opt_rpitit_info(p.def_id)
2445+
{
2446+
// The lifetime found in the `impl` is longer than the one on the RPITIT.
2447+
// Do not suggest `<Type as Trait>::{opaque}: 'static`.
24402448
} else if let Some(generics) = self.tcx.hir().get_generics(suggestion_scope) {
24412449
let pred = format!("{bound_kind}: {lt_name}");
24422450
let suggestion = format!("{} {}", generics.add_where_or_trailing_comma(), pred);

compiler/rustc_target/src/spec/base/apple/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn simulator_targets_set_abi() {
1414
aarch64_apple_watchos_sim::target(),
1515
];
1616

17-
for target in all_sim_targets {
17+
for target in &all_sim_targets {
1818
assert_eq!(target.abi, "sim")
1919
}
2020
}

compiler/rustc_trait_selection/src/traits/coherence.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -320,22 +320,25 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>(
320320
let mut errors = fulfill_cx.select_where_possible(infcx);
321321
errors.pop().map(|err| err.obligation)
322322
} else {
323-
obligations.iter().cloned().find(|obligation| {
324-
// We use `evaluate_root_obligation` to correctly track intercrate
325-
// ambiguity clauses. We cannot use this in the new solver.
326-
let evaluation_result = selcx.evaluate_root_obligation(obligation);
327-
328-
match evaluation_result {
329-
Ok(result) => !result.may_apply(),
330-
// If overflow occurs, we need to conservatively treat the goal as possibly holding,
331-
// since there can be instantiations of this goal that don't overflow and result in
332-
// success. This isn't much of a problem in the old solver, since we treat overflow
333-
// fatally (this still can be encountered: <https://github.com/rust-lang/rust/issues/105231>),
334-
// but in the new solver, this is very important for correctness, since overflow
335-
// *must* be treated as ambiguity for completeness.
336-
Err(_overflow) => false,
337-
}
338-
})
323+
obligations
324+
.iter()
325+
.find(|obligation| {
326+
// We use `evaluate_root_obligation` to correctly track intercrate
327+
// ambiguity clauses. We cannot use this in the new solver.
328+
let evaluation_result = selcx.evaluate_root_obligation(obligation);
329+
330+
match evaluation_result {
331+
Ok(result) => !result.may_apply(),
332+
// If overflow occurs, we need to conservatively treat the goal as possibly holding,
333+
// since there can be instantiations of this goal that don't overflow and result in
334+
// success. This isn't much of a problem in the old solver, since we treat overflow
335+
// fatally (this still can be encountered: <https://github.com/rust-lang/rust/issues/105231>),
336+
// but in the new solver, this is very important for correctness, since overflow
337+
// *must* be treated as ambiguity for completeness.
338+
Err(_overflow) => false,
339+
}
340+
})
341+
.cloned()
339342
}
340343
}
341344

library/stdarch

src/librustdoc/html/format.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -879,11 +879,16 @@ fn primitive_link_fragment(
879879
match m.primitive_locations.get(&prim) {
880880
Some(&def_id) if def_id.is_local() => {
881881
let len = cx.current.len();
882-
let len = if len == 0 { 0 } else { len - 1 };
882+
let path = if len == 0 {
883+
let cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx());
884+
format!("{cname_sym}/")
885+
} else {
886+
"../".repeat(len - 1)
887+
};
883888
write!(
884889
f,
885890
"<a class=\"primitive\" href=\"{}primitive.{}.html{fragment}\">",
886-
"../".repeat(len),
891+
path,
887892
prim.as_sym()
888893
)?;
889894
needs_termination = true;

src/tools/compiletest/src/runtest.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2503,8 +2503,11 @@ impl<'test> TestCx<'test> {
25032503
// overridden by `compile-flags`.
25042504
rustc.arg("-Copt-level=2");
25052505
}
2506-
RunPassValgrind | Pretty | DebugInfo | Codegen | Rustdoc | RustdocJson | RunMake
2507-
| CodegenUnits | JsDocTest | Assembly => {
2506+
Assembly | Codegen => {
2507+
rustc.arg("-Cdebug-assertions=no");
2508+
}
2509+
RunPassValgrind | Pretty | DebugInfo | Rustdoc | RustdocJson | RunMake
2510+
| CodegenUnits | JsDocTest => {
25082511
// do not use JSON output
25092512
}
25102513
}

src/tools/miri/src/shims/intrinsics/simd.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
563563
let right_idx = src_index.checked_sub(left_len).unwrap();
564564
this.read_immediate(&this.project_index(&right, right_idx)?)?
565565
} else {
566-
span_bug!(
567-
this.cur_span(),
568-
"simd_shuffle index {src_index} is out of bounds for 2 vectors of size {left_len}",
566+
throw_ub_format!(
567+
"`simd_shuffle_generic` index {src_index} is out-of-bounds for 2 vectors with length {dest_len}"
569568
);
570569
};
571570
this.write_immediate(*val, &dest)?;
@@ -604,9 +603,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
604603
let right_idx = src_index.checked_sub(left_len).unwrap();
605604
this.read_immediate(&this.project_index(&right, right_idx)?)?
606605
} else {
607-
span_bug!(
608-
this.cur_span(),
609-
"simd_shuffle index {src_index} is out of bounds for 2 vectors of size {left_len}",
606+
throw_ub_format!(
607+
"`simd_shuffle` index {src_index} is out-of-bounds for 2 vectors with length {dest_len}"
610608
);
611609
};
612610
this.write_immediate(*val, &dest)?;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(portable_simd, core_intrinsics)]
2+
use std::simd::*;
3+
4+
fn main() {
5+
let v = i32x4::splat(0);
6+
let _x: i32 = unsafe { std::intrinsics::simd::simd_extract(v, 4) };
7+
//~^ERROR: index 4 is out-of-bounds
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: `simd_extract` index 4 is out-of-bounds of vector with length 4
2+
--> $DIR/simd-extract.rs:LL:CC
3+
|
4+
LL | let _x: i32 = unsafe { std::intrinsics::simd::simd_extract(v, 4) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `simd_extract` index 4 is out-of-bounds of vector with length 4
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at $DIR/simd-extract.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+

tests/assembly/option-nonzero-eq.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//@ compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel
66
//@ only-x86_64
77
//@ ignore-sgx
8-
//@ ignore-debug
98

109
use std::cmp::Ordering;
1110

tests/assembly/slice-is_ascii.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//@ compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel
66
//@ only-x86_64
77
//@ ignore-sgx
8-
//@ ignore-debug
98

109
#![feature(str_internals)]
1110

tests/assembly/static-relocation-model.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//@ [A64] needs-llvm-components: aarch64
77
//@ [ppc64le] compile-flags: --target powerpc64le-unknown-linux-gnu -Crelocation-model=static
88
//@ [ppc64le] needs-llvm-components: powerpc
9-
//@ ignore-debug: alignment checks insert panics that we don't have a lang item for
109

1110
#![feature(no_core, lang_items)]
1211
#![no_core]

tests/codegen/align-offset.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ compile-flags: -O
2-
//@ ignore-debug (debug assertions in `slice::from_raw_parts` block optimizations)
32

43
#![crate_type = "lib"]
54

tests/codegen/array-map.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ compile-flags: -C opt-level=3 -C target-cpu=x86-64-v3
22
//@ only-x86_64
3-
//@ ignore-debug (the extra assertions get in the way)
43

54
#![crate_type = "lib"]
65

tests/codegen/ascii-char.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ compile-flags: -C opt-level=1
2-
//@ ignore-debug (the extra assertions get in the way)
32

43
#![crate_type = "lib"]
54
#![feature(ascii_char)]

tests/codegen/binary-search-index-no-bound-check.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ compile-flags: -O
2-
//@ ignore-debug: the debug assertions get in the way
32
#![crate_type = "lib"]
43

54
// Make sure no bounds checks are emitted when slicing or indexing

tests/codegen/infallible-unwrap-in-opt-z.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ compile-flags: -C opt-level=z --edition=2021
2-
//@ ignore-debug
32

43
#![crate_type = "lib"]
54

tests/codegen/issue-97217.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ compile-flags: -C opt-level=3
2-
//@ ignore-debug: the debug assertions get in the way
32
//@ min-llvm-version: 17.0.2
43
#![crate_type = "lib"]
54

tests/codegen/issues/issue-101082.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ compile-flags: -O
2-
//@ ignore-debug: the debug assertions get in the way
32

43
#![crate_type = "lib"]
54

tests/codegen/issues/issue-101814.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ compile-flags: -O
2-
//@ ignore-debug: the debug assertions get in the way
32

43
#![crate_type = "lib"]
54

tests/codegen/issues/issue-106369.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ compile-flags: -O
2-
//@ ignore-debug (the extra assertions get in the way)
32

43
#![crate_type = "lib"]
54

tests/codegen/issues/issue-116878.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ compile-flags: -O
2-
//@ ignore-debug: the debug assertions get in the way
32
#![crate_type = "lib"]
43

54
/// Make sure no bounds checks are emitted after a `get_unchecked`.

tests/codegen/issues/issue-37945.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ compile-flags: -O -Zmerge-functions=disabled
22
//@ ignore-32bit LLVM has a bug with them
3-
//@ ignore-debug
43

54
// Check that LLVM understands that `Iter` pointer is not null. Issue #37945.
65

0 commit comments

Comments
 (0)