migrate: deref_into_dyn_supertrait.rs
This commit is contained in:
parent
f38db48dbd
commit
fe09291036
3 changed files with 33 additions and 18 deletions
|
@ -457,6 +457,9 @@ lint_builtin_special_module_name_used_lib = found module declaration for lib.rs
|
||||||
lint_builtin_special_module_name_used_main = found module declaration for main.rs
|
lint_builtin_special_module_name_used_main = found module declaration for main.rs
|
||||||
.note = a binary crate cannot be used as library
|
.note = a binary crate cannot be used as library
|
||||||
|
|
||||||
|
lint_supertrait_as_deref_target = `{$t}` implements `Deref` with supertrait `{$target_principal}` as target
|
||||||
|
.label = target type is set here
|
||||||
|
|
||||||
lint_overruled_attribute = {$lint_level}({$lint_source}) incompatible with previous forbid
|
lint_overruled_attribute = {$lint_level}({$lint_source}) incompatible with previous forbid
|
||||||
.label = overruled by previous forbid
|
.label = overruled by previous forbid
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use crate::{LateContext, LateLintPass, LintContext};
|
use crate::{
|
||||||
|
lints::{SupertraitAsDerefTarget, SupertraitAsDerefTargetLabel},
|
||||||
|
LateContext, LateLintPass, LintContext,
|
||||||
|
};
|
||||||
|
|
||||||
use rustc_errors::DelayDm;
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_middle::{traits::util::supertraits, ty};
|
use rustc_middle::{traits::util::supertraits, ty};
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
|
@ -71,22 +73,14 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
|
||||||
&& supertraits(cx.tcx, t_principal.with_self_ty(cx.tcx, cx.tcx.types.trait_object_dummy_self))
|
&& supertraits(cx.tcx, t_principal.with_self_ty(cx.tcx, cx.tcx.types.trait_object_dummy_self))
|
||||||
.any(|sup| sup.map_bound(|x| ty::ExistentialTraitRef::erase_self_ty(cx.tcx, x)) == target_principal)
|
.any(|sup| sup.map_bound(|x| ty::ExistentialTraitRef::erase_self_ty(cx.tcx, x)) == target_principal)
|
||||||
{
|
{
|
||||||
cx.struct_span_lint(
|
let label = impl_.items.iter().find_map(|i| (i.ident.name == sym::Target).then_some(i.span)).map(|label| SupertraitAsDerefTargetLabel {
|
||||||
DEREF_INTO_DYN_SUPERTRAIT,
|
label,
|
||||||
cx.tcx.def_span(item.owner_id.def_id),
|
});
|
||||||
DelayDm(|| {
|
cx.emit_spanned_lint(DEREF_INTO_DYN_SUPERTRAIT, cx.tcx.def_span(item.owner_id.def_id), SupertraitAsDerefTarget {
|
||||||
format!(
|
t,
|
||||||
"`{t}` implements `Deref` with supertrait `{target_principal}` as target"
|
target_principal: target_principal.to_string(),
|
||||||
)
|
label,
|
||||||
}),
|
});
|
||||||
|lint| {
|
|
||||||
if let Some(target_span) = impl_.items.iter().find_map(|i| (i.ident.name == sym::Target).then_some(i.span)) {
|
|
||||||
lint.span_label(target_span, "target type is set here");
|
|
||||||
}
|
|
||||||
|
|
||||||
lint
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -551,6 +551,24 @@ pub struct BuiltinUnexpectedCliConfigValue {
|
||||||
pub value: Symbol,
|
pub value: Symbol,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deref_into_dyn_supertrait.rs
|
||||||
|
#[derive(LintDiagnostic)]
|
||||||
|
#[diag(lint_supertrait_as_deref_target)]
|
||||||
|
pub struct SupertraitAsDerefTarget<'a> {
|
||||||
|
pub t: Ty<'a>,
|
||||||
|
pub target_principal: String,
|
||||||
|
// pub target_principal: Binder<'a, ExistentialTraitRef<'b>>,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub label: Option<SupertraitAsDerefTargetLabel>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
#[label(label)]
|
||||||
|
pub struct SupertraitAsDerefTargetLabel {
|
||||||
|
#[primary_span]
|
||||||
|
pub label: Span,
|
||||||
|
}
|
||||||
|
|
||||||
// enum_intrinsics_non_enums.rs
|
// enum_intrinsics_non_enums.rs
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
#[diag(lint_enum_intrinsics_mem_discriminant)]
|
#[diag(lint_enum_intrinsics_mem_discriminant)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue