From ac670721c90985af11ddfe7d00b6ffcb8b5d226d Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 24 Jun 2024 16:22:47 -0700 Subject: [PATCH 1/8] test: dont optimize to invalid bitcasts --- tests/ui/simd/dont-invalid-bitcast-masks.rs | 17 ++++++++++++ tests/ui/simd/dont-invalid-bitcast-x86_64.rs | 27 ++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/ui/simd/dont-invalid-bitcast-masks.rs create mode 100644 tests/ui/simd/dont-invalid-bitcast-x86_64.rs diff --git a/tests/ui/simd/dont-invalid-bitcast-masks.rs b/tests/ui/simd/dont-invalid-bitcast-masks.rs new file mode 100644 index 00000000000..3d8376207cd --- /dev/null +++ b/tests/ui/simd/dont-invalid-bitcast-masks.rs @@ -0,0 +1,17 @@ +//@ build-pass +//@ compile-flags: -Copt-level=3 + +// regression test for https://github.com/rust-lang/rust/issues/110722 +// in --release we were optimizing to invalid bitcasts, due to a combination of MIR inlining and +// mostly bad repr(simd) lowering which prevented even basic splats from working +#![crate_type = "rlib"] +#![feature(portable_simd)] +use std::simd::*; +use std::simd::num::*; + +pub unsafe fn mask_to_array(mask: u8) -> [i32; 8] { + let mut output = [0; 8]; + let m = masksizex8::from_bitmask(mask as _); + output.copy_from_slice(&m.to_int().cast::().to_array()); + output +} diff --git a/tests/ui/simd/dont-invalid-bitcast-x86_64.rs b/tests/ui/simd/dont-invalid-bitcast-x86_64.rs new file mode 100644 index 00000000000..e6e435bcfc9 --- /dev/null +++ b/tests/ui/simd/dont-invalid-bitcast-x86_64.rs @@ -0,0 +1,27 @@ +//@ build-pass +//@ compile-flags: -Copt-level=3 +//@ only-x86_64 +// ignore-tidy-linelength + +// regression test for https://github.com/rust-lang/rust/issues/110707 +// in --release we were optimizing to invalid bitcasts, due to a combination of MIR inlining and +// mostly bad repr(simd) lowering which prevented even basic splats from working + +#![crate_type = "rlib"] +#![feature(portable_simd)] +use std::simd::*; +use std::arch::x86_64::*; + +#[target_feature(enable = "sse4.1")] +pub unsafe fn fast_round_sse(i: f32x8) -> f32x8 { + let a = i.to_array(); + let [low, high]: [[f32; 4]; 2] = + unsafe { std::mem::transmute::<[f32; 8], [[f32; 4]; 2]>(a) }; + + let low = f32x4::from(_mm_round_ps::<{_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC}>(f32x4::from_array(low).into())); + let high = f32x4::from(_mm_round_ps::<{_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC}>(f32x4::from_array(high).into())); + + let a: [f32; 8] = + unsafe { std::mem::transmute::<[[f32; 4]; 2], [f32; 8]>([low.to_array(), high.to_array()]) }; + f32x8::from_array(a) +} From 4061fd9e4e415f4c09b221895039c7c9d9d8eb9e Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 28 Jun 2024 18:15:12 +0100 Subject: [PATCH 2/8] Reduce merge conflicts from rustfmt's wrapping --- compiler/rustc_interface/src/tests.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 02322c9b282..9bd67a1154b 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -2,14 +2,22 @@ use crate::interface::{initialize_checked_jobserver, parse_cfg}; use rustc_data_structures::profiling::TimePassesFormat; use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig}; +use rustc_session::config::{build_configuration, build_session_options, rustc_optgroups}; use rustc_session::config::{ - build_configuration, build_session_options, rustc_optgroups, BranchProtection, CFGuard, Cfg, - CollapseMacroDebuginfo, CoverageLevel, CoverageOptions, DebugInfo, DumpMonoStatsFormat, - ErrorOutputType, ExternEntry, ExternLocation, Externs, FunctionReturn, InliningThreshold, - Input, InstrumentCoverage, InstrumentXRay, LinkSelfContained, LinkerPluginLto, LocationDetail, - LtoCli, NextSolverConfig, OomStrategy, Options, OutFileName, OutputType, OutputTypes, PAuthKey, - PacRet, Passes, PatchableFunctionEntry, Polonius, ProcMacroExecutionStrategy, Strip, - SwitchWithOptPath, SymbolManglingVersion, WasiExecModel, + BranchProtection, CFGuard, Cfg, CollapseMacroDebuginfo, CoverageLevel, CoverageOptions, + DebugInfo, DumpMonoStatsFormat, ErrorOutputType, +}; +use rustc_session::config::{ + ExternEntry, ExternLocation, Externs, FunctionReturn, InliningThreshold, Input, + InstrumentCoverage, InstrumentXRay, LinkSelfContained, LinkerPluginLto, +}; +use rustc_session::config::{ + LocationDetail, LtoCli, NextSolverConfig, OomStrategy, Options, OutFileName, OutputType, + OutputTypes, PAuthKey, PacRet, Passes, PatchableFunctionEntry, +}; +use rustc_session::config::{ + Polonius, ProcMacroExecutionStrategy, Strip, SwitchWithOptPath, SymbolManglingVersion, + WasiExecModel, }; use rustc_session::lint::Level; use rustc_session::search_paths::SearchPath; From c9f36f8cd7a6b0c76b5c99e12e888405fffdb829 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 28 Jun 2024 19:05:01 -0700 Subject: [PATCH 3/8] Only update `Eq` operands in GVN if you can update both sides Otherwise the types might not match Fixes 127089 --- compiler/rustc_mir_transform/src/gvn.rs | 10 ++-- .../gvn_ptr_eq_with_constant.main.GVN.diff | 52 +++++++++++++++++++ tests/mir-opt/gvn_ptr_eq_with_constant.rs | 23 ++++++++ 3 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff create mode 100644 tests/mir-opt/gvn_ptr_eq_with_constant.rs diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 936a7e2d9de..3dbdeb615cf 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -1074,11 +1074,11 @@ fn simplify_binary( { lhs = *lhs_value; rhs = *rhs_value; - if let Some(op) = self.try_as_operand(lhs, location) { - *lhs_operand = op; - } - if let Some(op) = self.try_as_operand(rhs, location) { - *rhs_operand = op; + if let Some(lhs_op) = self.try_as_operand(lhs, location) + && let Some(rhs_op) = self.try_as_operand(rhs, location) + { + *lhs_operand = lhs_op; + *rhs_operand = rhs_op; } } diff --git a/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff b/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff new file mode 100644 index 00000000000..3af78d9b6ce --- /dev/null +++ b/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff @@ -0,0 +1,52 @@ +- // MIR for `main` before GVN ++ // MIR for `main` after GVN + + fn main() -> () { + let mut _0: (); + let _1: bool; + let mut _2: *mut u8; + scope 1 (inlined dangling_mut::) { + let mut _3: usize; + scope 2 (inlined align_of::) { + } + scope 3 (inlined without_provenance_mut::) { + } + } + scope 4 (inlined Foo::::cmp_ptr) { + let mut _4: *const u8; + let mut _5: *mut u8; + let mut _6: *const u8; + scope 5 (inlined std::ptr::eq::) { + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); +- _3 = AlignOf(u8); +- _2 = _3 as *mut u8 (Transmute); ++ _3 = const 1_usize; ++ _2 = const {0x1 as *mut u8}; + StorageDead(_3); + StorageLive(_4); + StorageLive(_5); +- _5 = _2; +- _4 = _2 as *const u8 (PtrToPtr); ++ _5 = const {0x1 as *mut u8}; ++ _4 = const {0x1 as *const u8}; + StorageDead(_5); + StorageLive(_6); +- _6 = const Foo::::SENTINEL as *const u8 (PtrToPtr); +- _1 = Eq(_4, _6); ++ _6 = const {0x1 as *const u8}; ++ _1 = const true; + StorageDead(_6); + StorageDead(_4); + StorageDead(_2); + StorageDead(_1); + _0 = const (); + return; + } + } + diff --git a/tests/mir-opt/gvn_ptr_eq_with_constant.rs b/tests/mir-opt/gvn_ptr_eq_with_constant.rs new file mode 100644 index 00000000000..d8025072ee3 --- /dev/null +++ b/tests/mir-opt/gvn_ptr_eq_with_constant.rs @@ -0,0 +1,23 @@ +// skip-filecheck +//@ test-mir-pass: GVN +//@ only-64bit +//@ compile-flags: -Z mir-enable-passes=+Inline + +// Regression for + +#![feature(strict_provenance)] + +struct Foo(std::marker::PhantomData); + +impl Foo { + const SENTINEL: *mut T = std::ptr::dangling_mut(); + + fn cmp_ptr(a: *mut T) -> bool { + std::ptr::eq(a, Self::SENTINEL) + } +} + +// EMIT_MIR gvn_ptr_eq_with_constant.main.GVN.diff +pub fn main() { + Foo::::cmp_ptr(std::ptr::dangling_mut()); +} From 03fce3648db08c8fdc726408930c276fec5af124 Mon Sep 17 00:00:00 2001 From: WANG Xuerui Date: Sun, 30 Jun 2024 14:55:36 +0800 Subject: [PATCH 4/8] Fix x86_64 code being produced for bare-metal LoongArch targets' `compiler_builtins` Formerly the `loongarch*-*-none*` targets were added to the `dist-various-2` CI job, but no corresponding toolchain was added along with them. This meant the `compiler_builtins` for the targets were built with the host toolchain. As the other `dist-various` toolchains are mostly pre-built so far, to avoid burdening them with crosstool-ng builds, simply move the two bare-metal LoongArch targets to the `dist-loongarch64-linux` job which has a ready-to-use LoongArch toolchain. With the proper CFLAGS applied it is possible to build artifacts suitable for bare-metal. I verified that the `compiler_builtins` objects are now correctly produced regarding architecture and ABI, with the changes here applied. Fixes #125908. cc @heiher try-job: dist-loongarch64-linux try-job: dist-various-2 --- .../dist-loongarch64-linux/Dockerfile | 20 ++++++++++++++++++- .../host-x86_64/dist-various-2/Dockerfile | 2 -- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-loongarch64-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-loongarch64-linux/Dockerfile index 7e35f781b6b..d3956651663 100644 --- a/src/ci/docker/host-x86_64/dist-loongarch64-linux/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-loongarch64-linux/Dockerfile @@ -23,7 +23,25 @@ ENV CC_loongarch64_unknown_linux_gnu=loongarch64-unknown-linux-gnu-gcc \ AR_loongarch64_unknown_linux_gnu=loongarch64-unknown-linux-gnu-ar \ CXX_loongarch64_unknown_linux_gnu=loongarch64-unknown-linux-gnu-g++ +# We re-use the Linux toolchain for bare-metal, because upstream bare-metal +# target support for LoongArch is only available from GCC 14+. +# +# See: https://github.com/gcc-mirror/gcc/commit/976f4f9e4770 +ENV CC_loongarch64_unknown_none=loongarch64-unknown-linux-gnu-gcc \ + AR_loongarch64_unknown_none=loongarch64-unknown-linux-gnu-ar \ + CXX_loongarch64_unknown_none=loongarch64-unknown-linux-gnu-g++ \ + CFLAGS_loongarch64_unknown_none="-ffreestanding -mabi=lp64d" \ + CXXFLAGS_loongarch64_unknown_none="-ffreestanding -mabi=lp64d" \ + CC_loongarch64_unknown_none_softfloat=loongarch64-unknown-linux-gnu-gcc \ + AR_loongarch64_unknown_none_softfloat=loongarch64-unknown-linux-gnu-ar \ + CXX_loongarch64_unknown_none_softfloat=loongarch64-unknown-linux-gnu-g++ \ + CFLAGS_loongarch64_unknown_none_softfloat="-ffreestanding -mabi=lp64s -mfpu=none" \ + CXXFLAGS_loongarch64_unknown_none_softfloat="-ffreestanding -mabi=lp64s -mfpu=none" + ENV HOSTS=loongarch64-unknown-linux-gnu +ENV TARGETS=$HOSTS +ENV TARGETS=$TARGETS,loongarch64-unknown-none +ENV TARGETS=$TARGETS,loongarch64-unknown-none-softfloat ENV RUST_CONFIGURE_ARGS \ --enable-extended \ @@ -31,4 +49,4 @@ ENV RUST_CONFIGURE_ARGS \ --enable-profiler \ --disable-docs -ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS +ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $TARGETS diff --git a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile index bb6254942cb..e3cb396b782 100644 --- a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile @@ -121,8 +121,6 @@ ENV TARGETS=$TARGETS,armv7-unknown-linux-gnueabi ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabi ENV TARGETS=$TARGETS,i686-unknown-freebsd ENV TARGETS=$TARGETS,x86_64-unknown-none -ENV TARGETS=$TARGETS,loongarch64-unknown-none -ENV TARGETS=$TARGETS,loongarch64-unknown-none-softfloat ENV TARGETS=$TARGETS,aarch64-unknown-uefi ENV TARGETS=$TARGETS,i686-unknown-uefi ENV TARGETS=$TARGETS,x86_64-unknown-uefi From f6942112eb44cb292463d457c603016cc16f4bc6 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 30 Jun 2024 11:30:22 -0700 Subject: [PATCH 5/8] Add a GVN test for 127089 that doesn't optimize to a constant --- ...ust_change_both_sides.GVN.panic-abort.diff | 16 +++++++++++++++ ...st_change_both_sides.GVN.panic-unwind.diff | 16 +++++++++++++++ tests/mir-opt/gvn.rs | 20 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 tests/mir-opt/gvn.remove_casts_must_change_both_sides.GVN.panic-abort.diff create mode 100644 tests/mir-opt/gvn.remove_casts_must_change_both_sides.GVN.panic-unwind.diff diff --git a/tests/mir-opt/gvn.remove_casts_must_change_both_sides.GVN.panic-abort.diff b/tests/mir-opt/gvn.remove_casts_must_change_both_sides.GVN.panic-abort.diff new file mode 100644 index 00000000000..8b4bfb70401 --- /dev/null +++ b/tests/mir-opt/gvn.remove_casts_must_change_both_sides.GVN.panic-abort.diff @@ -0,0 +1,16 @@ +- // MIR for `remove_casts_must_change_both_sides` before GVN ++ // MIR for `remove_casts_must_change_both_sides` after GVN + + fn remove_casts_must_change_both_sides(_1: &*mut u8, _2: *mut u8) -> bool { + let mut _0: bool; + let mut _3: *const u8; + let mut _4: *const u8; + + bb0: { + _3 = (*_1) as *const u8 (PtrToPtr); + _4 = _2 as *const u8 (PtrToPtr); + _0 = Eq(_3, _4); + return; + } + } + diff --git a/tests/mir-opt/gvn.remove_casts_must_change_both_sides.GVN.panic-unwind.diff b/tests/mir-opt/gvn.remove_casts_must_change_both_sides.GVN.panic-unwind.diff new file mode 100644 index 00000000000..8b4bfb70401 --- /dev/null +++ b/tests/mir-opt/gvn.remove_casts_must_change_both_sides.GVN.panic-unwind.diff @@ -0,0 +1,16 @@ +- // MIR for `remove_casts_must_change_both_sides` before GVN ++ // MIR for `remove_casts_must_change_both_sides` after GVN + + fn remove_casts_must_change_both_sides(_1: &*mut u8, _2: *mut u8) -> bool { + let mut _0: bool; + let mut _3: *const u8; + let mut _4: *const u8; + + bb0: { + _3 = (*_1) as *const u8 (PtrToPtr); + _4 = _2 as *const u8 (PtrToPtr); + _0 = Eq(_3, _4); + return; + } + } + diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs index 86f42d23f38..c7fae0bd081 100644 --- a/tests/mir-opt/gvn.rs +++ b/tests/mir-opt/gvn.rs @@ -926,6 +926,25 @@ unsafe fn cast_pointer_then_transmute(thin: *mut u32, fat: *mut [u8]) { let fat_addr: usize = std::intrinsics::transmute(fat as *const ()); } +#[custom_mir(dialect = "analysis")] +fn remove_casts_must_change_both_sides(mut_a: &*mut u8, mut_b: *mut u8) -> bool { + // CHECK-LABEL: fn remove_casts_must_change_both_sides( + mir! { + // We'd like to remove these casts, but we can't change *both* of them + // to be locals, so make sure we don't change one without the other, as + // that would be a type error. + { + // CHECK: [[A:_.+]] = (*_1) as *const u8 (PtrToPtr); + let a = *mut_a as *const u8; + // CHECK: [[B:_.+]] = _2 as *const u8 (PtrToPtr); + let b = mut_b as *const u8; + // CHECK: _0 = Eq([[A]], [[B]]); + RET = a == b; + Return() + } + } +} + fn main() { subexpression_elimination(2, 4, 5); wrap_unwrap(5); @@ -995,3 +1014,4 @@ fn identity(x: T) -> T { // EMIT_MIR gvn.generic_cast_metadata.GVN.diff // EMIT_MIR gvn.cast_pointer_eq.GVN.diff // EMIT_MIR gvn.cast_pointer_then_transmute.GVN.diff +// EMIT_MIR gvn.remove_casts_must_change_both_sides.GVN.diff From 552794410a9237a26aded88990dbe8be26c72dfc Mon Sep 17 00:00:00 2001 From: Boxy Date: Sun, 30 Jun 2024 19:31:15 +0100 Subject: [PATCH 6/8] add `rustc_dump_def_parents` attribute --- compiler/rustc_feature/src/builtin_attrs.rs | 4 + .../rustc_hir_analysis/src/collect/dump.rs | 50 ++++++- compiler/rustc_hir_analysis/src/lib.rs | 1 + compiler/rustc_span/src/symbol.rs | 1 + tests/ui/attributes/dump_def_parents.rs | 34 +++++ tests/ui/attributes/dump_def_parents.stderr | 128 ++++++++++++++++++ 6 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 tests/ui/attributes/dump_def_parents.rs create mode 100644 tests/ui/attributes/dump_def_parents.stderr diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index a4245f0908e..910402d5499 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -1117,6 +1117,10 @@ pub struct BuiltinAttribute { TEST, rustc_dump_predicates, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No ), + rustc_attr!( + TEST, rustc_dump_def_parents, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::No + ), rustc_attr!( TEST, rustc_object_lifetime_default, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No diff --git a/compiler/rustc_hir_analysis/src/collect/dump.rs b/compiler/rustc_hir_analysis/src/collect/dump.rs index 85e1c600d6d..c73d3a5390d 100644 --- a/compiler/rustc_hir_analysis/src/collect/dump.rs +++ b/compiler/rustc_hir_analysis/src/collect/dump.rs @@ -1,5 +1,7 @@ use rustc_hir::def::DefKind; -use rustc_hir::def_id::CRATE_DEF_ID; +use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; +use rustc_hir::intravisit; +use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::ty::TyCtxt; use rustc_span::sym; @@ -41,3 +43,49 @@ pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) { } } } + +pub(crate) fn def_parents(tcx: TyCtxt<'_>) { + for did in tcx.hir().body_owners() { + if tcx.has_attr(did, sym::rustc_dump_def_parents) { + struct AnonConstFinder<'tcx> { + tcx: TyCtxt<'tcx>, + anon_consts: Vec, + } + + impl<'tcx> intravisit::Visitor<'tcx> for AnonConstFinder<'tcx> { + type NestedFilter = OnlyBodies; + + fn nested_visit_map(&mut self) -> Self::Map { + self.tcx.hir() + } + + fn visit_anon_const(&mut self, c: &'tcx rustc_hir::AnonConst) { + self.anon_consts.push(c.def_id); + intravisit::walk_anon_const(self, c) + } + } + + // Look for any anon consts inside of this body owner as there is no way to apply + // the `rustc_dump_def_parents` attribute to the anon const so it would not be possible + // to see what its def parent is. + let mut anon_ct_finder = AnonConstFinder { tcx, anon_consts: vec![] }; + intravisit::walk_expr(&mut anon_ct_finder, tcx.hir().body_owned_by(did).value); + + for did in [did].into_iter().chain(anon_ct_finder.anon_consts) { + let span = tcx.def_span(did); + + let mut diag = tcx.dcx().struct_span_err( + span, + format!("{}: {did:?}", sym::rustc_dump_def_parents.as_str()), + ); + + let mut current_did = did.to_def_id(); + while let Some(parent_did) = tcx.opt_parent(current_did) { + current_did = parent_did; + diag.span_note(tcx.def_span(parent_did), format!("{parent_did:?}")); + } + diag.emit(); + } + } + } +} diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 0428abcdf24..dcf60edafe2 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -169,6 +169,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) { tcx.sess.time("variance_dumping", || variance::dump::variances(tcx)); collect::dump::opaque_hidden_types(tcx); collect::dump::predicates_and_item_bounds(tcx); + collect::dump::def_parents(tcx); } // Make sure we evaluate all static and (non-associated) const items, even if unused. diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 8b7a63f5eb9..7da9211bcbf 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1614,6 +1614,7 @@ rustc_do_not_const_check, rustc_doc_primitive, rustc_dummy, + rustc_dump_def_parents, rustc_dump_item_bounds, rustc_dump_predicates, rustc_dump_user_args, diff --git a/tests/ui/attributes/dump_def_parents.rs b/tests/ui/attributes/dump_def_parents.rs new file mode 100644 index 00000000000..af1c210d2cd --- /dev/null +++ b/tests/ui/attributes/dump_def_parents.rs @@ -0,0 +1,34 @@ +//@ normalize-stderr-test "DefId\(.+?\)" -> "DefId(..)" +#![feature(rustc_attrs)] + +fn bar() { + fn foo() { + fn baz() { + #[rustc_dump_def_parents] + || { + //~^ ERROR: rustc_dump_def_parents: DefId + qux::< + { + //~^ ERROR: rustc_dump_def_parents: DefId + fn inhibits_dump() { + qux::< + { + "hi"; + 1 + }, + >(); + } + + qux::<{ 1 + 1 }>(); + //~^ ERROR: rustc_dump_def_parents: DefId + 1 + }, + >(); + }; + } + } +} + +const fn qux() {} + +fn main() {} diff --git a/tests/ui/attributes/dump_def_parents.stderr b/tests/ui/attributes/dump_def_parents.stderr new file mode 100644 index 00000000000..b2cc32d09b0 --- /dev/null +++ b/tests/ui/attributes/dump_def_parents.stderr @@ -0,0 +1,128 @@ +error: rustc_dump_def_parents: DefId(..) + --> $DIR/dump_def_parents.rs:8:13 + | +LL | || { + | ^^ + | +note: DefId(..) + --> $DIR/dump_def_parents.rs:6:9 + | +LL | fn baz() { + | ^^^^^^^^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:5:5 + | +LL | fn foo() { + | ^^^^^^^^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:4:1 + | +LL | fn bar() { + | ^^^^^^^^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:2:1 + | +LL | / #![feature(rustc_attrs)] +LL | | +LL | | fn bar() { +LL | | fn foo() { +... | +LL | | +LL | | fn main() {} + | |____________^ + +error: rustc_dump_def_parents: DefId(..) + --> $DIR/dump_def_parents.rs:11:21 + | +LL | / { +LL | | +LL | | fn inhibits_dump() { +LL | | qux::< +... | +LL | | 1 +LL | | }, + | |_____________________^ + | +note: DefId(..) + --> $DIR/dump_def_parents.rs:8:13 + | +LL | || { + | ^^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:6:9 + | +LL | fn baz() { + | ^^^^^^^^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:5:5 + | +LL | fn foo() { + | ^^^^^^^^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:4:1 + | +LL | fn bar() { + | ^^^^^^^^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:2:1 + | +LL | / #![feature(rustc_attrs)] +LL | | +LL | | fn bar() { +LL | | fn foo() { +... | +LL | | +LL | | fn main() {} + | |____________^ + +error: rustc_dump_def_parents: DefId(..) + --> $DIR/dump_def_parents.rs:22:31 + | +LL | qux::<{ 1 + 1 }>(); + | ^^^^^^^^^ + | +note: DefId(..) + --> $DIR/dump_def_parents.rs:11:21 + | +LL | / { +LL | | +LL | | fn inhibits_dump() { +LL | | qux::< +... | +LL | | 1 +LL | | }, + | |_____________________^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:8:13 + | +LL | || { + | ^^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:6:9 + | +LL | fn baz() { + | ^^^^^^^^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:5:5 + | +LL | fn foo() { + | ^^^^^^^^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:4:1 + | +LL | fn bar() { + | ^^^^^^^^ +note: DefId(..) + --> $DIR/dump_def_parents.rs:2:1 + | +LL | / #![feature(rustc_attrs)] +LL | | +LL | | fn bar() { +LL | | fn foo() { +... | +LL | | +LL | | fn main() {} + | |____________^ + +error: aborting due to 3 previous errors + From af3d7f869b7a10ee5ccd7b7f8c6ce184be480d5e Mon Sep 17 00:00:00 2001 From: Daniel Huang Date: Sun, 30 Jun 2024 14:54:05 -0400 Subject: [PATCH 7/8] Update ip_addr.rs --- library/core/src/net/ip_addr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/net/ip_addr.rs b/library/core/src/net/ip_addr.rs index b578756e46a..c11a508a135 100644 --- a/library/core/src/net/ip_addr.rs +++ b/library/core/src/net/ip_addr.rs @@ -406,7 +406,7 @@ pub const fn is_ipv6(&self) -> bool { matches!(self, IpAddr::V6(_)) } - /// Converts this address to an `IpAddr::V4` if it is an IPv4-mapped IPv6 addresses, otherwise it + /// Converts this address to an `IpAddr::V4` if it is an IPv4-mapped IPv6 address, otherwise it /// returns `self` as-is. /// /// # Examples @@ -1879,7 +1879,7 @@ pub const fn to_ipv4(&self) -> Option { } } - /// Converts this address to an `IpAddr::V4` if it is an IPv4-mapped addresses, otherwise it + /// Converts this address to an `IpAddr::V4` if it is an IPv4-mapped address, otherwise it /// returns self wrapped in an `IpAddr::V6`. /// /// # Examples From 4c919ac50b5fabe341b35d9440bc84dcc3388130 Mon Sep 17 00:00:00 2001 From: beetrees Date: Mon, 1 Jul 2024 00:24:56 +0100 Subject: [PATCH 8/8] Ensure `out_of_scope_macro_calls` lint is registered --- compiler/rustc_lint_defs/src/builtin.rs | 1 + tests/ui/macros/out-of-scope-macro-calls-lint-registered.rs | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 tests/ui/macros/out-of-scope-macro-calls-lint-registered.rs diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 472e93d202d..2ade6964ca8 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -74,6 +74,7 @@ NON_CONTIGUOUS_RANGE_ENDPOINTS, NON_EXHAUSTIVE_OMITTED_PATTERNS, ORDER_DEPENDENT_TRAIT_OBJECTS, + OUT_OF_SCOPE_MACRO_CALLS, OVERLAPPING_RANGE_ENDPOINTS, PATTERNS_IN_FNS_WITHOUT_BODY, PRIVATE_BOUNDS, diff --git a/tests/ui/macros/out-of-scope-macro-calls-lint-registered.rs b/tests/ui/macros/out-of-scope-macro-calls-lint-registered.rs new file mode 100644 index 00000000000..0736c373d57 --- /dev/null +++ b/tests/ui/macros/out-of-scope-macro-calls-lint-registered.rs @@ -0,0 +1,6 @@ +//@ check-pass + +#![deny(unknown_lints)] +#![allow(out_of_scope_macro_calls)] + +fn main() {}