Skip to content

Commit 71e3314

Browse files
committed
rustc_pass_by_value remove dependency on rustc_diagnostic_item
1 parent 91ed689 commit 71e3314

File tree

5 files changed

+10
-18
lines changed

5 files changed

+10
-18
lines changed

compiler/rustc_lint/src/pass_by_value.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ declare_tool_lint! {
1111
/// The `rustc_pass_by_value` lint marks a type with `#[rustc_pass_by_value]` requiring it to always be passed by value.
1212
/// This is usually used for types that are thin wrappers around references, so there is no benefit to an extra
1313
/// layer of indirection. (Example: `Ty` which is a reference to a `TyS`)
14-
/// This lint relies on `#[rustc_diagnostic_item]` being available for the target.
1514
pub rustc::PASS_BY_VALUE,
1615
Warn,
1716
"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
5251
if let TyKind::Path(QPath::Resolved(_, path)) = &ty.kind {
5352
match path.res {
5453
Res::Def(_, def_id) if has_pass_by_value_attr(cx, def_id) => {
55-
if let Some(name) = cx.tcx.get_diagnostic_name(def_id) {
56-
return Some(format!("{}{}", name, gen_args(path.segments.last().unwrap())));
57-
}
54+
let name = cx.tcx.item_name(def_id).to_ident_string();
55+
return Some(format!("{}{}", name, gen_args(path.segments.last().unwrap())));
5856
}
5957
Res::SelfTy(None, Some((did, _))) => {
6058
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
6159
if has_pass_by_value_attr(cx, adt.did) {
62-
if let Some(name) = cx.tcx.get_diagnostic_name(adt.did) {
63-
return Some(format!("{}<{}>", name, substs[0]));
64-
}
60+
let name = cx.tcx.item_name(adt.did).to_ident_string();
61+
return Some(format!("{}<{}>", name, substs[0]));
6562
}
6663
}
6764
}

src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs

-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ impl Foo {
6262
//~^^ ERROR passing `TyCtxt<'_>` by reference
6363
}
6464

65-
#[rustc_diagnostic_item = "CustomEnum"]
6665
#[rustc_pass_by_value]
6766
enum CustomEnum {
6867
A,
@@ -77,13 +76,11 @@ impl CustomEnum {
7776
}
7877
}
7978

80-
#[rustc_diagnostic_item = "CustomStruct"]
8179
#[rustc_pass_by_value]
8280
struct CustomStruct {
8381
s: u8,
8482
}
8583

86-
#[rustc_diagnostic_item = "CustomAlias"]
8784
#[rustc_pass_by_value]
8885
type CustomAlias<'a> = &'a CustomStruct; //~ ERROR passing `CustomStruct` by reference
8986

src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,25 @@ LL | fn ty_multi_ref_assoc(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_>
7777
| ^^^^^^^^^^^ help: try passing by value: `TyCtxt<'_>`
7878

7979
error: passing `CustomEnum` by reference
80-
--> $DIR/rustc_pass_by_value.rs:75:20
80+
--> $DIR/rustc_pass_by_value.rs:74:20
8181
|
8282
LL | reference: &CustomEnum,
8383
| ^^^^^^^^^^^ help: try passing by value: `CustomEnum`
8484

8585
error: passing `CustomStruct` by reference
86-
--> $DIR/rustc_pass_by_value.rs:88:24
86+
--> $DIR/rustc_pass_by_value.rs:85:24
8787
|
8888
LL | type CustomAlias<'a> = &'a CustomStruct;
8989
| ^^^^^^^^^^^^^^^^ help: try passing by value: `CustomStruct`
9090

9191
error: passing `CustomStruct` by reference
92-
--> $DIR/rustc_pass_by_value.rs:93:20
92+
--> $DIR/rustc_pass_by_value.rs:90:20
9393
|
9494
LL | reference: &CustomStruct,
9595
| ^^^^^^^^^^^^^ help: try passing by value: `CustomStruct`
9696

9797
error: passing `CustomAlias<>` by reference
98-
--> $DIR/rustc_pass_by_value.rs:99:20
98+
--> $DIR/rustc_pass_by_value.rs:96:20
9999
|
100100
LL | reference: &CustomAlias,
101101
| ^^^^^^^^^^^^ help: try passing by value: `CustomAlias<>`

src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#![deny(rustc::pass_by_value)]
99
#![allow(unused)]
1010

11-
#[rustc_diagnostic_item = "TyCtxt"]
1211
#[rustc_pass_by_value]
1312
struct TyCtxt<'tcx> {
1413
inner: &'tcx (),
@@ -23,7 +22,6 @@ struct TyS<'tcx> {
2322
inner: &'tcx (),
2423
}
2524

26-
#[rustc_diagnostic_item = "Ty"]
2725
#[rustc_pass_by_value]
2826
type Ty<'tcx> = &'tcx TyS<'tcx>;
2927

src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: passing `TyCtxt<'tcx>` by reference
2-
--> $DIR/rustc_pass_by_value_self.rs:19:15
2+
--> $DIR/rustc_pass_by_value_self.rs:18:15
33
|
44
LL | fn by_ref(&self) {}
55
| ^^^^^ help: try passing by value: `TyCtxt<'tcx>`
@@ -11,7 +11,7 @@ LL | #![deny(rustc::pass_by_value)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: passing `Ty<'tcx>` by reference
14-
--> $DIR/rustc_pass_by_value_self.rs:32:21
14+
--> $DIR/rustc_pass_by_value_self.rs:30:21
1515
|
1616
LL | fn by_ref(self: &Ty<'tcx>) {}
1717
| ^^^^^^^^^ help: try passing by value: `Ty<'tcx>`

0 commit comments

Comments
 (0)