Skip to content

Commit 402580b

Browse files
committed
non_local_defs: improve exception note for impl and macro_rules!
- Remove wrong exception text for non-local macro_rules! - Simplify anonymous const exception note
1 parent 22095fb commit 402580b

File tree

7 files changed

+6
-14
lines changed

7 files changed

+6
-14
lines changed

compiler/rustc_lint/messages.ftl

+1-2
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks sho
551551
.without_trait = methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block
552552
.with_trait = an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
553553
.bounds = `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
554-
.exception = anon-const (`const _: () = {"{"} ... {"}"}`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
554+
.exception = items in an anonymous const item (`const _: () = {"{"} ... {"}"}`) are treated as in the same scope as the anonymous const's declaration
555555
.const_anon = use a const-anon item to suppress this lint
556556
557557
lint_non_local_definitions_macro_rules = non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module
@@ -563,7 +563,6 @@ lint_non_local_definitions_macro_rules = non-local `macro_rules!` definition, `#
563563
.help_doctest =
564564
remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() {"{"} ... {"}"}`
565565
.non_local = a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
566-
.exception = one exception to the rule are anon-const (`const _: () = {"{"} ... {"}"}`) at top-level module
567566
568567
lint_non_local_definitions_may_move = may need to be moved as well
569568

compiler/rustc_lint/src/lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,6 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
14211421
}
14221422

14231423
diag.note(fluent::lint_non_local);
1424-
diag.note(fluent::lint_exception);
14251424
diag.note(fluent::lint_non_local_definitions_deprecation);
14261425

14271426
if let Some(cargo_update) = cargo_update {

tests/rustdoc-ui/doctest/non_local_defs.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | macro_rules! a_macro { () => {} }
66
|
77
= help: remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() { ... }`
88
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
9-
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
109
= 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>
1110
= note: `#[warn(non_local_definitions)]` on by default
1211

tests/ui/lint/non-local-defs/cargo-update.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | non_local_macro::non_local_impl!(LocalStruct);
1515
| may need to be moved as well
1616
| may need to be moved as well
1717
= note: the macro `non_local_macro::non_local_impl` may come from an old version of the `non_local_macro` crate, try updating your dependency with `cargo update -p non_local_macro`
18-
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
18+
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
1919
= 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>
2020
= note: `#[warn(non_local_definitions)]` on by default
2121
= note: this warning originates in the macro `non_local_macro::non_local_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

tests/ui/lint/non-local-defs/consts.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | impl Uto for &Test {}
1717
| | |
1818
| | may need to be moved as well
1919
| may need to be moved as well
20-
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
20+
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
2121
= 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>
2222
= note: `#[warn(non_local_definitions)]` on by default
2323

@@ -37,7 +37,7 @@ LL | impl Uto2 for Test {}
3737
| | |
3838
| | may need to be moved as well
3939
| may need to be moved as well
40-
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
40+
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
4141
= 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>
4242

4343
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -56,7 +56,7 @@ LL | impl Uto3 for Test {}
5656
| | |
5757
| | may need to be moved as well
5858
| may need to be moved as well
59-
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
59+
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
6060
= 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>
6161

6262
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -117,7 +117,7 @@ LL | |
117117
LL | | fn foo2() {}
118118
LL | | }
119119
| |_________^
120-
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
120+
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
121121
= 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>
122122

123123
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item

tests/ui/lint/non-local-defs/macro_rules.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LL | macro_rules! m0 { () => { } };
66
|
77
= help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current constant `B`
88
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
9-
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
109
= 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>
1110
= note: `#[warn(non_local_definitions)]` on by default
1211

@@ -18,7 +17,6 @@ LL | non_local_macro::non_local_macro_rules!(my_macro);
1817
|
1918
= help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current constant `_MACRO_EXPORT`
2019
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
21-
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
2220
= 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>
2321
= note: the macro `non_local_macro::non_local_macro_rules` may come from an old version of the `non_local_macro` crate, try updating your dependency with `cargo update -p non_local_macro`
2422
= note: this warning originates in the macro `non_local_macro::non_local_macro_rules` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -31,7 +29,6 @@ LL | macro_rules! m { () => { } };
3129
|
3230
= help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current function `main`
3331
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
34-
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
3532
= 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>
3633

3734
warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module
@@ -42,7 +39,6 @@ LL | macro_rules! m2 { () => { } };
4239
|
4340
= help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current associated function `bar` and up 2 bodies
4441
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
45-
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
4642
= 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>
4743

4844
warning: 4 warnings emitted

tests/ui/proc-macro/nested-macro-rules.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ LL | nested_macro_rules::outer_macro!(SecondStruct, SecondAttrStruct);
1919
|
2020
= help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current function `main`
2121
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
22-
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
2322
= 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>
2423
note: the lint level is defined here
2524
--> $DIR/nested-macro-rules.rs:8:9

0 commit comments

Comments
 (0)