Implement RFC3373 non local definitions lint

This commit is contained in:
Urgau 2024-01-26 15:25:18 +01:00
parent c1144436f6
commit 6170394313
10 changed files with 1241 additions and 0 deletions

View File

@ -4164,6 +4164,7 @@ dependencies = [
"rustc_target",
"rustc_trait_selection",
"rustc_type_ir",
"smallvec",
"tracing",
"unicode-security",
]

View File

@ -23,6 +23,7 @@ rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_type_ir = { path = "../rustc_type_ir" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tracing = "0.1"
unicode-security = "0.1.0"
# tidy-alphabetical-end

View File

@ -411,6 +411,26 @@ lint_non_fmt_panic_unused =
}
.add_fmt_suggestion = or add a "{"{"}{"}"}" format string to use the message literally
lint_non_local_definitions_deprecation = this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
lint_non_local_definitions_impl = non-local `impl` definition, they should be avoided as they go against expectation
.help =
move this `impl` block outside the of the current {$body_kind_descr} {$depth ->
[one] `{$body_name}`
*[other] `{$body_name}` and up {$depth} bodies
}
.non_local = 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
.exception = 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
lint_non_local_definitions_macro_rules = non-local `macro_rules!` definition, they should be avoided as they go against expectation
.help =
remove the `#[macro_export]` or move this `macro_rules!` outside the of the current {$body_kind_descr} {$depth ->
[one] `{$body_name}`
*[other] `{$body_name}` and up {$depth} bodies
}
.non_local = a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
.exception = one exception to the rule are anon-const (`const _: () = {"{"} ... {"}"}`) at top-level module
lint_non_snake_case = {$sort} `{$name}` should have a snake case name
.rename_or_convert_suggestion = rename the identifier or convert it to a snake case raw identifier
.cannot_convert_note = `{$sc}` cannot be used as a raw identifier

View File

@ -70,6 +70,7 @@
mod multiple_supertrait_upcastable;
mod non_ascii_idents;
mod non_fmt_panic;
mod non_local_def;
mod nonstandard_style;
mod noop_method_call;
mod opaque_hidden_inferred_bound;
@ -105,6 +106,7 @@
use multiple_supertrait_upcastable::*;
use non_ascii_idents::*;
use non_fmt_panic::NonPanicFmt;
use non_local_def::*;
use nonstandard_style::*;
use noop_method_call::*;
use opaque_hidden_inferred_bound::*;
@ -231,6 +233,7 @@ fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
MissingDebugImplementations: MissingDebugImplementations,
MissingDoc: MissingDoc,
AsyncFnInTrait: AsyncFnInTrait,
NonLocalDefinitions: NonLocalDefinitions::default(),
]
]
);

View File

@ -1293,6 +1293,23 @@ pub struct SuspiciousDoubleRefCloneDiag<'a> {
pub ty: Ty<'a>,
}
// non_local_defs.rs
#[derive(LintDiagnostic)]
pub enum NonLocalDefinitionsDiag {
#[diag(lint_non_local_definitions_impl)]
#[help]
#[note(lint_non_local)]
#[note(lint_exception)]
#[note(lint_non_local_definitions_deprecation)]
Impl { depth: u32, body_kind_descr: &'static str, body_name: String },
#[diag(lint_non_local_definitions_macro_rules)]
#[help]
#[note(lint_non_local)]
#[note(lint_exception)]
#[note(lint_non_local_definitions_deprecation)]
MacroRules { depth: u32, body_kind_descr: &'static str, body_name: String },
}
// pass_by_value.rs
#[derive(LintDiagnostic)]
#[diag(lint_pass_by_value)]

View File

@ -0,0 +1,187 @@
use rustc_hir::{def::DefKind, Body, Item, ItemKind, Path, QPath, TyKind};
use rustc_span::{def_id::DefId, sym, symbol::kw, MacroKind};
use smallvec::{smallvec, SmallVec};
use crate::{lints::NonLocalDefinitionsDiag, LateContext, LateLintPass, LintContext};
declare_lint! {
/// The `non_local_definitions` lint checks for `impl` blocks and `#[macro_export]`
/// macro inside bodies (functions, enum discriminant, ...).
///
/// ### Example
///
/// ```rust
/// trait MyTrait {}
/// struct MyStruct;
///
/// fn foo() {
/// impl MyTrait for MyStruct {}
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Creating non-local definitions go against expectation and can create discrepancies
/// in tooling. It should be avoided. It may become deny-by-default in edition 2024
/// and higher, see see the tracking issue <https://github.com/rust-lang/rust/issues/120363>.
///
/// 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.
///
/// All nested bodies (functions, enum discriminant, array length, consts) (expect for
/// `const _: Ty = { ... }` in top-level module, which is still undecided) are checked.
pub NON_LOCAL_DEFINITIONS,
Warn,
"checks for non-local definitions",
report_in_external_macro
}
#[derive(Default)]
pub struct NonLocalDefinitions {
body_depth: u32,
}
impl_lint_pass!(NonLocalDefinitions => [NON_LOCAL_DEFINITIONS]);
// FIXME(Urgau): Figure out how to handle modules nested in bodies.
// It's currently not handled by the current logic because modules are not bodies.
// They don't even follow the correct order (check_body -> check_mod -> check_body_post)
// instead check_mod is called after every body has been handled.
impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
fn check_body(&mut self, _cx: &LateContext<'tcx>, _body: &'tcx Body<'tcx>) {
self.body_depth += 1;
}
fn check_body_post(&mut self, _cx: &LateContext<'tcx>, _body: &'tcx Body<'tcx>) {
self.body_depth -= 1;
}
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
if self.body_depth == 0 {
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);
// 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)
{
return;
}
match item.kind {
ItemKind::Impl(impl_) => {
// The RFC states:
//
// > An item nested inside an expression-containing item (through any
// > level of nesting) may not define an impl Trait for Type unless
// > either the **Trait** or the **Type** is also nested inside the
// > same expression-containing item.
//
// To achieve this we get try to get the paths of the _Trait_ and
// _Type_, and we look inside thoses paths to try a find in one
// of them a type whose parent is the same as the impl definition.
//
// If that's the case this means that this impl block declaration
// is using local items and so we don't lint on it.
// 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 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::TraitObject([principle_poly_trait_ref, ..], _, _) => {
path_has_local_parent(
principle_poly_trait_ref.trait_ref.path,
cx,
&*local_parents,
)
}
TyKind::TraitObject([], _, _)
| TyKind::InferDelegation(_, _)
| TyKind::Slice(_)
| TyKind::Array(_, _)
| TyKind::Ptr(_)
| TyKind::Ref(_, _)
| TyKind::BareFn(_)
| TyKind::Never
| TyKind::Tup(_)
| TyKind::Path(_)
| TyKind::AnonAdt(_)
| TyKind::OpaqueDef(_, _, _)
| TyKind::Typeof(_)
| TyKind::Infer
| TyKind::Err(_) => false,
};
let of_trait_has_local_parent = impl_
.of_trait
.map(|of_trait| path_has_local_parent(of_trait.path, cx, &*local_parents))
.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) {
cx.emit_span_lint(
NON_LOCAL_DEFINITIONS,
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())
.unwrap_or_else(|| "<unnameable>".to_string()),
},
)
}
}
ItemKind::Macro(_macro, MacroKind::Bang)
if cx.tcx.has_attr(item.owner_id.def_id, sym::macro_export) =>
{
cx.emit_span_lint(
NON_LOCAL_DEFINITIONS,
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())
.unwrap_or_else(|| "<unnameable>".to_string()),
},
)
}
_ => {}
}
}
}
/// Given a path and a parent impl def id, this checks if the if parent resolution
/// def id correspond to the def id of the parent impl definition.
///
/// Given this path, we will look at the path (and ignore any generic args):
///
/// ```text
/// std::convert::PartialEq<Foo<Bar>>
/// ^^^^^^^^^^^^^^^^^^^^^^^
/// ```
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)))
}

View File

@ -0,0 +1,373 @@
//@ check-pass
//@ edition:2021
#![feature(inline_const)]
use std::fmt::{Debug, Display};
struct Test;
impl Debug for Test {
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
mod do_not_lint_mod {
pub trait Tait {}
impl super::Test {
fn hugo() {}
}
impl Tait for super::Test {}
}
trait Uto {}
const Z: () = {
trait Uto1 {}
impl Uto1 for Test {} // the trait is local, don't lint
impl Uto for &Test {}
//~^ WARN non-local `impl` definition
};
trait Ano {}
const _: () = {
impl Ano for &Test {} // ignored since the parent is an anon-const
};
type A = [u32; {
impl Uto for *mut Test {}
//~^ WARN non-local `impl` definition
1
}];
enum Enum {
Discr = {
impl Uto for Test {}
//~^ WARN non-local `impl` definition
1
}
}
trait Uto2 {}
static A: u32 = {
impl Uto2 for Test {}
//~^ WARN non-local `impl` definition
1
};
trait Uto3 {}
const B: u32 = {
impl Uto3 for Test {}
//~^ WARN non-local `impl` definition
#[macro_export]
macro_rules! m0 { () => { } };
//~^ WARN non-local `macro_rules!` definition
trait Uto4 {}
impl Uto4 for Test {}
1
};
trait Uto5 {}
fn main() {
#[macro_export]
macro_rules! m { () => { } };
//~^ WARN non-local `macro_rules!` definition
impl Test {
//~^ WARN non-local `impl` definition
fn foo() {}
}
let _array = [0i32; {
impl Test {
//~^ WARN non-local `impl` definition
fn bar() {}
}
1
}];
const {
impl Test {
//~^ WARN non-local `impl` definition
fn hoo() {}
}
1
};
const _: u32 = {
impl Test {
//~^ WARN non-local `impl` definition
fn foo2() {}
}
1
};
impl Display for Test {
//~^ WARN non-local `impl` definition
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl dyn Uto5 {}
//~^ WARN non-local `impl` definition
impl<T: Uto5> Uto5 for Vec<T> { }
//~^ WARN non-local `impl` definition
impl Uto5 for &dyn Uto5 {}
//~^ WARN non-local `impl` definition
impl Uto5 for *mut Test {}
//~^ WARN non-local `impl` definition
impl Uto5 for *mut [Test] {}
//~^ WARN non-local `impl` definition
impl Uto5 for [Test; 8] {}
//~^ WARN non-local `impl` definition
impl Uto5 for (Test,) {}
//~^ WARN non-local `impl` definition
impl Uto5 for fn(Test) -> () {}
//~^ WARN non-local `impl` definition
impl Uto5 for fn() -> Test {}
//~^ WARN non-local `impl` definition
let _a = || {
impl Uto5 for Test {}
//~^ WARN non-local `impl` definition
1
};
type A = [u32; {
impl Uto5 for &Test {}
//~^ WARN non-local `impl` definition
1
}];
fn a(_: [u32; {
impl Uto5 for &(Test,) {}
//~^ WARN non-local `impl` definition
1
}]) {}
fn b() -> [u32; {
impl Uto5 for &(Test,Test) {}
//~^ WARN non-local `impl` definition
1
}] { todo!() }
struct InsideMain;
impl Uto5 for *mut InsideMain {}
//~^ WARN non-local `impl` definition
impl Uto5 for *mut [InsideMain] {}
//~^ WARN non-local `impl` definition
impl Uto5 for [InsideMain; 8] {}
//~^ WARN non-local `impl` definition
impl Uto5 for (InsideMain,) {}
//~^ WARN non-local `impl` definition
impl Uto5 for fn(InsideMain) -> () {}
//~^ WARN non-local `impl` definition
impl Uto5 for fn() -> InsideMain {}
//~^ WARN non-local `impl` definition
impl Debug for InsideMain {
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl InsideMain {
fn foo() {}
}
fn inside_inside() {
impl Display for InsideMain {
//~^ WARN non-local `impl` definition
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl InsideMain {
//~^ WARN non-local `impl` definition
fn bar() {
#[macro_export]
macro_rules! m2 { () => { } };
//~^ WARN non-local `macro_rules!` definition
}
}
}
trait Uto6 {}
impl dyn Uto6 {}
impl Uto5 for dyn Uto6 {}
impl<T: Uto6> Uto3 for Vec<T> { }
//~^ WARN non-local `impl` definition
}
trait Uto7 {}
trait Uto8 {}
fn bad() {
struct Local;
impl Uto7 for Test where Local: std::any::Any {}
//~^ WARN non-local `impl` definition
impl<T> Uto8 for T {}
//~^ WARN non-local `impl` definition
}
struct UwU<T>(T);
fn fun() {
#[derive(Debug)]
struct OwO;
impl Default for UwU<OwO> {
//~^ WARN non-local `impl` definition
fn default() -> Self {
UwU(OwO)
}
}
}
struct Cat;
fn meow() {
impl From<Cat> for () {
//~^ WARN non-local `impl` definition
fn from(_: Cat) -> () {
todo!()
}
}
#[derive(Debug)]
struct Cat;
impl AsRef<Cat> for () {
//~^ WARN non-local `impl` definition
fn as_ref(&self) -> &Cat { &Cat }
}
}
struct G;
fn fun2() {
#[derive(Debug, Default)]
struct B;
impl PartialEq<B> for G {
//~^ WARN non-local `impl` definition
fn eq(&self, _: &B) -> bool {
true
}
}
}
fn side_effects() {
dbg!(().as_ref()); // prints `Cat`
dbg!(UwU::default().0);
let _ = G::eq(&G, dbg!(&<_>::default()));
}
struct Dog;
fn woof() {
impl PartialEq<Dog> for &Dog {
//~^ WARN non-local `impl` definition
fn eq(&self, _: &Dog) -> bool {
todo!()
}
}
impl PartialEq<()> for Dog {
//~^ WARN non-local `impl` definition
fn eq(&self, _: &()) -> bool {
todo!()
}
}
impl PartialEq<()> for &Dog {
//~^ WARN non-local `impl` definition
fn eq(&self, _: &()) -> bool {
todo!()
}
}
impl PartialEq<Dog> for () {
//~^ WARN non-local `impl` definition
fn eq(&self, _: &Dog) -> bool {
todo!()
}
}
struct Test;
impl PartialEq<Dog> for Test {
fn eq(&self, _: &Dog) -> bool {
todo!()
}
}
}
struct Wrap<T>(T);
impl Wrap<Wrap<Wrap<()>>> {}
fn rawr() {
struct Lion;
impl From<Wrap<Wrap<Lion>>> for () {
//~^ WARN non-local `impl` definition
fn from(_: Wrap<Wrap<Lion>>) -> Self {
todo!()
}
}
impl From<()> for Wrap<Lion> {
//~^ WARN non-local `impl` definition
fn from(_: ()) -> Self {
todo!()
}
}
}
macro_rules! m {
() => {
trait MacroTrait {}
struct OutsideStruct;
fn my_func() {
impl MacroTrait for OutsideStruct {}
//~^ WARN non-local `impl` definition
}
}
}
m!();
fn bitflags() {
struct Flags;
const _: () = {
impl Flags {}
};
}

View File

@ -0,0 +1,611 @@
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:32:5
|
LL | impl Uto for &Test {}
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current constant `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 <https://github.com/rust-lang/rust/issues/120363>
= note: `#[warn(non_local_definitions)]` on by default
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:42:5
|
LL | impl Uto for *mut Test {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current constant expression `<unnameable>`
= 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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:50:9
|
LL | impl Uto for Test {}
| ^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current constant expression `<unnameable>`
= 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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:59:5
|
LL | impl Uto2 for Test {}
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current static `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:67:5
|
LL | impl Uto3 for Test {}
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current constant `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:71:5
|
LL | macro_rules! m0 { () => { } };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current constant `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:83:5
|
LL | macro_rules! m { () => { } };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:86:5
|
LL | / impl Test {
LL | |
LL | | fn foo() {}
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:92:9
|
LL | / impl Test {
LL | |
LL | | fn bar() {}
LL | | }
| |_________^
|
= help: move this `impl` block outside the of the current constant expression `<unnameable>` 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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:101:9
|
LL | / impl Test {
LL | |
LL | | fn hoo() {}
LL | | }
| |_________^
|
= help: move this `impl` block outside the of the current inline constant `<unnameable>` 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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:110:9
|
LL | / impl Test {
LL | |
LL | | fn foo2() {}
LL | | }
| |_________^
|
= help: move this `impl` block outside the of the current constant `_` 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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:118:5
|
LL | / impl Display for Test {
LL | |
LL | | fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
LL | | todo!()
LL | | }
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:125:5
|
LL | impl dyn Uto5 {}
| ^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:128:5
|
LL | impl<T: Uto5> Uto5 for Vec<T> { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:131:5
|
LL | impl Uto5 for &dyn Uto5 {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:134:5
|
LL | impl Uto5 for *mut Test {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:137:5
|
LL | impl Uto5 for *mut [Test] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:140:5
|
LL | impl Uto5 for [Test; 8] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:143:5
|
LL | impl Uto5 for (Test,) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:146:5
|
LL | impl Uto5 for fn(Test) -> () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:149:5
|
LL | impl Uto5 for fn() -> Test {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:153:9
|
LL | impl Uto5 for Test {}
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current closure `<unnameable>` 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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:160:9
|
LL | impl Uto5 for &Test {}
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current constant expression `<unnameable>` 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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:167:9
|
LL | impl Uto5 for &(Test,) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current constant expression `<unnameable>` 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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:174:9
|
LL | impl Uto5 for &(Test,Test) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current constant expression `<unnameable>` 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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:182:5
|
LL | impl Uto5 for *mut InsideMain {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:184:5
|
LL | impl Uto5 for *mut [InsideMain] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:186:5
|
LL | impl Uto5 for [InsideMain; 8] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:188:5
|
LL | impl Uto5 for (InsideMain,) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:190:5
|
LL | impl Uto5 for fn(InsideMain) -> () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:192:5
|
LL | impl Uto5 for fn() -> InsideMain {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:206:9
|
LL | / impl Display for InsideMain {
LL | |
LL | | fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
LL | | todo!()
LL | | }
LL | | }
| |_________^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:213:9
|
LL | / impl InsideMain {
LL | |
LL | | fn bar() {
LL | | #[macro_export]
... |
LL | | }
LL | | }
| |_________^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:217:17
|
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
= 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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:227:5
|
LL | impl<T: Uto6> Uto3 for Vec<T> { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:236:5
|
LL | impl Uto7 for Test where Local: std::any::Any {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:239:5
|
LL | impl<T> Uto8 for T {}
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:248:5
|
LL | / impl Default for UwU<OwO> {
LL | |
LL | | fn default() -> Self {
LL | | UwU(OwO)
LL | | }
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:259:5
|
LL | / impl From<Cat> for () {
LL | |
LL | | fn from(_: Cat) -> () {
LL | | todo!()
LL | | }
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:268:5
|
LL | / impl AsRef<Cat> for () {
LL | |
LL | | fn as_ref(&self) -> &Cat { &Cat }
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:279:5
|
LL | / impl PartialEq<B> for G {
LL | |
LL | | fn eq(&self, _: &B) -> bool {
LL | | true
LL | | }
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:296:5
|
LL | / impl PartialEq<Dog> for &Dog {
LL | |
LL | | fn eq(&self, _: &Dog) -> bool {
LL | | todo!()
LL | | }
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:303:5
|
LL | / impl PartialEq<()> for Dog {
LL | |
LL | | fn eq(&self, _: &()) -> bool {
LL | | todo!()
LL | | }
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:310:5
|
LL | / impl PartialEq<()> for &Dog {
LL | |
LL | | fn eq(&self, _: &()) -> bool {
LL | | todo!()
LL | | }
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:317:5
|
LL | / impl PartialEq<Dog> for () {
LL | |
LL | | fn eq(&self, _: &Dog) -> bool {
LL | | todo!()
LL | | }
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:339:5
|
LL | / impl From<Wrap<Wrap<Lion>>> for () {
LL | |
LL | | fn from(_: Wrap<Wrap<Lion>>) -> Self {
LL | | todo!()
LL | | }
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:346:5
|
LL | / impl From<()> for Wrap<Lion> {
LL | |
LL | | fn from(_: ()) -> Self {
LL | | todo!()
LL | | }
LL | | }
| |_____^
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/non_local_definitions.rs:359:13
|
LL | impl MacroTrait for OutsideStruct {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | m!();
| ---- in this macro invocation
|
= help: move this `impl` block outside the of the current function `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 <https://github.com/rust-lang/rust/issues/120363>
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: 48 warnings emitted

View File

@ -19,5 +19,6 @@ fn main() {
nested_macro_rules::inner_macro!(print_bang, print_attr);
nested_macro_rules::outer_macro!(SecondStruct, SecondAttrStruct);
//~^ WARN non-local `macro_rules!` definition
inner_macro!(print_bang, print_attr);
}

View File

@ -0,0 +1,27 @@
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
--> $DIR/auxiliary/nested-macro-rules.rs:7:9
|
LL | macro_rules! outer_macro {
| ------------------------ in this expansion of `nested_macro_rules::outer_macro!`
...
LL | / macro_rules! inner_macro {
LL | | ($bang_macro:ident, $attr_macro:ident) => {
LL | | $bang_macro!($name);
LL | | #[$attr_macro] struct $attr_struct_name {}
LL | | }
LL | | }
| |_________^
|
::: $DIR/nested-macro-rules.rs:21:5
|
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`
= 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 <https://github.com/rust-lang/rust/issues/120363>
= note: `#[warn(non_local_definitions)]` on by default
warning: 1 warning emitted