Auto merge of #125722 - Urgau:non_local_defs-macro-to-change, r=estebank · rust-lang/rust@1d1356d (original) (raw)
File tree
5 files changed
lines changed
- tests/ui/lint/non-local-defs
5 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -550,6 +550,7 @@ lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks sho | ||
550 | 550 | .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 |
551 | 551 | .exception = items in an anonymous const item (`const _: () = {"{"} ... {"}"}`) are treated as in the same scope as the anonymous const's declaration |
552 | 552 | .const_anon = use a const-anon item to suppress this lint |
553 | + .macro_to_change = the {$macro_kind} `{$macro_to_change}` defines the non-local `impl`, and may need to be changed | |
553 | 554 | |
554 | 555 | lint_non_local_definitions_impl_move_help = |
555 | 556 | move the `impl` block outside of this {$body_kind_descr} {$depth -> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1362,6 +1362,7 @@ pub enum NonLocalDefinitionsDiag { | ||
1362 | 1362 | has_trait: bool, |
1363 | 1363 | self_ty_str: String, |
1364 | 1364 | of_trait_str: Option<String>, |
1365 | +macro_to_change: Option<(String, &'static str)>, | |
1365 | 1366 | }, |
1366 | 1367 | MacroRules { |
1367 | 1368 | depth: u32, |
@@ -1387,6 +1388,7 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag { | ||
1387 | 1388 | has_trait, |
1388 | 1389 | self_ty_str, |
1389 | 1390 | of_trait_str, |
1391 | + macro_to_change, | |
1390 | 1392 | } => { |
1391 | 1393 | diag.primary_message(fluent::lint_non_local_definitions_impl); |
1392 | 1394 | diag.arg("depth", depth); |
@@ -1397,6 +1399,15 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag { | ||
1397 | 1399 | diag.arg("of_trait_str", of_trait_str); |
1398 | 1400 | } |
1399 | 1401 | |
1402 | +if let Some((macro_to_change, macro_kind)) = macro_to_change { | |
1403 | + diag.arg("macro_to_change", macro_to_change); | |
1404 | + diag.arg("macro_kind", macro_kind); | |
1405 | + diag.note(fluent::lint_macro_to_change); | |
1406 | +} | |
1407 | +if let Some(cargo_update) = cargo_update { | |
1408 | + diag.subdiagnostic(&diag.dcx, cargo_update); | |
1409 | +} | |
1410 | + | |
1400 | 1411 | if has_trait { |
1401 | 1412 | diag.note(fluent::lint_bounds); |
1402 | 1413 | diag.note(fluent::lint_with_trait); |
@@ -1422,9 +1433,6 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag { | ||
1422 | 1433 | ); |
1423 | 1434 | } |
1424 | 1435 | |
1425 | -if let Some(cargo_update) = cargo_update { | |
1426 | - diag.subdiagnostic(&diag.dcx, cargo_update); | |
1427 | -} | |
1428 | 1436 | if let Some(const_anon) = const_anon { |
1429 | 1437 | diag.note(fluent::lint_exception); |
1430 | 1438 | if let Some(const_anon) = const_anon { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -258,6 +258,13 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { | ||
258 | 258 | Some((cx.tcx.def_span(parent), may_move)) |
259 | 259 | }; |
260 | 260 | |
261 | +let macro_to_change = | |
262 | +if let ExpnKind::Macro(kind, name) = item.span.ctxt().outer_expn_data().kind { | |
263 | +Some((name.to_string(), kind.descr())) | |
264 | +} else { | |
265 | +None | |
266 | +}; | |
267 | + | |
261 | 268 | cx.emit_span_lint( |
262 | 269 | NON_LOCAL_DEFINITIONS, |
263 | 270 | ms, |
@@ -274,6 +281,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { | ||
274 | 281 | move_to, |
275 | 282 | may_remove, |
276 | 283 | has_trait: impl_.of_trait.is_some(), |
284 | + macro_to_change, | |
277 | 285 | }, |
278 | 286 | ) |
279 | 287 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8,9 +8,10 @@ LL | non_local_macro::non_local_impl!(LocalStruct); | ||
8 | 8 | | `Debug` is not local |
9 | 9 | | move the `impl` block outside of this constant `_IMPL_DEBUG` |
10 | 10 | | |
11 | + = note: the macro `non_local_macro::non_local_impl` defines the non-local `impl`, and may need to be changed | |
12 | + = 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` | |
11 | 13 | = note: `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 |
12 | 14 | = note: 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` |
13 | - = 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` | |
14 | 15 | = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration |
15 | 16 | = 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 |
16 | 17 | = note: `#[warn(non_local_definitions)]` on by default |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -12,6 +12,7 @@ LL | impl MacroTrait for OutsideStruct {} | ||
12 | 12 | LL | m!(); |
13 | 13 | | ---- in this macro invocation |
14 | 14 | | |
15 | + = note: the macro `m` defines the non-local `impl`, and may need to be changed | |
15 | 16 | = note: `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 |
16 | 17 | = note: 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` |
17 | 18 | = 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 |