rustc_pass_by_value remove dependency on rustc_diagnostic_item
This commit is contained in:
parent
91ed6892f7
commit
71e3314673
5 changed files with 10 additions and 18 deletions
|
@ -11,7 +11,6 @@ declare_tool_lint! {
|
|||
/// The `rustc_pass_by_value` lint marks a type with `#[rustc_pass_by_value]` requiring it to always be passed by value.
|
||||
/// This is usually used for types that are thin wrappers around references, so there is no benefit to an extra
|
||||
/// layer of indirection. (Example: `Ty` which is a reference to a `TyS`)
|
||||
/// This lint relies on `#[rustc_diagnostic_item]` being available for the target.
|
||||
pub rustc::PASS_BY_VALUE,
|
||||
Warn,
|
||||
"pass by reference of a type flagged as `#[rustc_pass_by_value]`",
|
||||
|
@ -52,16 +51,14 @@ fn path_for_pass_by_value(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> Option<Stri
|
|||
if let TyKind::Path(QPath::Resolved(_, path)) = &ty.kind {
|
||||
match path.res {
|
||||
Res::Def(_, def_id) if has_pass_by_value_attr(cx, def_id) => {
|
||||
if let Some(name) = cx.tcx.get_diagnostic_name(def_id) {
|
||||
return Some(format!("{}{}", name, gen_args(path.segments.last().unwrap())));
|
||||
}
|
||||
let name = cx.tcx.item_name(def_id).to_ident_string();
|
||||
return Some(format!("{}{}", name, gen_args(path.segments.last().unwrap())));
|
||||
}
|
||||
Res::SelfTy(None, Some((did, _))) => {
|
||||
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
|
||||
if has_pass_by_value_attr(cx, adt.did) {
|
||||
if let Some(name) = cx.tcx.get_diagnostic_name(adt.did) {
|
||||
return Some(format!("{}<{}>", name, substs[0]));
|
||||
}
|
||||
let name = cx.tcx.item_name(adt.did).to_ident_string();
|
||||
return Some(format!("{}<{}>", name, substs[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue