From 299a71d751139b1f269cd0f888b4f409f1505890 Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Thu, 9 Jul 2026 15:57:47 -0500 Subject: [PATCH 1/9] resolve: fix effective visibilities for items in ambiguous glob sets Since PR 154149, when one item is glob-imported into a module twice with different visibilities, the first-arrived declaration stays in the resolution slot and the most visible declaration of the ambiguous glob set is only recorded in `ambiguity_vis_max`. `DeclData::vis()` returns the max, so name resolution, metadata reexports and `cross_crate_inlinable` export the item at the maximum visibility, but `set_bindings_effective_visibilities` walked only the slot-resident declaration's reexport chain. When the restricted route arrives first, the definition's effective visibility caps at the restricted visibility while the item is still exported: spurious dead_code, the item missing from reachable_set, should_encode_mir returning false, and downstream crates failing with "missing optimized MIR" (a 1.96.1 -> 1.97.0 stable-to-stable regression). Generalize the one-level `ambiguity_vis_max` update that PR 154149 added in `update_import` (to keep the most visible import from being reported as unused) into a walk of that declaration's whole reexport chain: extract the chain walk into `update_decl_chain` and recurse into `ambiguity_vis_max` at every hop, so the most visible declaration drives the effective visibility of everything on its route, including the final definition. Updates are monotone, so the dual walk is order-independent. The `ambiguous_import_visibilities` lint and the PR 156284 diagnostic suppression are untouched. --- .../src/effective_visibilities.rs | 54 +++++++++++-------- ...mbiguous-import-visibility-globglob-mir.rs | 20 +++++++ ...us-import-visibility-globglob-reachable.rs | 26 +++++++++ ...mport-visibility-globglob-reachable.stderr | 8 +++ ...mbiguous-import-visibility-globglob-mir.rs | 19 +++++++ 5 files changed, 106 insertions(+), 21 deletions(-) create mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob-mir.rs create mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob-reachable.rs create mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob-reachable.stderr create mode 100644 tests/ui/imports/auxiliary/ambiguous-import-visibility-globglob-mir.rs diff --git a/compiler/rustc_resolve/src/effective_visibilities.rs b/compiler/rustc_resolve/src/effective_visibilities.rs index e20c86d65af3f..8f051cf02d41c 100644 --- a/compiler/rustc_resolve/src/effective_visibilities.rs +++ b/compiler/rustc_resolve/src/effective_visibilities.rs @@ -125,26 +125,42 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { fn set_bindings_effective_visibilities(&mut self, module_id: LocalDefId) { let module = self.r.expect_module(module_id.to_def_id()); for (_, name_resolution) in self.r.resolutions(module).borrow().iter() { - let Some(mut decl) = name_resolution.borrow().best_decl() else { + let Some(decl) = name_resolution.borrow().best_decl() else { continue; }; - // Set the given effective visibility level to `Level::Direct` and - // sets the rest of the `use` chain to `Level::Reexported` until - // we hit the actual exported item. - let priv_vis = |this: &Self, parent_id, decl| match parent_id { - ParentId::Def(_) => this.current_private_vis, - ParentId::Import(_) => this.r.private_vis_decl(decl), - }; - let mut parent_id = ParentId::Def(module_id); - while let DeclKind::Import { source_decl, .. } = decl.kind { - self.update_import(decl, parent_id, priv_vis(self, parent_id, decl)); - parent_id = ParentId::Import(decl); - decl = source_decl; - } - if let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local()) { - let priv_vis = priv_vis(self, parent_id, decl); - self.update_def(def_id, decl.vis().expect_local(), parent_id, priv_vis); + self.update_decl_chain(decl, ParentId::Def(module_id)); + } + } + + /// Update effective visibilities for the whole reexport chain of a declaration. + /// Set the given effective visibility level to `Level::Direct` and + /// sets the rest of the `use` chain to `Level::Reexported` until + /// we hit the actual exported item. + fn update_decl_chain(&mut self, mut decl: Decl<'ra>, mut parent_id: ParentId<'ra>) { + let priv_vis = |this: &Self, parent_id, decl| match parent_id { + ParentId::Def(_) => this.current_private_vis, + ParentId::Import(_) => this.r.private_vis_decl(decl), + }; + while let DeclKind::Import { source_decl, .. } = decl.kind { + self.update_import(decl, parent_id, priv_vis(self, parent_id, decl)); + if let Some(max_vis_decl) = decl.ambiguity_vis_max.get() { + // The name is exported with the visibility of the most visible declaration + // in its ambiguous glob set (see `DeclData::vis`), so everything on that + // declaration's reexport chain, including the final item, must get its + // effective visibility from that declaration as well. Otherwise the item + // would be considered unreachable by dead code analysis and metadata + // encoding despite being exported (see the regression test + // `ambiguous-import-visibility-globglob-mir.rs`). + // This also avoids the most visible import in an ambiguous glob set + // being reported as unused. + self.update_decl_chain(max_vis_decl, parent_id); } + parent_id = ParentId::Import(decl); + decl = source_decl; + } + if let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local()) { + let priv_vis = priv_vis(self, parent_id, decl); + self.update_def(def_id, decl.vis().expect_local(), parent_id, priv_vis); } } @@ -194,10 +210,6 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { parent_id.level(), tcx, ); - if let Some(max_vis_decl) = decl.ambiguity_vis_max.get() { - // Avoid the most visible import in an ambiguous glob set being reported as unused. - self.update_import(max_vis_decl, parent_id, priv_vis); - } } fn update_def( diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-mir.rs b/tests/ui/imports/ambiguous-import-visibility-globglob-mir.rs new file mode 100644 index 0000000000000..a411e2cc4394d --- /dev/null +++ b/tests/ui/imports/ambiguous-import-visibility-globglob-mir.rs @@ -0,0 +1,20 @@ +// Regression test for the 1.96 -> 1.97 stable-to-stable regression: an item exported +// only through a public glob, and also glob-imported with restricted visibility through +// a private facade, lost its exported effective visibility. The defining crate then +// skipped encoding its optimized MIR (and warned dead_code) while name resolution still +// exported the item and it remained `cross_crate_inlinable`, so downstream crates failed +// with "missing optimized MIR". The dead_code half is checked by `#![deny(dead_code)]` +// in the auxiliary crate itself. + +//@ build-pass +//@ aux-build:ambiguous-import-visibility-globglob-mir.rs + +extern crate ambiguous_import_visibility_globglob_mir as dep; + +pub fn call_f() -> u32 { + dep::f() +} + +fn main() { + call_f(); +} diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-reachable.rs b/tests/ui/imports/ambiguous-import-visibility-globglob-reachable.rs new file mode 100644 index 0000000000000..1a533b1d4ee21 --- /dev/null +++ b/tests/ui/imports/ambiguous-import-visibility-globglob-reachable.rs @@ -0,0 +1,26 @@ +// Regression test for the 1.96 -> 1.97 stable-to-stable regression: an item exported +// only through a public glob, and also glob-imported with restricted visibility through +// a private facade, lost its exported effective visibility while name resolution still +// exported it. Downstream: spurious dead_code in this crate, "missing optimized MIR" in +// dependent crates (see ambiguous-import-visibility-globglob-mir.rs). The public glob +// declaration must drive the effective visibility of the whole reexport chain. + +#![feature(rustc_attrs)] +#![allow(internal_features)] +#![deny(dead_code)] + +mod inner { + #[rustc_effective_visibility] + pub fn f() {} //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub +} + +mod facade { + #[allow(unused_imports)] + pub(crate) use super::inner::f; +} + +#[allow(unused_imports)] +use facade::*; +pub use inner::*; + +fn main() {} diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-reachable.stderr b/tests/ui/imports/ambiguous-import-visibility-globglob-reachable.stderr new file mode 100644 index 0000000000000..c27e6a2ac807b --- /dev/null +++ b/tests/ui/imports/ambiguous-import-visibility-globglob-reachable.stderr @@ -0,0 +1,8 @@ +error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub + --> $DIR/ambiguous-import-visibility-globglob-reachable.rs:14:5 + | +LL | pub fn f() {} + | ^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/imports/auxiliary/ambiguous-import-visibility-globglob-mir.rs b/tests/ui/imports/auxiliary/ambiguous-import-visibility-globglob-mir.rs new file mode 100644 index 0000000000000..a1e125bd55637 --- /dev/null +++ b/tests/ui/imports/auxiliary/ambiguous-import-visibility-globglob-mir.rs @@ -0,0 +1,19 @@ +// An item exported only through a public glob, while also glob-imported into the +// same module through a facade with restricted visibility. The restricted duplicate +// must not make `f` unreachable: its optimized MIR must still be encoded for +// downstream crates (it is `cross_crate_inlinable`). + +mod inner { + pub fn f() -> u32 { + 42 + } +} + +mod facade { + #[allow(unused_imports)] + pub(crate) use super::inner::f; +} + +#[allow(unused_imports)] +use facade::*; +pub use inner::*; From d7418a0e6c38a2e70ce7ba39f08ce21ebe0c7f86 Mon Sep 17 00:00:00 2001 From: Yukang Date: Tue, 7 Jul 2026 19:52:54 +0800 Subject: [PATCH 2/9] Skip trivial cast lint for trait object upcasts --- compiler/rustc_hir_typeck/src/cast.rs | 33 +++++++++++++++++++ .../trivial-casts-dyn-any-issue-148219.rs | 27 +++++++++++++++ .../trivial-casts-dyn-any-issue-148219.stderr | 15 +++++++++ 3 files changed, 75 insertions(+) create mode 100644 tests/ui/lint/trivial-casts-dyn-any-issue-148219.rs create mode 100644 tests/ui/lint/trivial-casts-dyn-any-issue-148219.stderr diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index f7f0b69873e1e..a54f74b37172f 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -724,6 +724,10 @@ impl<'a, 'tcx> CastCheck<'tcx> { } fn trivial_cast_lint(&self, fcx: &FnCtxt<'a, 'tcx>) { + if self.is_non_trivial_ref_trait_object_upcast(fcx) { + return; + } + let (numeric, lint) = if self.cast_ty.is_numeric() && self.expr_ty.is_numeric() { (true, lint::builtin::TRIVIAL_NUMERIC_CASTS) } else { @@ -739,6 +743,35 @@ impl<'a, 'tcx> CastCheck<'tcx> { ); } + // A trait-object upcast from a method receiver, such as + // `(other as &dyn Any).downcast_ref::()`, + // is not trivial, because it may change the method resolution, we want to skip the lint in this case. + // see issue #148219 + fn is_non_trivial_ref_trait_object_upcast(&self, fcx: &FnCtxt<'a, 'tcx>) -> bool { + if !matches!( + (self.expr_ty.kind(), self.cast_ty.kind()), + (ty::Ref(_, from_ty, _), ty::Ref(_, to_ty, _)) + if matches!( + (from_ty.kind(), to_ty.kind()), + (ty::Dynamic(from_data, _), ty::Dynamic(to_data, _)) if from_data != to_data + ) + ) { + return false; + } + + let hir::Node::Expr(cast_expr) = fcx.tcx.parent_hir_node(self.expr.hir_id) else { + return false; + }; + let hir::Node::Expr(parent) = fcx.tcx.parent_hir_node(cast_expr.hir_id) else { + return false; + }; + + matches!( + parent.kind, + hir::ExprKind::MethodCall(_, receiver, ..) if receiver.hir_id == cast_expr.hir_id + ) + } + fn expr_span_for_type_resolution(&self, fcx: &FnCtxt<'a, 'tcx>) -> Span { if let hir::ExprKind::Index(_, idx, _) = self.expr.kind && fcx.resolve_vars_if_possible(self.expr_ty).is_ty_var() diff --git a/tests/ui/lint/trivial-casts-dyn-any-issue-148219.rs b/tests/ui/lint/trivial-casts-dyn-any-issue-148219.rs new file mode 100644 index 0000000000000..2988f2c59bab8 --- /dev/null +++ b/tests/ui/lint/trivial-casts-dyn-any-issue-148219.rs @@ -0,0 +1,27 @@ +//! Trait-object upcasts used as method receivers can affect method lookup. + +//@ check-pass + +#![warn(trivial_casts)] + +use std::any::Any; + +trait DynKey: Any {} + +impl DynKey for T {} + +fn method_receiver(other: &dyn DynKey) { + let _ = (other as &dyn Any).downcast_ref::(); +} + +fn plain_binding(other: &dyn DynKey) { + // This cast is trivial, but it is not used as a method receiver, + // so it should be linted. + let _ = other as &dyn Any; + //~^ WARN trivial cast +} + +fn main() { + method_receiver(&0u32); + plain_binding(&0u32); +} diff --git a/tests/ui/lint/trivial-casts-dyn-any-issue-148219.stderr b/tests/ui/lint/trivial-casts-dyn-any-issue-148219.stderr new file mode 100644 index 0000000000000..3c4937fc6249d --- /dev/null +++ b/tests/ui/lint/trivial-casts-dyn-any-issue-148219.stderr @@ -0,0 +1,15 @@ +warning: trivial cast: `&(dyn DynKey + 'static)` as `&(dyn Any + 'static)` + --> $DIR/trivial-casts-dyn-any-issue-148219.rs:20:13 + | +LL | let _ = other as &dyn Any; + | ^^^^^^^^^^^^^^^^^ + | + = help: cast can be replaced by coercion; this might require a temporary variable +note: the lint level is defined here + --> $DIR/trivial-casts-dyn-any-issue-148219.rs:5:9 + | +LL | #![warn(trivial_casts)] + | ^^^^^^^^^^^^^ + +warning: 1 warning emitted + From 159b9a0c557ed43c9be3d52a58b8cbf10fbc2f4f Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Fri, 10 Jul 2026 16:17:09 -0500 Subject: [PATCH 3/9] Fix stale test comment: the dead_code half is pinned by the sibling -reachable test --- tests/ui/imports/ambiguous-import-visibility-globglob-mir.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-mir.rs b/tests/ui/imports/ambiguous-import-visibility-globglob-mir.rs index a411e2cc4394d..6633be4ba6bb3 100644 --- a/tests/ui/imports/ambiguous-import-visibility-globglob-mir.rs +++ b/tests/ui/imports/ambiguous-import-visibility-globglob-mir.rs @@ -3,8 +3,9 @@ // a private facade, lost its exported effective visibility. The defining crate then // skipped encoding its optimized MIR (and warned dead_code) while name resolution still // exported the item and it remained `cross_crate_inlinable`, so downstream crates failed -// with "missing optimized MIR". The dead_code half is checked by `#![deny(dead_code)]` -// in the auxiliary crate itself. +// with "missing optimized MIR". This test pins the missing-MIR half; the dead_code half +// is checked by the sibling test `ambiguous-import-visibility-globglob-reachable.rs` +// (via its `#![deny(dead_code)]`). //@ build-pass //@ aux-build:ambiguous-import-visibility-globglob-mir.rs From 5f3f5dd2c4732fec6c2c9885e97bbf11da47bf6e Mon Sep 17 00:00:00 2001 From: rustbot <47979223+rustbot@users.noreply.github.com> Date: Mon, 13 Jul 2026 19:00:58 +0200 Subject: [PATCH 4/9] Update books --- src/doc/book | 2 +- src/doc/edition-guide | 2 +- src/doc/reference | 2 +- src/doc/rust-by-example | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/book b/src/doc/book index 05d114287b7d6..dd7ab4f4f4541 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 05d114287b7d6f6c9253d5242540f00fbd6172ab +Subproject commit dd7ab4f4f4541adf4aa2a872cdac06c206b73288 diff --git a/src/doc/edition-guide b/src/doc/edition-guide index c3c0f0b3da266..53686db907c45 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit c3c0f0b3da26610138b7ba7663f60cd2c68cf184 +Subproject commit 53686db907c45268d1b323afd9a3545a37abbced diff --git a/src/doc/reference b/src/doc/reference index 86635e30bf861..afdc77bab886d 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 86635e30bf861a038dc197d7e16fd09e7e514e7a +Subproject commit afdc77bab886d4455c11247cdd32391bfab636ae diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index d3117f6c873ac..15308f3e95181 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit d3117f6c873acbbf331c1d510371d061dfcc975c +Subproject commit 15308f3e951814ef3475d2b58f48276e6b17b9af From 7e1c0b6ebbf96fbee7757f58d69b1fdaddf06100 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 13 Jul 2026 10:13:02 -0700 Subject: [PATCH 5/9] compiler: Remove `-Zmutable-noalias` --- compiler/rustc_interface/src/tests.rs | 1 - compiler/rustc_session/src/options.rs | 2 -- compiler/rustc_ty_utils/src/abi.rs | 7 +------ 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 640f31355ac33..71d1829f76584 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -852,7 +852,6 @@ fn test_unstable_options_tracking_hash() { tracked!(mir_opt_level, Some(4)); tracked!(mir_preserve_ub, true); tracked!(move_size_limit, Some(4096)); - tracked!(mutable_noalias, false); tracked!(next_solver, NextSolverConfig { coherence: true, globally: true }); tracked!(no_generate_arange_section, true); tracked!(no_link, true); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 2f44b4c102486..d508c963791d4 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2568,8 +2568,6 @@ options! { "Whether to remove some of the MIR debug info from methods. Default: None"), move_size_limit: Option = (None, parse_opt_number, [TRACKED], "the size at which the `large_assignments` lint starts to be emitted"), - mutable_noalias: bool = (true, parse_bool, [TRACKED], - "emit noalias metadata for mutable references (default: yes)"), namespaced_crates: bool = (false, parse_bool, [TRACKED], "allow crates to be namespaced by other crates (default: no)"), next_solver: NextSolverConfig = (NextSolverConfig::default(), parse_next_solver_config, [TRACKED], diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 8873fb13efe03..1cc128c9b46eb 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -366,11 +366,6 @@ fn arg_attrs_for_rust_scalar<'tcx>( // See https://github.com/rust-lang/unsafe-code-guidelines/issues/326 let noalias_for_box = tcx.sess.opts.unstable_opts.box_noalias; - // LLVM prior to version 12 had known miscompiles in the presence of noalias attributes - // (see #54878), so it was conditionally disabled, but we don't support earlier - // versions at all anymore. We still support turning it off using -Zmutable-noalias. - let noalias_mut_ref = tcx.sess.opts.unstable_opts.mutable_noalias; - // `&T` where `T` contains no `UnsafeCell` is immutable, and can be marked as both // `readonly` and `noalias`, as LLVM's definition of `noalias` is based solely on memory // dependencies rather than pointer equality. However this only applies to arguments, @@ -379,7 +374,7 @@ fn arg_attrs_for_rust_scalar<'tcx>( // `&mut T` and `Box` where `T: Unpin` are unique and hence `noalias`. let no_alias = match kind { PointerKind::SharedRef { frozen } => frozen, - PointerKind::MutableRef { unpin } => unpin && noalias_mut_ref, + PointerKind::MutableRef { unpin } => unpin, PointerKind::Box { unpin, global } => unpin && global && noalias_for_box, }; // We can never add `noalias` in return position; that LLVM attribute has some very surprising semantics From 1ccd7e1391d0285a5706cc38b92129085af21d4a Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 13 Jul 2026 10:14:58 -0700 Subject: [PATCH 6/9] Remove noalias tests --- tests/codegen-llvm/noalias-flag.rs | 23 ------------------- tests/codegen-llvm/noalias-refcell.rs | 2 +- tests/codegen-llvm/noalias-rwlockreadguard.rs | 2 +- tests/codegen-llvm/noalias-unpin.rs | 2 +- 4 files changed, 3 insertions(+), 26 deletions(-) delete mode 100644 tests/codegen-llvm/noalias-flag.rs diff --git a/tests/codegen-llvm/noalias-flag.rs b/tests/codegen-llvm/noalias-flag.rs deleted file mode 100644 index 67ba68ee6f80a..0000000000000 --- a/tests/codegen-llvm/noalias-flag.rs +++ /dev/null @@ -1,23 +0,0 @@ -//@ compile-flags: -Copt-level=3 -Zmutable-noalias=no - -#![crate_type = "lib"] - -// `-Zmutable-noalias=no` should disable noalias on mut refs... - -// CHECK-LABEL: @test_mut_ref( -// CHECK-NOT: noalias -// CHECK-SAME: %x -#[no_mangle] -pub fn test_mut_ref(x: &mut i32) -> &mut i32 { - x -} - -// ...but not on shared refs - -// CHECK-LABEL: @test_ref( -// CHECK-SAME: noalias -// CHECK-SAME: %x -#[no_mangle] -pub fn test_ref(x: &i32) -> &i32 { - x -} diff --git a/tests/codegen-llvm/noalias-refcell.rs b/tests/codegen-llvm/noalias-refcell.rs index b37adf92b9cc3..87f3ea624700a 100644 --- a/tests/codegen-llvm/noalias-refcell.rs +++ b/tests/codegen-llvm/noalias-refcell.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Copt-level=3 -C no-prepopulate-passes -Z mutable-noalias=yes +//@ compile-flags: -Copt-level=3 -C no-prepopulate-passes #![crate_type = "lib"] diff --git a/tests/codegen-llvm/noalias-rwlockreadguard.rs b/tests/codegen-llvm/noalias-rwlockreadguard.rs index c676dc32399da..7eacf6c792eb8 100644 --- a/tests/codegen-llvm/noalias-rwlockreadguard.rs +++ b/tests/codegen-llvm/noalias-rwlockreadguard.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Copt-level=3 -C no-prepopulate-passes -Z mutable-noalias=yes +//@ compile-flags: -Copt-level=3 -C no-prepopulate-passes #![crate_type = "lib"] diff --git a/tests/codegen-llvm/noalias-unpin.rs b/tests/codegen-llvm/noalias-unpin.rs index 30a8b399b9798..b164495e50724 100644 --- a/tests/codegen-llvm/noalias-unpin.rs +++ b/tests/codegen-llvm/noalias-unpin.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Copt-level=3 -Z mutable-noalias=yes +//@ compile-flags: -Copt-level=3 #![crate_type = "lib"] From f779a137cbcdc5819598a0a8a5a9edfb47687546 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 13 Jul 2026 22:31:25 +0200 Subject: [PATCH 7/9] Rename `rustc_session/src/errors.rs` into `rustc_session/src/diagnostics.rs` --- compiler/rustc_session/src/config.rs | 2 +- compiler/rustc_session/src/config/cfg.rs | 4 +- .../src/{errors.rs => diagnostics.rs} | 0 compiler/rustc_session/src/lib.rs | 2 +- compiler/rustc_session/src/output.rs | 2 +- compiler/rustc_session/src/session.rs | 90 +++++++++---------- 6 files changed, 50 insertions(+), 50 deletions(-) rename compiler/rustc_session/src/{errors.rs => diagnostics.rs} (100%) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 4492cdf2d2f8a..f500382719544 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -34,7 +34,7 @@ use tracing::debug; pub use crate::config::cfg::{Cfg, CheckCfg, ExpectedValues}; use crate::config::native_libs::parse_native_libs; pub use crate::config::print_request::{PrintKind, PrintRequest}; -use crate::errors::FileWriteFail; +use crate::diagnostics::FileWriteFail; pub use crate::options::*; use crate::search_paths::SearchPath; use crate::utils::CanonicalizedPath; diff --git a/compiler/rustc_session/src/config/cfg.rs b/compiler/rustc_session/src/config/cfg.rs index 955a77f808588..84a26af6b54ce 100644 --- a/compiler/rustc_session/src/config/cfg.rs +++ b/compiler/rustc_session/src/config/cfg.rs @@ -31,7 +31,7 @@ use rustc_span::{Symbol, sym}; use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, Target}; use crate::config::{CrateType, FmtDebug}; -use crate::{Session, errors}; +use crate::{Session, diagnostics}; /// The parsed `--cfg` options that define the compilation environment of the /// crate, used to drive conditional compilation. @@ -105,7 +105,7 @@ pub(crate) fn disallow_cfgs(sess: &Session, user_cfgs: &Cfg) { EXPLICIT_BUILTIN_CFGS_IN_FLAGS, None, ast::CRATE_NODE_ID, - errors::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by }.into(), + diagnostics::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by }.into(), ) }; diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/diagnostics.rs similarity index 100% rename from compiler/rustc_session/src/errors.rs rename to compiler/rustc_session/src/diagnostics.rs diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index cc83867dc1a9e..94566c943d7ed 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -19,7 +19,7 @@ pub use rustc_lint_defs as lint; pub use session::*; pub mod code_stats; -pub mod errors; +pub mod diagnostics; pub mod parse; pub mod utils; #[macro_use] diff --git a/compiler/rustc_session/src/output.rs b/compiler/rustc_session/src/output.rs index 9224368f90d6e..120eb04c6e8c4 100644 --- a/compiler/rustc_session/src/output.rs +++ b/compiler/rustc_session/src/output.rs @@ -6,7 +6,7 @@ use rustc_span::{Span, Symbol}; use crate::Session; use crate::config::{CrateType, OutFileName, OutputFilenames, OutputType}; -use crate::errors::{CrateNameEmpty, FileIsNotWriteable, InvalidCharacterInCrateName}; +use crate::diagnostics::{CrateNameEmpty, FileIsNotWriteable, InvalidCharacterInCrateName}; pub fn out_filename( sess: &Session, diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 986dababf770a..e176259c23f29 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -45,7 +45,7 @@ use crate::filesearch::FileSearch; use crate::lint::LintId; use crate::parse::ParseSess; use crate::search_paths::SearchPath; -use crate::{errors, filesearch, lint}; +use crate::{diagnostics, filesearch, lint}; /// The behavior of the CTFE engine when an error occurs with regards to backtraces. #[derive(Clone, Copy)] @@ -233,15 +233,15 @@ impl Session { if !unleashed_features.is_empty() { let mut must_err = false; // Create a diagnostic pointing at where things got unleashed. - self.dcx().emit_warn(errors::SkippingConstChecks { + self.dcx().emit_warn(diagnostics::SkippingConstChecks { unleashed_features: unleashed_features .iter() .map(|(span, gate)| { gate.map(|gate| { must_err = true; - errors::UnleashedFeatureHelp::Named { span: *span, gate } + diagnostics::UnleashedFeatureHelp::Named { span: *span, gate } }) - .unwrap_or(errors::UnleashedFeatureHelp::Unnamed { span: *span }) + .unwrap_or(diagnostics::UnleashedFeatureHelp::Unnamed { span: *span }) }) .collect(), }); @@ -249,7 +249,7 @@ impl Session { // If we should err, make sure we did. if must_err && self.dcx().has_errors().is_none() { // We have skipped a feature gate, and not run into other errors... reject. - guar = Some(self.dcx().emit_err(errors::NotCircumventFeature)); + guar = Some(self.dcx().emit_err(diagnostics::NotCircumventFeature)); } } guar @@ -279,7 +279,7 @@ impl Session { if err.code.is_none() { err.code(E0658); } - errors::add_feature_diagnostics(&mut err, self, feature); + diagnostics::add_feature_diagnostics(&mut err, self, feature); err } @@ -650,7 +650,7 @@ impl Session { // The user explicitly asked for ThinLTO if !self.thin_lto_supported { // Backend doesn't support ThinLTO, fallback to fat LTO. - self.dcx().emit_warn(errors::ThinLtoNotSupportedByBackend); + self.dcx().emit_warn(diagnostics::ThinLtoNotSupportedByBackend); return config::Lto::Fat; } return config::Lto::Thin; @@ -921,7 +921,7 @@ impl Session { // is lower than the minimum OS supported by rustc, not when the variable is lower // than the minimum for a specific target. if version < os_min { - self.dcx().emit_warn(errors::AppleDeploymentTarget::TooLow { + self.dcx().emit_warn(diagnostics::AppleDeploymentTarget::TooLow { env_var, version: version.fmt_pretty().to_string(), os_min: os_min.fmt_pretty().to_string(), @@ -932,7 +932,7 @@ impl Session { version.max(min) } Err(error) => { - self.dcx().emit_err(errors::AppleDeploymentTarget::Invalid { env_var, error }); + self.dcx().emit_err(diagnostics::AppleDeploymentTarget::Invalid { env_var, error }); min } } @@ -1063,7 +1063,7 @@ pub fn build_session( match profiler { Ok(profiler) => Some(Arc::new(profiler)), Err(e) => { - dcx.handle().emit_warn(errors::FailedToCreateProfiler { err: e.to_string() }); + dcx.handle().emit_warn(diagnostics::FailedToCreateProfiler { err: e.to_string() }); None } } @@ -1167,28 +1167,28 @@ fn validate_commandline_args_with_session_available(sess: &Session) { && sess.opts.cg.prefer_dynamic && sess.target.is_like_windows { - sess.dcx().emit_err(errors::LinkerPluginToWindowsNotSupported); + sess.dcx().emit_err(diagnostics::LinkerPluginToWindowsNotSupported); } // Make sure that any given profiling data actually exists so LLVM can't // decide to silently skip PGO. if let Some(ref path) = sess.opts.cg.profile_use { if !path.exists() { - sess.dcx().emit_err(errors::ProfileUseFileDoesNotExist { path }); + sess.dcx().emit_err(diagnostics::ProfileUseFileDoesNotExist { path }); } } // Do the same for sample profile data. if let Some(ref path) = sess.opts.unstable_opts.profile_sample_use { if !path.exists() { - sess.dcx().emit_err(errors::ProfileSampleUseFileDoesNotExist { path }); + sess.dcx().emit_err(diagnostics::ProfileSampleUseFileDoesNotExist { path }); } } // Unwind tables cannot be disabled if the target requires them. if let Some(include_uwtables) = sess.opts.cg.force_unwind_tables { if sess.target.requires_uwtable && !include_uwtables { - sess.dcx().emit_err(errors::TargetRequiresUnwindTables); + sess.dcx().emit_err(diagnostics::TargetRequiresUnwindTables); } } @@ -1204,10 +1204,10 @@ fn validate_commandline_args_with_session_available(sess: &Session) { 0 => {} 1 => { sess.dcx() - .emit_err(errors::SanitizerNotSupported { us: unsupported_sanitizers.to_string() }); + .emit_err(diagnostics::SanitizerNotSupported { us: unsupported_sanitizers.to_string() }); } _ => { - sess.dcx().emit_err(errors::SanitizersNotSupported { + sess.dcx().emit_err(diagnostics::SanitizersNotSupported { us: unsupported_sanitizers.to_string(), }); } @@ -1215,7 +1215,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { // Cannot mix and match mutually-exclusive sanitizers. if let Some((first, second)) = sess.opts.unstable_opts.sanitizer.mutually_exclusive() { - sess.dcx().emit_err(errors::CannotMixAndMatchSanitizers { + sess.dcx().emit_err(diagnostics::CannotMixAndMatchSanitizers { first: first.to_string(), second: second.to_string(), }); @@ -1226,26 +1226,26 @@ fn validate_commandline_args_with_session_available(sess: &Session) { && !sess.opts.unstable_opts.sanitizer.is_empty() && !sess.target.is_like_msvc { - sess.dcx().emit_err(errors::CannotEnableCrtStaticLinux); + sess.dcx().emit_err(diagnostics::CannotEnableCrtStaticLinux); } // FIXME(jchlanda) Pauthtest does not support static linking. It must be dynamically linked, // with a dynamic linker acting as the ELF interpreter that can resolve pauth relocations and // enforce pointer authentication constraints. if sess.crt_static(None) && sess.target.cfg_abi == CfgAbi::Pauthtest { - sess.dcx().emit_err(errors::CannotEnableCrtStaticPointerAuth); + sess.dcx().emit_err(diagnostics::CannotEnableCrtStaticPointerAuth); } // LLVM CFI requires LTO. if sess.is_sanitizer_cfi_enabled() && !(sess.lto() == config::Lto::Fat || sess.opts.cg.linker_plugin_lto.enabled()) { - sess.dcx().emit_err(errors::SanitizerCfiRequiresLto); + sess.dcx().emit_err(diagnostics::SanitizerCfiRequiresLto); } // KCFI requires panic=abort if sess.is_sanitizer_kcfi_enabled() && sess.panic_strategy().unwinds() { - sess.dcx().emit_err(errors::SanitizerKcfiRequiresPanicAbort); + sess.dcx().emit_err(diagnostics::SanitizerKcfiRequiresPanicAbort); } // LLVM CFI using rustc LTO requires a single codegen unit. @@ -1253,32 +1253,32 @@ fn validate_commandline_args_with_session_available(sess: &Session) { && sess.lto() == config::Lto::Fat && (sess.codegen_units().as_usize() != 1) { - sess.dcx().emit_err(errors::SanitizerCfiRequiresSingleCodegenUnit); + sess.dcx().emit_err(diagnostics::SanitizerCfiRequiresSingleCodegenUnit); } // Canonical jump tables requires CFI. if sess.is_sanitizer_cfi_canonical_jump_tables_disabled() { if !sess.is_sanitizer_cfi_enabled() { - sess.dcx().emit_err(errors::SanitizerCfiCanonicalJumpTablesRequiresCfi); + sess.dcx().emit_err(diagnostics::SanitizerCfiCanonicalJumpTablesRequiresCfi); } } // KCFI arity indicator requires KCFI. if sess.is_sanitizer_kcfi_arity_enabled() && !sess.is_sanitizer_kcfi_enabled() { - sess.dcx().emit_err(errors::SanitizerKcfiArityRequiresKcfi); + sess.dcx().emit_err(diagnostics::SanitizerKcfiArityRequiresKcfi); } // LLVM CFI pointer generalization requires CFI or KCFI. if sess.is_sanitizer_cfi_generalize_pointers_enabled() { if !(sess.is_sanitizer_cfi_enabled() || sess.is_sanitizer_kcfi_enabled()) { - sess.dcx().emit_err(errors::SanitizerCfiGeneralizePointersRequiresCfi); + sess.dcx().emit_err(diagnostics::SanitizerCfiGeneralizePointersRequiresCfi); } } // LLVM CFI integer normalization requires CFI or KCFI. if sess.is_sanitizer_cfi_normalize_integers_enabled() { if !(sess.is_sanitizer_cfi_enabled() || sess.is_sanitizer_kcfi_enabled()) { - sess.dcx().emit_err(errors::SanitizerCfiNormalizeIntegersRequiresCfi); + sess.dcx().emit_err(diagnostics::SanitizerCfiNormalizeIntegersRequiresCfi); } } @@ -1288,19 +1288,19 @@ fn validate_commandline_args_with_session_available(sess: &Session) { || sess.lto() == config::Lto::Thin || sess.opts.cg.linker_plugin_lto.enabled()) { - sess.dcx().emit_err(errors::SplitLtoUnitRequiresLto); + sess.dcx().emit_err(diagnostics::SplitLtoUnitRequiresLto); } // VFE requires LTO. if sess.lto() != config::Lto::Fat { if sess.opts.unstable_opts.virtual_function_elimination { - sess.dcx().emit_err(errors::UnstableVirtualFunctionElimination); + sess.dcx().emit_err(diagnostics::UnstableVirtualFunctionElimination); } } if sess.opts.unstable_opts.stack_protector != StackProtector::None { if !sess.target.options.supports_stack_protector { - sess.dcx().emit_warn(errors::StackProtectorNotSupportedForTarget { + sess.dcx().emit_warn(diagnostics::StackProtectorNotSupportedForTarget { stack_protector: sess.opts.unstable_opts.stack_protector, target_triple: &sess.opts.target_triple, }); @@ -1309,14 +1309,14 @@ fn validate_commandline_args_with_session_available(sess: &Session) { if sess.opts.unstable_opts.small_data_threshold.is_some() { if sess.target.small_data_threshold_support() == SmallDataThresholdSupport::None { - sess.dcx().emit_warn(errors::SmallDataThresholdNotSupportedForTarget { + sess.dcx().emit_warn(diagnostics::SmallDataThresholdNotSupportedForTarget { target_triple: &sess.opts.target_triple, }) } } if sess.opts.unstable_opts.branch_protection.is_some() && sess.target.arch != Arch::AArch64 { - sess.dcx().emit_err(errors::BranchProtectionRequiresAArch64); + sess.dcx().emit_err(diagnostics::BranchProtectionRequiresAArch64); } if let Some(dwarf_version) = @@ -1324,7 +1324,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { { // DWARF 1 is not supported by LLVM and DWARF 6 is not yet finalized. if dwarf_version < 2 || dwarf_version > 5 { - sess.dcx().emit_err(errors::UnsupportedDwarfVersion { dwarf_version }); + sess.dcx().emit_err(diagnostics::UnsupportedDwarfVersion { dwarf_version }); } } @@ -1332,61 +1332,61 @@ fn validate_commandline_args_with_session_available(sess: &Session) { && !sess.opts.unstable_opts.unstable_options { sess.dcx() - .emit_err(errors::SplitDebugInfoUnstablePlatform { debuginfo: sess.split_debuginfo() }); + .emit_err(diagnostics::SplitDebugInfoUnstablePlatform { debuginfo: sess.split_debuginfo() }); } if sess.opts.unstable_opts.embed_source { let dwarf_version = sess.dwarf_version(); if dwarf_version < 5 { - sess.dcx().emit_warn(errors::EmbedSourceInsufficientDwarfVersion { dwarf_version }); + sess.dcx().emit_warn(diagnostics::EmbedSourceInsufficientDwarfVersion { dwarf_version }); } if sess.opts.debuginfo == DebugInfo::None { - sess.dcx().emit_warn(errors::EmbedSourceRequiresDebugInfo); + sess.dcx().emit_warn(diagnostics::EmbedSourceRequiresDebugInfo); } } if sess.opts.unstable_opts.instrument_mcount == InstrumentMcount::Fentry && !sess.target.options.supports_fentry { - sess.dcx().emit_err(errors::InstrumentationNotSupported { us: "fentry".to_string() }); + sess.dcx().emit_err(diagnostics::InstrumentationNotSupported { us: "fentry".to_string() }); } if sess.opts.unstable_opts.instrument_xray.is_some() && !sess.target.options.supports_xray { - sess.dcx().emit_err(errors::InstrumentationNotSupported { us: "XRay".to_string() }); + sess.dcx().emit_err(diagnostics::InstrumentationNotSupported { us: "XRay".to_string() }); } if let Some(flavor) = sess.opts.cg.linker_flavor && let Some(compatible_list) = sess.target.linker_flavor.check_compatibility(flavor) { let flavor = flavor.desc(); - sess.dcx().emit_err(errors::IncompatibleLinkerFlavor { flavor, compatible_list }); + sess.dcx().emit_err(diagnostics::IncompatibleLinkerFlavor { flavor, compatible_list }); } if sess.opts.unstable_opts.function_return != FunctionReturn::default() { if !matches!(sess.target.arch, Arch::X86 | Arch::X86_64) { - sess.dcx().emit_err(errors::FunctionReturnRequiresX86OrX8664); + sess.dcx().emit_err(diagnostics::FunctionReturnRequiresX86OrX8664); } } if sess.opts.unstable_opts.indirect_branch_cs_prefix { if !matches!(sess.target.arch, Arch::X86 | Arch::X86_64) { - sess.dcx().emit_err(errors::IndirectBranchCsPrefixRequiresX86OrX8664); + sess.dcx().emit_err(diagnostics::IndirectBranchCsPrefixRequiresX86OrX8664); } } if let Some(regparm) = sess.opts.unstable_opts.regparm { if regparm > 3 { - sess.dcx().emit_err(errors::UnsupportedRegparm { regparm }); + sess.dcx().emit_err(diagnostics::UnsupportedRegparm { regparm }); } if sess.target.arch != Arch::X86 { - sess.dcx().emit_err(errors::UnsupportedRegparmArch); + sess.dcx().emit_err(diagnostics::UnsupportedRegparmArch); } } if sess.opts.unstable_opts.reg_struct_return { if sess.target.arch != Arch::X86 { - sess.dcx().emit_err(errors::UnsupportedRegStructReturnArch); + sess.dcx().emit_err(diagnostics::UnsupportedRegStructReturnArch); } } @@ -1401,14 +1401,14 @@ fn validate_commandline_args_with_session_available(sess: &Session) { if let Some(code_model) = sess.code_model() && code_model == CodeModel::Large { - sess.dcx().emit_err(errors::FunctionReturnThunkExternRequiresNonLargeCodeModel); + sess.dcx().emit_err(diagnostics::FunctionReturnThunkExternRequiresNonLargeCodeModel); } } } if sess.opts.unstable_opts.packed_stack { if sess.target.arch != Arch::S390x { - sess.dcx().emit_err(errors::UnsupportedPackedStack); + sess.dcx().emit_err(diagnostics::UnsupportedPackedStack); } } } From 2a74949017bdce8f1e7931960005391be2f6009c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 13 Jul 2026 22:31:51 +0200 Subject: [PATCH 8/9] Update `rustc_session::errors` import --- compiler/rustc_ast_lowering/src/asm.rs | 2 +- compiler/rustc_ast_lowering/src/expr.rs | 4 ++-- compiler/rustc_ast_lowering/src/lib.rs | 2 +- compiler/rustc_ast_lowering/src/path.rs | 2 +- compiler/rustc_ast_lowering/src/stability.rs | 2 +- .../rustc_ast_passes/src/ast_validation.rs | 2 +- compiler/rustc_ast_passes/src/feature_gate.rs | 2 +- .../rustc_attr_parsing/src/attributes/cfg.rs | 2 +- .../src/attributes/codegen_attrs.rs | 2 +- .../rustc_attr_parsing/src/attributes/doc.rs | 2 +- .../src/attributes/link_attrs.rs | 2 +- .../rustc_attr_parsing/src/attributes/repr.rs | 2 +- compiler/rustc_attr_parsing/src/parser.rs | 2 +- compiler/rustc_attr_parsing/src/stability.rs | 2 +- .../rustc_attr_parsing/src/validate_attr.rs | 2 +- compiler/rustc_builtin_macros/src/concat.rs | 2 +- .../rustc_builtin_macros/src/concat_bytes.rs | 2 +- compiler/rustc_builtin_macros/src/util.rs | 2 +- compiler/rustc_codegen_llvm/src/intrinsic.rs | 2 +- .../rustc_codegen_ssa/src/codegen_attrs.rs | 2 +- .../rustc_codegen_ssa/src/target_features.rs | 2 +- .../rustc_const_eval/src/check_consts/ops.rs | 2 +- compiler/rustc_expand/src/config.rs | 2 +- compiler/rustc_expand/src/expand.rs | 2 +- compiler/rustc_expand/src/mbe/macro_rules.rs | 2 +- compiler/rustc_expand/src/mbe/quoted.rs | 2 +- compiler/rustc_hir_analysis/src/check/mod.rs | 4 ++-- .../rustc_hir_analysis/src/check/wfcheck.rs | 2 +- .../rustc_hir_analysis/src/coherence/mod.rs | 2 +- .../src/collect/resolve_bound_vars.rs | 13 +++++++------ .../rustc_hir_analysis/src/collect/type_of.rs | 2 +- .../src/hir_ty_lowering/errors.rs | 2 +- .../src/hir_ty_lowering/mod.rs | 2 +- compiler/rustc_hir_analysis/src/lib.rs | 2 +- compiler/rustc_hir_typeck/src/expr.rs | 4 ++-- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 2 +- .../src/fn_ctxt/suggestions.rs | 2 +- compiler/rustc_hir_typeck/src/op.rs | 2 +- compiler/rustc_hir_typeck/src/pat.rs | 2 +- compiler/rustc_interface/src/passes.rs | 2 +- compiler/rustc_lint/src/levels.rs | 2 +- compiler/rustc_lint/src/lints.rs | 2 +- compiler/rustc_middle/src/middle/stability.rs | 2 +- compiler/rustc_parse/src/diagnostics.rs | 2 +- .../rustc_parse/src/parser/diagnostics.rs | 2 +- compiler/rustc_parse/src/parser/expr.rs | 2 +- compiler/rustc_parse/src/parser/pat.rs | 2 +- compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_resolve/src/ident.rs | 2 +- compiler/rustc_resolve/src/imports.rs | 2 +- compiler/rustc_resolve/src/late.rs | 2 +- compiler/rustc_resolve/src/macros.rs | 2 +- compiler/rustc_session/src/session.rs | 19 ++++++++++++------- .../src/error_reporting/traits/ambiguity.rs | 2 +- .../rustc_trait_selection/src/traits/wf.rs | 2 +- .../passes/collect_intra_doc_links.rs | 2 +- 56 files changed, 76 insertions(+), 70 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index 5628dffd51358..c6124fdfff38c 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_errors::msg; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::{Span, sym}; use rustc_target::asm; diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 4ed23e032d234..d427291b3048a 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -11,7 +11,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::{HirId, Target, find_attr}; use rustc_middle::span_bug; use rustc_middle::ty::TyCtxt; -use rustc_session::errors::report_lit_error; +use rustc_session::diagnostics::report_lit_error; use rustc_span::{ByteSymbol, DUMMY_SP, DesugaringKind, Ident, Span, Spanned, Symbol, respan, sym}; use thin_vec::{ThinVec, thin_vec}; use visit::{Visitor, walk_expr}; @@ -1644,7 +1644,7 @@ impl<'hir> LoweringContext<'_, 'hir> { && !self.tcx.features().coroutines() && !self.tcx.features().gen_blocks() { - rustc_session::errors::feature_err( + rustc_session::diagnostics::feature_err( &self.tcx.sess, sym::yield_expr, span, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 06fd76a6bde47..ffe24c2adfc95 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -67,7 +67,7 @@ use rustc_macros::extension; use rustc_middle::queries::Providers; use rustc_middle::span_bug; use rustc_middle::ty::{PerOwnerResolverData, ResolverAstLowering, TyCtxt}; -use rustc_session::errors::add_feature_diagnostics; +use rustc_session::diagnostics::add_feature_diagnostics; use rustc_span::symbol::{Ident, Symbol, kw, sym}; use rustc_span::{DUMMY_SP, DesugaringKind, Span}; use smallvec::{SmallVec, smallvec}; diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 18e037527836a..8ac9654d4ba53 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -6,7 +6,7 @@ use rustc_hir::def::{DefKind, PartialRes, PerNS, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, GenericArg}; use rustc_middle::{span_bug, ty}; -use rustc_session::errors::add_feature_diagnostics; +use rustc_session::diagnostics::add_feature_diagnostics; use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym}; use smallvec::smallvec; use tracing::{debug, instrument}; diff --git a/compiler/rustc_ast_lowering/src/stability.rs b/compiler/rustc_ast_lowering/src/stability.rs index b58087e4aa3a6..c56edb5f8ee7e 100644 --- a/compiler/rustc_ast_lowering/src/stability.rs +++ b/compiler/rustc_ast_lowering/src/stability.rs @@ -3,7 +3,7 @@ use std::fmt; use rustc_abi::ExternAbi; use rustc_feature::Features; use rustc_session::Session; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::symbol::sym; use rustc_span::{Span, Symbol}; diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 281f417500c55..b1fe45845fd8d 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -30,7 +30,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_errors::{DiagCtxtHandle, Diagnostic, LintBuffer}; use rustc_feature::Features; use rustc_session::Session; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint::builtin::{ DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, MISSING_UNSAFE_ON_EXTERN, PATTERNS_IN_FNS_WITHOUT_BODY, UNUSED_VISIBILITIES, diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index b5df56600b4f5..9411a34f85e6d 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -6,7 +6,7 @@ use rustc_feature::Features; use rustc_hir::Attribute; use rustc_hir::attrs::AttributeKind; use rustc_session::Session; -use rustc_session::errors::{feature_err, feature_warn}; +use rustc_session::diagnostics::{feature_err, feature_warn}; use rustc_span::{Span, Spanned, Symbol, sym}; use crate::diagnostics; diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg.rs b/compiler/rustc_attr_parsing/src/attributes/cfg.rs index 6ec677d0d1f1a..da37e51286d53 100644 --- a/compiler/rustc_attr_parsing/src/attributes/cfg.rs +++ b/compiler/rustc_attr_parsing/src/attributes/cfg.rs @@ -11,7 +11,7 @@ use rustc_parse::parser::{ForceCollect, Parser, Recovery}; use rustc_parse::{exp, parse_in}; use rustc_session::Session; use rustc_session::config::ExpectedValues; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint::builtin::UNEXPECTED_CFGS; use rustc_session::parse::ParseSess; use rustc_span::{ErrorGuaranteed, Span, Symbol, sym}; diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs index f48fbe6324834..3f9313b19ccd0 100644 --- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs @@ -2,7 +2,7 @@ use rustc_feature::AttributeStability; use rustc_hir::attrs::{ CoverageAttrKind, InstrumentFnAttr, OptimizeAttr, RtsanSetting, SanitizerSet, UsedBy, }; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::edition::Edition::Edition2024; use super::prelude::*; diff --git a/compiler/rustc_attr_parsing/src/attributes/doc.rs b/compiler/rustc_attr_parsing/src/attributes/doc.rs index 9b03792057b33..da0598abc17af 100644 --- a/compiler/rustc_attr_parsing/src/attributes/doc.rs +++ b/compiler/rustc_attr_parsing/src/attributes/doc.rs @@ -7,7 +7,7 @@ use rustc_hir::attrs::{ AttributeKind, CfgEntry, CfgHideShow, DocAttribute, DocCfgHideShow, DocCfgHideShowValue, DocInline, HideOrShow, }; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::{Span, Symbol, edition, sym}; use super::prelude::{ALL_TARGETS, AllowedTargets}; diff --git a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs index 2c640ab5385b9..c76661b80e11d 100644 --- a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs @@ -3,7 +3,7 @@ use rustc_feature::{AttributeStability, Features}; use rustc_hir::attrs::AttributeKind::{LinkName, LinkOrdinal, LinkSection}; use rustc_hir::attrs::*; use rustc_session::Session; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT; use rustc_span::edition::Edition::Edition2024; use rustc_span::kw; diff --git a/compiler/rustc_attr_parsing/src/attributes/repr.rs b/compiler/rustc_attr_parsing/src/attributes/repr.rs index 630edafef8c98..dfb7ce5e7b2f4 100644 --- a/compiler/rustc_attr_parsing/src/attributes/repr.rs +++ b/compiler/rustc_attr_parsing/src/attributes/repr.rs @@ -3,7 +3,7 @@ use rustc_ast::{IntTy, LitIntType, LitKind, UintTy}; use rustc_feature::AttributeStability; use rustc_hir::attrs::IntType::{SignedInt, UnsignedInt}; use rustc_hir::attrs::ReprAttr; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use super::prelude::*; use crate::session_diagnostics; diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs index 5450a51484542..269db3c8c6c38 100644 --- a/compiler/rustc_attr_parsing/src/parser.rs +++ b/compiler/rustc_attr_parsing/src/parser.rs @@ -23,7 +23,7 @@ use rustc_errors::{Applicability, Diag, PResult}; use rustc_hir::{self as hir, AttrPath}; use rustc_parse::exp; use rustc_parse::parser::{ForceCollect, Parser, PathStyle, Recovery, token_descr}; -use rustc_session::errors::create_lit_error; +use rustc_session::diagnostics::create_lit_error; use rustc_session::parse::ParseSess; use rustc_span::{Ident, Span, Symbol, sym}; use thin_vec::ThinVec; diff --git a/compiler/rustc_attr_parsing/src/stability.rs b/compiler/rustc_attr_parsing/src/stability.rs index 7d5843e1c950f..c4cb5acd2426e 100644 --- a/compiler/rustc_attr_parsing/src/stability.rs +++ b/compiler/rustc_attr_parsing/src/stability.rs @@ -1,6 +1,6 @@ use rustc_feature::AttributeStability; use rustc_hir::AttrPath; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::{Span, sym}; use crate::{AttributeParser, ShouldEmit}; diff --git a/compiler/rustc_attr_parsing/src/validate_attr.rs b/compiler/rustc_attr_parsing/src/validate_attr.rs index 22a47434e5873..748e452a24cac 100644 --- a/compiler/rustc_attr_parsing/src/validate_attr.rs +++ b/compiler/rustc_attr_parsing/src/validate_attr.rs @@ -12,7 +12,7 @@ use rustc_errors::{Applicability, Diagnostic, PResult}; use rustc_feature::BUILTIN_ATTRIBUTE_MAP; use rustc_hir::AttrPath; use rustc_parse::parse_in; -use rustc_session::errors::report_lit_error; +use rustc_session::diagnostics::report_lit_error; use rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT; use rustc_session::parse::ParseSess; use rustc_span::{Span, Symbol, sym}; diff --git a/compiler/rustc_builtin_macros/src/concat.rs b/compiler/rustc_builtin_macros/src/concat.rs index f359b8336dbd5..a260b3c43e8af 100644 --- a/compiler/rustc_builtin_macros/src/concat.rs +++ b/compiler/rustc_builtin_macros/src/concat.rs @@ -1,7 +1,7 @@ use rustc_ast::tokenstream::TokenStream; use rustc_ast::{ExprKind, LitKind, UnOp}; use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult}; -use rustc_session::errors::report_lit_error; +use rustc_session::diagnostics::report_lit_error; use rustc_span::Symbol; use crate::diagnostics; diff --git a/compiler/rustc_builtin_macros/src/concat_bytes.rs b/compiler/rustc_builtin_macros/src/concat_bytes.rs index f86b1daa13d2d..15d0f43d039f2 100644 --- a/compiler/rustc_builtin_macros/src/concat_bytes.rs +++ b/compiler/rustc_builtin_macros/src/concat_bytes.rs @@ -1,7 +1,7 @@ use rustc_ast::tokenstream::TokenStream; use rustc_ast::{ExprKind, LitIntType, LitKind, StrStyle, UintTy, token}; use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult}; -use rustc_session::errors::report_lit_error; +use rustc_session::diagnostics::report_lit_error; use rustc_span::{ErrorGuaranteed, Span}; use crate::diagnostics; diff --git a/compiler/rustc_builtin_macros/src/util.rs b/compiler/rustc_builtin_macros/src/util.rs index c6ea73295efba..80fa3e3b8ac8d 100644 --- a/compiler/rustc_builtin_macros/src/util.rs +++ b/compiler/rustc_builtin_macros/src/util.rs @@ -6,7 +6,7 @@ use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt}; use rustc_expand::expand::AstFragment; use rustc_lint_defs::builtin::DUPLICATE_MACRO_ATTRIBUTES; use rustc_parse::{exp, parser}; -use rustc_session::errors::report_lit_error; +use rustc_session::diagnostics::report_lit_error; use rustc_span::{BytePos, Span, Symbol}; use crate::diagnostics; diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 24e9a6cb3e2d4..78fcae8d54c8c 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -23,7 +23,7 @@ use rustc_middle::ty::offload_meta::OffloadMetadata; use rustc_middle::ty::{self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv}; use rustc_middle::{bug, span_bug}; use rustc_session::config::CrateType; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint::builtin::DEPRECATED_LLVM_INTRINSIC; use rustc_span::{ErrorGuaranteed, Span, Symbol, sym}; use rustc_symbol_mangling::{mangle_internal_symbol, symbol_name_for_instance_in_crate}; diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 46bb1182c298c..9a758d99a82d2 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -13,7 +13,7 @@ use rustc_middle::middle::codegen_fn_attrs::{ use rustc_middle::mono::Visibility; use rustc_middle::query::Providers; use rustc_middle::ty::{self as ty, TyCtxt}; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint; use rustc_span::{Span, sym}; use rustc_target::spec::Os; diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 3c771f0eb7ec4..b23472c794b88 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -7,7 +7,7 @@ use rustc_middle::middle::codegen_fn_attrs::{TargetFeature, TargetFeatureKind}; use rustc_middle::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::Session; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint::builtin::AARCH64_SOFTFLOAT_NEON; use rustc_span::{Span, Symbol, edit_distance, sym}; use rustc_target::spec::{Arch, SanitizerSet}; diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index 1f4b2c7879cc7..c8e404ed3236f 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -14,7 +14,7 @@ use rustc_middle::ty::{ self, AssocContainer, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, Param, TraitRef, Ty, suggest_constraining_type_param, }; -use rustc_session::errors::add_feature_diagnostics; +use rustc_session::diagnostics::add_feature_diagnostics; use rustc_span::{BytePos, Pos, Span, Symbol, sym}; use rustc_trait_selection::error_reporting::traits::call_kind::{ CallDesugaringKind, CallKind, call_kind, diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index b3582494f226e..3127fd9b49789 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -27,7 +27,7 @@ use rustc_hir::{ }; use rustc_parse::parser::Recovery; use rustc_session::Session; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::{STDLIB_STABLE_CRATES, Span, Symbol, sym}; use tracing::instrument; diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 6dbac58cc6dbe..48d3b5db6e822 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -29,7 +29,7 @@ use rustc_parse::parser::{ AllowConstBlockItems, AttemptLocalParseRecovery, CommaRecoveryMode, ForceCollect, Parser, RecoverColon, RecoverComma, Recovery, token_descr, }; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS}; use rustc_span::hygiene::SyntaxContext; use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, Symbol, sym}; diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 4a0cacc977529..9883c8120fd5f 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -23,7 +23,7 @@ use rustc_lint_defs::builtin::{ use rustc_parse::exp; use rustc_parse::parser::{Parser, Recovery}; use rustc_session::Session; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::parse::ParseSess; use rustc_span::edition::Edition; use rustc_span::hygiene::Transparency; diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index 3e82a61067af4..2779291abf361 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -5,7 +5,7 @@ use rustc_ast_pretty::pprust; use rustc_errors::Applicability; use rustc_feature::Features; use rustc_session::Session; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::edition::Edition; use rustc_span::{Ident, Span, kw, sym}; diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index f0c5f6b85423c..39ef5e370ba5d 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -91,7 +91,7 @@ use rustc_middle::ty::{ self, GenericArgs, GenericArgsRef, OutlivesPredicate, Region, Ty, TyCtxt, TypingMode, }; use rustc_middle::{bug, span_bug}; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::{BytePos, DUMMY_SP, Ident, Span, Symbol, kw}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; @@ -311,7 +311,7 @@ fn default_body_is_unstable( }); let inject_span = item_did.is_local().then(|| tcx.crate_level_attribute_injection_span()); - rustc_session::errors::add_feature_diagnostics_for_issue( + rustc_session::diagnostics::add_feature_diagnostics_for_issue( &mut err, &tcx.sess, feature, diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index c6308a2765084..0200418700c53 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -27,7 +27,7 @@ use rustc_middle::ty::{ Upcast, }; use rustc_middle::{bug, span_bug}; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::{DUMMY_SP, Span, sym}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::regions::{ diff --git a/compiler/rustc_hir_analysis/src/coherence/mod.rs b/compiler/rustc_hir_analysis/src/coherence/mod.rs index 237c2c72ca3bc..8391a47902e42 100644 --- a/compiler/rustc_hir_analysis/src/coherence/mod.rs +++ b/compiler/rustc_hir_analysis/src/coherence/mod.rs @@ -11,7 +11,7 @@ use rustc_hir::LangItem; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::query::Providers; use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt, elaborate}; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::{ErrorGuaranteed, sym}; use tracing::debug; diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index abef0d52f8ac9..f2a9c09f7303c 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -1310,12 +1310,13 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { && !self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id).is_async() && !self.tcx.features().anonymous_lifetime_in_impl_trait() { - let mut diag: rustc_errors::Diag<'_> = rustc_session::errors::feature_err( - &self.tcx.sess, - sym::anonymous_lifetime_in_impl_trait, - lifetime_ref.ident.span, - "anonymous lifetimes in `impl Trait` are unstable", - ); + let mut diag: rustc_errors::Diag<'_> = + rustc_session::diagnostics::feature_err( + &self.tcx.sess, + sym::anonymous_lifetime_in_impl_trait, + lifetime_ref.ident.span, + "anonymous lifetimes in `impl Trait` are unstable", + ); if let Some(generics) = self.tcx.hir_get_generics(lifetime_ref.hir_id.owner.def_id) diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 9c8e61d89da97..081efa3eec33e 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -522,7 +522,7 @@ fn infer_placeholder_type<'tcx>( fn check_feature_inherent_assoc_ty(tcx: TyCtxt<'_>, span: Span) { if !tcx.features().inherent_associated_types() { - use rustc_session::errors::feature_err; + use rustc_session::diagnostics::feature_err; use rustc_span::sym; feature_err( &tcx.sess, diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs index b9495c8519fa2..71858951731e6 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs @@ -16,7 +16,7 @@ use rustc_middle::ty::{ self, AdtDef, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt, suggest_constraining_type_param, }; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::{BytePos, DUMMY_SP, Ident, Span, Symbol, kw, sym}; use rustc_trait_selection::error_reporting::traits::report_dyn_incompatibility; diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 300eb5263d5dd..2f9e655ca44ec 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -43,7 +43,7 @@ use rustc_middle::ty::{ const_lit_matches_ty, fold_regions, }; use rustc_middle::{bug, span_bug}; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS; use rustc_span::{DUMMY_SP, Ident, Span, kw, sym}; use rustc_trait_selection::infer::InferCtxtExt; diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 464d17fc22bb1..9ec74543719dc 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -90,7 +90,7 @@ use rustc_middle::mir::interpret::GlobalId; use rustc_middle::query::Providers; use rustc_middle::ty::{Const, Ty, TyCtxt}; use rustc_middle::{middle, ty}; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::{ErrorGuaranteed, Span}; use rustc_trait_selection::traits; diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 5a30f0fb56c66..a83d367510248 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -30,7 +30,7 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase}; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::{self, AdtKind, GenericArgsRef, Ty, TypeVisitableExt, Unnormalized}; use rustc_middle::{bug, span_bug}; -use rustc_session::errors::{ExprParenthesesNeeded, feature_err}; +use rustc_session::diagnostics::{ExprParenthesesNeeded, feature_err}; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::hygiene::DesugaringKind; use rustc_span::{Ident, Span, Spanned, Symbol, kw, sym}; @@ -3773,7 +3773,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ident = self.tcx.adjust_ident(field, container_def.did()); if !self.tcx.features().offset_of_enum() { - rustc_session::errors::feature_err( + rustc_session::diagnostics::feature_err( &self.tcx.sess, sym::offset_of_enum, ident.span, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index e7b25dec4db59..c76febd539ef8 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -21,7 +21,7 @@ use rustc_middle::ty::error::TypeError; use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, Unnormalized}; use rustc_middle::{bug, span_bug}; use rustc_session::Session; -use rustc_session::errors::ExprParenthesesNeeded; +use rustc_session::diagnostics::ExprParenthesesNeeded; use rustc_span::{DUMMY_SP, Ident, Span, kw, sym}; use rustc_trait_selection::error_reporting::infer::{FailureCode, ObligationCauseExt}; use rustc_trait_selection::infer::InferCtxtExt; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 6fb72f414a049..6f5c86610cd53 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -23,7 +23,7 @@ use rustc_middle::ty::{ self, Article, Binder, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, Unnormalized, Upcast, suggest_constraining_type_params, }; -use rustc_session::errors::ExprParenthesesNeeded; +use rustc_session::diagnostics::ExprParenthesesNeeded; use rustc_span::{ExpnKind, Ident, MacroKind, Span, Spanned, Symbol, sym}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::error_reporting::traits::DefIdOrName; diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index 682ae998b411d..9605b956f53a4 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -13,7 +13,7 @@ use rustc_middle::ty::adjustment::{ }; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt}; -use rustc_session::errors::ExprParenthesesNeeded; +use rustc_session::diagnostics::ExprParenthesesNeeded; use rustc_span::{Span, Spanned, Symbol, sym}; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::{FulfillmentError, Obligation, ObligationCtxt}; diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index ad9d0df78b333..ebe9645550454 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -21,7 +21,7 @@ use rustc_infer::infer::RegionVariableOrigin; use rustc_middle::traits::PatternOriginExpr; use rustc_middle::ty::{self, Pinnedness, Ty, TypeVisitableExt, Unnormalized}; use rustc_middle::{bug, span_bug}; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::edition::Edition; diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index fad197acd2330..ca983db29bcf7 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -39,7 +39,7 @@ use rustc_resolve::{Resolver, ResolverOutputs}; use rustc_session::Session; use rustc_session::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType}; use rustc_session::cstore::Untracked; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::output::{filename_for_input, invalid_output_for_target}; use rustc_session::search_paths::PathKind; use rustc_span::{ diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 492131ca8b32e..ef23085417352 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -971,7 +971,7 @@ where let mut lint = Diag::new(dcx, level, msg!("unknown lint: `{$name}`")) .with_arg("name", lint_id.lint.name_lower()) .with_note(msg!("the `{$name}` lint is unstable")); - rustc_session::errors::add_feature_diagnostics_for_issue( + rustc_session::diagnostics::add_feature_diagnostics_for_issue( &mut lint, sess, feature, diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index eb82afab13186..c3555b8fe44d2 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -266,7 +266,7 @@ impl<'a> Diagnostic<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> { fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { let mut diag = Diag::new(dcx, level, "`#[track_caller]` on async functions is a no-op") .with_span_label(self.label, "this function will not propagate the caller location"); - rustc_session::errors::add_feature_diagnostics( + rustc_session::diagnostics::add_feature_diagnostics( &mut diag, self.session, sym::async_fn_track_caller, diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index db91a889bec4b..6c8d2808eb65b 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -11,7 +11,7 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, ConstStability, DefaultBodyStability, HirId, Stability}; use rustc_macros::{Decodable, Encodable, StableHash, Subdiagnostic}; use rustc_session::Session; -use rustc_session::errors::feature_err_issue; +use rustc_session::diagnostics::feature_err_issue; use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE}; use rustc_session::lint::{DeprecatedSinceKind, Lint}; use rustc_span::{Span, Symbol, sym}; diff --git a/compiler/rustc_parse/src/diagnostics.rs b/compiler/rustc_parse/src/diagnostics.rs index c0336cd57603c..a382db5b58a13 100644 --- a/compiler/rustc_parse/src/diagnostics.rs +++ b/compiler/rustc_parse/src/diagnostics.rs @@ -11,7 +11,7 @@ use rustc_errors::{ Level, Subdiagnostic, SuggestionStyle, msg, }; use rustc_macros::{Diagnostic, Subdiagnostic}; -use rustc_session::errors::ExprParenthesesNeeded; +use rustc_session::diagnostics::ExprParenthesesNeeded; use rustc_span::edition::{Edition, LATEST_STABLE_EDITION}; use rustc_span::{Ident, Span, Symbol}; diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 9a7236920d255..e5be778458135 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -15,7 +15,7 @@ use rustc_errors::{ Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, PResult, Subdiagnostic, Suggestions, msg, pluralize, }; -use rustc_session::errors::ExprParenthesesNeeded; +use rustc_session::diagnostics::ExprParenthesesNeeded; use rustc_span::symbol::used_keywords; use rustc_span::{BytePos, DUMMY_SP, Ident, Span, SpanSnippetError, Spanned, Symbol, kw, sym}; use thin_vec::{ThinVec, thin_vec}; diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index e899bf1627681..b1a83507896dc 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -22,7 +22,7 @@ use rustc_ast_pretty::pprust; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::{Applicability, Diag, PResult, StashKey, Subdiagnostic}; use rustc_literal_escaper::unescape_char; -use rustc_session::errors::{ExprParenthesesNeeded, report_lit_error}; +use rustc_session::diagnostics::{ExprParenthesesNeeded, report_lit_error}; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; use rustc_span::edition::Edition; use rustc_span::{BytePos, ErrorGuaranteed, Ident, Pos, Span, Spanned, Symbol, kw, respan, sym}; diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 3563dca21c2ef..74b2194cc97fa 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -12,7 +12,7 @@ use rustc_ast::{ }; use rustc_ast_pretty::pprust; use rustc_errors::{Applicability, Diag, DiagArgValue, PResult, StashKey}; -use rustc_session::errors::ExprParenthesesNeeded; +use rustc_session::diagnostics::ExprParenthesesNeeded; use rustc_span::{BytePos, ErrorGuaranteed, Ident, Span, Spanned, kw, respan, sym}; use thin_vec::{ThinVec, thin_vec}; diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 863e4d88872c9..a9d0f6defe45d 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -37,7 +37,7 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::{self, TyCtxt, TypingMode, Unnormalized}; use rustc_middle::{bug, span_bug}; use rustc_session::config::CrateType; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint; use rustc_session::lint::builtin::{ CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, MALFORMED_DIAGNOSTIC_ATTRIBUTES, diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 12dd05bfe6e60..134aec3d0c7d2 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -6,7 +6,7 @@ use rustc_ast::{self as ast, NodeId}; use rustc_errors::ErrorGuaranteed; use rustc_hir::def::{DefKind, MacroKinds, Namespace, NonMacroAttrKind, PartialRes, PerNS}; use rustc_middle::{bug, span_bug}; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK; use rustc_span::edition::Edition; use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext}; diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index d62bf538133f2..d3b1d06b870a9 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -13,7 +13,7 @@ use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap}; use rustc_middle::metadata::{AmbigModChild, ModChild, Reexport}; use rustc_middle::span_bug; use rustc_middle::ty::Visibility; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint::LintId; use rustc_session::lint::builtin::{ AMBIGUOUS_GLOB_REEXPORTS, EXPORTED_PRIVATE_DEPENDENCIES, HIDDEN_GLOB_REEXPORTS, diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 8c375f6d26611..a7b8140acf644 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -32,7 +32,7 @@ use rustc_middle::middle::resolve_bound_vars::Set1; use rustc_middle::ty::{AssocTag, DelegationInfo, Visibility}; use rustc_middle::{bug, span_bug}; use rustc_session::config::{CrateType, ResolveDocLinks}; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint; use rustc_span::{BytePos, DUMMY_SP, Ident, Span, Spanned, Symbol, kw, respan, sym}; use smallvec::{SmallVec, smallvec}; diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 595c2fdf011dd..f78b790e2aa87 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -23,7 +23,7 @@ use rustc_hir::{Attribute, StabilityLevel}; use rustc_middle::middle::stability; use rustc_middle::ty::{RegisteredTools, TyCtxt}; use rustc_session::Session; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_session::lint::builtin::{ LEGACY_DERIVE_HELPERS, OUT_OF_SCOPE_MACRO_CALLS, UNKNOWN_DIAGNOSTIC_ATTRIBUTES, UNUSED_MACRO_RULES, UNUSED_MACROS, diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index e176259c23f29..b7c0923163b4d 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -932,7 +932,8 @@ impl Session { version.max(min) } Err(error) => { - self.dcx().emit_err(diagnostics::AppleDeploymentTarget::Invalid { env_var, error }); + self.dcx() + .emit_err(diagnostics::AppleDeploymentTarget::Invalid { env_var, error }); min } } @@ -1203,8 +1204,9 @@ fn validate_commandline_args_with_session_available(sess: &Session) { match unsupported_sanitizers.into_iter().count() { 0 => {} 1 => { - sess.dcx() - .emit_err(diagnostics::SanitizerNotSupported { us: unsupported_sanitizers.to_string() }); + sess.dcx().emit_err(diagnostics::SanitizerNotSupported { + us: unsupported_sanitizers.to_string(), + }); } _ => { sess.dcx().emit_err(diagnostics::SanitizersNotSupported { @@ -1331,15 +1333,17 @@ fn validate_commandline_args_with_session_available(sess: &Session) { if !sess.target.options.supported_split_debuginfo.contains(&sess.split_debuginfo()) && !sess.opts.unstable_opts.unstable_options { - sess.dcx() - .emit_err(diagnostics::SplitDebugInfoUnstablePlatform { debuginfo: sess.split_debuginfo() }); + sess.dcx().emit_err(diagnostics::SplitDebugInfoUnstablePlatform { + debuginfo: sess.split_debuginfo(), + }); } if sess.opts.unstable_opts.embed_source { let dwarf_version = sess.dwarf_version(); if dwarf_version < 5 { - sess.dcx().emit_warn(diagnostics::EmbedSourceInsufficientDwarfVersion { dwarf_version }); + sess.dcx() + .emit_warn(diagnostics::EmbedSourceInsufficientDwarfVersion { dwarf_version }); } if sess.opts.debuginfo == DebugInfo::None { @@ -1401,7 +1405,8 @@ fn validate_commandline_args_with_session_available(sess: &Session) { if let Some(code_model) = sess.code_model() && code_model == CodeModel::Large { - sess.dcx().emit_err(diagnostics::FunctionReturnThunkExternRequiresNonLargeCodeModel); + sess.dcx() + .emit_err(diagnostics::FunctionReturnThunkExternRequiresNonLargeCodeModel); } } } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs index 40bae03a649db..5e2e9f67103dd 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs @@ -13,7 +13,7 @@ use rustc_infer::traits::{ }; use rustc_middle::ty::print::PrintPolyTraitPredicateExt; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable as _, TypeVisitableExt as _, Unnormalized}; -use rustc_session::errors::feature_err_unstable_feature_bound; +use rustc_session::diagnostics::feature_err_unstable_feature_bound; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span}; use tracing::{debug, instrument}; diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 8ecea8279aac1..48d449c64ba9d 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -13,7 +13,7 @@ use rustc_middle::ty::{ self, GenericArgsRef, Term, TermKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, }; -use rustc_session::errors::feature_err; +use rustc_session::diagnostics::feature_err; use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::{Span, sym}; use tracing::{debug, instrument, trace}; diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 4a3e6ac218a67..02423c4b9391b 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1506,7 +1506,7 @@ impl LinkCollector<'_, '_> { Some((sp, _)) => sp, None => item.attr_span(self.cx.tcx), }; - rustc_session::errors::feature_err( + rustc_session::diagnostics::feature_err( self.cx.tcx.sess, sym::intra_doc_pointers, span, From 4882893863fabec457aeea337eb654d479c96cca Mon Sep 17 00:00:00 2001 From: IsaiahCoroama Date: Mon, 13 Jul 2026 21:07:56 -0500 Subject: [PATCH 9/9] Fix where-bound suggestion for legacy const generics Point the suggestion at the const argument's span instead of the whole obligation, and parenthesize the snippet when the const expression needs it (e.g. `(N + 1) as usize`) so the suggested bound parses and compiles. Also add regression tests for legacy const generic where-bound suggestions. --- compiler/rustc_ast_lowering/src/expr.rs | 2 +- .../traits/fulfillment_errors.rs | 20 ++- .../auxiliary/legacy_const_generics_bounds.rs | 32 +++++ ...gacy-const-generics-bound-suggestion.fixed | 86 +++++++++++ .../legacy-const-generics-bound-suggestion.rs | 86 +++++++++++ ...acy-const-generics-bound-suggestion.stderr | 134 ++++++++++++++++++ 6 files changed, 355 insertions(+), 5 deletions(-) create mode 100644 tests/ui/const-generics/generic_const_exprs/auxiliary/legacy_const_generics_bounds.rs create mode 100644 tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.fixed create mode 100644 tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.rs create mode 100644 tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.stderr diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 4ed23e032d234..312722b680bff 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -597,7 +597,7 @@ impl<'hir> LoweringContext<'_, 'hir> { for (idx, arg) in args.iter().cloned().enumerate() { if legacy_args_idx.contains(&idx) { let node_id = self.next_node_id(); - self.create_def(node_id, None, DefKind::AnonConst, f.span); + self.create_def(node_id, None, DefKind::AnonConst, arg.span); let const_value = if let ControlFlow::Break(span) = WillCreateDefIdsVisitor.visit_expr(&arg) { Box::new(Expr { diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index b38c933151eb2..c7791b9deee29 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -16,7 +16,7 @@ use rustc_errors::{ use rustc_hir::attrs::diagnostic::CustomDiagnostic; use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId}; use rustc_hir::intravisit::Visitor; -use rustc_hir::{self as hir, LangItem, Node, find_attr}; +use rustc_hir::{self as hir, LangItem, Node, expr_needs_parens, find_attr}; use rustc_infer::infer::{InferOk, TypeTrace}; use rustc_infer::traits::ImplSource; use rustc_infer::traits::solve::Goal; @@ -3798,13 +3798,24 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { ty::ConstKind::Alias(_, alias_const) => { let mut err = self.dcx().struct_span_err(span, "unconstrained generic constant"); - let const_span = alias_const.kind.def_span(self.tcx); + let const_span = alias_const.kind.def_span(self.tcx); let const_ty = alias_const.type_of(self.tcx).skip_norm_wip(); - let cast = if const_ty != self.tcx.types.usize { " as usize" } else { "" }; + let msg = "try adding a `where` bound"; if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(const_span) { - let code = format!("[(); {snippet}{cast}]:"); + let code = if const_ty == self.tcx.types.usize { + format!("[(); {snippet}]:") + } else if let ty::AliasConstKind::Anon { def_id } = alias_const.kind + && let Some(local_def_id) = def_id.as_local() + && let Some(local_body) = self.tcx.hir_maybe_body_owned_by(local_def_id) + && expr_needs_parens(local_body.value) + { + format!("[(); ({snippet}) as usize]:") + } else { + format!("[(); {snippet} as usize]:") + }; + let suggestion_def_id = if let ObligationCauseCode::CompareImplItem { trait_item_def_id, .. @@ -3814,6 +3825,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } else { Some(obligation.cause.body_def_id) }; + if let Some(suggestion_def_id) = suggestion_def_id && let Some(generics) = self.tcx.hir_get_generics(suggestion_def_id) { diff --git a/tests/ui/const-generics/generic_const_exprs/auxiliary/legacy_const_generics_bounds.rs b/tests/ui/const-generics/generic_const_exprs/auxiliary/legacy_const_generics_bounds.rs new file mode 100644 index 0000000000000..821ed040e1dbc --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/auxiliary/legacy_const_generics_bounds.rs @@ -0,0 +1,32 @@ +#![allow(internal_features)] +#![feature(rustc_attrs)] + +// Signed Primitive Integers + +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_i8() {} +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_i16() {} +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_i32() {} +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_i64() {} +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_i128() {} +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_isize() {} + +// Unsigned Primitive Integers + +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_u8() {} +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_u16() {} +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_u32() {} +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_u64() {} +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_u128() {} +#[rustc_legacy_const_generics(0)] +pub fn arg0_as_usize() {} diff --git a/tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.fixed b/tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.fixed new file mode 100644 index 0000000000000..835b0de582922 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.fixed @@ -0,0 +1,86 @@ +//@ run-rustfix +//@ aux-crate: legacy_const_generics_bounds=legacy_const_generics_bounds.rs +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] + +// Signed Primitive Integers + +fn invoke_arg0_as_i8() where [(); (N + 1) as usize]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_i8(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_i16() where [(); (N + 1) as usize]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_i16(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_i32() where [(); (N + 1) as usize]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_i32(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_i64() where [(); (N + 1) as usize]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_i64(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_i128() where [(); (N + 1) as usize]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_i128(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_isize() where [(); (N + 1) as usize]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_isize(N + 1); + //~^ ERROR unconstrained generic constant +} + +// Unsigned Primitive Integers + +fn invoke_arg0_as_u8() where [(); (N + 1) as usize]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_u8(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_u16() where [(); (N + 1) as usize]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_u16(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_u32() where [(); (N + 1) as usize]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_u32(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_u64() where [(); (N + 1) as usize]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_u64(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_u128() where [(); (N + 1) as usize]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_u128(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_usize() where [(); N + 1]: { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_usize(N + 1); + //~^ ERROR unconstrained generic constant +} + +fn main() { + invoke_arg0_as_i8::<0>(); + invoke_arg0_as_i16::<0>(); + invoke_arg0_as_i32::<0>(); + invoke_arg0_as_i64::<0>(); + invoke_arg0_as_i128::<0>(); + invoke_arg0_as_isize::<0>(); + + invoke_arg0_as_u8::<0>(); + invoke_arg0_as_u16::<0>(); + invoke_arg0_as_u32::<0>(); + invoke_arg0_as_u64::<0>(); + invoke_arg0_as_u128::<0>(); + invoke_arg0_as_usize::<0>(); +} diff --git a/tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.rs b/tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.rs new file mode 100644 index 0000000000000..485a24783c8cd --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.rs @@ -0,0 +1,86 @@ +//@ run-rustfix +//@ aux-crate: legacy_const_generics_bounds=legacy_const_generics_bounds.rs +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] + +// Signed Primitive Integers + +fn invoke_arg0_as_i8() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_i8(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_i16() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_i16(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_i32() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_i32(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_i64() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_i64(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_i128() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_i128(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_isize() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_isize(N + 1); + //~^ ERROR unconstrained generic constant +} + +// Unsigned Primitive Integers + +fn invoke_arg0_as_u8() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_u8(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_u16() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_u16(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_u32() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_u32(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_u64() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_u64(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_u128() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_u128(N + 1); + //~^ ERROR unconstrained generic constant +} +fn invoke_arg0_as_usize() { + //~^ HELP try adding a `where` bound + legacy_const_generics_bounds::arg0_as_usize(N + 1); + //~^ ERROR unconstrained generic constant +} + +fn main() { + invoke_arg0_as_i8::<0>(); + invoke_arg0_as_i16::<0>(); + invoke_arg0_as_i32::<0>(); + invoke_arg0_as_i64::<0>(); + invoke_arg0_as_i128::<0>(); + invoke_arg0_as_isize::<0>(); + + invoke_arg0_as_u8::<0>(); + invoke_arg0_as_u16::<0>(); + invoke_arg0_as_u32::<0>(); + invoke_arg0_as_u64::<0>(); + invoke_arg0_as_u128::<0>(); + invoke_arg0_as_usize::<0>(); +} diff --git a/tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.stderr b/tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.stderr new file mode 100644 index 0000000000000..2c3b641540efb --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/legacy-const-generics-bound-suggestion.stderr @@ -0,0 +1,134 @@ +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:10:46 + | +LL | legacy_const_generics_bounds::arg0_as_i8(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_i8() where [(); (N + 1) as usize]: { + | +++++++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:15:47 + | +LL | legacy_const_generics_bounds::arg0_as_i16(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_i16() where [(); (N + 1) as usize]: { + | +++++++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:20:47 + | +LL | legacy_const_generics_bounds::arg0_as_i32(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_i32() where [(); (N + 1) as usize]: { + | +++++++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:25:47 + | +LL | legacy_const_generics_bounds::arg0_as_i64(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_i64() where [(); (N + 1) as usize]: { + | +++++++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:30:48 + | +LL | legacy_const_generics_bounds::arg0_as_i128(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_i128() where [(); (N + 1) as usize]: { + | +++++++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:35:49 + | +LL | legacy_const_generics_bounds::arg0_as_isize(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_isize() where [(); (N + 1) as usize]: { + | +++++++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:43:46 + | +LL | legacy_const_generics_bounds::arg0_as_u8(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_u8() where [(); (N + 1) as usize]: { + | +++++++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:48:47 + | +LL | legacy_const_generics_bounds::arg0_as_u16(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_u16() where [(); (N + 1) as usize]: { + | +++++++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:53:47 + | +LL | legacy_const_generics_bounds::arg0_as_u32(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_u32() where [(); (N + 1) as usize]: { + | +++++++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:58:47 + | +LL | legacy_const_generics_bounds::arg0_as_u64(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_u64() where [(); (N + 1) as usize]: { + | +++++++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:63:48 + | +LL | legacy_const_generics_bounds::arg0_as_u128(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_u128() where [(); (N + 1) as usize]: { + | +++++++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/legacy-const-generics-bound-suggestion.rs:68:49 + | +LL | legacy_const_generics_bounds::arg0_as_usize(N + 1); + | ^^^^^ + | +help: try adding a `where` bound + | +LL | fn invoke_arg0_as_usize() where [(); N + 1]: { + | ++++++++++++++++++ + +error: aborting due to 12 previous errors +