rustc_pass_by_value remove dependency on rustc_diagnostic_item
This commit is contained in:
parent
91ed6892f7
commit
71e3314673
@ -11,7 +11,6 @@
|
||||
/// 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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,6 @@ fn ty_multi_ref_assoc(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_>) {}
|
||||
//~^^ ERROR passing `TyCtxt<'_>` by reference
|
||||
}
|
||||
|
||||
#[rustc_diagnostic_item = "CustomEnum"]
|
||||
#[rustc_pass_by_value]
|
||||
enum CustomEnum {
|
||||
A,
|
||||
@ -77,13 +76,11 @@ fn test(
|
||||
}
|
||||
}
|
||||
|
||||
#[rustc_diagnostic_item = "CustomStruct"]
|
||||
#[rustc_pass_by_value]
|
||||
struct CustomStruct {
|
||||
s: u8,
|
||||
}
|
||||
|
||||
#[rustc_diagnostic_item = "CustomAlias"]
|
||||
#[rustc_pass_by_value]
|
||||
type CustomAlias<'a> = &'a CustomStruct; //~ ERROR passing `CustomStruct` by reference
|
||||
|
||||
|
@ -77,25 +77,25 @@ LL | fn ty_multi_ref_assoc(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_>
|
||||
| ^^^^^^^^^^^ help: try passing by value: `TyCtxt<'_>`
|
||||
|
||||
error: passing `CustomEnum` by reference
|
||||
--> $DIR/rustc_pass_by_value.rs:75:20
|
||||
--> $DIR/rustc_pass_by_value.rs:74:20
|
||||
|
|
||||
LL | reference: &CustomEnum,
|
||||
| ^^^^^^^^^^^ help: try passing by value: `CustomEnum`
|
||||
|
||||
error: passing `CustomStruct` by reference
|
||||
--> $DIR/rustc_pass_by_value.rs:88:24
|
||||
--> $DIR/rustc_pass_by_value.rs:85:24
|
||||
|
|
||||
LL | type CustomAlias<'a> = &'a CustomStruct;
|
||||
| ^^^^^^^^^^^^^^^^ help: try passing by value: `CustomStruct`
|
||||
|
||||
error: passing `CustomStruct` by reference
|
||||
--> $DIR/rustc_pass_by_value.rs:93:20
|
||||
--> $DIR/rustc_pass_by_value.rs:90:20
|
||||
|
|
||||
LL | reference: &CustomStruct,
|
||||
| ^^^^^^^^^^^^^ help: try passing by value: `CustomStruct`
|
||||
|
||||
error: passing `CustomAlias<>` by reference
|
||||
--> $DIR/rustc_pass_by_value.rs:99:20
|
||||
--> $DIR/rustc_pass_by_value.rs:96:20
|
||||
|
|
||||
LL | reference: &CustomAlias,
|
||||
| ^^^^^^^^^^^^ help: try passing by value: `CustomAlias<>`
|
||||
|
@ -8,7 +8,6 @@
|
||||
#![deny(rustc::pass_by_value)]
|
||||
#![allow(unused)]
|
||||
|
||||
#[rustc_diagnostic_item = "TyCtxt"]
|
||||
#[rustc_pass_by_value]
|
||||
struct TyCtxt<'tcx> {
|
||||
inner: &'tcx (),
|
||||
@ -23,7 +22,6 @@ struct TyS<'tcx> {
|
||||
inner: &'tcx (),
|
||||
}
|
||||
|
||||
#[rustc_diagnostic_item = "Ty"]
|
||||
#[rustc_pass_by_value]
|
||||
type Ty<'tcx> = &'tcx TyS<'tcx>;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: passing `TyCtxt<'tcx>` by reference
|
||||
--> $DIR/rustc_pass_by_value_self.rs:19:15
|
||||
--> $DIR/rustc_pass_by_value_self.rs:18:15
|
||||
|
|
||||
LL | fn by_ref(&self) {}
|
||||
| ^^^^^ help: try passing by value: `TyCtxt<'tcx>`
|
||||
@ -11,7 +11,7 @@ LL | #![deny(rustc::pass_by_value)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: passing `Ty<'tcx>` by reference
|
||||
--> $DIR/rustc_pass_by_value_self.rs:32:21
|
||||
--> $DIR/rustc_pass_by_value_self.rs:30:21
|
||||
|
|
||||
LL | fn by_ref(self: &Ty<'tcx>) {}
|
||||
| ^^^^^^^^^ help: try passing by value: `Ty<'tcx>`
|
||||
|
Loading…
Reference in New Issue
Block a user