-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.I-types-nominatedNominated for discussion during a types team meeting.Nominated for discussion during a types team meeting.L-non_local_definitionsLint: non_local_definitionsLint: non_local_definitionsT-langRelevant to the language teamRelevant to the language team
Description
I wonder whether the following code should be triggering non_local_definitions
. It currently does and I think it's a bug:
pub trait Trait {}
fn main() {
struct Thing;
impl Trait for &Thing {}
}
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> src/main.rs:5:5
|
5 | impl Trait for &Thing {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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>
= note: `#[warn(non_local_definitions)]` on by default
A real-world occurrence can be seen in https://github.com/serde-rs/json/blob/e1b3a6d8a161ff5ec4865b487d148c17d0188e3e/tests/test.rs#L2334-L2346.
In general #[fundamental] exists to allow what would otherwise be a coherence violation, and it would make sense for the same exception to be applied here for the non_local_definitions lint.
jonasbb
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.I-types-nominatedNominated for discussion during a types team meeting.Nominated for discussion during a types team meeting.L-non_local_definitionsLint: non_local_definitionsLint: non_local_definitionsT-langRelevant to the language teamRelevant to the language team