From 31851d4770774ac95a694f2596138fc43fcd39b4 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 14 Jun 2024 15:49:45 -0700 Subject: [PATCH 01/18] Add `-Zdump-mir-exclude-alloc-bytes` --- compiler/rustc_interface/src/tests.rs | 1 + compiler/rustc_middle/src/mir/pretty.rs | 3 +++ compiler/rustc_session/src/options.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 6ffc518097ef0..619b125a8780d 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -683,6 +683,7 @@ fn test_unstable_options_tracking_hash() { untracked!(dump_mir, Some(String::from("abc"))); untracked!(dump_mir_dataflow, true); untracked!(dump_mir_dir, String::from("abc")); + untracked!(dump_mir_exclude_alloc_bytes, true); untracked!(dump_mir_exclude_pass_number, true); untracked!(dump_mir_graphviz, true); untracked!(dump_mono_stats, SwitchWithOptPath::Enabled(Some("mono-items-dir/".into()))); diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 4657f4dcf8132..3ea98de1a177d 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1521,6 +1521,9 @@ impl<'a, 'tcx, Prov: Provenance, Extra, Bytes: AllocBytes> std::fmt::Display // We are done. return write!(w, " {{}}"); } + if tcx.sess.opts.unstable_opts.dump_mir_exclude_alloc_bytes { + return write!(w, " {{ .. }}"); + } // Write allocation bytes. writeln!(w, " {{")?; write_allocation_bytes(tcx, alloc, w, " ")?; diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 9a10adeb6d1a1..a3f1369776de4 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1662,6 +1662,8 @@ options! { (default: no)"), dump_mir_dir: String = ("mir_dump".to_string(), parse_string, [UNTRACKED], "the directory the MIR is dumped into (default: `mir_dump`)"), + dump_mir_exclude_alloc_bytes: bool = (false, parse_bool, [UNTRACKED], + "exclude the raw bytes of allocations when dumping MIR (used in tests) (default: no)"), dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED], "exclude the pass number when dumping MIR (used in tests) (default: no)"), dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED], From 1a05cb2d9358879468c87645b0c1d5d1e8e12a12 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 14 Jun 2024 16:01:26 -0700 Subject: [PATCH 02/18] Use `-Zdump-mir-exclude-alloc-bytes` in some mir-opt tests --- tests/mir-opt/const_debuginfo.rs | 2 +- tests/mir-opt/const_prop/address_of_pair.rs | 1 + tests/mir-opt/const_prop/checked_add.rs | 2 +- tests/mir-opt/const_prop/mutable_variable_aggregate.rs | 1 + tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs | 1 + tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs | 1 + tests/mir-opt/const_prop/return_place.rs | 2 +- tests/mir-opt/const_prop/slice_len.rs | 2 +- tests/mir-opt/const_prop/tuple_literal_propagation.rs | 1 + tests/mir-opt/dataflow-const-prop/checked.rs | 2 +- tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs | 2 +- tests/mir-opt/dataflow-const-prop/enum.rs | 1 + tests/mir-opt/dataflow-const-prop/struct.rs | 1 + tests/mir-opt/dataflow-const-prop/tuple.rs | 1 + tests/mir-opt/enum_opt.rs | 2 +- tests/mir-opt/gvn.rs | 1 + tests/mir-opt/pre-codegen/optimizes_into_variable.rs | 2 +- 17 files changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/mir-opt/const_debuginfo.rs b/tests/mir-opt/const_debuginfo.rs index 907d7fef06746..3b2bc4559ced9 100644 --- a/tests/mir-opt/const_debuginfo.rs +++ b/tests/mir-opt/const_debuginfo.rs @@ -1,5 +1,5 @@ //@ test-mir-pass: SingleUseConsts -//@ compile-flags: -C overflow-checks=no -Zmir-enable-passes=+GVN +//@ compile-flags: -C overflow-checks=no -Zmir-enable-passes=+GVN -Zdump-mir-exclude-alloc-bytes #![allow(unused)] diff --git a/tests/mir-opt/const_prop/address_of_pair.rs b/tests/mir-opt/const_prop/address_of_pair.rs index 6d0c0f8ad52a7..9acaaa0ccaf9d 100644 --- a/tests/mir-opt/const_prop/address_of_pair.rs +++ b/tests/mir-opt/const_prop/address_of_pair.rs @@ -1,4 +1,5 @@ //@ test-mir-pass: GVN +//@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR address_of_pair.fn0.GVN.diff pub fn fn0() -> bool { diff --git a/tests/mir-opt/const_prop/checked_add.rs b/tests/mir-opt/const_prop/checked_add.rs index 0560b04957311..d450f7d03f38c 100644 --- a/tests/mir-opt/const_prop/checked_add.rs +++ b/tests/mir-opt/const_prop/checked_add.rs @@ -1,6 +1,6 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY //@ test-mir-pass: GVN -//@ compile-flags: -C overflow-checks=on +//@ compile-flags: -C overflow-checks=on -Zdump-mir-exclude-alloc-bytes // EMIT_MIR checked_add.main.GVN.diff fn main() { diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate.rs b/tests/mir-opt/const_prop/mutable_variable_aggregate.rs index 7de647ed9c37f..80cd75215c1b7 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate.rs +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate.rs @@ -1,4 +1,5 @@ //@ test-mir-pass: GVN +//@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR mutable_variable_aggregate.main.GVN.diff fn main() { diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs index 5656c0e7a6863..856afd53ab46b 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs @@ -1,4 +1,5 @@ //@ test-mir-pass: GVN +//@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR mutable_variable_aggregate_mut_ref.main.GVN.diff fn main() { diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs index cc92949128f72..2c6cc0db6b211 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs @@ -1,5 +1,6 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY //@ test-mir-pass: GVN +//@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR mutable_variable_unprop_assign.main.GVN.diff fn main() { diff --git a/tests/mir-opt/const_prop/return_place.rs b/tests/mir-opt/const_prop/return_place.rs index e7eea11ae492f..c5293aa73e55b 100644 --- a/tests/mir-opt/const_prop/return_place.rs +++ b/tests/mir-opt/const_prop/return_place.rs @@ -1,6 +1,6 @@ //@ test-mir-pass: GVN // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -//@ compile-flags: -C overflow-checks=on +//@ compile-flags: -C overflow-checks=on -Zdump-mir-exclude-alloc-bytes // EMIT_MIR return_place.add.GVN.diff // EMIT_MIR return_place.add.PreCodegen.before.mir diff --git a/tests/mir-opt/const_prop/slice_len.rs b/tests/mir-opt/const_prop/slice_len.rs index 63cdbf01b3e82..265a496f39a36 100644 --- a/tests/mir-opt/const_prop/slice_len.rs +++ b/tests/mir-opt/const_prop/slice_len.rs @@ -1,5 +1,5 @@ //@ test-mir-pass: GVN -//@ compile-flags: -Zmir-enable-passes=+InstSimplify +//@ compile-flags: -Zmir-enable-passes=+InstSimplify -Zdump-mir-exclude-alloc-bytes // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR_FOR_EACH_BIT_WIDTH diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.rs b/tests/mir-opt/const_prop/tuple_literal_propagation.rs index e42a62cb6fdf3..baed5670dda81 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.rs +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.rs @@ -1,4 +1,5 @@ //@ test-mir-pass: GVN +//@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR tuple_literal_propagation.main.GVN.diff diff --git a/tests/mir-opt/dataflow-const-prop/checked.rs b/tests/mir-opt/dataflow-const-prop/checked.rs index a73693464f95b..f5a6cdb2c8d35 100644 --- a/tests/mir-opt/dataflow-const-prop/checked.rs +++ b/tests/mir-opt/dataflow-const-prop/checked.rs @@ -1,5 +1,5 @@ //@ test-mir-pass: DataflowConstProp -//@ compile-flags: -Coverflow-checks=on +//@ compile-flags: -Coverflow-checks=on -Zdump-mir-exclude-alloc-bytes // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR checked.main.DataflowConstProp.diff diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs index 3a0cbac328cb5..087bd7a18572c 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs @@ -1,5 +1,5 @@ //@ test-mir-pass: DataflowConstProp -//@ compile-flags: -Zmir-enable-passes=+GVN,+Inline +//@ compile-flags: -Zmir-enable-passes=+GVN,+Inline -Zdump-mir-exclude-alloc-bytes // EMIT_MIR_FOR_EACH_BIT_WIDTH // EMIT_MIR_FOR_EACH_PANIC_STRATEGY diff --git a/tests/mir-opt/dataflow-const-prop/enum.rs b/tests/mir-opt/dataflow-const-prop/enum.rs index 946cfa4c76c02..37304e3a270e9 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.rs +++ b/tests/mir-opt/dataflow-const-prop/enum.rs @@ -1,4 +1,5 @@ //@ test-mir-pass: DataflowConstProp +//@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR_FOR_EACH_BIT_WIDTH #![feature(custom_mir, core_intrinsics, rustc_attrs)] diff --git a/tests/mir-opt/dataflow-const-prop/struct.rs b/tests/mir-opt/dataflow-const-prop/struct.rs index eed782c9036b2..4b160c3dab7e8 100644 --- a/tests/mir-opt/dataflow-const-prop/struct.rs +++ b/tests/mir-opt/dataflow-const-prop/struct.rs @@ -1,4 +1,5 @@ //@ test-mir-pass: DataflowConstProp +//@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR_FOR_EACH_BIT_WIDTH #[derive(Copy, Clone)] diff --git a/tests/mir-opt/dataflow-const-prop/tuple.rs b/tests/mir-opt/dataflow-const-prop/tuple.rs index d624e21f21ac4..19b675770abe9 100644 --- a/tests/mir-opt/dataflow-const-prop/tuple.rs +++ b/tests/mir-opt/dataflow-const-prop/tuple.rs @@ -1,4 +1,5 @@ //@ test-mir-pass: DataflowConstProp +//@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR_FOR_EACH_BIT_WIDTH // EMIT_MIR tuple.main.DataflowConstProp.diff diff --git a/tests/mir-opt/enum_opt.rs b/tests/mir-opt/enum_opt.rs index 2cc5df84d6b59..e42be8ac06dc9 100644 --- a/tests/mir-opt/enum_opt.rs +++ b/tests/mir-opt/enum_opt.rs @@ -1,7 +1,7 @@ // skip-filecheck //@ test-mir-pass: EnumSizeOpt // EMIT_MIR_FOR_EACH_BIT_WIDTH -//@ compile-flags: -Zunsound-mir-opts +//@ compile-flags: -Zunsound-mir-opts -Zdump-mir-exclude-alloc-bytes #![feature(arbitrary_enum_discriminant, repr128)] diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs index 86f42d23f3835..29f28e7af4145 100644 --- a/tests/mir-opt/gvn.rs +++ b/tests/mir-opt/gvn.rs @@ -1,4 +1,5 @@ //@ test-mir-pass: GVN +//@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR_FOR_EACH_PANIC_STRATEGY //@ only-64bit diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.rs b/tests/mir-opt/pre-codegen/optimizes_into_variable.rs index de5e2d5c3121b..44b4b0ad888a5 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.rs +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.rs @@ -1,6 +1,6 @@ // skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -//@ compile-flags: -C overflow-checks=on +//@ compile-flags: -C overflow-checks=on -Zdump-mir-exclude-alloc-bytes struct Point { x: u32, From 7c3673ff6f2ff4e8e85344c091c9feb4b5da1290 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 14 Jun 2024 16:05:22 -0700 Subject: [PATCH 03/18] Bless mir-opt for excluded alloc bytes --- .../const_debuginfo.main.SingleUseConsts.diff | 8 +-- .../const_prop/address_of_pair.fn0.GVN.diff | 6 +- .../checked_add.main.GVN.panic-abort.diff | 6 +- .../checked_add.main.GVN.panic-unwind.diff | 6 +- .../mutable_variable_aggregate.main.GVN.diff | 6 +- ...e_variable_aggregate_mut_ref.main.GVN.diff | 6 +- ...le_unprop_assign.main.GVN.panic-abort.diff | 6 +- ...e_unprop_assign.main.GVN.panic-unwind.diff | 6 +- .../return_place.add.GVN.panic-abort.diff | 6 +- .../return_place.add.GVN.panic-unwind.diff | 6 +- ...lace.add.PreCodegen.before.panic-abort.mir | 4 +- ...ace.add.PreCodegen.before.panic-unwind.mir | 4 +- .../slice_len.main.GVN.32bit.panic-abort.diff | 6 +- ...slice_len.main.GVN.32bit.panic-unwind.diff | 6 +- .../slice_len.main.GVN.64bit.panic-abort.diff | 6 +- ...slice_len.main.GVN.64bit.panic-unwind.diff | 6 +- ...eral_propagation.main.GVN.panic-abort.diff | 6 +- ...ral_propagation.main.GVN.panic-unwind.diff | 6 +- ...ed.main.DataflowConstProp.panic-abort.diff | 10 +--- ...d.main.DataflowConstProp.panic-unwind.diff | 10 +--- ...n.DataflowConstProp.32bit.panic-abort.diff | 12 +--- ....DataflowConstProp.32bit.panic-unwind.diff | 12 +--- ...n.DataflowConstProp.64bit.panic-abort.diff | 12 +--- ....DataflowConstProp.64bit.panic-unwind.diff | 12 +--- ...oxed_slice.main.GVN.32bit.panic-abort.diff | 14 ++--- ...xed_slice.main.GVN.32bit.panic-unwind.diff | 14 ++--- ...oxed_slice.main.GVN.64bit.panic-abort.diff | 14 ++--- ...xed_slice.main.GVN.64bit.panic-unwind.diff | 14 ++--- .../enum.simple.DataflowConstProp.32bit.diff | 6 +- .../enum.simple.DataflowConstProp.64bit.diff | 6 +- .../enum.statics.DataflowConstProp.32bit.diff | 23 +++----- .../enum.statics.DataflowConstProp.64bit.diff | 23 +++----- .../struct.main.DataflowConstProp.32bit.diff | 58 ++++++------------- .../struct.main.DataflowConstProp.64bit.diff | 58 ++++++------------- .../tuple.main.DataflowConstProp.32bit.diff | 18 ++---- .../tuple.main.DataflowConstProp.64bit.diff | 18 ++---- .../enum_opt.cand.EnumSizeOpt.32bit.diff | 6 +- .../enum_opt.cand.EnumSizeOpt.64bit.diff | 6 +- .../enum_opt.unin.EnumSizeOpt.32bit.diff | 6 +- .../enum_opt.unin.EnumSizeOpt.64bit.diff | 6 +- ...vn.arithmetic_checked.GVN.panic-abort.diff | 6 +- ...n.arithmetic_checked.GVN.panic-unwind.diff | 6 +- .../gvn.fn_pointers.GVN.panic-abort.diff | 18 +++--- .../gvn.fn_pointers.GVN.panic-unwind.diff | 18 +++--- .../gvn.indirect_static.GVN.panic-abort.diff | 4 +- .../gvn.indirect_static.GVN.panic-unwind.diff | 4 +- .../gvn.wide_ptr_integer.GVN.panic-abort.diff | 10 +--- ...gvn.wide_ptr_integer.GVN.panic-unwind.diff | 10 +--- ...o_variable.main.GVN.32bit.panic-abort.diff | 6 +- ..._variable.main.GVN.32bit.panic-unwind.diff | 6 +- ...o_variable.main.GVN.64bit.panic-abort.diff | 6 +- ..._variable.main.GVN.64bit.panic-unwind.diff | 6 +- 52 files changed, 182 insertions(+), 382 deletions(-) diff --git a/tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff b/tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff index ac33f51984cd8..8088984bc77ab 100644 --- a/tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff +++ b/tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff @@ -119,11 +119,7 @@ } } - ALLOC0 (size: 8, align: 4) { - 20 00 00 00 20 00 00 00 │ ... ... - } + ALLOC0 (size: 8, align: 4) { .. } - ALLOC1 (size: 4, align: 2) { - 01 00 63 00 │ ..c. - } + ALLOC1 (size: 4, align: 2) { .. } diff --git a/tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff b/tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff index 3f4958f60e85b..ac372f837268b 100644 --- a/tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff +++ b/tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff @@ -44,9 +44,7 @@ StorageDead(_2); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 01 00 00 00 00 __ __ __ │ .....░░░ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/checked_add.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/checked_add.main.GVN.panic-abort.diff index 0e93c167ebc96..798f957caa58c 100644 --- a/tests/mir-opt/const_prop/checked_add.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/checked_add.main.GVN.panic-abort.diff @@ -24,9 +24,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 02 00 00 00 00 __ __ __ │ .....░░░ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/checked_add.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/checked_add.main.GVN.panic-unwind.diff index 589eed5776c9f..a09f8ee5be12a 100644 --- a/tests/mir-opt/const_prop/checked_add.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/checked_add.main.GVN.panic-unwind.diff @@ -24,9 +24,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 02 00 00 00 00 __ __ __ │ .....░░░ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate.main.GVN.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate.main.GVN.diff index b6ff7b0fc234d..7584353620ec5 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate.main.GVN.diff +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate.main.GVN.diff @@ -24,9 +24,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 2a 00 00 00 2b 00 00 00 │ *...+... } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff index 4ed7c98514796..e16e2969eb895 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff @@ -31,9 +31,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 2a 00 00 00 2b 00 00 00 │ *...+... } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-abort.diff index d1d23675bfd91..19d79694666f2 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-abort.diff @@ -48,9 +48,7 @@ + nop; return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff index 4d69c9ce2efe6..2bb277bf27f7f 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff @@ -48,9 +48,7 @@ + nop; return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/return_place.add.GVN.panic-abort.diff b/tests/mir-opt/const_prop/return_place.add.GVN.panic-abort.diff index b2d40daa80c4c..037fe60c2fdb3 100644 --- a/tests/mir-opt/const_prop/return_place.add.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/return_place.add.GVN.panic-abort.diff @@ -17,9 +17,7 @@ + _0 = const 4_u32; return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 04 00 00 00 00 __ __ __ │ .....░░░ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/return_place.add.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/return_place.add.GVN.panic-unwind.diff index 2eafc51cd3db6..438a1cebea8cb 100644 --- a/tests/mir-opt/const_prop/return_place.add.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/return_place.add.GVN.panic-unwind.diff @@ -17,9 +17,7 @@ + _0 = const 4_u32; return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 04 00 00 00 00 __ __ __ │ .....░░░ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir index f87c26bb004c6..66fd61cc3aee9 100644 --- a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir +++ b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir @@ -15,6 +15,4 @@ fn add() -> u32 { } } -ALLOC0 (size: 8, align: 4) { - 04 00 00 00 00 __ __ __ │ .....░░░ -} +ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir index 33f97591387c3..f9b07a59de9c3 100644 --- a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir +++ b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir @@ -15,6 +15,4 @@ fn add() -> u32 { } } -ALLOC0 (size: 8, align: 4) { - 04 00 00 00 00 __ __ __ │ .....░░░ -} +ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff index ef298dddd5a49..8415789de6ecd 100644 --- a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff @@ -49,9 +49,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 12, align: 4) { -+ 01 00 00 00 02 00 00 00 03 00 00 00 │ ............ } ++ ++ ALLOC0 (size: 12, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff index 5379df3f60b44..fea7caac3cdce 100644 --- a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff @@ -49,9 +49,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 12, align: 4) { -+ 01 00 00 00 02 00 00 00 03 00 00 00 │ ............ } ++ ++ ALLOC0 (size: 12, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff index ef298dddd5a49..8415789de6ecd 100644 --- a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff @@ -49,9 +49,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 12, align: 4) { -+ 01 00 00 00 02 00 00 00 03 00 00 00 │ ............ } ++ ++ ALLOC0 (size: 12, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff index 5379df3f60b44..fea7caac3cdce 100644 --- a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff @@ -49,9 +49,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 12, align: 4) { -+ 01 00 00 00 02 00 00 00 03 00 00 00 │ ............ } ++ ++ ALLOC0 (size: 12, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-abort.diff index c2f3fb1b3b575..bf8fece3d37b9 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-abort.diff @@ -31,9 +31,7 @@ + nop; return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff index 55d9a3b0cac67..02a75849d8872 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff @@ -31,9 +31,7 @@ + nop; return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-abort.diff index 53663c6476bdc..79ea55617481e 100644 --- a/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-abort.diff @@ -76,13 +76,9 @@ StorageDead(_1); return; } -+ } + } + -+ ALLOC0 (size: 8, align: 4) { -+ 00 00 00 80 01 __ __ __ │ .....░░░ -+ } ++ ALLOC0 (size: 8, align: 4) { .. } + -+ ALLOC1 (size: 8, align: 4) { -+ 03 00 00 00 00 __ __ __ │ .....░░░ - } ++ ALLOC1 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-unwind.diff index 34feb2a640629..bd22c50dd8fcf 100644 --- a/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-unwind.diff @@ -76,13 +76,9 @@ StorageDead(_1); return; } -+ } + } + -+ ALLOC0 (size: 8, align: 4) { -+ 00 00 00 80 01 __ __ __ │ .....░░░ -+ } ++ ALLOC0 (size: 8, align: 4) { .. } + -+ ALLOC1 (size: 8, align: 4) { -+ 03 00 00 00 00 __ __ __ │ .....░░░ - } ++ ALLOC1 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff index 8005bc23cf699..4097e060f4d47 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff @@ -94,15 +94,9 @@ } } - ALLOC2 (size: 8, align: 4) { - 01 00 00 00 00 00 00 00 │ ........ - } + ALLOC2 (size: 8, align: 4) { .. } - ALLOC1 (size: 8, align: 4) { - 01 00 00 00 00 00 00 00 │ ........ - } + ALLOC1 (size: 8, align: 4) { .. } - ALLOC0 (size: 8, align: 4) { - 01 00 00 00 00 00 00 00 │ ........ - } + ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff index 42b1be32387c4..ff44d0df5e3e9 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff @@ -98,15 +98,9 @@ } } - ALLOC2 (size: 8, align: 4) { - 01 00 00 00 00 00 00 00 │ ........ - } + ALLOC2 (size: 8, align: 4) { .. } - ALLOC1 (size: 8, align: 4) { - 01 00 00 00 00 00 00 00 │ ........ - } + ALLOC1 (size: 8, align: 4) { .. } - ALLOC0 (size: 8, align: 4) { - 01 00 00 00 00 00 00 00 │ ........ - } + ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff index 7b57b0db50c94..3662c3b59d271 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff @@ -94,15 +94,9 @@ } } - ALLOC2 (size: 16, align: 8) { - 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ - } + ALLOC2 (size: 16, align: 8) { .. } - ALLOC1 (size: 16, align: 8) { - 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ - } + ALLOC1 (size: 16, align: 8) { .. } - ALLOC0 (size: 16, align: 8) { - 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ - } + ALLOC0 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff index 2e75a63e29052..68dee57dee9e0 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff @@ -98,15 +98,9 @@ } } - ALLOC2 (size: 16, align: 8) { - 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ - } + ALLOC2 (size: 16, align: 8) { .. } - ALLOC1 (size: 16, align: 8) { - 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ - } + ALLOC1 (size: 16, align: 8) { .. } - ALLOC0 (size: 16, align: 8) { - 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ - } + ALLOC0 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff index 06011f9d75967..9d96e895c8aa5 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff @@ -102,17 +102,11 @@ _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; } -+ } + } + -+ ALLOC2 (size: 8, align: 4) { -+ 01 00 00 00 00 00 00 00 │ ........ -+ } ++ ALLOC2 (size: 8, align: 4) { .. } + -+ ALLOC1 (size: 8, align: 4) { -+ 01 00 00 00 00 00 00 00 │ ........ -+ } ++ ALLOC1 (size: 8, align: 4) { .. } + -+ ALLOC0 (size: 8, align: 4) { -+ 01 00 00 00 00 00 00 00 │ ........ - } ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff index eb4a3ffd91d2e..0bdff584b01ec 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff @@ -106,17 +106,11 @@ _0 = const (); drop(_1) -> [return: bb1, unwind: bb2]; } -+ } + } + -+ ALLOC2 (size: 8, align: 4) { -+ 01 00 00 00 00 00 00 00 │ ........ -+ } ++ ALLOC2 (size: 8, align: 4) { .. } + -+ ALLOC1 (size: 8, align: 4) { -+ 01 00 00 00 00 00 00 00 │ ........ -+ } ++ ALLOC1 (size: 8, align: 4) { .. } + -+ ALLOC0 (size: 8, align: 4) { -+ 01 00 00 00 00 00 00 00 │ ........ - } ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff index a7cc243e548e9..99e96fe5d70fd 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff @@ -102,17 +102,11 @@ _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; } -+ } + } + -+ ALLOC2 (size: 16, align: 8) { -+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ -+ } ++ ALLOC2 (size: 16, align: 8) { .. } + -+ ALLOC1 (size: 16, align: 8) { -+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ -+ } ++ ALLOC1 (size: 16, align: 8) { .. } + -+ ALLOC0 (size: 16, align: 8) { -+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ - } ++ ALLOC0 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff index c905a48862caa..5eefabeac3868 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff @@ -106,17 +106,11 @@ _0 = const (); drop(_1) -> [return: bb1, unwind: bb2]; } -+ } + } + -+ ALLOC2 (size: 16, align: 8) { -+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ -+ } ++ ALLOC2 (size: 16, align: 8) { .. } + -+ ALLOC1 (size: 16, align: 8) { -+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ -+ } ++ ALLOC1 (size: 16, align: 8) { .. } + -+ ALLOC0 (size: 16, align: 8) { -+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ - } ++ ALLOC0 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.32bit.diff index 89ed26f065b28..a64dda0d06c48 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.32bit.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.32bit.diff @@ -60,9 +60,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 00 00 00 00 00 00 00 00 │ ........ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff index 89ed26f065b28..a64dda0d06c48 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff @@ -60,9 +60,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 00 00 00 00 00 00 00 00 │ ........ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff index fe8ed0114897d..b4d14f25fe2ab 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff @@ -43,7 +43,7 @@ bb0: { StorageLive(_1); StorageLive(_2); - _2 = const {ALLOC1: &E}; + _2 = const {ALLOC0: &E}; - _1 = (*_2); + _1 = const E::V1(0_i32); StorageDead(_2); @@ -79,7 +79,7 @@ bb4: { StorageLive(_7); StorageLive(_8); - _8 = const {ALLOC2: &&E}; + _8 = const {ALLOC1: &&E}; _7 = (*_8); StorageDead(_8); StorageLive(_9); @@ -111,21 +111,14 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC3 (size: 8, align: 4) { -+ 00 00 00 00 00 00 00 00 │ ........ } - ALLOC2 (static: RC, size: 4, align: 4) { - ╾ALLOC0╼ │ ╾──╼ - } ++ ALLOC2 (size: 8, align: 4) { .. } ++ + ALLOC1 (static: RC, size: 4, align: 4) { .. } - ALLOC0 (size: 8, align: 4) { - 01 00 00 00 04 00 00 00 │ ........ - } +- ALLOC2 (size: 8, align: 4) { .. } ++ ALLOC3 (size: 8, align: 4) { .. } - ALLOC1 (static: statics::C, size: 8, align: 4) { - 00 00 00 00 00 00 00 00 │ ........ - } + ALLOC0 (static: statics::C, size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff index df3a989d09eba..57d02b87d1369 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff @@ -43,7 +43,7 @@ bb0: { StorageLive(_1); StorageLive(_2); - _2 = const {ALLOC1: &E}; + _2 = const {ALLOC0: &E}; - _1 = (*_2); + _1 = const E::V1(0_i32); StorageDead(_2); @@ -79,7 +79,7 @@ bb4: { StorageLive(_7); StorageLive(_8); - _8 = const {ALLOC2: &&E}; + _8 = const {ALLOC1: &&E}; _7 = (*_8); StorageDead(_8); StorageLive(_9); @@ -111,21 +111,14 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC3 (size: 8, align: 4) { -+ 00 00 00 00 00 00 00 00 │ ........ } - ALLOC2 (static: RC, size: 8, align: 8) { - ╾ALLOC0╼ │ ╾──────╼ - } ++ ALLOC2 (size: 8, align: 4) { .. } ++ + ALLOC1 (static: RC, size: 8, align: 8) { .. } - ALLOC0 (size: 8, align: 4) { - 01 00 00 00 04 00 00 00 │ ........ - } +- ALLOC2 (size: 8, align: 4) { .. } ++ ALLOC3 (size: 8, align: 4) { .. } - ALLOC1 (static: statics::C, size: 8, align: 4) { - 00 00 00 00 00 00 00 00 │ ........ - } + ALLOC0 (static: statics::C, size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.32bit.diff index f674169e28b26..a6da1483c1ac5 100644 --- a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.32bit.diff +++ b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.32bit.diff @@ -112,7 +112,7 @@ _9 = (_10.2: &[f32]); StorageDead(_10); StorageLive(_14); - _14 = const {ALLOC4: &&SmallStruct}; + _14 = const {ALLOC0: &&SmallStruct}; _31 = deref_copy (*_14); StorageLive(_11); _32 = deref_copy (*_14); @@ -149,7 +149,7 @@ _21 = (_22.2: &[f32]); StorageDead(_22); StorageLive(_26); - _26 = const {ALLOC5: &&BigStruct}; + _26 = const {ALLOC1: &&BigStruct}; _35 = deref_copy (*_26); StorageLive(_23); _36 = deref_copy (*_26); @@ -197,51 +197,31 @@ StorageDead(_1); return; } -+ } + } + ++ ALLOC2 (size: 8, align: 4) { .. } + -+ ALLOC6 (size: 8, align: 4) { -+ 01 00 00 00 23 00 00 00 │ ....#... -+ } ++ ALLOC3 (size: 8, align: 4) { .. } + -+ ALLOC7 (size: 8, align: 4) { -+ 01 00 00 00 23 00 00 00 │ ....#... -+ } ++ ALLOC4 (size: 8, align: 4) { .. } + -+ ALLOC8 (size: 8, align: 4) { -+ 01 00 00 00 23 00 00 00 │ ....#... -+ } ++ ALLOC5 (size: 8, align: 4) { .. } + -+ ALLOC9 (size: 8, align: 4) { -+ 01 00 00 00 01 00 00 00 │ ........ -+ } ++ ALLOC6 (size: 4, align: 4) { .. } + -+ ALLOC10 (size: 4, align: 4) { -+ 01 00 00 00 │ .... - } - - ALLOC5 (static: BIG_STAT, size: 4, align: 4) { - ╾ALLOC0╼ │ ╾──╼ - } + ALLOC1 (static: BIG_STAT, size: 4, align: 4) { .. } - ALLOC0 (size: 20, align: 4) { - 0x00 │ 01 00 00 00 23 00 00 00 ╾ALLOC1╼ 02 00 00 00 │ ....#...╾──╼.... - 0x10 │ 00 00 a4 42 │ ...B - } +- ALLOC2 (size: 20, align: 4) { .. } ++ ALLOC7 (size: 20, align: 4) { .. } - ALLOC1 (size: 8, align: 4) { - 00 00 34 42 00 00 90 42 │ ..4B...B - } +- ALLOC3 (size: 8, align: 4) { .. } ++ ALLOC8 (size: 8, align: 4) { .. } - ALLOC4 (static: SMALL_STAT, size: 4, align: 4) { - ╾ALLOC2╼ │ ╾──╼ - } + ALLOC0 (static: SMALL_STAT, size: 4, align: 4) { .. } - ALLOC2 (size: 20, align: 4) { - 0x00 │ 00 00 00 00 __ __ __ __ ╾ALLOC3╼ 01 00 00 00 │ ....░░░░╾──╼.... - 0x10 │ 00 00 10 41 │ ...A - } +- ALLOC4 (size: 20, align: 4) { .. } ++ ALLOC9 (size: 20, align: 4) { .. } - ALLOC3 (size: 4, align: 4) { - 00 00 50 41 │ ..PA - } +- ALLOC5 (size: 4, align: 4) { .. } ++ ALLOC10 (size: 4, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff index c2608190a6b97..7ca25e4429953 100644 --- a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff +++ b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff @@ -112,7 +112,7 @@ _9 = (_10.2: &[f32]); StorageDead(_10); StorageLive(_14); - _14 = const {ALLOC4: &&SmallStruct}; + _14 = const {ALLOC0: &&SmallStruct}; _31 = deref_copy (*_14); StorageLive(_11); _32 = deref_copy (*_14); @@ -149,7 +149,7 @@ _21 = (_22.2: &[f32]); StorageDead(_22); StorageLive(_26); - _26 = const {ALLOC5: &&BigStruct}; + _26 = const {ALLOC1: &&BigStruct}; _35 = deref_copy (*_26); StorageLive(_23); _36 = deref_copy (*_26); @@ -197,51 +197,31 @@ StorageDead(_1); return; } -+ } + } + ++ ALLOC2 (size: 8, align: 4) { .. } + -+ ALLOC6 (size: 8, align: 4) { -+ 01 00 00 00 23 00 00 00 │ ....#... -+ } ++ ALLOC3 (size: 8, align: 4) { .. } + -+ ALLOC7 (size: 8, align: 4) { -+ 01 00 00 00 23 00 00 00 │ ....#... -+ } ++ ALLOC4 (size: 8, align: 4) { .. } + -+ ALLOC8 (size: 8, align: 4) { -+ 01 00 00 00 23 00 00 00 │ ....#... -+ } ++ ALLOC5 (size: 8, align: 4) { .. } + -+ ALLOC9 (size: 8, align: 4) { -+ 01 00 00 00 01 00 00 00 │ ........ -+ } ++ ALLOC6 (size: 4, align: 4) { .. } + -+ ALLOC10 (size: 4, align: 4) { -+ 01 00 00 00 │ .... - } - - ALLOC5 (static: BIG_STAT, size: 8, align: 8) { - ╾ALLOC0╼ │ ╾──────╼ - } + ALLOC1 (static: BIG_STAT, size: 8, align: 8) { .. } - ALLOC0 (size: 32, align: 8) { - 0x00 │ 01 00 00 00 23 00 00 00 ╾ALLOC1╼ │ ....#...╾──────╼ - 0x10 │ 02 00 00 00 00 00 00 00 00 00 a4 42 __ __ __ __ │ ...........B░░░░ - } +- ALLOC2 (size: 32, align: 8) { .. } ++ ALLOC7 (size: 32, align: 8) { .. } - ALLOC1 (size: 8, align: 4) { - 00 00 34 42 00 00 90 42 │ ..4B...B - } +- ALLOC3 (size: 8, align: 4) { .. } ++ ALLOC8 (size: 8, align: 4) { .. } - ALLOC4 (static: SMALL_STAT, size: 8, align: 8) { - ╾ALLOC2╼ │ ╾──────╼ - } + ALLOC0 (static: SMALL_STAT, size: 8, align: 8) { .. } - ALLOC2 (size: 32, align: 8) { - 0x00 │ 00 00 00 00 __ __ __ __ ╾ALLOC3╼ │ ....░░░░╾──────╼ - 0x10 │ 01 00 00 00 00 00 00 00 00 00 10 41 __ __ __ __ │ ...........A░░░░ - } +- ALLOC4 (size: 32, align: 8) { .. } ++ ALLOC9 (size: 32, align: 8) { .. } - ALLOC3 (size: 4, align: 4) { - 00 00 50 41 │ ..PA - } +- ALLOC5 (size: 4, align: 4) { .. } ++ ALLOC10 (size: 4, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.32bit.diff index f5723cac7d9c8..e4031b65caafe 100644 --- a/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.32bit.diff +++ b/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.32bit.diff @@ -92,21 +92,13 @@ StorageDead(_1); return; } -+ } + } + -+ ALLOC0 (size: 8, align: 4) { -+ 02 00 00 00 03 00 00 00 │ ........ -+ } ++ ALLOC0 (size: 8, align: 4) { .. } + -+ ALLOC1 (size: 8, align: 4) { -+ 02 00 00 00 03 00 00 00 │ ........ -+ } ++ ALLOC1 (size: 8, align: 4) { .. } + -+ ALLOC2 (size: 8, align: 4) { -+ 02 00 00 00 03 00 00 00 │ ........ -+ } ++ ALLOC2 (size: 8, align: 4) { .. } + -+ ALLOC3 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ - } ++ ALLOC3 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.64bit.diff index f5723cac7d9c8..e4031b65caafe 100644 --- a/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.64bit.diff +++ b/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.64bit.diff @@ -92,21 +92,13 @@ StorageDead(_1); return; } -+ } + } + -+ ALLOC0 (size: 8, align: 4) { -+ 02 00 00 00 03 00 00 00 │ ........ -+ } ++ ALLOC0 (size: 8, align: 4) { .. } + -+ ALLOC1 (size: 8, align: 4) { -+ 02 00 00 00 03 00 00 00 │ ........ -+ } ++ ALLOC1 (size: 8, align: 4) { .. } + -+ ALLOC2 (size: 8, align: 4) { -+ 02 00 00 00 03 00 00 00 │ ........ -+ } ++ ALLOC2 (size: 8, align: 4) { .. } + -+ ALLOC3 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ - } ++ ALLOC3 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/enum_opt.cand.EnumSizeOpt.32bit.diff b/tests/mir-opt/enum_opt.cand.EnumSizeOpt.32bit.diff index 775a60f1c9603..085c55caaa03c 100644 --- a/tests/mir-opt/enum_opt.cand.EnumSizeOpt.32bit.diff +++ b/tests/mir-opt/enum_opt.cand.EnumSizeOpt.32bit.diff @@ -64,9 +64,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 02 00 00 00 05 20 00 00 │ ..... .. } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/enum_opt.cand.EnumSizeOpt.64bit.diff b/tests/mir-opt/enum_opt.cand.EnumSizeOpt.64bit.diff index c4b57579943d4..798b7c10fe8d5 100644 --- a/tests/mir-opt/enum_opt.cand.EnumSizeOpt.64bit.diff +++ b/tests/mir-opt/enum_opt.cand.EnumSizeOpt.64bit.diff @@ -64,9 +64,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 16, align: 8) { -+ 02 00 00 00 00 00 00 00 05 20 00 00 00 00 00 00 │ ......... ...... } ++ ++ ALLOC0 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/enum_opt.unin.EnumSizeOpt.32bit.diff b/tests/mir-opt/enum_opt.unin.EnumSizeOpt.32bit.diff index f7d0d1fb56c3e..a04829af4b532 100644 --- a/tests/mir-opt/enum_opt.unin.EnumSizeOpt.32bit.diff +++ b/tests/mir-opt/enum_opt.unin.EnumSizeOpt.32bit.diff @@ -64,9 +64,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 05 20 00 00 01 00 00 00 │ . ...... } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/enum_opt.unin.EnumSizeOpt.64bit.diff b/tests/mir-opt/enum_opt.unin.EnumSizeOpt.64bit.diff index 15f1bd0df51a2..f5521a1e22a47 100644 --- a/tests/mir-opt/enum_opt.unin.EnumSizeOpt.64bit.diff +++ b/tests/mir-opt/enum_opt.unin.EnumSizeOpt.64bit.diff @@ -64,9 +64,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 16, align: 8) { -+ 05 20 00 00 00 00 00 00 01 00 00 00 00 00 00 00 │ . .............. } ++ ++ ALLOC0 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff index 5bf22af6ae83d..0e3f2459fae35 100644 --- a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff @@ -140,9 +140,7 @@ _0 = const (); return; } -+ } -+ -+ ALLOC0 (size: 16, align: 8) { -+ 00 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ │ .........░░░░░░░ } ++ ++ ALLOC0 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff index 18d2029e44500..2873d7ef0ab13 100644 --- a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff @@ -140,9 +140,7 @@ _0 = const (); return; } -+ } -+ -+ ALLOC0 (size: 16, align: 8) { -+ 00 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ │ .........░░░░░░░ } ++ ++ ALLOC0 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff b/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff index 0c49e706c9ecf..b5c0cee784688 100644 --- a/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff @@ -8,10 +8,10 @@ let mut _3: fn(u8) -> u8; let _5: (); let mut _6: fn(u8) -> u8; - let mut _9: {closure@$DIR/gvn.rs:614:19: 614:21}; + let mut _9: {closure@$DIR/gvn.rs:615:19: 615:21}; let _10: (); let mut _11: fn(); - let mut _13: {closure@$DIR/gvn.rs:614:19: 614:21}; + let mut _13: {closure@$DIR/gvn.rs:615:19: 615:21}; let _14: (); let mut _15: fn(); scope 1 { @@ -19,7 +19,7 @@ let _4: fn(u8) -> u8; scope 2 { debug g => _4; - let _7: {closure@$DIR/gvn.rs:614:19: 614:21}; + let _7: {closure@$DIR/gvn.rs:615:19: 615:21}; scope 3 { debug closure => _7; let _8: fn(); @@ -62,16 +62,16 @@ StorageDead(_6); StorageDead(_5); - StorageLive(_7); -- _7 = {closure@$DIR/gvn.rs:614:19: 614:21}; +- _7 = {closure@$DIR/gvn.rs:615:19: 615:21}; - StorageLive(_8); + nop; -+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21}; ++ _7 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21}; + nop; StorageLive(_9); - _9 = _7; - _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Safe))); -+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21}; -+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} as fn() (PointerCoercion(ClosureFnPointer(Safe))); ++ _9 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21}; ++ _8 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe))); StorageDead(_9); StorageLive(_10); StorageLive(_11); @@ -88,8 +88,8 @@ StorageLive(_13); - _13 = _7; - _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Safe))); -+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21}; -+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} as fn() (PointerCoercion(ClosureFnPointer(Safe))); ++ _13 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21}; ++ _12 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe))); StorageDead(_13); StorageLive(_14); StorageLive(_15); diff --git a/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff b/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff index e5f865b74b9f4..7bc6573c13d4d 100644 --- a/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff @@ -8,10 +8,10 @@ let mut _3: fn(u8) -> u8; let _5: (); let mut _6: fn(u8) -> u8; - let mut _9: {closure@$DIR/gvn.rs:614:19: 614:21}; + let mut _9: {closure@$DIR/gvn.rs:615:19: 615:21}; let _10: (); let mut _11: fn(); - let mut _13: {closure@$DIR/gvn.rs:614:19: 614:21}; + let mut _13: {closure@$DIR/gvn.rs:615:19: 615:21}; let _14: (); let mut _15: fn(); scope 1 { @@ -19,7 +19,7 @@ let _4: fn(u8) -> u8; scope 2 { debug g => _4; - let _7: {closure@$DIR/gvn.rs:614:19: 614:21}; + let _7: {closure@$DIR/gvn.rs:615:19: 615:21}; scope 3 { debug closure => _7; let _8: fn(); @@ -62,16 +62,16 @@ StorageDead(_6); StorageDead(_5); - StorageLive(_7); -- _7 = {closure@$DIR/gvn.rs:614:19: 614:21}; +- _7 = {closure@$DIR/gvn.rs:615:19: 615:21}; - StorageLive(_8); + nop; -+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21}; ++ _7 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21}; + nop; StorageLive(_9); - _9 = _7; - _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Safe))); -+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21}; -+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} as fn() (PointerCoercion(ClosureFnPointer(Safe))); ++ _9 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21}; ++ _8 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe))); StorageDead(_9); StorageLive(_10); StorageLive(_11); @@ -88,8 +88,8 @@ StorageLive(_13); - _13 = _7; - _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Safe))); -+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21}; -+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} as fn() (PointerCoercion(ClosureFnPointer(Safe))); ++ _13 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21}; ++ _12 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe))); StorageDead(_13); StorageLive(_14); StorageLive(_15); diff --git a/tests/mir-opt/gvn.indirect_static.GVN.panic-abort.diff b/tests/mir-opt/gvn.indirect_static.GVN.panic-abort.diff index f853942bbb664..e84f91e495d9c 100644 --- a/tests/mir-opt/gvn.indirect_static.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.indirect_static.GVN.panic-abort.diff @@ -13,7 +13,5 @@ } } - ALLOC0 (static: A, size: 2, align: 1) { - 00 __ │ .░ - } + ALLOC0 (static: A, size: 2, align: 1) { .. } diff --git a/tests/mir-opt/gvn.indirect_static.GVN.panic-unwind.diff b/tests/mir-opt/gvn.indirect_static.GVN.panic-unwind.diff index f853942bbb664..e84f91e495d9c 100644 --- a/tests/mir-opt/gvn.indirect_static.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.indirect_static.GVN.panic-unwind.diff @@ -13,7 +13,5 @@ } } - ALLOC0 (static: A, size: 2, align: 1) { - 00 __ │ .░ - } + ALLOC0 (static: A, size: 2, align: 1) { .. } diff --git a/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-abort.diff b/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-abort.diff index 07c4c7663c154..3eed0473f7fc2 100644 --- a/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-abort.diff @@ -176,13 +176,9 @@ + nop; return; } -+ } + } + -+ ALLOC1 (size: 16, align: 8) { -+ 01 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 │ ................ -+ } ++ ALLOC1 (size: 16, align: 8) { .. } + -+ ALLOC0 (size: 16, align: 8) { -+ 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 │ ................ - } ++ ALLOC0 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-unwind.diff b/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-unwind.diff index df0f93f1077ee..9a6e255a872ea 100644 --- a/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-unwind.diff @@ -176,13 +176,9 @@ + nop; return; } -+ } + } + -+ ALLOC1 (size: 16, align: 8) { -+ 01 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 │ ................ -+ } ++ ALLOC1 (size: 16, align: 8) { .. } + -+ ALLOC0 (size: 16, align: 8) { -+ 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 │ ................ - } ++ ALLOC0 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-abort.diff index 2f34a62b3d136..45b8d89c0f4fa 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-abort.diff @@ -61,9 +61,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 04 00 00 00 00 __ __ __ │ .....░░░ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-unwind.diff index da7add371a5bf..e6ee1e6f9a348 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-unwind.diff @@ -61,9 +61,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 04 00 00 00 00 __ __ __ │ .....░░░ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-abort.diff index 2f34a62b3d136..45b8d89c0f4fa 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-abort.diff @@ -61,9 +61,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 04 00 00 00 00 __ __ __ │ .....░░░ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-unwind.diff index da7add371a5bf..e6ee1e6f9a348 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-unwind.diff @@ -61,9 +61,7 @@ StorageDead(_1); return; } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 04 00 00 00 00 __ __ __ │ .....░░░ } ++ ++ ALLOC0 (size: 8, align: 4) { .. } From fe5581dd31eb1b86c915e5c3eaae9ebfdea28037 Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 4 Jul 2024 09:55:00 +0000 Subject: [PATCH 04/18] Fix import suggestion ice --- compiler/rustc_resolve/src/diagnostics.rs | 10 ++--- ...import-ice-issue-127302.edition2015.stderr | 41 +++++++++++++++++++ ...import-ice-issue-127302.edition2021.stderr | 41 +++++++++++++++++++ .../suggest-import-ice-issue-127302.rs | 12 ++++++ ...st-import-issue-120074.edition2015.stderr} | 2 +- ...est-import-issue-120074.edition2021.stderr | 23 +++++++++++ .../ui/imports/suggest-import-issue-120074.rs | 2 + 7 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 tests/ui/imports/suggest-import-ice-issue-127302.edition2015.stderr create mode 100644 tests/ui/imports/suggest-import-ice-issue-127302.edition2021.stderr create mode 100644 tests/ui/imports/suggest-import-ice-issue-127302.rs rename tests/ui/imports/{suggest-import-issue-120074.stderr => suggest-import-issue-120074.edition2015.stderr} (93%) create mode 100644 tests/ui/imports/suggest-import-issue-120074.edition2021.stderr diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 50a4e03d233a7..7e1251b3a3a5d 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1989,12 +1989,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some(candidate) = candidates.get(0) { let path = { // remove the possible common prefix of the path - let start_index = (0..failed_segment_idx) - .find(|&i| path[i].ident != candidate.path.segments[i].ident) + let len = candidate.path.segments.len(); + let start_index = (0..=failed_segment_idx.min(len - 1)) + .find(|&i| path[i].ident.name != candidate.path.segments[i].ident.name) .unwrap_or_default(); - let segments = (start_index..=failed_segment_idx) - .map(|s| candidate.path.segments[s].clone()) - .collect(); + let segments = + (start_index..len).map(|s| candidate.path.segments[s].clone()).collect(); Path { segments, span: Span::default(), tokens: None } }; ( diff --git a/tests/ui/imports/suggest-import-ice-issue-127302.edition2015.stderr b/tests/ui/imports/suggest-import-ice-issue-127302.edition2015.stderr new file mode 100644 index 0000000000000..24574c8796b9d --- /dev/null +++ b/tests/ui/imports/suggest-import-ice-issue-127302.edition2015.stderr @@ -0,0 +1,41 @@ +error[E0583]: file not found for module `config` + --> $DIR/suggest-import-ice-issue-127302.rs:3:1 + | +LL | mod config; + | ^^^^^^^^^^^ + | + = help: to create the module `config`, create file "$DIR/config.rs" or "$DIR/config/mod.rs" + = note: if there is a `mod config` elsewhere in the crate already, import it with `use crate::...` instead + +error: format argument must be a string literal + --> $DIR/suggest-import-ice-issue-127302.rs:10:14 + | +LL | println!(args.ctx.compiler.display()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you might be missing a string literal to format with + | +LL | println!("{}", args.ctx.compiler.display()); + | +++++ + +error[E0425]: cannot find value `args` in this scope + --> $DIR/suggest-import-ice-issue-127302.rs:6:12 + | +LL | match &args.cmd { + | ^^^^ not found in this scope + | +help: consider importing this function + | +LL + use std::env::args; + | + +error[E0532]: expected unit struct, unit variant or constant, found module `crate::config` + --> $DIR/suggest-import-ice-issue-127302.rs:7:9 + | +LL | crate::config => {} + | ^^^^^^^^^^^^^ not a unit struct, unit variant or constant + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0425, E0532, E0583. +For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/imports/suggest-import-ice-issue-127302.edition2021.stderr b/tests/ui/imports/suggest-import-ice-issue-127302.edition2021.stderr new file mode 100644 index 0000000000000..24574c8796b9d --- /dev/null +++ b/tests/ui/imports/suggest-import-ice-issue-127302.edition2021.stderr @@ -0,0 +1,41 @@ +error[E0583]: file not found for module `config` + --> $DIR/suggest-import-ice-issue-127302.rs:3:1 + | +LL | mod config; + | ^^^^^^^^^^^ + | + = help: to create the module `config`, create file "$DIR/config.rs" or "$DIR/config/mod.rs" + = note: if there is a `mod config` elsewhere in the crate already, import it with `use crate::...` instead + +error: format argument must be a string literal + --> $DIR/suggest-import-ice-issue-127302.rs:10:14 + | +LL | println!(args.ctx.compiler.display()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you might be missing a string literal to format with + | +LL | println!("{}", args.ctx.compiler.display()); + | +++++ + +error[E0425]: cannot find value `args` in this scope + --> $DIR/suggest-import-ice-issue-127302.rs:6:12 + | +LL | match &args.cmd { + | ^^^^ not found in this scope + | +help: consider importing this function + | +LL + use std::env::args; + | + +error[E0532]: expected unit struct, unit variant or constant, found module `crate::config` + --> $DIR/suggest-import-ice-issue-127302.rs:7:9 + | +LL | crate::config => {} + | ^^^^^^^^^^^^^ not a unit struct, unit variant or constant + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0425, E0532, E0583. +For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/imports/suggest-import-ice-issue-127302.rs b/tests/ui/imports/suggest-import-ice-issue-127302.rs new file mode 100644 index 0000000000000..6b8d4c718310e --- /dev/null +++ b/tests/ui/imports/suggest-import-ice-issue-127302.rs @@ -0,0 +1,12 @@ +//@ revisions: edition2015 edition2021 + +mod config; //~ ERROR file not found for module + +fn main() { + match &args.cmd { //~ ERROR cannot find value `args` in this scope + crate::config => {} //~ ERROR expected unit struct, unit variant or constant, found module `crate::config` + } + + println!(args.ctx.compiler.display()); + //~^ ERROR format argument must be a string literal +} diff --git a/tests/ui/imports/suggest-import-issue-120074.stderr b/tests/ui/imports/suggest-import-issue-120074.edition2015.stderr similarity index 93% rename from tests/ui/imports/suggest-import-issue-120074.stderr rename to tests/ui/imports/suggest-import-issue-120074.edition2015.stderr index c1dff93bbdbff..414eeee0fedc8 100644 --- a/tests/ui/imports/suggest-import-issue-120074.stderr +++ b/tests/ui/imports/suggest-import-issue-120074.edition2015.stderr @@ -1,5 +1,5 @@ error[E0433]: failed to resolve: unresolved import - --> $DIR/suggest-import-issue-120074.rs:10:35 + --> $DIR/suggest-import-issue-120074.rs:12:35 | LL | println!("Hello, {}!", crate::bar::do_the_thing); | ^^^ unresolved import diff --git a/tests/ui/imports/suggest-import-issue-120074.edition2021.stderr b/tests/ui/imports/suggest-import-issue-120074.edition2021.stderr new file mode 100644 index 0000000000000..414eeee0fedc8 --- /dev/null +++ b/tests/ui/imports/suggest-import-issue-120074.edition2021.stderr @@ -0,0 +1,23 @@ +error[E0433]: failed to resolve: unresolved import + --> $DIR/suggest-import-issue-120074.rs:12:35 + | +LL | println!("Hello, {}!", crate::bar::do_the_thing); + | ^^^ unresolved import + | +help: a similar path exists + | +LL | println!("Hello, {}!", crate::foo::bar::do_the_thing); + | ~~~~~~~~ +help: consider importing this module + | +LL + use foo::bar; + | +help: if you import `bar`, refer to it directly + | +LL - println!("Hello, {}!", crate::bar::do_the_thing); +LL + println!("Hello, {}!", bar::do_the_thing); + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/imports/suggest-import-issue-120074.rs b/tests/ui/imports/suggest-import-issue-120074.rs index a798e9eeeb809..7b6b5c73103a1 100644 --- a/tests/ui/imports/suggest-import-issue-120074.rs +++ b/tests/ui/imports/suggest-import-issue-120074.rs @@ -1,3 +1,5 @@ +//@ revisions: edition2015 edition2021 + pub mod foo { pub mod bar { pub fn do_the_thing() -> usize { From 87856c4461c29eb8c8ef7e3fb28ccfcbd41e4120 Mon Sep 17 00:00:00 2001 From: asquared31415 <34665709+asquared31415@users.noreply.github.com> Date: Mon, 24 Jun 2024 22:37:44 +0000 Subject: [PATCH 05/18] add lint for inline asm labels that look like binary --- compiler/rustc_lint/messages.ftl | 17 +- compiler/rustc_lint/src/builtin.rs | 131 +++++++++++---- compiler/rustc_lint/src/lib.rs | 2 +- compiler/rustc_lint/src/lints.rs | 30 +++- tests/ui/asm/binary_asm_labels.rs | 17 ++ tests/ui/asm/binary_asm_labels.stderr | 43 +++++ tests/ui/asm/named-asm-labels.rs | 24 ++- tests/ui/asm/named-asm-labels.stderr | 224 ++++++++++++++++++++------ 8 files changed, 397 insertions(+), 91 deletions(-) create mode 100644 tests/ui/asm/binary_asm_labels.rs create mode 100644 tests/ui/asm/binary_asm_labels.stderr diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 3e952558d29d3..9d8271a6acb36 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -52,10 +52,6 @@ lint_builtin_allow_internal_unsafe = lint_builtin_anonymous_params = anonymous parameters are deprecated and will be removed in the next edition .suggestion = try naming the parameter or explicitly ignoring it -lint_builtin_asm_labels = avoid using named labels in inline assembly - .help = only local labels of the form `:` should be used in inline asm - .note = see the asm section of Rust By Example for more information - lint_builtin_clashing_extern_diff_name = `{$this}` redeclares `{$orig}` with a different signature .previous_decl_label = `{$orig}` previously declared here .mismatch_label = this signature doesn't match the previous declaration @@ -399,6 +395,19 @@ lint_incomplete_include = lint_inner_macro_attribute_unstable = inner macro attributes are unstable +lint_invalid_asm_label_binary = avoid using labels containing only the digits `0` and `1` in inline assembly + .label = use a different label that doesn't start with `0` or `1` + .note = an LLVM bug makes these labels ambiguous with a binary literal number + .note = see for more information + +lint_invalid_asm_label_format_arg = avoid using named labels in inline assembly + .help = only local labels of the form `:` should be used in inline asm + .note1 = format arguments may expand to a non-numeric value + .note2 = see the asm section of Rust By Example for more information +lint_invalid_asm_label_named = avoid using named labels in inline assembly + .help = only local labels of the form `:` should be used in inline asm + .note = see the asm section of Rust By Example for more information +lint_invalid_asm_label_no_span = the label may be declared in the expansion of a macro lint_invalid_crate_type_value = invalid `crate_type` value .suggestion = did you mean diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 79c8046f9b741..a661c74cf91d9 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -30,13 +30,13 @@ use crate::{ BuiltinExplicitOutlivesSuggestion, BuiltinFeatureIssueNote, BuiltinIncompleteFeatures, BuiltinIncompleteFeaturesHelp, BuiltinInternalFeatures, BuiltinKeywordIdents, BuiltinMissingCopyImpl, BuiltinMissingDebugImpl, BuiltinMissingDoc, - BuiltinMutablesTransmutes, BuiltinNamedAsmLabel, BuiltinNoMangleGeneric, - BuiltinNonShorthandFieldPatterns, BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds, - BuiltinTypeAliasGenericBounds, BuiltinTypeAliasGenericBoundsSuggestion, - BuiltinTypeAliasWhereClause, BuiltinUngatedAsyncFnTrackCaller, BuiltinUnpermittedTypeInit, + BuiltinMutablesTransmutes, BuiltinNoMangleGeneric, BuiltinNonShorthandFieldPatterns, + BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds, BuiltinTypeAliasGenericBounds, + BuiltinTypeAliasGenericBoundsSuggestion, BuiltinTypeAliasWhereClause, + BuiltinUngatedAsyncFnTrackCaller, BuiltinUnpermittedTypeInit, BuiltinUnpermittedTypeInitSub, BuiltinUnreachablePub, BuiltinUnsafe, BuiltinUnstableFeatures, BuiltinUnusedDocComment, BuiltinUnusedDocCommentSub, - BuiltinWhileTrue, SuggestChangingAssocTypes, + BuiltinWhileTrue, InvalidAsmLabel, SuggestChangingAssocTypes, }, EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext, }; @@ -45,7 +45,7 @@ use rustc_ast::tokenstream::{TokenStream, TokenTree}; use rustc_ast::visit::{FnCtxt, FnKind}; use rustc_ast::{self as ast, *}; use rustc_ast_pretty::pprust::{self, expr_to_string}; -use rustc_errors::{Applicability, LintDiagnostic, MultiSpan}; +use rustc_errors::{Applicability, LintDiagnostic}; use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -69,7 +69,6 @@ use rustc_target::abi::Abi; use rustc_trait_selection::infer::{InferCtxtExt, TyCtxtInferExt}; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_trait_selection::traits::{self, misc::type_allowed_to_implement_copy}; -use tracing::debug; use crate::nonstandard_style::{method_context, MethodLateContext}; @@ -2728,10 +2727,52 @@ declare_lint! { "named labels in inline assembly", } -declare_lint_pass!(NamedAsmLabels => [NAMED_ASM_LABELS]); +declare_lint! { + /// The `binary_asm_labels` lint detects the use of numeric labels containing only binary + /// digits in the inline `asm!` macro. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// # #![feature(asm_experimental_arch)] + /// use std::arch::asm; + /// + /// fn main() { + /// unsafe { + /// asm!("0: jmp 0b"); + /// } + /// } + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// A [LLVM bug] causes this code to fail to compile because it interprets the `0b` as a binary + /// literal instead of a reference to the previous local label `0`. Note that even though the + /// bug is marked as fixed, it only fixes a specific usage of intel syntax within standalone + /// files, not inline assembly. To work around this bug, don't use labels that could be + /// confused with a binary literal. + /// + /// See the explanation in [Rust By Example] for more details. + /// + /// [LLVM bug]: https://bugs.llvm.org/show_bug.cgi?id=36144 + /// [Rust By Example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels + pub BINARY_ASM_LABELS, + Deny, + "labels in inline assembly containing only 0 or 1 digits", +} -impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels { - #[allow(rustc::diagnostic_outside_of_impl)] +declare_lint_pass!(AsmLabels => [NAMED_ASM_LABELS, BINARY_ASM_LABELS]); + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum AsmLabelKind { + Named, + FormatArg, + Binary, +} + +impl<'tcx> LateLintPass<'tcx> for AsmLabels { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) { if let hir::Expr { kind: hir::ExprKind::InlineAsm(hir::InlineAsm { template_strs, options, .. }), @@ -2759,7 +2800,8 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels { None }; - let mut found_labels = Vec::new(); + // diagnostics are emitted per-template, so this is created here as opposed to the outer loop + let mut spans = Vec::new(); // A semicolon might not actually be specified as a separator for all targets, but // it seems like LLVM accepts it always. @@ -2782,16 +2824,21 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels { // Whether a { bracket has been seen and its } hasn't been found yet. let mut in_bracket = false; + let mut label_kind = AsmLabelKind::Named; - // A label starts with an ASCII alphabetic character or . or _ // A label can also start with a format arg, if it's not a raw asm block. if !raw && start == '{' { in_bracket = true; + label_kind = AsmLabelKind::FormatArg; + } else if matches!(start, '0' | '1') { + // Binary labels have only the characters `0` or `1`. + label_kind = AsmLabelKind::Binary; } else if !(start.is_ascii_alphabetic() || matches!(start, '.' | '_')) { + // Named labels start with ASCII letters, `.` or `_`. + // anything else is not a label break 'label_loop; } - // Labels continue with ASCII alphanumeric characters, _, or $ for c in chars { // Inside a template format arg, any character is permitted for the // puproses of label detection because we assume that it can be @@ -2812,8 +2859,18 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels { } else if !raw && c == '{' { // Start of a format arg. in_bracket = true; + label_kind = AsmLabelKind::FormatArg; } else { - if !(c.is_ascii_alphanumeric() || matches!(c, '_' | '$')) { + let can_continue = match label_kind { + // Format arg labels are considered to be named labels for the purposes + // of continuing outside of their {} pair. + AsmLabelKind::Named | AsmLabelKind::FormatArg => { + c.is_ascii_alphanumeric() || matches!(c, '_' | '$') + } + AsmLabelKind::Binary => matches!(c, '0' | '1'), + }; + + if !can_continue { // The potential label had an invalid character inside it, it // cannot be a label. break 'label_loop; @@ -2821,25 +2878,41 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels { } } - // If all characters passed the label checks, this is likely a label. - found_labels.push(possible_label); + // If all characters passed the label checks, this is a label. + spans.push((find_label_span(possible_label), label_kind)); start_idx = idx + 1; } } - debug!("NamedAsmLabels::check_expr(): found_labels: {:#?}", &found_labels); - - if found_labels.len() > 0 { - let spans = found_labels - .into_iter() - .filter_map(|label| find_label_span(label)) - .collect::>(); - // If there were labels but we couldn't find a span, combine the warnings and - // use the template span. - let target_spans: MultiSpan = - if spans.len() > 0 { spans.into() } else { (*template_span).into() }; - - cx.emit_span_lint(NAMED_ASM_LABELS, target_spans, BuiltinNamedAsmLabel); + for (span, label_kind) in spans { + let missing_precise_span = span.is_none(); + let span = span.unwrap_or(*template_span); + match label_kind { + AsmLabelKind::Named => { + cx.emit_span_lint( + NAMED_ASM_LABELS, + span, + InvalidAsmLabel::Named { missing_precise_span }, + ); + } + AsmLabelKind::FormatArg => { + cx.emit_span_lint( + NAMED_ASM_LABELS, + span, + InvalidAsmLabel::FormatArg { missing_precise_span }, + ); + } + AsmLabelKind::Binary => { + // the binary asm issue only occurs when using intel syntax + if !options.contains(InlineAsmOptions::ATT_SYNTAX) { + cx.emit_span_lint( + BINARY_ASM_LABELS, + span, + InvalidAsmLabel::Binary { missing_precise_span, span }, + ) + } + } + }; } } } diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 17f9d4421aef2..31b76b7c6ff82 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -220,7 +220,7 @@ late_lint_methods!( NoopMethodCall: NoopMethodCall, EnumIntrinsicsNonEnums: EnumIntrinsicsNonEnums, InvalidAtomicOrdering: InvalidAtomicOrdering, - NamedAsmLabels: NamedAsmLabels, + AsmLabels: AsmLabels, OpaqueHiddenInferredBound: OpaqueHiddenInferredBound, MultipleSupertraitUpcastable: MultipleSupertraitUpcastable, MapUnitFn: MapUnitFn, diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 7c5640f5959a0..b3f715c217475 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -2040,10 +2040,32 @@ pub struct UnitBindingsDiag { } #[derive(LintDiagnostic)] -#[diag(lint_builtin_asm_labels)] -#[help] -#[note] -pub struct BuiltinNamedAsmLabel; +pub enum InvalidAsmLabel { + #[diag(lint_invalid_asm_label_named)] + #[help] + #[note] + Named { + #[note(lint_invalid_asm_label_no_span)] + missing_precise_span: bool, + }, + #[diag(lint_invalid_asm_label_format_arg)] + #[help] + #[note(lint_note1)] + #[note(lint_note2)] + FormatArg { + #[note(lint_invalid_asm_label_no_span)] + missing_precise_span: bool, + }, + #[diag(lint_invalid_asm_label_binary)] + #[note] + Binary { + #[note(lint_invalid_asm_label_no_span)] + missing_precise_span: bool, + // hack to get a label on the whole span, must match the emitted span + #[label] + span: Span, + }, +} #[derive(Subdiagnostic)] pub enum UnexpectedCfgCargoHelp { diff --git a/tests/ui/asm/binary_asm_labels.rs b/tests/ui/asm/binary_asm_labels.rs new file mode 100644 index 0000000000000..3f545880254c2 --- /dev/null +++ b/tests/ui/asm/binary_asm_labels.rs @@ -0,0 +1,17 @@ +//@ needs-asm-support +//@ only-x86_64 + +// tests that labels containing only the digits 0 and 1 are rejected +// uses of such labels can sometimes be interpreted as a binary literal + +use std::arch::{asm, global_asm}; + +fn main() { + unsafe { + asm!("0: jmp 0b"); //~ ERROR avoid using labels containing only the digits + asm!("1: jmp 1b"); //~ ERROR avoid using labels containing only the digits + asm!("10: jmp 10b"); //~ ERROR avoid using labels containing only the digits + asm!("01: jmp 01b"); //~ ERROR avoid using labels containing only the digits + asm!("1001101: jmp 1001101b"); //~ ERROR avoid using labels containing only the digits + } +} diff --git a/tests/ui/asm/binary_asm_labels.stderr b/tests/ui/asm/binary_asm_labels.stderr new file mode 100644 index 0000000000000..1f2943084f1eb --- /dev/null +++ b/tests/ui/asm/binary_asm_labels.stderr @@ -0,0 +1,43 @@ +error: avoid using labels containing only the digits `0` and `1` in inline assembly + --> $DIR/binary_asm_labels.rs:11:15 + | +LL | asm!("0: jmp 0b"); + | ^ use a different label that doesn't start with `0` or `1` + | + = note: an LLVM bug makes these labels ambiguous with a binary literal number + = note: `#[deny(binary_asm_labels)]` on by default + +error: avoid using labels containing only the digits `0` and `1` in inline assembly + --> $DIR/binary_asm_labels.rs:12:15 + | +LL | asm!("1: jmp 1b"); + | ^ use a different label that doesn't start with `0` or `1` + | + = note: an LLVM bug makes these labels ambiguous with a binary literal number + +error: avoid using labels containing only the digits `0` and `1` in inline assembly + --> $DIR/binary_asm_labels.rs:13:15 + | +LL | asm!("10: jmp 10b"); + | ^^ use a different label that doesn't start with `0` or `1` + | + = note: an LLVM bug makes these labels ambiguous with a binary literal number + +error: avoid using labels containing only the digits `0` and `1` in inline assembly + --> $DIR/binary_asm_labels.rs:14:15 + | +LL | asm!("01: jmp 01b"); + | ^^ use a different label that doesn't start with `0` or `1` + | + = note: an LLVM bug makes these labels ambiguous with a binary literal number + +error: avoid using labels containing only the digits `0` and `1` in inline assembly + --> $DIR/binary_asm_labels.rs:15:15 + | +LL | asm!("1001101: jmp 1001101b"); + | ^^^^^^^ use a different label that doesn't start with `0` or `1` + | + = note: an LLVM bug makes these labels ambiguous with a binary literal number + +error: aborting due to 5 previous errors + diff --git a/tests/ui/asm/named-asm-labels.rs b/tests/ui/asm/named-asm-labels.rs index 96ccdef75b0ce..d2ca6fe8808bc 100644 --- a/tests/ui/asm/named-asm-labels.rs +++ b/tests/ui/asm/named-asm-labels.rs @@ -28,11 +28,13 @@ fn main() { // Multiple labels on one line asm!("foo: bar1: nop"); //~^ ERROR avoid using named labels + //~^^ ERROR avoid using named labels // Multiple lines asm!("foo1: nop", "nop"); //~ ERROR avoid using named labels asm!("foo2: foo3: nop", "nop"); //~^ ERROR avoid using named labels + //~^^ ERROR avoid using named labels asm!("nop", "foo4: nop"); //~ ERROR avoid using named labels asm!("foo5: nop", "foo6: nop"); //~^ ERROR avoid using named labels @@ -41,16 +43,19 @@ fn main() { // Statement separator asm!("foo7: nop; foo8: nop"); //~^ ERROR avoid using named labels + //~^^ ERROR avoid using named labels asm!("foo9: nop; nop"); //~ ERROR avoid using named labels asm!("nop; foo10: nop"); //~ ERROR avoid using named labels // Escaped newline asm!("bar2: nop\n bar3: nop"); //~^ ERROR avoid using named labels + //~^^ ERROR avoid using named labels asm!("bar4: nop\n nop"); //~ ERROR avoid using named labels asm!("nop\n bar5: nop"); //~ ERROR avoid using named labels asm!("nop\n bar6: bar7: nop"); //~^ ERROR avoid using named labels + //~^^ ERROR avoid using named labels // Raw strings asm!( @@ -60,6 +65,7 @@ fn main() { " ); //~^^^^ ERROR avoid using named labels + //~^^^^ ERROR avoid using named labels asm!( r###" @@ -81,9 +87,15 @@ fn main() { asm!("blah1: 2bar: nop"); //~ ERROR avoid using named labels // Duplicate labels - asm!("def: def: nop"); //~ ERROR avoid using named labels - asm!("def: nop\ndef: nop"); //~ ERROR avoid using named labels - asm!("def: nop; def: nop"); //~ ERROR avoid using named labels + asm!("def: def: nop"); + //~^ ERROR avoid using named labels + //~^^ ERROR avoid using named labels + asm!("def: nop\ndef: nop"); + //~^ ERROR avoid using named labels + //~^^ ERROR avoid using named labels + asm!("def: nop; def: nop"); + //~^ ERROR avoid using named labels + //~^^ ERROR avoid using named labels // Trying to break parsing asm!(":"); @@ -141,7 +153,11 @@ fn main() { asm!("{1}: nop", "/* {0} */", const 10, const 20); //~ ERROR avoid using named labels // Test include_str in asm - asm!(include_str!("named-asm-labels.s")); //~ ERROR avoid using named labels + asm!(include_str!("named-asm-labels.s")); + //~^ ERROR avoid using named labels + //~^^ ERROR avoid using named labels + //~^^^ ERROR avoid using named labels + //~^^^^ ERROR avoid using named labels // Test allowing or warning on the lint instead #[allow(named_asm_labels)] diff --git a/tests/ui/asm/named-asm-labels.stderr b/tests/ui/asm/named-asm-labels.stderr index 36fd69839518f..20b7d64f9e752 100644 --- a/tests/ui/asm/named-asm-labels.stderr +++ b/tests/ui/asm/named-asm-labels.stderr @@ -21,13 +21,22 @@ error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:29:15 | LL | asm!("foo: bar1: nop"); - | ^^^ ^^^^ + | ^^^ | = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:33:15 + --> $DIR/named-asm-labels.rs:29:20 + | +LL | asm!("foo: bar1: nop"); + | ^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:34:15 | LL | asm!("foo1: nop", "nop"); | ^^^^ @@ -36,16 +45,25 @@ LL | asm!("foo1: nop", "nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:34:15 + --> $DIR/named-asm-labels.rs:35:15 | LL | asm!("foo2: foo3: nop", "nop"); - | ^^^^ ^^^^ + | ^^^^ | = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:36:22 + --> $DIR/named-asm-labels.rs:35:21 + | +LL | asm!("foo2: foo3: nop", "nop"); + | ^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:38:22 | LL | asm!("nop", "foo4: nop"); | ^^^^ @@ -54,7 +72,7 @@ LL | asm!("nop", "foo4: nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:37:15 + --> $DIR/named-asm-labels.rs:39:15 | LL | asm!("foo5: nop", "foo6: nop"); | ^^^^ @@ -63,7 +81,7 @@ LL | asm!("foo5: nop", "foo6: nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:37:28 + --> $DIR/named-asm-labels.rs:39:28 | LL | asm!("foo5: nop", "foo6: nop"); | ^^^^ @@ -72,16 +90,25 @@ LL | asm!("foo5: nop", "foo6: nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:42:15 + --> $DIR/named-asm-labels.rs:44:15 | LL | asm!("foo7: nop; foo8: nop"); - | ^^^^ ^^^^ + | ^^^^ | = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:44:15 + --> $DIR/named-asm-labels.rs:44:26 + | +LL | asm!("foo7: nop; foo8: nop"); + | ^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:47:15 | LL | asm!("foo9: nop; nop"); | ^^^^ @@ -90,7 +117,7 @@ LL | asm!("foo9: nop; nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:45:20 + --> $DIR/named-asm-labels.rs:48:20 | LL | asm!("nop; foo10: nop"); | ^^^^^ @@ -99,16 +126,25 @@ LL | asm!("nop; foo10: nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:48:15 + --> $DIR/named-asm-labels.rs:51:15 | LL | asm!("bar2: nop\n bar3: nop"); - | ^^^^ ^^^^ + | ^^^^ | = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:50:15 + --> $DIR/named-asm-labels.rs:51:27 + | +LL | asm!("bar2: nop\n bar3: nop"); + | ^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:54:15 | LL | asm!("bar4: nop\n nop"); | ^^^^ @@ -117,7 +153,7 @@ LL | asm!("bar4: nop\n nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:51:21 + --> $DIR/named-asm-labels.rs:55:21 | LL | asm!("nop\n bar5: nop"); | ^^^^ @@ -126,19 +162,35 @@ LL | asm!("nop\n bar5: nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:52:21 + --> $DIR/named-asm-labels.rs:56:21 | LL | asm!("nop\n bar6: bar7: nop"); - | ^^^^ ^^^^ + | ^^^^ | = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:58:13 + --> $DIR/named-asm-labels.rs:56:27 + | +LL | asm!("nop\n bar6: bar7: nop"); + | ^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:63:13 | LL | blah2: nop | ^^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:64:13 + | LL | blah3: nop | ^^^^^ | @@ -146,7 +198,7 @@ LL | blah3: nop = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:67:19 + --> $DIR/named-asm-labels.rs:73:19 | LL | nop ; blah4: nop | ^^^^^ @@ -155,7 +207,7 @@ LL | nop ; blah4: nop = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:81:15 + --> $DIR/named-asm-labels.rs:87:15 | LL | asm!("blah1: 2bar: nop"); | ^^^^^ @@ -164,7 +216,7 @@ LL | asm!("blah1: 2bar: nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:84:15 + --> $DIR/named-asm-labels.rs:90:15 | LL | asm!("def: def: nop"); | ^^^ @@ -173,7 +225,17 @@ LL | asm!("def: def: nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:85:15 + --> $DIR/named-asm-labels.rs:90:15 + | +LL | asm!("def: def: nop"); + | ^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:93:15 | LL | asm!("def: nop\ndef: nop"); | ^^^ @@ -182,16 +244,36 @@ LL | asm!("def: nop\ndef: nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:86:15 + --> $DIR/named-asm-labels.rs:93:15 + | +LL | asm!("def: nop\ndef: nop"); + | ^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:96:15 + | +LL | asm!("def: nop; def: nop"); + | ^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:96:15 | LL | asm!("def: nop; def: nop"); | ^^^ | = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of Rust By Example for more information + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:94:15 + --> $DIR/named-asm-labels.rs:106:15 | LL | asm!("fooo\u{003A} nop"); | ^^^^^^^^^^^^^^^^ @@ -200,7 +282,7 @@ LL | asm!("fooo\u{003A} nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:95:15 + --> $DIR/named-asm-labels.rs:107:15 | LL | asm!("foooo\x3A nop"); | ^^^^^^^^^^^^^ @@ -209,7 +291,7 @@ LL | asm!("foooo\x3A nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:98:15 + --> $DIR/named-asm-labels.rs:110:15 | LL | asm!("fooooo:\u{000A} nop"); | ^^^^^^ @@ -218,7 +300,7 @@ LL | asm!("fooooo:\u{000A} nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:99:15 + --> $DIR/named-asm-labels.rs:111:15 | LL | asm!("foooooo:\x0A nop"); | ^^^^^^^ @@ -227,16 +309,17 @@ LL | asm!("foooooo:\x0A nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:103:14 + --> $DIR/named-asm-labels.rs:115:14 | LL | asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of Rust By Example for more information + = note: the label may be declared in the expansion of a macro error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:111:13 + --> $DIR/named-asm-labels.rs:123:13 | LL | ab: nop // ab: does foo | ^^ @@ -245,97 +328,140 @@ LL | ab: nop // ab: does foo = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:131:19 + --> $DIR/named-asm-labels.rs:143:19 | LL | asm!("test_{}: nop", in(reg) 10); | ^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: format arguments may expand to a non-numeric value = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:133:15 + --> $DIR/named-asm-labels.rs:145:15 | LL | asm!("test_{}: nop", const 10); | ^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: format arguments may expand to a non-numeric value = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:134:15 + --> $DIR/named-asm-labels.rs:146:15 | LL | asm!("test_{}: nop", sym main); | ^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: format arguments may expand to a non-numeric value = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:135:15 + --> $DIR/named-asm-labels.rs:147:15 | LL | asm!("{}_test: nop", const 10); | ^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: format arguments may expand to a non-numeric value = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:136:15 + --> $DIR/named-asm-labels.rs:148:15 | LL | asm!("test_{}_test: nop", const 10); | ^^^^^^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: format arguments may expand to a non-numeric value = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:137:15 + --> $DIR/named-asm-labels.rs:149:15 | LL | asm!("{}: nop", const 10); | ^^ | = help: only local labels of the form `:` should be used in inline asm + = note: format arguments may expand to a non-numeric value = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:139:15 + --> $DIR/named-asm-labels.rs:151:15 | LL | asm!("{uwu}: nop", uwu = const 10); | ^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: format arguments may expand to a non-numeric value = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:140:15 + --> $DIR/named-asm-labels.rs:152:15 | LL | asm!("{0}: nop", const 10); | ^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: format arguments may expand to a non-numeric value = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:141:15 + --> $DIR/named-asm-labels.rs:153:15 | LL | asm!("{1}: nop", "/* {0} */", const 10, const 20); | ^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: format arguments may expand to a non-numeric value + = note: see the asm section of Rust By Example for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:156:14 + | +LL | asm!(include_str!("named-asm-labels.s")); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information + = note: the label may be declared in the expansion of a macro + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:156:14 + | +LL | asm!(include_str!("named-asm-labels.s")); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information + = note: the label may be declared in the expansion of a macro + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:156:14 + | +LL | asm!(include_str!("named-asm-labels.s")); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of Rust By Example for more information + = note: the label may be declared in the expansion of a macro + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:144:14 + --> $DIR/named-asm-labels.rs:156:14 | LL | asm!(include_str!("named-asm-labels.s")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of Rust By Example for more information + = note: the label may be declared in the expansion of a macro + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:154:19 + --> $DIR/named-asm-labels.rs:170:19 | LL | asm!("warned: nop"); | ^^^^^^ @@ -343,13 +469,13 @@ LL | asm!("warned: nop"); = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of Rust By Example for more information note: the lint level is defined here - --> $DIR/named-asm-labels.rs:152:16 + --> $DIR/named-asm-labels.rs:168:16 | LL | #[warn(named_asm_labels)] | ^^^^^^^^^^^^^^^^ error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:163:20 + --> $DIR/named-asm-labels.rs:179:20 | LL | unsafe { asm!(".Lfoo: mov rax, {}; ret;", "nop", const 1, options(noreturn)) } | ^^^^^ @@ -358,7 +484,7 @@ LL | unsafe { asm!(".Lfoo: mov rax, {}; ret;", "nop", const 1, options(noret = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:169:20 + --> $DIR/named-asm-labels.rs:185:20 | LL | unsafe { asm!(".Lbar: mov rax, {}; ret;", "nop", const 1, options(noreturn)) } | ^^^^^ @@ -367,7 +493,7 @@ LL | unsafe { asm!(".Lbar: mov rax, {}; ret;", "nop", const 1, options(noret = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:177:20 + --> $DIR/named-asm-labels.rs:193:20 | LL | unsafe { asm!(".Laaa: nop; ret;", options(noreturn)) } | ^^^^^ @@ -376,7 +502,7 @@ LL | unsafe { asm!(".Laaa: nop; ret;", options(noreturn)) } = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:187:24 + --> $DIR/named-asm-labels.rs:203:24 | LL | unsafe { asm!(".Lbbb: nop; ret;", options(noreturn)) } | ^^^^^ @@ -385,7 +511,7 @@ LL | unsafe { asm!(".Lbbb: nop; ret;", options(noreturn)) } = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:196:15 + --> $DIR/named-asm-labels.rs:212:15 | LL | asm!("closure1: nop"); | ^^^^^^^^ @@ -394,7 +520,7 @@ LL | asm!("closure1: nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:200:15 + --> $DIR/named-asm-labels.rs:216:15 | LL | asm!("closure2: nop"); | ^^^^^^^^ @@ -403,7 +529,7 @@ LL | asm!("closure2: nop"); = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:210:19 + --> $DIR/named-asm-labels.rs:226:19 | LL | asm!("closure3: nop"); | ^^^^^^^^ @@ -411,5 +537,5 @@ LL | asm!("closure3: nop"); = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of Rust By Example for more information -error: aborting due to 44 previous errors; 1 warning emitted +error: aborting due to 56 previous errors; 1 warning emitted From a3ef94e80e0ec7bacd42a70bd8a2203c5cc3fab8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 9 Jul 2024 17:35:51 -0300 Subject: [PATCH 06/18] Fire unsafe_code lint on unsafe extern blocks --- compiler/rustc_lint/messages.ftl | 2 ++ compiler/rustc_lint/src/builtin.rs | 6 ++++++ compiler/rustc_lint/src/lints.rs | 2 ++ .../ui/lint/unsafe_code/unsafe-extern-blocks.rs | 14 ++++++++++++++ .../unsafe_code/unsafe-extern-blocks.stderr | 17 +++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 tests/ui/lint/unsafe_code/unsafe-extern-blocks.rs create mode 100644 tests/ui/lint/unsafe_code/unsafe-extern-blocks.stderr diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 3e952558d29d3..9d429d5131ec1 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -163,6 +163,8 @@ lint_builtin_unreachable_pub = unreachable `pub` {$what} lint_builtin_unsafe_block = usage of an `unsafe` block +lint_builtin_unsafe_extern_block = usage of an `unsafe extern` block + lint_builtin_unsafe_impl = implementation of an `unsafe` trait lint_builtin_unsafe_trait = declaration of an `unsafe` trait diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 79c8046f9b741..2d596564d52ca 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -326,6 +326,12 @@ impl EarlyLintPass for UnsafeCode { self.report_unsafe(cx, it.span, BuiltinUnsafe::GlobalAsm); } + ast::ItemKind::ForeignMod(ForeignMod { safety, .. }) => { + if let Safety::Unsafe(_) = safety { + self.report_unsafe(cx, it.span, BuiltinUnsafe::UnsafeExternBlock); + } + } + _ => {} } } diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 7c5640f5959a0..eacc66b197aa7 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -81,6 +81,8 @@ pub enum BuiltinUnsafe { AllowInternalUnsafe, #[diag(lint_builtin_unsafe_block)] UnsafeBlock, + #[diag(lint_builtin_unsafe_extern_block)] + UnsafeExternBlock, #[diag(lint_builtin_unsafe_trait)] UnsafeTrait, #[diag(lint_builtin_unsafe_impl)] diff --git a/tests/ui/lint/unsafe_code/unsafe-extern-blocks.rs b/tests/ui/lint/unsafe_code/unsafe-extern-blocks.rs new file mode 100644 index 0000000000000..6f2ead70db80c --- /dev/null +++ b/tests/ui/lint/unsafe_code/unsafe-extern-blocks.rs @@ -0,0 +1,14 @@ +#![feature(unsafe_extern_blocks)] +#![deny(unsafe_code)] + +#[allow(unsafe_code)] +unsafe extern "C" { + fn foo(); +} + +unsafe extern "C" { + //~^ ERROR usage of an `unsafe extern` block [unsafe_code] + fn bar(); +} + +fn main() {} diff --git a/tests/ui/lint/unsafe_code/unsafe-extern-blocks.stderr b/tests/ui/lint/unsafe_code/unsafe-extern-blocks.stderr new file mode 100644 index 0000000000000..5439a3112560e --- /dev/null +++ b/tests/ui/lint/unsafe_code/unsafe-extern-blocks.stderr @@ -0,0 +1,17 @@ +error: usage of an `unsafe extern` block + --> $DIR/unsafe-extern-blocks.rs:9:1 + | +LL | / unsafe extern "C" { +LL | | +LL | | fn bar(); +LL | | } + | |_^ + | +note: the lint level is defined here + --> $DIR/unsafe-extern-blocks.rs:2:9 + | +LL | #![deny(unsafe_code)] + | ^^^^^^^^^^^ + +error: aborting due to 1 previous error + From 03bee1e1e56b10a3bff0e8eb524faacdb745cabc Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 11 Jul 2024 14:00:54 -0400 Subject: [PATCH 07/18] Suggest using precise capturing for hidden type that captures region --- .../src/infer/error_reporting/region.rs | 124 ++++++++++++++++-- .../forgot-to-capture-lifetime.stderr | 6 +- .../hidden-type-suggestion.rs | 30 +++++ .../hidden-type-suggestion.stderr | 67 ++++++++++ 4 files changed, 212 insertions(+), 15 deletions(-) create mode 100644 tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.rs create mode 100644 tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.stderr diff --git a/compiler/rustc_infer/src/infer/error_reporting/region.rs b/compiler/rustc_infer/src/infer/error_reporting/region.rs index 5a465f46e47dc..793e0c70d3cf7 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/region.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/region.rs @@ -1,5 +1,6 @@ use std::iter; +use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{ struct_span_code_err, Applicability, Diag, Subdiagnostic, E0309, E0310, E0311, E0495, }; @@ -12,7 +13,7 @@ use rustc_middle::traits::ObligationCauseCode; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::{self, IsSuggestable, Region, Ty, TyCtxt, TypeVisitableExt as _}; use rustc_span::symbol::kw; -use rustc_span::{ErrorGuaranteed, Span}; +use rustc_span::{BytePos, ErrorGuaranteed, Span, Symbol}; use rustc_type_ir::Upcast as _; use super::nice_region_error::find_anon_type; @@ -1201,17 +1202,21 @@ pub fn unexpected_hidden_region_diagnostic<'a, 'tcx>( "", ); if let Some(reg_info) = tcx.is_suitable_region(generic_param_scope, hidden_region) { - let fn_returns = tcx.return_type_impl_or_dyn_traits(reg_info.def_id); - nice_region_error::suggest_new_region_bound( - tcx, - &mut err, - fn_returns, - hidden_region.to_string(), - None, - format!("captures `{hidden_region}`"), - None, - Some(reg_info.def_id), - ) + if infcx.tcx.features().precise_capturing { + suggest_precise_capturing(tcx, opaque_ty_key.def_id, hidden_region, &mut err); + } else { + let fn_returns = tcx.return_type_impl_or_dyn_traits(reg_info.def_id); + nice_region_error::suggest_new_region_bound( + tcx, + &mut err, + fn_returns, + hidden_region.to_string(), + None, + format!("captures `{hidden_region}`"), + None, + Some(reg_info.def_id), + ) + } } } ty::RePlaceholder(_) => { @@ -1257,3 +1262,98 @@ pub fn unexpected_hidden_region_diagnostic<'a, 'tcx>( err } + +fn suggest_precise_capturing<'tcx>( + tcx: TyCtxt<'tcx>, + opaque_def_id: LocalDefId, + captured_lifetime: ty::Region<'tcx>, + diag: &mut Diag<'_>, +) { + let hir::OpaqueTy { bounds, .. } = + tcx.hir_node_by_def_id(opaque_def_id).expect_item().expect_opaque_ty(); + + let new_lifetime = Symbol::intern(&captured_lifetime.to_string()); + + if let Some((args, span)) = bounds.iter().find_map(|bound| match bound { + hir::GenericBound::Use(args, span) => Some((args, span)), + _ => None, + }) { + let last_lifetime_span = args.iter().rev().find_map(|arg| match arg { + hir::PreciseCapturingArg::Lifetime(lt) => Some(lt.ident.span), + _ => None, + }); + + let first_param_span = args.iter().find_map(|arg| match arg { + hir::PreciseCapturingArg::Param(p) => Some(p.ident.span), + _ => None, + }); + + let (insertion_span, pre, post) = if let Some(last_lifetime_span) = last_lifetime_span { + (last_lifetime_span.shrink_to_hi(), ", ", "") + } else if let Some(first_param_span) = first_param_span { + (first_param_span.shrink_to_lo(), "", ", ") + } else { + (span.with_hi(span.hi() - BytePos(1)).shrink_to_hi(), "", "") + }; + + diag.span_suggestion_verbose( + insertion_span, + format!("add `{new_lifetime}` to the `use<...>` bound to explicitly capture it",), + format!("{pre}{new_lifetime}{post}"), + Applicability::MachineApplicable, + ); + } else { + let mut captured_lifetimes = FxIndexSet::default(); + let mut captured_non_lifetimes = FxIndexSet::default(); + + let variances = tcx.variances_of(opaque_def_id); + let mut generics = tcx.generics_of(opaque_def_id); + loop { + for param in &generics.own_params { + if variances[param.index as usize] == ty::Bivariant { + continue; + } + + match param.kind { + ty::GenericParamDefKind::Lifetime => { + captured_lifetimes.insert(param.name); + } + ty::GenericParamDefKind::Type { synthetic: true, .. } => { + // FIXME: We can't provide a good suggestion for + // `use<...>` if we have an APIT. Bail for now. + return; + } + ty::GenericParamDefKind::Type { .. } + | ty::GenericParamDefKind::Const { .. } => { + captured_non_lifetimes.insert(param.name); + } + } + } + + if let Some(parent) = generics.parent { + generics = tcx.generics_of(parent); + } else { + break; + } + } + + if !captured_lifetimes.insert(new_lifetime) { + // Uh, strange. This lifetime appears to already be captured... + return; + } + + let concatenated_bounds = captured_lifetimes + .into_iter() + .chain(captured_non_lifetimes) + .map(|sym| sym.to_string()) + .collect::>() + .join(", "); + + diag.span_suggestion_verbose( + tcx.def_span(opaque_def_id).shrink_to_hi(), + format!("add a `use<...>` bound to explicitly capture `{new_lifetime}`",), + format!(" + use<{concatenated_bounds}>"), + Applicability::MachineApplicable, + ); + } +} diff --git a/tests/ui/impl-trait/precise-capturing/forgot-to-capture-lifetime.stderr b/tests/ui/impl-trait/precise-capturing/forgot-to-capture-lifetime.stderr index 6544837ba8329..979c0ca6d7b6e 100644 --- a/tests/ui/impl-trait/precise-capturing/forgot-to-capture-lifetime.stderr +++ b/tests/ui/impl-trait/precise-capturing/forgot-to-capture-lifetime.stderr @@ -16,10 +16,10 @@ LL | fn lifetime_in_hidden<'a>(x: &'a ()) -> impl Sized + use<> { x } | | opaque type defined here | hidden type `&'a ()` captures the lifetime `'a` as defined here | -help: to declare that `impl Sized` captures `'a`, you can add an explicit `'a` lifetime bound +help: add `'a` to the `use<...>` bound to explicitly capture it | -LL | fn lifetime_in_hidden<'a>(x: &'a ()) -> impl Sized + use<> + 'a { x } - | ++++ +LL | fn lifetime_in_hidden<'a>(x: &'a ()) -> impl Sized + use<'a> { x } + | ++ error: aborting due to 2 previous errors diff --git a/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.rs b/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.rs new file mode 100644 index 0000000000000..e0b115b0ce412 --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.rs @@ -0,0 +1,30 @@ +#![feature(precise_capturing)] + +fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b> { +//~^ HELP add `'a` to the `use<...>` bound + x +//~^ ERROR hidden type for +} + +fn param<'a, T>(x: &'a ()) -> impl Sized + use { +//~^ HELP add `'a` to the `use<...>` bound + x +//~^ ERROR hidden type for +} + +fn empty<'a>(x: &'a ()) -> impl Sized + use<> { +//~^ HELP add `'a` to the `use<...>` bound + x +//~^ ERROR hidden type for +} + +trait Captures<'a> {} +impl Captures<'_> for T {} + +fn missing<'a, 'captured, 'not_captured, Captured>(x: &'a ()) -> impl Captures<'captured> { +//~^ HELP add a `use<...>` bound + x +//~^ ERROR hidden type for +} + +fn main() {} diff --git a/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.stderr b/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.stderr new file mode 100644 index 0000000000000..391f16d012e4b --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.stderr @@ -0,0 +1,67 @@ +error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds + --> $DIR/hidden-type-suggestion.rs:5:5 + | +LL | fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b> { + | -- -------------------- opaque type defined here + | | + | hidden type `&'a ()` captures the lifetime `'a` as defined here +LL | +LL | x + | ^ + | +help: add `'a` to the `use<...>` bound to explicitly capture it + | +LL | fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b, 'a> { + | ++++ + +error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds + --> $DIR/hidden-type-suggestion.rs:11:5 + | +LL | fn param<'a, T>(x: &'a ()) -> impl Sized + use { + | -- ------------------- opaque type defined here + | | + | hidden type `&'a ()` captures the lifetime `'a` as defined here +LL | +LL | x + | ^ + | +help: add `'a` to the `use<...>` bound to explicitly capture it + | +LL | fn param<'a, T>(x: &'a ()) -> impl Sized + use<'a, T> { + | +++ + +error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds + --> $DIR/hidden-type-suggestion.rs:17:5 + | +LL | fn empty<'a>(x: &'a ()) -> impl Sized + use<> { + | -- ------------------ opaque type defined here + | | + | hidden type `&'a ()` captures the lifetime `'a` as defined here +LL | +LL | x + | ^ + | +help: add `'a` to the `use<...>` bound to explicitly capture it + | +LL | fn empty<'a>(x: &'a ()) -> impl Sized + use<'a> { + | ++ + +error[E0700]: hidden type for `impl Captures<'captured>` captures lifetime that does not appear in bounds + --> $DIR/hidden-type-suggestion.rs:26:5 + | +LL | fn missing<'a, 'captured, 'not_captured, Captured>(x: &'a ()) -> impl Captures<'captured> { + | -- ------------------------ opaque type defined here + | | + | hidden type `&'a ()` captures the lifetime `'a` as defined here +LL | +LL | x + | ^ + | +help: add a `use<...>` bound to explicitly capture `'a` + | +LL | fn missing<'a, 'captured, 'not_captured, Captured>(x: &'a ()) -> impl Captures<'captured> + use<'captured, 'a, Captured> { + | ++++++++++++++++++++++++++++++ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0700`. From 42653c0045e46c26d2468b2aa2bba97802c08795 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 11 Jul 2024 14:14:17 -0400 Subject: [PATCH 08/18] Make it translatable too --- compiler/rustc_infer/messages.ftl | 4 +++ compiler/rustc_infer/src/errors/mod.rs | 29 +++++++++++++++++++ .../src/infer/error_reporting/region.rs | 23 +++++++-------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_infer/messages.ftl b/compiler/rustc_infer/messages.ftl index fbe8d31370cc3..7a5e71599203e 100644 --- a/compiler/rustc_infer/messages.ftl +++ b/compiler/rustc_infer/messages.ftl @@ -221,6 +221,10 @@ infer_opaque_hidden_type = infer_outlives_bound = lifetime of the source pointer does not outlive lifetime bound of the object type infer_outlives_content = lifetime of reference outlives lifetime of borrowed content... + +infer_precise_capturing_existing = add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it +infer_precise_capturing_new = add a `use<...>` bound to explicitly capture `{$new_lifetime}` + infer_prlf_defined_with_sub = the lifetime `{$sub_symbol}` defined here... infer_prlf_defined_without_sub = the lifetime defined here... infer_prlf_known_limitation = this is a known limitation that will be removed in the future (see issue #100013 for more information) diff --git a/compiler/rustc_infer/src/errors/mod.rs b/compiler/rustc_infer/src/errors/mod.rs index a801001eaf988..ce1b0f86d0341 100644 --- a/compiler/rustc_infer/src/errors/mod.rs +++ b/compiler/rustc_infer/src/errors/mod.rs @@ -1581,3 +1581,32 @@ pub enum ObligationCauseFailureCode { subdiags: Vec, }, } + +#[derive(Subdiagnostic)] +pub enum AddPreciseCapturing { + #[suggestion( + infer_precise_capturing_new, + style = "verbose", + code = " + use<{concatenated_bounds}>", + applicability = "machine-applicable" + )] + New { + #[primary_span] + span: Span, + new_lifetime: Symbol, + concatenated_bounds: String, + }, + #[suggestion( + infer_precise_capturing_existing, + style = "verbose", + code = "{pre}{new_lifetime}{post}", + applicability = "machine-applicable" + )] + Existing { + #[primary_span] + span: Span, + new_lifetime: Symbol, + pre: &'static str, + post: &'static str, + }, +} diff --git a/compiler/rustc_infer/src/infer/error_reporting/region.rs b/compiler/rustc_infer/src/infer/error_reporting/region.rs index 793e0c70d3cf7..191cb23184da1 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/region.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/region.rs @@ -1288,20 +1288,18 @@ fn suggest_precise_capturing<'tcx>( _ => None, }); - let (insertion_span, pre, post) = if let Some(last_lifetime_span) = last_lifetime_span { + let (span, pre, post) = if let Some(last_lifetime_span) = last_lifetime_span { (last_lifetime_span.shrink_to_hi(), ", ", "") } else if let Some(first_param_span) = first_param_span { (first_param_span.shrink_to_lo(), "", ", ") } else { + // If we have no args, then have `use<>` and need to fall back to using + // span math. This sucks, but should be reliable due to the construction + // of the `use<>` span. (span.with_hi(span.hi() - BytePos(1)).shrink_to_hi(), "", "") }; - diag.span_suggestion_verbose( - insertion_span, - format!("add `{new_lifetime}` to the `use<...>` bound to explicitly capture it",), - format!("{pre}{new_lifetime}{post}"), - Applicability::MachineApplicable, - ); + diag.subdiagnostic(errors::AddPreciseCapturing::Existing { span, new_lifetime, pre, post }); } else { let mut captured_lifetimes = FxIndexSet::default(); let mut captured_non_lifetimes = FxIndexSet::default(); @@ -1349,11 +1347,10 @@ fn suggest_precise_capturing<'tcx>( .collect::>() .join(", "); - diag.span_suggestion_verbose( - tcx.def_span(opaque_def_id).shrink_to_hi(), - format!("add a `use<...>` bound to explicitly capture `{new_lifetime}`",), - format!(" + use<{concatenated_bounds}>"), - Applicability::MachineApplicable, - ); + diag.subdiagnostic(errors::AddPreciseCapturing::New { + span: tcx.def_span(opaque_def_id).shrink_to_hi(), + new_lifetime, + concatenated_bounds, + }); } } From 2c8bbeebf1c630d06e44fa131d1cb0908b5ad56c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 11 Jul 2024 19:15:00 -0400 Subject: [PATCH 09/18] Remove fully_normalize --- .../src/opaque_hidden_inferred_bound.rs | 27 +++++------ .../rustc_trait_selection/src/traits/mod.rs | 46 ++++--------------- .../src/traits/normalize.rs | 8 ++-- .../src/traits/specialize/mod.rs | 29 +++++------- 4 files changed, 36 insertions(+), 74 deletions(-) diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index 5ee73dbfdc658..fdb71ad41a754 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -5,8 +5,7 @@ use rustc_middle::ty::print::{PrintTraitPredicateExt as _, TraitPredPrintModifie use rustc_middle::ty::{self, fold::BottomUpFolder, Ty, TypeFoldable}; use rustc_session::{declare_lint, declare_lint_pass}; use rustc_span::{symbol::kw, Span}; -use rustc_trait_selection::traits; -use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; +use rustc_trait_selection::traits::{self, ObligationCtxt}; use crate::{LateContext, LateLintPass, LintContext}; @@ -130,24 +129,26 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { .iter_instantiated_copied(cx.tcx, proj.projection_term.args) { let assoc_pred = assoc_pred.fold_with(proj_replacer); - let Ok(assoc_pred) = traits::fully_normalize( - infcx, + + let ocx = ObligationCtxt::new(infcx); + let assoc_pred = + ocx.normalize(&traits::ObligationCause::dummy(), cx.param_env, assoc_pred); + if !ocx.select_all_or_error().is_empty() { + // Can't normalize for some reason...? + continue; + } + + ocx.register_obligation(traits::Obligation::new( + cx.tcx, traits::ObligationCause::dummy(), cx.param_env, assoc_pred, - ) else { - continue; - }; + )); // If that predicate doesn't hold modulo regions (but passed during type-check), // then we must've taken advantage of the hack in `project_and_unify_types` where // we replace opaques with inference vars. Emit a warning! - if !infcx.predicate_must_hold_modulo_regions(&traits::Obligation::new( - cx.tcx, - traits::ObligationCause::dummy(), - cx.param_env, - assoc_pred, - )) { + if !ocx.select_all_or_error().is_empty() { // If it's a trait bound and an opaque that doesn't satisfy it, // then we can emit a suggestion to add the bound. let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) { diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 703ff2f7f1698..d28982ed84925 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -271,13 +271,14 @@ fn do_normalize_predicates<'tcx>( // them here too, and we will remove this function when // we move over to lazy normalization *anyway*. let infcx = tcx.infer_ctxt().ignoring_regions().build(); - let predicates = match fully_normalize(&infcx, cause, elaborated_env, predicates) { - Ok(predicates) => predicates, - Err(errors) => { - let reported = infcx.err_ctxt().report_fulfillment_errors(errors); - return Err(reported); - } - }; + let ocx = ObligationCtxt::new_with_diagnostics(&infcx); + let predicates = ocx.normalize(&cause, elaborated_env, predicates); + + let errors = ocx.select_all_or_error(); + if !errors.is_empty() { + let reported = infcx.err_ctxt().report_fulfillment_errors(errors); + return Err(reported); + } debug!("do_normalize_predicates: normalized predicates = {:?}", predicates); @@ -465,37 +466,6 @@ pub fn normalize_param_env_or_error<'tcx>( ty::ParamEnv::new(tcx.mk_clauses(&predicates), unnormalized_env.reveal()) } -/// Normalize a type and process all resulting obligations, returning any errors. -/// -/// FIXME(-Znext-solver): This should be replaced by `At::deeply_normalize` -/// which has the same behavior with the new solver. Because using a separate -/// fulfillment context worsens caching in the old solver, `At::deeply_normalize` -/// is still lazy with the old solver as it otherwise negatively impacts perf. -#[instrument(skip_all)] -pub fn fully_normalize<'tcx, T>( - infcx: &InferCtxt<'tcx>, - cause: ObligationCause<'tcx>, - param_env: ty::ParamEnv<'tcx>, - value: T, -) -> Result>> -where - T: TypeFoldable>, -{ - let ocx = ObligationCtxt::new_with_diagnostics(infcx); - debug!(?value); - let normalized_value = ocx.normalize(&cause, param_env, value); - debug!(?normalized_value); - debug!("select_all_or_error start"); - let errors = ocx.select_all_or_error(); - if !errors.is_empty() { - return Err(errors); - } - debug!("select_all_or_error complete"); - let resolved_value = infcx.resolve_vars_if_possible(normalized_value); - debug!(?resolved_value); - Ok(resolved_value) -} - /// Normalizes the predicates and checks whether they hold in an empty environment. If this /// returns true, then either normalize encountered an error or one of the predicates did not /// hold. Used when creating vtables to check for unsatisfiable methods. diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 3a7481acbafd3..01ba8c02ea6eb 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -42,11 +42,9 @@ impl<'tcx> At<'_, 'tcx> { /// same goals in both a temporary and the shared context which negatively impacts /// performance as these don't share caching. /// - /// FIXME(-Znext-solver): This has the same behavior as `traits::fully_normalize` - /// in the new solver, but because of performance reasons, we currently reuse an - /// existing fulfillment context in the old solver. Once we also eagerly prove goals with - /// the old solver or have removed the old solver, remove `traits::fully_normalize` and - /// rename this function to `At::fully_normalize`. + /// FIXME(-Znext-solver): For performance reasons, we currently reuse an existing + /// fulfillment context in the old solver. Once we have removed the old solver, we + /// can remove the `fulfill_cx` parameter on this function. fn deeply_normalize( self, value: T, diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index 6a904ef487eae..3c33d13567d78 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -18,9 +18,7 @@ use crate::error_reporting::traits::to_pretty_impl_header; use crate::errors::NegativePositiveConflict; use crate::infer::{InferCtxt, InferOk, TyCtxtInferExt}; use crate::traits::select::IntercrateAmbiguityCause; -use crate::traits::{ - self, coherence, FutureCompatOverlapErrorKind, ObligationCause, ObligationCtxt, -}; +use crate::traits::{coherence, FutureCompatOverlapErrorKind, ObligationCause, ObligationCtxt}; use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{codes::*, Diag, EmissionGuarantee}; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -219,19 +217,17 @@ fn fulfill_implication<'tcx>( param_env, source_trait_ref, target_impl ); - let source_trait_ref = - match traits::fully_normalize(infcx, ObligationCause::dummy(), param_env, source_trait_ref) - { - Ok(source_trait_ref) => source_trait_ref, - Err(_errors) => { - infcx.dcx().span_delayed_bug( - infcx.tcx.def_span(source_impl), - format!("failed to fully normalize {source_trait_ref}"), - ); - source_trait_ref - } - }; + let ocx = ObligationCtxt::new(infcx); + let source_trait_ref = ocx.normalize(&ObligationCause::dummy(), param_env, source_trait_ref); + if !ocx.select_all_or_error().is_empty() { + infcx.dcx().span_delayed_bug( + infcx.tcx.def_span(source_impl), + format!("failed to fully normalize {source_trait_ref}"), + ); + } + + let source_trait_ref = infcx.resolve_vars_if_possible(source_trait_ref); let source_trait = ImplSubject::Trait(source_trait_ref); let selcx = SelectionContext::new(infcx); @@ -253,9 +249,6 @@ fn fulfill_implication<'tcx>( return Err(()); }; - // Needs to be `in_snapshot` because this function is used to rebase - // generic parameters, which may happen inside of a select within a probe. - let ocx = ObligationCtxt::new(infcx); // attempt to prove all of the predicates for impl2 given those for impl1 // (which are packed up in penv) ocx.register_obligations(obligations.chain(more_obligations)); From 843f5dd93b3edc65034eb8b9e16673c2bf8e28f2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 11 Jul 2024 19:49:51 -0400 Subject: [PATCH 10/18] Add rustdoc support for use<> in (local) RPITs --- compiler/rustc_hir/src/hir.rs | 7 +++++++ src/librustdoc/clean/mod.rs | 5 +++-- src/librustdoc/clean/simplify.rs | 2 +- src/librustdoc/clean/types.rs | 2 ++ src/librustdoc/html/format.rs | 14 ++++++++++++++ tests/rustdoc/impl-trait-precise-capturing.rs | 14 ++++++++++++++ 6 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 tests/rustdoc/impl-trait-precise-capturing.rs diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index d57fad6ba4c2d..4561f9d9b49df 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2708,6 +2708,13 @@ impl PreciseCapturingArg<'_> { PreciseCapturingArg::Param(param) => param.hir_id, } } + + pub fn name(self) -> Symbol { + match self { + PreciseCapturingArg::Lifetime(lt) => lt.ident.name, + PreciseCapturingArg::Param(param) => param.ident.name, + } + } } /// We need to have a [`Node`] for the [`HirId`] that we attach the type/const param diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index aa596897fc42f..98ce268a77466 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -228,8 +228,9 @@ fn clean_generic_bound<'tcx>( GenericBound::TraitBound(clean_poly_trait_ref(t, cx), modifier) } - // FIXME(precise_capturing): Implement rustdoc support - hir::GenericBound::Use(..) => return None, + hir::GenericBound::Use(args, ..) => { + GenericBound::Use(args.iter().map(|arg| arg.name()).collect()) + } }) } diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 58eef36677b23..1b7d84add1f85 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -79,7 +79,7 @@ pub(crate) fn merge_bounds( !bounds.iter_mut().any(|b| { let trait_ref = match *b { clean::GenericBound::TraitBound(ref mut tr, _) => tr, - clean::GenericBound::Outlives(..) => return false, + clean::GenericBound::Outlives(..) | clean::GenericBound::Use(_) => return false, }; // If this QPath's trait `trait_did` is the same as, or a supertrait // of, the bound's trait `did` then we can keep going, otherwise diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index fe01d17b08a8c..a31adc9949a3f 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1244,6 +1244,8 @@ impl Eq for Attributes {} pub(crate) enum GenericBound { TraitBound(PolyTrait, hir::TraitBoundModifier), Outlives(Lifetime), + /// `use<'a, T>` precise-capturing bound syntax + Use(Vec), } impl GenericBound { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 4268fadd6c59c..9b0b2571ec115 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -412,6 +412,20 @@ impl clean::GenericBound { })?; ty.print(cx).fmt(f) } + clean::GenericBound::Use(args) => { + if f.alternate() { + f.write_str("use<")?; + } else { + f.write_str("use<")?; + } + for (i, arg) in args.iter().enumerate() { + if i > 0 { + write!(f, ", ")?; + } + arg.fmt(f)?; + } + if f.alternate() { f.write_str(">") } else { f.write_str(">") } + } }) } } diff --git a/tests/rustdoc/impl-trait-precise-capturing.rs b/tests/rustdoc/impl-trait-precise-capturing.rs new file mode 100644 index 0000000000000..d1987a555c151 --- /dev/null +++ b/tests/rustdoc/impl-trait-precise-capturing.rs @@ -0,0 +1,14 @@ +#![crate_name = "foo"] +#![feature(precise_capturing)] + +//@ has foo/fn.two.html '//section[@id="main-content"]//pre' "-> impl Sized + use<'b, 'a>" +pub fn two<'a, 'b, 'c>() -> impl Sized + use<'b, 'a /* no 'c */> {} + +//@ has foo/fn.params.html '//section[@id="main-content"]//pre' "-> impl Sized + use<'a, T, N>" +pub fn params<'a, T, const N: usize>() -> impl Sized + use<'a, T, N> {} + +//@ has foo/fn.none.html '//section[@id="main-content"]//pre' "-> impl Sized + use<>" +pub fn none() -> impl Sized + use<> {} + +//@ has foo/fn.first.html '//section[@id="main-content"]//pre' "-> impl use<> + Sized" +pub fn first() -> impl use<> + Sized {} From bd135e487f904e757f6c3d2ebcc2d216ac4d9aaf Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 11 Jul 2024 19:50:03 -0400 Subject: [PATCH 11/18] Add rustdoc-json support for use<> --- rustfmt.toml | 2 ++ src/librustdoc/json/conversions.rs | 1 + src/rustdoc-json-types/lib.rs | 4 +++- src/tools/jsondoclint/src/validator.rs | 1 + tests/rustdoc-json/impl-trait-precise-capturing.rs | 6 ++++++ 5 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/rustdoc-json/impl-trait-precise-capturing.rs diff --git a/rustfmt.toml b/rustfmt.toml index b15ffdca38a06..e060fd8fe8bfa 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -22,6 +22,8 @@ ignore = [ "/tests/rustdoc-ui/", # Some have syntax errors, some are whitespace-sensitive. "/tests/ui/", # Some have syntax errors, some are whitespace-sensitive. "/tests/ui-fulldeps/", # Some are whitespace-sensitive (e.g. `// ~ERROR` comments). + # #[cfg(bootstrap)] so that t-release sees this when they search for it + "/tests/rustdoc-json/impl-trait-precise-capturing.rs", # Do not format submodules. # FIXME: sync submodule list with tidy/bootstrap/etc diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 5111e363c522e..4ab0df3670859 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -542,6 +542,7 @@ impl FromWithTcx for GenericBound { } } Outlives(lifetime) => GenericBound::Outlives(convert_lifetime(lifetime)), + Use(args) => GenericBound::Use(args.into_iter().map(|arg| arg.to_string()).collect()), } } } diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 89115d4d7d667..6fd23b60c8ad6 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use std::path::PathBuf; /// rustdoc format-version. -pub const FORMAT_VERSION: u32 = 31; +pub const FORMAT_VERSION: u32 = 32; /// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information /// about the language items in the local crate, as well as info about external items to allow @@ -538,6 +538,8 @@ pub enum GenericBound { modifier: TraitBoundModifier, }, Outlives(String), + /// `use<'a, T>` precise-capturing bound syntax + Use(Vec), } #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/src/tools/jsondoclint/src/validator.rs b/src/tools/jsondoclint/src/validator.rs index cd011dce7844e..ea1e573384b82 100644 --- a/src/tools/jsondoclint/src/validator.rs +++ b/src/tools/jsondoclint/src/validator.rs @@ -298,6 +298,7 @@ impl<'a> Validator<'a> { generic_params.iter().for_each(|gpd| self.check_generic_param_def(gpd)); } GenericBound::Outlives(_) => {} + GenericBound::Use(_) => {} } } diff --git a/tests/rustdoc-json/impl-trait-precise-capturing.rs b/tests/rustdoc-json/impl-trait-precise-capturing.rs new file mode 100644 index 0000000000000..bf98868d1453d --- /dev/null +++ b/tests/rustdoc-json/impl-trait-precise-capturing.rs @@ -0,0 +1,6 @@ +#![feature(precise_capturing)] + +// @is "$.index[*][?(@.name=='hello')].inner.function.decl.output.impl_trait[1].use[0]" \"\'a\" +// @is "$.index[*][?(@.name=='hello')].inner.function.decl.output.impl_trait[1].use[1]" \"T\" +// @is "$.index[*][?(@.name=='hello')].inner.function.decl.output.impl_trait[1].use[2]" \"N\" +pub fn hello<'a, T, const N: usize>() -> impl Sized + use<'a, T, N> {} From cef8a044ea73f8056d70d4d9f1f90fad47807786 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 4 Jul 2024 16:45:48 -0400 Subject: [PATCH 12/18] rewrite extra-filename-with-temp-outputs to rmake --- src/tools/run-make-support/src/lib.rs | 5 ++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../extra-filename-with-temp-outputs/Makefile | 7 ------ .../extra-filename-with-temp-outputs/rmake.rs | 23 +++++++++++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) delete mode 100644 tests/run-make/extra-filename-with-temp-outputs/Makefile create mode 100644 tests/run-make/extra-filename-with-temp-outputs/rmake.rs diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 5655318267a2f..04b6fd2d6c18d 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -303,6 +303,11 @@ pub fn filename_not_in_denylist, V: AsRef<[String]>>(path: P, exp .is_some_and(|name| !expected.contains(&name.to_str().unwrap().to_owned())) } +/// Returns true if the filename at `path` ends with `suffix`. +pub fn has_suffix>(path: P, suffix: &str) -> bool { + path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().ends_with(suffix)) +} + /// Gathers all files in the current working directory that have the extension `ext`, and counts /// the number of lines within that contain a match with the regex pattern `re`. pub fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str) -> usize { diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 33120cf93f903..1879d60e287a5 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -37,7 +37,6 @@ run-make/extern-fn-with-packed-struct/Makefile run-make/extern-fn-with-union/Makefile run-make/extern-multiple-copies/Makefile run-make/extern-multiple-copies2/Makefile -run-make/extra-filename-with-temp-outputs/Makefile run-make/fmt-write-bloat/Makefile run-make/foreign-double-unwind/Makefile run-make/foreign-exceptions/Makefile diff --git a/tests/run-make/extra-filename-with-temp-outputs/Makefile b/tests/run-make/extra-filename-with-temp-outputs/Makefile deleted file mode 100644 index 64745bef5b869..0000000000000 --- a/tests/run-make/extra-filename-with-temp-outputs/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) -C extra-filename=bar foo.rs -C save-temps - rm $(TMPDIR)/foobar.foo*0.rcgu.o - rm $(TMPDIR)/$(call BIN,foobar) diff --git a/tests/run-make/extra-filename-with-temp-outputs/rmake.rs b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs new file mode 100644 index 0000000000000..546e462499f9f --- /dev/null +++ b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs @@ -0,0 +1,23 @@ +// In order to prevent temporary files from overwriting each other in parallel +// compilation, rustc was changed to mix an extra filename with temporary +// outputs. However, as this is a similar behavior with the codegen flag +// -C extra-filename, this test checks that the manually passed flag +// is not overwritten by this feature, and that the output files +// are named as expected. +// See https://github.com/rust-lang/rust/pull/15686 + +//FIXME(Oneirical): ignore-cross-compile + +use run_make_support::{ + bin_name, cwd, fs_wrapper, has_prefix, has_suffix, rustc, shallow_find_files, +}; + +fn main() { + rustc().extra_filename("bar").input("foo.rs").arg("-Csave-temps").run(); + let object_files = shallow_find_files(cwd(), |path| { + has_prefix(path, "foobar.foo") && has_suffix(path, "0.rcgu.o") + }); + let object_file = object_files.get(0).unwrap(); + fs_wrapper::remove_file(object_file); + fs_wrapper::remove_file(bin_name("foobar")); +} From c6cdbe635b08f278ae2d7f1945dca79b9e69ee9c Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 4 Jul 2024 17:04:20 -0400 Subject: [PATCH 13/18] rewrite and rename issue-85019-moved-src-dir to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../extra-filename-with-temp-outputs/rmake.rs | 2 - .../issue-85019-moved-src-dir/Makefile | 28 -------------- .../main.rs | 0 .../my_lib.rs | 0 .../moved-src-dir-fingerprint-ice/rmake.rs | 38 +++++++++++++++++++ 6 files changed, 38 insertions(+), 31 deletions(-) delete mode 100644 tests/run-make/issue-85019-moved-src-dir/Makefile rename tests/run-make/{issue-85019-moved-src-dir => moved-src-dir-fingerprint-ice}/main.rs (100%) rename tests/run-make/{issue-85019-moved-src-dir => moved-src-dir-fingerprint-ice}/my_lib.rs (100%) create mode 100644 tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 1879d60e287a5..07d047a481514 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -59,7 +59,6 @@ run-make/issue-47551/Makefile run-make/issue-69368/Makefile run-make/issue-83045/Makefile run-make/issue-84395-lto-embed-bitcode/Makefile -run-make/issue-85019-moved-src-dir/Makefile run-make/issue-85401-static-mir/Makefile run-make/issue-88756-default-output/Makefile run-make/issue-97463-abi-param-passing/Makefile diff --git a/tests/run-make/extra-filename-with-temp-outputs/rmake.rs b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs index 546e462499f9f..c39e397a7cb35 100644 --- a/tests/run-make/extra-filename-with-temp-outputs/rmake.rs +++ b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs @@ -6,8 +6,6 @@ // are named as expected. // See https://github.com/rust-lang/rust/pull/15686 -//FIXME(Oneirical): ignore-cross-compile - use run_make_support::{ bin_name, cwd, fs_wrapper, has_prefix, has_suffix, rustc, shallow_find_files, }; diff --git a/tests/run-make/issue-85019-moved-src-dir/Makefile b/tests/run-make/issue-85019-moved-src-dir/Makefile deleted file mode 100644 index dec289058f936..0000000000000 --- a/tests/run-make/issue-85019-moved-src-dir/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -include ../tools.mk - -INCR=$(TMPDIR)/incr -FIRST_SRC=$(TMPDIR)/first_src -SECOND_SRC=$(TMPDIR)/second_src - -# ignore-none no-std is not supported -# ignore-nvptx64-nvidia-cuda FIXME: can't find crate for 'std' - -# Tests that we don't get an ICE when the working directory -# (but not the build directory!) changes between compilation -# sessions - -all: - mkdir $(INCR) - # Build from 'FIRST_SRC' - mkdir $(FIRST_SRC) - cp my_lib.rs $(FIRST_SRC)/my_lib.rs - cp main.rs $(FIRST_SRC)/main.rs - cd $(FIRST_SRC) && \ - $(RUSTC) -C incremental=$(INCR) --crate-type lib my_lib.rs --target $(TARGET) && \ - $(RUSTC) -C incremental=$(INCR) --extern my_lib=$(TMPDIR)/libmy_lib.rlib main.rs --target $(TARGET) - # Build from 'SECOND_SRC', keeping the output directory and incremental directory - # the same - mv $(FIRST_SRC) $(SECOND_SRC) - cd $(SECOND_SRC) && \ - $(RUSTC) -C incremental=$(INCR) --crate-type lib my_lib.rs --target $(TARGET) && \ - $(RUSTC) -C incremental=$(INCR) --extern my_lib=$(TMPDIR)/libmy_lib.rlib main.rs --target $(TARGET) diff --git a/tests/run-make/issue-85019-moved-src-dir/main.rs b/tests/run-make/moved-src-dir-fingerprint-ice/main.rs similarity index 100% rename from tests/run-make/issue-85019-moved-src-dir/main.rs rename to tests/run-make/moved-src-dir-fingerprint-ice/main.rs diff --git a/tests/run-make/issue-85019-moved-src-dir/my_lib.rs b/tests/run-make/moved-src-dir-fingerprint-ice/my_lib.rs similarity index 100% rename from tests/run-make/issue-85019-moved-src-dir/my_lib.rs rename to tests/run-make/moved-src-dir-fingerprint-ice/my_lib.rs diff --git a/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs b/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs new file mode 100644 index 0000000000000..c642602998922 --- /dev/null +++ b/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs @@ -0,0 +1,38 @@ +// A SourceFile created during compilation may have a relative +// path (e.g. if rustc itself is invoked with a relative path). +// When we write out crate metadata, we convert all relative paths +// to absolute paths using the current working directory. +// However, the working directory was previously not included in the crate hash. +// This meant that the crate metadata could change while the crate +// hash remained the same. Among other problems, this could cause a +// fingerprint mismatch ICE, since incremental compilation uses +// the crate metadata hash to determine if a foreign query is green. +// This test checks that we don't get an ICE when the working directory +// (but not the build directory!) changes between compilation +// sessions. +// See https://github.com/rust-lang/rust/issues/85019 + +//@ ignore-none +// Reason: no-std is not supported +//@ ignore-nvptx64-nvidia-cuda +// FIXME: can't find crate for 'std' + +use run_make_support::{fs_wrapper, rust_lib_name, rustc}; + +fn main() { + fs_wrapper::create_dir("incr"); + fs_wrapper::create_dir("first_src"); + fs_wrapper::create_dir("output"); + fs_wrapper::rename("my_lib.rs", "first_src/my_lib.rs"); + fs_wrapper::rename("main.rs", "first_src/main.rs"); + // Build from "first_src" + std::env::set_current_dir("first_src").unwrap(); + rustc().input("my_lib.rs").incremental("incr").crate_type("lib").run(); + rustc().input("main.rs").incremental("incr").extern_("my_lib", rust_lib_name("my_lib")).run(); + std::env::set_current_dir("..").unwrap(); + fs_wrapper::rename("first_src", "second_src"); + std::env::set_current_dir("second_src").unwrap(); + // Build from "second_src" - the output and incremental directory remain identical + rustc().input("my_lib.rs").incremental("incr").crate_type("lib").run(); + rustc().input("main.rs").incremental("incr").extern_("my_lib", rust_lib_name("my_lib")).run(); +} From f768db6ba6d8415fab3bd51ec85ebf41f2209f7e Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 5 Jul 2024 15:07:15 -0400 Subject: [PATCH 14/18] rewrite and rename issue-83045 to rmake --- .../a.rs | 0 .../b.rs | 0 .../c.rs | 0 .../run-make/ice-dep-cannot-find-dep/rmake.rs | 39 +++++++++++++++++++ tests/run-make/issue-83045/Makefile | 33 ---------------- 5 files changed, 39 insertions(+), 33 deletions(-) rename tests/run-make/{issue-83045 => ice-dep-cannot-find-dep}/a.rs (100%) rename tests/run-make/{issue-83045 => ice-dep-cannot-find-dep}/b.rs (100%) rename tests/run-make/{issue-83045 => ice-dep-cannot-find-dep}/c.rs (100%) create mode 100644 tests/run-make/ice-dep-cannot-find-dep/rmake.rs delete mode 100644 tests/run-make/issue-83045/Makefile diff --git a/tests/run-make/issue-83045/a.rs b/tests/run-make/ice-dep-cannot-find-dep/a.rs similarity index 100% rename from tests/run-make/issue-83045/a.rs rename to tests/run-make/ice-dep-cannot-find-dep/a.rs diff --git a/tests/run-make/issue-83045/b.rs b/tests/run-make/ice-dep-cannot-find-dep/b.rs similarity index 100% rename from tests/run-make/issue-83045/b.rs rename to tests/run-make/ice-dep-cannot-find-dep/b.rs diff --git a/tests/run-make/issue-83045/c.rs b/tests/run-make/ice-dep-cannot-find-dep/c.rs similarity index 100% rename from tests/run-make/issue-83045/c.rs rename to tests/run-make/ice-dep-cannot-find-dep/c.rs diff --git a/tests/run-make/ice-dep-cannot-find-dep/rmake.rs b/tests/run-make/ice-dep-cannot-find-dep/rmake.rs new file mode 100644 index 0000000000000..4256831a1eea3 --- /dev/null +++ b/tests/run-make/ice-dep-cannot-find-dep/rmake.rs @@ -0,0 +1,39 @@ +// This test case creates a situation where the crate loader would run +// into an ICE (internal compiler error) when confronted with an invalid setup where it cannot +// find the dependency of a direct dependency. +// +// The test case makes sure that the compiler produces the expected +// error message but does not ICE immediately after. +// +// See https://github.com/rust-lang/rust/issues/83045 + +//@ only-x86_64 +//@ only-linux +// Reason: This is a platform-independent issue, no need to waste time testing +// everywhere. + +// NOTE: We use `bare_rustc` below so that the compiler can't find liba.rlib +// If we used `rustc` the additional '-L rmake_out' option would allow rustc to +// actually find the crate. + +use run_make_support::{bare_rustc, fs_wrapper, rust_lib_name, rustc}; + +fn main() { + rustc().crate_name("a").crate_type("rlib").input("a.rs").arg("--verbose").run(); + rustc() + .crate_name("b") + .crate_type("rlib") + .extern_("a", rust_lib_name("a")) + .input("b.rs") + .arg("--verbose") + .run(); + fs_wrapper::create_dir("wrong_directory"); + bare_rustc() + .extern_("b", rust_lib_name("b")) + .crate_type("rlib") + .edition("2018") + .input("c.rs") + .run_fail() + .assert_stderr_contains("E0463") + .assert_stderr_not_contains("internal compiler error"); +} diff --git a/tests/run-make/issue-83045/Makefile b/tests/run-make/issue-83045/Makefile deleted file mode 100644 index b76e184b610c5..0000000000000 --- a/tests/run-make/issue-83045/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -include ../tools.mk - -# This test case creates a situation where the crate loader would run -# into an ICE when confronted with an invalid setup where it cannot -# find the dependency of a direct dependency. -# -# The test case makes sure that the compiler produces the expected -# error message but does not ICE immediately after. -# -# See https://github.com/rust-lang/rust/issues/83045 - -# This is a platform-independent issue, no need to waste time testing -# everywhere. -# only-x86_64 -# only-linux - -# NOTE: We use BARE_RUSTC below so that the compiler can't find liba.rlib -# If we used RUSTC the additional '-L TMPDIR' option would allow rustc to -# actually find the crate. -# -# We check that we get the expected error message -# But that we do not get an ICE - -all: - $(RUSTC) --crate-name=a --crate-type=rlib a.rs --verbose - $(RUSTC) --crate-name=b --crate-type=rlib --extern a=$(TMPDIR)/liba.rlib b.rs --verbose - $(BARE_RUSTC) --out-dir $(TMPDIR) \ - --extern b=$(TMPDIR)/libb.rlib \ - --crate-type=rlib \ - --edition=2018 \ - c.rs 2>&1 | tee $(TMPDIR)/output.txt || exit 0 - $(CGREP) E0463 < $(TMPDIR)/output.txt - $(CGREP) -v "internal compiler error" < $(TMPDIR)/output.txt From 87c7a42ba92d341c6d4a330a5d4c02b839158c1e Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 5 Jul 2024 15:14:55 -0400 Subject: [PATCH 15/18] rewrite rustc-macro-dep-files to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/rustc-macro-dep-files/Makefile | 11 ----------- tests/run-make/rustc-macro-dep-files/rmake.rs | 13 +++++++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) delete mode 100644 tests/run-make/rustc-macro-dep-files/Makefile create mode 100644 tests/run-make/rustc-macro-dep-files/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 33120cf93f903..22edea79adf2f 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -116,7 +116,6 @@ run-make/return-non-c-like-enum-from-c/Makefile run-make/rlib-format-packed-bundled-libs-2/Makefile run-make/rlib-format-packed-bundled-libs-3/Makefile run-make/rlib-format-packed-bundled-libs/Makefile -run-make/rustc-macro-dep-files/Makefile run-make/sanitizer-cdylib-link/Makefile run-make/sanitizer-dylib-link/Makefile run-make/sanitizer-staticlib-link/Makefile diff --git a/tests/run-make/rustc-macro-dep-files/Makefile b/tests/run-make/rustc-macro-dep-files/Makefile deleted file mode 100644 index 76d713c4bb3c4..0000000000000 --- a/tests/run-make/rustc-macro-dep-files/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -include ../tools.mk - -# FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC` -# instead of hardcoding them everywhere they're needed. -ifeq ($(IS_MUSL_HOST),1) -ADDITIONAL_ARGS := $(RUSTFLAGS) -endif -all: - $(BARE_RUSTC) $(ADDITIONAL_ARGS) foo.rs --out-dir $(TMPDIR) - $(RUSTC) bar.rs --target $(TARGET) --emit dep-info - $(CGREP) -v "proc-macro source" < $(TMPDIR)/bar.d diff --git a/tests/run-make/rustc-macro-dep-files/rmake.rs b/tests/run-make/rustc-macro-dep-files/rmake.rs new file mode 100644 index 0000000000000..b90e719b7d68a --- /dev/null +++ b/tests/run-make/rustc-macro-dep-files/rmake.rs @@ -0,0 +1,13 @@ +// --emit dep-info used to print all macro-generated code it could +// find as if it was part of a nonexistent file named "proc-macro source", +// which is not a valid path. After this was fixed in #36776, this test checks +// that macro code is not falsely seen as coming from a different file in dep-info. +// See https://github.com/rust-lang/rust/issues/36625 + +use run_make_support::{fs_wrapper, rustc, target}; + +fn main() { + rustc().input("foo.rs").run(); + rustc().input("bar.rs").target(target()).emit("dep-info").run(); + assert!(!fs_wrapper::read_to_string("bar.d").contains("proc-macro source")); +} From fe76650144a6da47583d50e6df8021bcf94e37d1 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 5 Jul 2024 15:26:29 -0400 Subject: [PATCH 16/18] rewrite env-dep-info to rmake --- src/tools/run-make-support/src/rustc.rs | 9 +++++--- .../tidy/src/allowed_run_make_makefiles.txt | 2 -- tests/run-make/env-dep-info/Makefile | 19 ----------------- tests/run-make/env-dep-info/correct_macro.d | 6 ++++++ tests/run-make/env-dep-info/correct_main.d | 8 +++++++ tests/run-make/env-dep-info/rmake.rs | 21 +++++++++++++++++++ .../run-make/ice-dep-cannot-find-dep/rmake.rs | 1 - .../run-make/rustc-macro-dep-files/correct.d | 3 +++ tests/run-make/rustc-macro-dep-files/rmake.rs | 5 +++-- 9 files changed, 47 insertions(+), 27 deletions(-) delete mode 100644 tests/run-make/env-dep-info/Makefile create mode 100644 tests/run-make/env-dep-info/correct_macro.d create mode 100644 tests/run-make/env-dep-info/correct_main.d create mode 100644 tests/run-make/env-dep-info/rmake.rs create mode 100644 tests/run-make/rustc-macro-dep-files/correct.d diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index a2a7c8064dca1..ae200d5143107 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -4,13 +4,15 @@ use std::path::Path; use crate::{command, cwd, env_var, set_host_rpath}; -/// Construct a new `rustc` invocation. +/// Construct a new `rustc` invocation. This will automatically set the library +/// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this. #[track_caller] pub fn rustc() -> Rustc { Rustc::new() } -/// Construct a plain `rustc` invocation with no flags set. +/// Construct a plain `rustc` invocation with no flags set. Note that [`set_host_rpath`] +/// still presets the environment variable `HOST_RPATH_DIR` by default. #[track_caller] pub fn bare_rustc() -> Rustc { Rustc::bare() @@ -42,7 +44,8 @@ fn setup_common() -> Command { impl Rustc { // `rustc` invocation constructor methods - /// Construct a new `rustc` invocation. + /// Construct a new `rustc` invocation. This will automatically set the library + /// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this. #[track_caller] pub fn new() -> Self { let mut cmd = setup_common(); diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 22edea79adf2f..b8e203fe0ea47 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -23,7 +23,6 @@ run-make/dep-info/Makefile run-make/dump-ice-to-disk/Makefile run-make/dump-mono-stats/Makefile run-make/emit-to-stdout/Makefile -run-make/env-dep-info/Makefile run-make/export-executable-symbols/Makefile run-make/extern-diff-internal-name/Makefile run-make/extern-flag-disambiguates/Makefile @@ -58,7 +57,6 @@ run-make/issue-35164/Makefile run-make/issue-36710/Makefile run-make/issue-47551/Makefile run-make/issue-69368/Makefile -run-make/issue-83045/Makefile run-make/issue-84395-lto-embed-bitcode/Makefile run-make/issue-85019-moved-src-dir/Makefile run-make/issue-85401-static-mir/Makefile diff --git a/tests/run-make/env-dep-info/Makefile b/tests/run-make/env-dep-info/Makefile deleted file mode 100644 index bc0ffc2df1e0b..0000000000000 --- a/tests/run-make/env-dep-info/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -include ../tools.mk - -# FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC` -# instead of hardcoding them everywhere they're needed. -ifeq ($(IS_MUSL_HOST),1) -ADDITIONAL_ARGS := $(RUSTFLAGS) -endif - -all: - EXISTING_ENV=1 EXISTING_OPT_ENV=1 $(RUSTC) --emit dep-info main.rs - $(CGREP) "# env-dep:EXISTING_ENV=1" < $(TMPDIR)/main.d - $(CGREP) "# env-dep:EXISTING_OPT_ENV=1" < $(TMPDIR)/main.d - $(CGREP) "# env-dep:NONEXISTENT_OPT_ENV" < $(TMPDIR)/main.d - $(CGREP) "# env-dep:ESCAPE\nESCAPE\\" < $(TMPDIR)/main.d - # Proc macro - $(BARE_RUSTC) $(ADDITIONAL_ARGS) --out-dir $(TMPDIR) macro_def.rs - EXISTING_PROC_MACRO_ENV=1 $(RUSTC) --emit dep-info macro_use.rs - $(CGREP) "# env-dep:EXISTING_PROC_MACRO_ENV=1" < $(TMPDIR)/macro_use.d - $(CGREP) "# env-dep:NONEXISTENT_PROC_MACEO_ENV" < $(TMPDIR)/macro_use.d diff --git a/tests/run-make/env-dep-info/correct_macro.d b/tests/run-make/env-dep-info/correct_macro.d new file mode 100644 index 0000000000000..edfe0e632024a --- /dev/null +++ b/tests/run-make/env-dep-info/correct_macro.d @@ -0,0 +1,6 @@ +macro_use.d: macro_use.rs + +macro_use.rs: + +# env-dep:EXISTING_PROC_MACRO_ENV=1 +# env-dep:NONEXISTENT_PROC_MACEO_ENV diff --git a/tests/run-make/env-dep-info/correct_main.d b/tests/run-make/env-dep-info/correct_main.d new file mode 100644 index 0000000000000..ef89729841d89 --- /dev/null +++ b/tests/run-make/env-dep-info/correct_main.d @@ -0,0 +1,8 @@ +main.d: main.rs + +main.rs: + +# env-dep:ESCAPE\nESCAPE\\ +# env-dep:EXISTING_ENV=1 +# env-dep:EXISTING_OPT_ENV=1 +# env-dep:NONEXISTENT_OPT_ENV diff --git a/tests/run-make/env-dep-info/rmake.rs b/tests/run-make/env-dep-info/rmake.rs new file mode 100644 index 0000000000000..5b51a5476f491 --- /dev/null +++ b/tests/run-make/env-dep-info/rmake.rs @@ -0,0 +1,21 @@ +// Inside dep-info emit files, #71858 made it so all accessed environment +// variables are usefully printed. This test checks that this feature works +// as intended by checking if the environment variables used in compilation +// appear in the output dep-info files. +// See https://github.com/rust-lang/rust/issues/40364 + +use run_make_support::{diff, rustc}; + +fn main() { + rustc() + .env("EXISTING_ENV", "1") + .env("EXISTING_OPT_ENV", "1") + .emit("dep-info") + .input("main.rs") + .run(); + diff().expected_file("correct_main.d").actual_file("main.d").run(); + // Procedural macro + rustc().input("macro_def.rs").run(); + rustc().env("EXISTING_PROC_MACRO_ENV", "1").emit("dep-info").input("macro_use.rs").run(); + diff().expected_file("correct_macro.d").actual_file("macro_use.d").run(); +} diff --git a/tests/run-make/ice-dep-cannot-find-dep/rmake.rs b/tests/run-make/ice-dep-cannot-find-dep/rmake.rs index 4256831a1eea3..33c755bddd7bf 100644 --- a/tests/run-make/ice-dep-cannot-find-dep/rmake.rs +++ b/tests/run-make/ice-dep-cannot-find-dep/rmake.rs @@ -27,7 +27,6 @@ fn main() { .input("b.rs") .arg("--verbose") .run(); - fs_wrapper::create_dir("wrong_directory"); bare_rustc() .extern_("b", rust_lib_name("b")) .crate_type("rlib") diff --git a/tests/run-make/rustc-macro-dep-files/correct.d b/tests/run-make/rustc-macro-dep-files/correct.d new file mode 100644 index 0000000000000..8cb708fff61b5 --- /dev/null +++ b/tests/run-make/rustc-macro-dep-files/correct.d @@ -0,0 +1,3 @@ +bar.d: bar.rs + +bar.rs: diff --git a/tests/run-make/rustc-macro-dep-files/rmake.rs b/tests/run-make/rustc-macro-dep-files/rmake.rs index b90e719b7d68a..bc02a04c9b8f1 100644 --- a/tests/run-make/rustc-macro-dep-files/rmake.rs +++ b/tests/run-make/rustc-macro-dep-files/rmake.rs @@ -4,10 +4,11 @@ // that macro code is not falsely seen as coming from a different file in dep-info. // See https://github.com/rust-lang/rust/issues/36625 -use run_make_support::{fs_wrapper, rustc, target}; +use run_make_support::{diff, rustc, target}; fn main() { rustc().input("foo.rs").run(); rustc().input("bar.rs").target(target()).emit("dep-info").run(); - assert!(!fs_wrapper::read_to_string("bar.d").contains("proc-macro source")); + // The emitted file should not contain "proc-macro source". + diff().expected_file("correct.d").actual_file("bar.d").run(); } From 2772f897976f01133d22cd730d0eda5346efa73a Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 12 Jul 2024 13:53:58 -0400 Subject: [PATCH 17/18] Rename the internal `const_strlen` to just `strlen` Since the libs and lang teams completed an FCP to allow for const `strlen` ([1]), currently implemented with `const_eval_select`, there is no longer any reason to avoid this specific function or use it only in const. Rename it to reflect this status change. [1]: https://github.com/rust-lang/rust/issues/113219#issuecomment-2016939401 --- library/core/src/ffi/c_str.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index dc2a5803a1b20..76752f22ed89a 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -282,7 +282,7 @@ impl CStr { pub const unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr { // SAFETY: The caller has provided a pointer that points to a valid C // string with a NUL terminator less than `isize::MAX` from `ptr`. - let len = unsafe { const_strlen(ptr) }; + let len = unsafe { strlen(ptr) }; // SAFETY: The caller has provided a valid pointer with length less than // `isize::MAX`, so `from_raw_parts` is safe. The content remains valid @@ -743,7 +743,7 @@ impl AsRef for CStr { #[unstable(feature = "cstr_internals", issue = "none")] #[rustc_const_stable(feature = "const_cstr_from_ptr", since = "CURRENT_RUSTC_VERSION")] #[rustc_allow_const_fn_unstable(const_eval_select)] -const unsafe fn const_strlen(ptr: *const c_char) -> usize { +const unsafe fn strlen(ptr: *const c_char) -> usize { const fn strlen_ct(s: *const c_char) -> usize { let mut len = 0; From 1fd0311eabd9d1307b21eafd2a5e9227b91dfb9a Mon Sep 17 00:00:00 2001 From: sayantn Date: Fri, 12 Jul 2024 23:30:22 +0530 Subject: [PATCH 18/18] Added the `xop` target feature and `xop_target_feature` gate --- compiler/rustc_codegen_ssa/src/target_features.rs | 1 + compiler/rustc_feature/src/unstable.rs | 2 ++ compiler/rustc_span/src/symbol.rs | 1 + compiler/rustc_target/src/target_features.rs | 1 + tests/ui/check-cfg/mix.stderr | 2 +- tests/ui/check-cfg/well-known-values.stderr | 2 +- .../feature-gate-xop_target_feature.rs | 6 ++++++ .../feature-gate-xop_target_feature.stderr | 13 +++++++++++++ 8 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/ui/feature-gates/feature-gate-xop_target_feature.rs create mode 100644 tests/ui/feature-gates/feature-gate-xop_target_feature.stderr diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 22006c0b4712a..cea164df61735 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -81,6 +81,7 @@ pub fn from_target_feature( Some(sym::lahfsahf_target_feature) => rust_features.lahfsahf_target_feature, Some(sym::prfchw_target_feature) => rust_features.prfchw_target_feature, Some(sym::x86_amx_intrinsics) => rust_features.x86_amx_intrinsics, + Some(sym::xop_target_feature) => rust_features.xop_target_feature, Some(name) => bug!("unknown target feature gate {}", name), None => true, }; diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index dfbe270822c0a..5673101dc2448 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -642,6 +642,8 @@ declare_features! ( (unstable, used_with_arg, "1.60.0", Some(93798)), /// Allows use of x86 `AMX` target-feature attributes and intrinsics (unstable, x86_amx_intrinsics, "CURRENT_RUSTC_VERSION", Some(126622)), + /// Allows use of the `xop` target-feature + (unstable, xop_target_feature, "CURRENT_RUSTC_VERSION", Some(127208)), /// Allows `do yeet` expressions (unstable, yeet_expr, "1.62.0", Some(96373)), // !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 827b9062d83ab..2fe7c951793f7 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2076,6 +2076,7 @@ symbols! { x87_reg, xer, xmm_reg, + xop_target_feature, yeet_desugar_details, yeet_expr, yes, diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index aec2828181b91..6667efb14e2d6 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -246,6 +246,7 @@ const X86_ALLOWED_FEATURES: &[(&str, Stability)] = &[ ("tbm", Unstable(sym::tbm_target_feature)), ("vaes", Unstable(sym::avx512_target_feature)), ("vpclmulqdq", Unstable(sym::avx512_target_feature)), + ("xop", Unstable(sym::xop_target_feature)), ("xsave", Stable), ("xsavec", Stable), ("xsaveopt", Stable), diff --git a/tests/ui/check-cfg/mix.stderr b/tests/ui/check-cfg/mix.stderr index 15b0100d7d23b..00a97ca1488af 100644 --- a/tests/ui/check-cfg/mix.stderr +++ b/tests/ui/check-cfg/mix.stderr @@ -251,7 +251,7 @@ warning: unexpected `cfg` condition value: `zebra` LL | cfg!(target_feature = "zebra"); | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, and `avx512vpopcntdq` and 196 more + = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, and `avx512vpopcntdq` and 197 more = note: see for more information about checking conditional configuration warning: 27 warnings emitted diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index c35fb68c839dd..78b7f0f5d997f 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -165,7 +165,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_feature = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, `avx512vpopcntdq`, `avxifma`, `avxneconvert`, `avxvnni`, `avxvnniint16`, `avxvnniint8`, `bf16`, `bmi1`, `bmi2`, `bti`, `bulk-memory`, `c`, `cache`, `cmpxchg16b`, `crc`, `crt-static`, `d`, `d32`, `dit`, `doloop`, `dotprod`, `dpb`, `dpb2`, `dsp`, `dsp1e2`, `dspe60`, `e`, `e1`, `e2`, `edsp`, `elrw`, `ermsb`, `exception-handling`, `extended-const`, `f`, `f16c`, `f32mm`, `f64mm`, `fcma`, `fdivdu`, `fhm`, `flagm`, `float1e2`, `float1e3`, `float3e4`, `float7e60`, `floate1`, `fma`, `fp-armv8`, `fp16`, `fp64`, `fpuv2_df`, `fpuv2_sf`, `fpuv3_df`, `fpuv3_hf`, `fpuv3_hi`, `fpuv3_sf`, `frecipe`, `frintts`, `fxsr`, `gfni`, `hard-float`, `hard-float-abi`, `hard-tp`, `high-registers`, `hvx`, `hvx-length128b`, `hwdiv`, `i8mm`, `jsconv`, `lahfsahf`, `lasx`, `lbt`, `lor`, `lse`, `lsx`, `lvz`, `lzcnt`, `m`, `mclass`, `movbe`, `mp`, `mp1e2`, `msa`, `mte`, `multivalue`, `mutable-globals`, `neon`, `nontrapping-fptoint`, `nvic`, `paca`, `pacg`, `pan`, `pclmulqdq`, `pmuv3`, `popcnt`, `power10-vector`, `power8-altivec`, `power8-vector`, `power9-altivec`, `power9-vector`, `prfchw`, `rand`, `ras`, `rclass`, `rcpc`, `rcpc2`, `rdm`, `rdrand`, `rdseed`, `reference-types`, `relax`, `relaxed-simd`, `rtm`, `sb`, `sha`, `sha2`, `sha3`, `sign-ext`, `simd128`, `sm4`, `spe`, `ssbs`, `sse`, `sse2`, `sse3`, `sse4.1`, `sse4.2`, `sse4a`, `ssse3`, `sve`, `sve2`, `sve2-aes`, `sve2-bitperm`, `sve2-sha3`, `sve2-sm4`, `tbm`, `thumb-mode`, `thumb2`, `tme`, `trust`, `trustzone`, `ual`, `unaligned-scalar-mem`, `v`, `v5te`, `v6`, `v6k`, `v6t2`, `v7`, `v8`, `v8.1a`, `v8.2a`, `v8.3a`, `v8.4a`, `v8.5a`, `v8.6a`, `v8.7a`, `vaes`, `vdsp2e60f`, `vdspv1`, `vdspv2`, `vfp2`, `vfp3`, `vfp4`, `vh`, `virt`, `virtualization`, `vpclmulqdq`, `vsx`, `xsave`, `xsavec`, `xsaveopt`, `xsaves`, `zba`, `zbb`, `zbc`, `zbkb`, `zbkc`, `zbkx`, `zbs`, `zdinx`, `zfh`, `zfhmin`, `zfinx`, `zhinx`, `zhinxmin`, `zk`, `zkn`, `zknd`, `zkne`, `zknh`, `zkr`, `zks`, `zksed`, `zksh`, and `zkt` + = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, `avx512vpopcntdq`, `avxifma`, `avxneconvert`, `avxvnni`, `avxvnniint16`, `avxvnniint8`, `bf16`, `bmi1`, `bmi2`, `bti`, `bulk-memory`, `c`, `cache`, `cmpxchg16b`, `crc`, `crt-static`, `d`, `d32`, `dit`, `doloop`, `dotprod`, `dpb`, `dpb2`, `dsp`, `dsp1e2`, `dspe60`, `e`, `e1`, `e2`, `edsp`, `elrw`, `ermsb`, `exception-handling`, `extended-const`, `f`, `f16c`, `f32mm`, `f64mm`, `fcma`, `fdivdu`, `fhm`, `flagm`, `float1e2`, `float1e3`, `float3e4`, `float7e60`, `floate1`, `fma`, `fp-armv8`, `fp16`, `fp64`, `fpuv2_df`, `fpuv2_sf`, `fpuv3_df`, `fpuv3_hf`, `fpuv3_hi`, `fpuv3_sf`, `frecipe`, `frintts`, `fxsr`, `gfni`, `hard-float`, `hard-float-abi`, `hard-tp`, `high-registers`, `hvx`, `hvx-length128b`, `hwdiv`, `i8mm`, `jsconv`, `lahfsahf`, `lasx`, `lbt`, `lor`, `lse`, `lsx`, `lvz`, `lzcnt`, `m`, `mclass`, `movbe`, `mp`, `mp1e2`, `msa`, `mte`, `multivalue`, `mutable-globals`, `neon`, `nontrapping-fptoint`, `nvic`, `paca`, `pacg`, `pan`, `pclmulqdq`, `pmuv3`, `popcnt`, `power10-vector`, `power8-altivec`, `power8-vector`, `power9-altivec`, `power9-vector`, `prfchw`, `rand`, `ras`, `rclass`, `rcpc`, `rcpc2`, `rdm`, `rdrand`, `rdseed`, `reference-types`, `relax`, `relaxed-simd`, `rtm`, `sb`, `sha`, `sha2`, `sha3`, `sign-ext`, `simd128`, `sm4`, `spe`, `ssbs`, `sse`, `sse2`, `sse3`, `sse4.1`, `sse4.2`, `sse4a`, `ssse3`, `sve`, `sve2`, `sve2-aes`, `sve2-bitperm`, `sve2-sha3`, `sve2-sm4`, `tbm`, `thumb-mode`, `thumb2`, `tme`, `trust`, `trustzone`, `ual`, `unaligned-scalar-mem`, `v`, `v5te`, `v6`, `v6k`, `v6t2`, `v7`, `v8`, `v8.1a`, `v8.2a`, `v8.3a`, `v8.4a`, `v8.5a`, `v8.6a`, `v8.7a`, `vaes`, `vdsp2e60f`, `vdspv1`, `vdspv2`, `vfp2`, `vfp3`, `vfp4`, `vh`, `virt`, `virtualization`, `vpclmulqdq`, `vsx`, `xop`, `xsave`, `xsavec`, `xsaveopt`, `xsaves`, `zba`, `zbb`, `zbc`, `zbkb`, `zbkc`, `zbkx`, `zbs`, `zdinx`, `zfh`, `zfhmin`, `zfinx`, `zhinx`, `zhinxmin`, `zk`, `zkn`, `zknd`, `zkne`, `zknh`, `zkr`, `zks`, `zksed`, `zksh`, and `zkt` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` diff --git a/tests/ui/feature-gates/feature-gate-xop_target_feature.rs b/tests/ui/feature-gates/feature-gate-xop_target_feature.rs new file mode 100644 index 0000000000000..3032a6fbb4755 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-xop_target_feature.rs @@ -0,0 +1,6 @@ +//@ only-x86_64 +#[target_feature(enable = "xop")] +//~^ ERROR: currently unstable +unsafe fn foo() {} + +fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-xop_target_feature.stderr b/tests/ui/feature-gates/feature-gate-xop_target_feature.stderr new file mode 100644 index 0000000000000..58f7b0b3b002a --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-xop_target_feature.stderr @@ -0,0 +1,13 @@ +error[E0658]: the target feature `xop` is currently unstable + --> $DIR/feature-gate-xop_target_feature.rs:2:18 + | +LL | #[target_feature(enable = "xop")] + | ^^^^^^^^^^^^^^ + | + = note: see issue #127208 for more information + = help: add `#![feature(xop_target_feature)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0658`.