non_local_defs: use labels to indicate what may need to be moved
This commit is contained in:
parent
26b873d030
commit
22095fbd8d
12 changed files with 587 additions and 59 deletions
|
@ -6,7 +6,7 @@ use crate::errors::RequestedLevel;
|
|||
use crate::fluent_generated as fluent;
|
||||
use rustc_errors::{
|
||||
codes::*, Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString,
|
||||
ElidedLifetimeInPathSubdiag, EmissionGuarantee, LintDiagnostic, SubdiagMessageOp,
|
||||
ElidedLifetimeInPathSubdiag, EmissionGuarantee, LintDiagnostic, MultiSpan, SubdiagMessageOp,
|
||||
Subdiagnostic, SuggestionStyle,
|
||||
};
|
||||
use rustc_hir::{def::Namespace, def_id::DefId};
|
||||
|
@ -1336,6 +1336,9 @@ pub enum NonLocalDefinitionsDiag {
|
|||
body_name: String,
|
||||
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
|
||||
const_anon: Option<Option<Span>>,
|
||||
move_help: Span,
|
||||
self_ty: Span,
|
||||
of_trait: Option<Span>,
|
||||
has_trait: bool,
|
||||
},
|
||||
MacroRules {
|
||||
|
@ -1357,6 +1360,9 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
|
|||
body_name,
|
||||
cargo_update,
|
||||
const_anon,
|
||||
move_help,
|
||||
self_ty,
|
||||
of_trait,
|
||||
has_trait,
|
||||
} => {
|
||||
diag.primary_message(fluent::lint_non_local_definitions_impl);
|
||||
|
@ -1364,13 +1370,18 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
|
|||
diag.arg("body_kind_descr", body_kind_descr);
|
||||
diag.arg("body_name", body_name);
|
||||
|
||||
diag.help(fluent::lint_help);
|
||||
if has_trait {
|
||||
diag.note(fluent::lint_bounds);
|
||||
diag.note(fluent::lint_with_trait);
|
||||
} else {
|
||||
diag.note(fluent::lint_without_trait);
|
||||
}
|
||||
let mut ms = MultiSpan::from_span(move_help);
|
||||
ms.push_span_label(self_ty, fluent::lint_non_local_definitions_may_move);
|
||||
if let Some(of_trait) = of_trait {
|
||||
ms.push_span_label(of_trait, fluent::lint_non_local_definitions_may_move);
|
||||
}
|
||||
diag.span_help(ms, fluent::lint_help);
|
||||
|
||||
if let Some(cargo_update) = cargo_update {
|
||||
diag.subdiagnostic(&diag.dcx, cargo_update);
|
||||
|
|
|
@ -222,6 +222,9 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
|
|||
item.span.shrink_to_lo().to(impl_.self_ty.span),
|
||||
NonLocalDefinitionsDiag::Impl {
|
||||
depth: self.body_depth,
|
||||
move_help: item.span,
|
||||
self_ty: impl_.self_ty.span,
|
||||
of_trait: impl_.of_trait.map(|t| t.path.span),
|
||||
body_kind_descr: cx.tcx.def_kind_descr(parent_def_kind, parent),
|
||||
body_name: parent_opt_item_name
|
||||
.map(|s| s.to_ident_string())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue