From 301ce3610f5a40b33162e38b30e0b7ee47c805c1 Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 26 Feb 2024 07:59:44 +0100 Subject: [PATCH 1/2] Limit non local defs lint logic to only impls and macros --- compiler/rustc_lint/src/non_local_def.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index 6cb6fd1cbd550..9ba04ca9ea434 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -67,6 +67,10 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { return; } + if !matches!(item.kind, ItemKind::Impl(_) | ItemKind::Macro(_, _)) { + return; + } + let parent = cx.tcx.parent(item.owner_id.def_id.into()); let parent_def_kind = cx.tcx.def_kind(parent); let parent_opt_item_name = cx.tcx.opt_item_name(parent); From 2b512024c031142a9a8765a15f6fc5171c3c6690 Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 26 Feb 2024 20:07:21 +0100 Subject: [PATCH 2/2] Use nearly exclusively HIR and avoid at all cost unnecessary query calls --- compiler/rustc_lint/src/non_local_def.rs | 102 ++++++++++++------ tests/ui/lint/non_local_definitions.stderr | 100 ++++++++--------- tests/ui/proc-macro/nested-macro-rules.stderr | 2 +- 3 files changed, 119 insertions(+), 85 deletions(-) diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index 9ba04ca9ea434..974a9bd8ca8f6 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -1,8 +1,6 @@ -use rustc_hir::{def::DefKind, Body, Item, ItemKind, Node, Path, QPath, TyKind}; +use rustc_hir::{Body, Item, ItemKind, OwnerNode, Path, QPath, TyKind}; use rustc_span::def_id::{DefId, LOCAL_CRATE}; -use rustc_span::{sym, symbol::kw, ExpnKind, MacroKind}; - -use smallvec::{smallvec, SmallVec}; +use rustc_span::{sym, symbol::kw, symbol::Ident, ExpnKind, MacroKind}; use crate::lints::{NonLocalDefinitionsCargoUpdateNote, NonLocalDefinitionsDiag}; use crate::{LateContext, LateLintPass, LintContext}; @@ -71,15 +69,20 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { return; } - let parent = cx.tcx.parent(item.owner_id.def_id.into()); - let parent_def_kind = cx.tcx.def_kind(parent); - let parent_opt_item_name = cx.tcx.opt_item_name(parent); + let Some((_, parent_node)) = cx.tcx.hir().parent_owner_iter(item.hir_id()).next() else { + return; + }; + let parent_is_anon_const = matches!( + parent_node, + OwnerNode::Item(Item { + ident: Ident { name: kw::Underscore, .. }, + kind: ItemKind::Const(..), + .. + }) + ); // Per RFC we (currently) ignore anon-const (`const _: Ty = ...`) in top-level module. - if self.body_depth == 1 - && parent_def_kind == DefKind::Const - && parent_opt_item_name == Some(kw::Underscore) - { + if self.body_depth == 1 && parent_is_anon_const { return; } @@ -119,23 +122,34 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { // We also ignore anon-const in item by including the anon-const // parent as well; and since it's quite uncommon, we use smallvec // to avoid unnecessary heap allocations. - let local_parents: SmallVec<[DefId; 1]> = if parent_def_kind == DefKind::Const - && parent_opt_item_name == Some(kw::Underscore) - { - smallvec![parent, cx.tcx.parent(parent)] - } else { - smallvec![parent] + let mut local_parent = { + let mut local_parent_cache = None; + move || { + *local_parent_cache + .get_or_insert_with(|| cx.tcx.parent(item.owner_id.to_def_id())) + } + }; + let mut extra_local_parent = { + let mut extra_parent_cache = None; + move |did| { + *extra_parent_cache + .get_or_insert_with(|| parent_is_anon_const.then(|| cx.tcx.parent(did))) + } }; let self_ty_has_local_parent = match impl_.self_ty.kind { - TyKind::Path(QPath::Resolved(_, ty_path)) => { - path_has_local_parent(ty_path, cx, &*local_parents) - } + TyKind::Path(QPath::Resolved(_, ty_path)) => path_has_local_parent( + ty_path, + cx, + &mut local_parent, + &mut extra_local_parent, + ), TyKind::TraitObject([principle_poly_trait_ref, ..], _, _) => { path_has_local_parent( principle_poly_trait_ref.trait_ref.path, cx, - &*local_parents, + &mut local_parent, + &mut extra_local_parent, ) } TyKind::TraitObject([], _, _) @@ -157,17 +171,21 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { let of_trait_has_local_parent = impl_ .of_trait - .map(|of_trait| path_has_local_parent(of_trait.path, cx, &*local_parents)) + .map(|of_trait| { + path_has_local_parent( + of_trait.path, + cx, + &mut local_parent, + &mut extra_local_parent, + ) + }) .unwrap_or(false); // If none of them have a local parent (LOGICAL NOR) this means that // this impl definition is a non-local definition and so we lint on it. if !(self_ty_has_local_parent || of_trait_has_local_parent) { let const_anon = if self.body_depth == 1 - && parent_def_kind == DefKind::Const - && parent_opt_item_name != Some(kw::Underscore) - && let Some(parent) = parent.as_local() - && let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent) + && let OwnerNode::Item(item) = parent_node && let ItemKind::Const(ty, _, _) = item.kind && let TyKind::Tup(&[]) = ty.kind { @@ -181,9 +199,10 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { item.span, NonLocalDefinitionsDiag::Impl { depth: self.body_depth, - body_kind_descr: cx.tcx.def_kind_descr(parent_def_kind, parent), - body_name: parent_opt_item_name - .map(|s| s.to_ident_string()) + body_kind_descr: "?" /* FIXME: cx.tcx.def_kind_descr(parent_def_kind, parent) */, + body_name: parent_node + .ident() + .map(|s| s.name.to_ident_string()) .unwrap_or_else(|| "".to_string()), cargo_update: cargo_update(), const_anon, @@ -199,9 +218,10 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { item.span, NonLocalDefinitionsDiag::MacroRules { depth: self.body_depth, - body_kind_descr: cx.tcx.def_kind_descr(parent_def_kind, parent), - body_name: parent_opt_item_name - .map(|s| s.to_ident_string()) + body_kind_descr: "?" /* FIXME: cx.tcx.def_kind_descr(parent_def_kind, parent) */, + body_name: parent_node + .ident() + .map(|s| s.name.to_ident_string()) .unwrap_or_else(|| "".to_string()), cargo_update: cargo_update(), }, @@ -221,6 +241,20 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { /// std::convert::PartialEq> /// ^^^^^^^^^^^^^^^^^^^^^^^ /// ``` -fn path_has_local_parent(path: &Path<'_>, cx: &LateContext<'_>, local_parents: &[DefId]) -> bool { - path.res.opt_def_id().is_some_and(|did| local_parents.contains(&cx.tcx.parent(did))) +fn path_has_local_parent( + path: &Path<'_>, + cx: &LateContext<'_>, + local_parent: &mut impl FnMut() -> DefId, + extra_local_parent: &mut impl FnMut(DefId) -> Option, +) -> bool { + if let Some(did) = path.res.opt_def_id() { + if !did.is_local() { + false + } else { + let res_parent = cx.tcx.parent(did); + res_parent == local_parent() || Some(res_parent) == extra_local_parent(local_parent()) + } + } else { + true + } } diff --git a/tests/ui/lint/non_local_definitions.stderr b/tests/ui/lint/non_local_definitions.stderr index f9f29ec63a805..f140b0133adf1 100644 --- a/tests/ui/lint/non_local_definitions.stderr +++ b/tests/ui/lint/non_local_definitions.stderr @@ -7,7 +7,7 @@ LL | const Z: () = { LL | impl Uto for &Test {} | ^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current constant `Z` + = help: move this `impl` block outside the of the current ? `Z` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -19,7 +19,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto for *mut Test {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current constant expression `` + = help: move this `impl` block outside the of the current ? `A` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -30,7 +30,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto for Test {} | ^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current constant expression `` + = help: move this `impl` block outside the of the current ? `Enum` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -41,7 +41,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto2 for Test {} | ^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current static `A` + = help: move this `impl` block outside the of the current ? `A` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -52,7 +52,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto3 for Test {} | ^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current constant `B` + = help: move this `impl` block outside the of the current ? `B` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -63,7 +63,7 @@ warning: non-local `macro_rules!` definition, they should be avoided as they go LL | macro_rules! m0 { () => { } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current constant `B` + = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current ? `B` = note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -74,7 +74,7 @@ warning: non-local `macro_rules!` definition, they should be avoided as they go LL | macro_rules! m { () => { } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current function `main` + = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current ? `main` = note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -88,7 +88,7 @@ LL | | fn foo() {} LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -102,7 +102,7 @@ LL | | fn bar() {} LL | | } | |_________^ | - = help: move this `impl` block outside the of the current constant expression `` and up 2 bodies + = help: move this `impl` block outside the of the current ? `main` and up 2 bodies = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -116,7 +116,7 @@ LL | | fn hoo() {} LL | | } | |_________^ | - = help: move this `impl` block outside the of the current inline constant `` and up 2 bodies + = help: move this `impl` block outside the of the current ? `main` and up 2 bodies = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -130,7 +130,7 @@ LL | | fn foo2() {} LL | | } | |_________^ | - = help: move this `impl` block outside the of the current constant `_` and up 2 bodies + = help: move this `impl` block outside the of the current ? `_` and up 2 bodies = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -146,7 +146,7 @@ LL | | } LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -157,7 +157,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl dyn Uto5 {} | ^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -168,7 +168,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for Vec { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -179,7 +179,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for &dyn Uto5 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -190,7 +190,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for *mut Test {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -201,7 +201,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for *mut [Test] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -212,7 +212,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for [Test; 8] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -223,7 +223,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for (Test,) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -234,7 +234,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for fn(Test) -> () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -245,7 +245,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for fn() -> Test {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -256,7 +256,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for Test {} | ^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current closure `` and up 2 bodies + = help: move this `impl` block outside the of the current ? `main` and up 2 bodies = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -267,7 +267,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for &Test {} | ^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current constant expression `` and up 2 bodies + = help: move this `impl` block outside the of the current ? `A` and up 2 bodies = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -278,7 +278,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for &(Test,) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current constant expression `` and up 2 bodies + = help: move this `impl` block outside the of the current ? `a` and up 2 bodies = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -289,7 +289,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for &(Test,Test) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current constant expression `` and up 2 bodies + = help: move this `impl` block outside the of the current ? `b` and up 2 bodies = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -300,7 +300,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for *mut InsideMain {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -311,7 +311,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for *mut [InsideMain] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -322,7 +322,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for [InsideMain; 8] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -333,7 +333,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for (InsideMain,) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -344,7 +344,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for fn(InsideMain) -> () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -355,7 +355,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto5 for fn() -> InsideMain {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -371,7 +371,7 @@ LL | | } LL | | } | |_________^ | - = help: move this `impl` block outside the of the current function `inside_inside` and up 2 bodies + = help: move this `impl` block outside the of the current ? `inside_inside` and up 2 bodies = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -388,7 +388,7 @@ LL | | } LL | | } | |_________^ | - = help: move this `impl` block outside the of the current function `inside_inside` and up 2 bodies + = help: move this `impl` block outside the of the current ? `inside_inside` and up 2 bodies = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -399,7 +399,7 @@ warning: non-local `macro_rules!` definition, they should be avoided as they go LL | macro_rules! m2 { () => { } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current associated function `bar` and up 3 bodies + = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current ? `bar` and up 3 bodies = note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -410,7 +410,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto3 for Vec { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `main` + = help: move this `impl` block outside the of the current ? `main` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -421,7 +421,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto7 for Test where Local: std::any::Any {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `bad` + = help: move this `impl` block outside the of the current ? `bad` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -432,7 +432,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | impl Uto8 for T {} | ^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current function `bad` + = help: move this `impl` block outside the of the current ? `bad` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -448,7 +448,7 @@ LL | | } LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `fun` + = help: move this `impl` block outside the of the current ? `fun` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -464,7 +464,7 @@ LL | | } LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `meow` + = help: move this `impl` block outside the of the current ? `meow` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -478,7 +478,7 @@ LL | | fn as_ref(&self) -> &Cat { &Cat } LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `meow` + = help: move this `impl` block outside the of the current ? `meow` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -494,7 +494,7 @@ LL | | } LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `fun2` + = help: move this `impl` block outside the of the current ? `fun2` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -510,7 +510,7 @@ LL | | } LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `woof` + = help: move this `impl` block outside the of the current ? `woof` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -526,7 +526,7 @@ LL | | } LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `woof` + = help: move this `impl` block outside the of the current ? `woof` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -542,7 +542,7 @@ LL | | } LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `woof` + = help: move this `impl` block outside the of the current ? `woof` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -558,7 +558,7 @@ LL | | } LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `woof` + = help: move this `impl` block outside the of the current ? `woof` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -574,7 +574,7 @@ LL | | } LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `rawr` + = help: move this `impl` block outside the of the current ? `rawr` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -590,7 +590,7 @@ LL | | } LL | | } | |_____^ | - = help: move this `impl` block outside the of the current function `rawr` + = help: move this `impl` block outside the of the current ? `rawr` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -604,7 +604,7 @@ LL | impl MacroTrait for OutsideStruct {} LL | m!(); | ---- in this macro invocation | - = help: move this `impl` block outside the of the current function `my_func` + = help: move this `impl` block outside the of the current ? `my_func` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -616,7 +616,7 @@ warning: non-local `impl` definition, they should be avoided as they go against LL | non_local_macro::non_local_impl!(CargoUpdate); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: move this `impl` block outside the of the current constant `_IMPL_DEBUG` + = help: move this `impl` block outside the of the current ? `_IMPL_DEBUG` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -629,7 +629,7 @@ warning: non-local `macro_rules!` definition, they should be avoided as they go LL | non_local_macro::non_local_macro_rules!(my_macro); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current constant `_MACRO_EXPORT` + = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current ? `_MACRO_EXPORT` = note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue diff --git a/tests/ui/proc-macro/nested-macro-rules.stderr b/tests/ui/proc-macro/nested-macro-rules.stderr index 111be8827714f..bc80e3f995f78 100644 --- a/tests/ui/proc-macro/nested-macro-rules.stderr +++ b/tests/ui/proc-macro/nested-macro-rules.stderr @@ -17,7 +17,7 @@ LL | | } LL | nested_macro_rules::outer_macro!(SecondStruct, SecondAttrStruct); | ---------------------------------------------------------------- in this macro invocation | - = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current function `main` + = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current ? `main` = note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue