about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMahdi Dibaiee <mdibaiee@pm.me>2022-01-10 18:12:28 +0000
committerMahdi Dibaiee <mdibaiee@pm.me>2022-01-10 18:16:13 +0000
commit71e33146734362984258df415ac8308618968ed4 (patch)
tree59ffac5b8466ddcb666240e1cc4cfa461962c00c
parent91ed6892f7ec60fb76eeaaa024919f293a58d733 (diff)
rustc_pass_by_value remove dependency on rustc_diagnostic_item
-rw-r--r--compiler/rustc_lint/src/pass_by_value.rs11
-rw-r--r--src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs3
-rw-r--r--src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.stderr8
-rw-r--r--src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.rs2
-rw-r--r--src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.stderr4
5 files changed, 10 insertions, 18 deletions
diff --git a/compiler/rustc_lint/src/pass_by_value.rs b/compiler/rustc_lint/src/pass_by_value.rs
index 0847f600f9d..c689f34d9e3 100644
--- a/compiler/rustc_lint/src/pass_by_value.rs
+++ b/compiler/rustc_lint/src/pass_by_value.rs
@@ -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]));
                     }
                 }
             }
diff --git a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs
index bf2b1fbaf45..293464c07ef 100644
--- a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs
+++ b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs
@@ -62,7 +62,6 @@ impl Foo {
     //~^^ ERROR passing `TyCtxt<'_>` by reference
 }
 
-#[rustc_diagnostic_item = "CustomEnum"]
 #[rustc_pass_by_value]
 enum CustomEnum {
     A,
@@ -77,13 +76,11 @@ impl CustomEnum {
     }
 }
 
-#[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
 
diff --git a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.stderr b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.stderr
index c59c1adf899..dbb9180ed7d 100644
--- a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.stderr
+++ b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.stderr
@@ -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<>`
diff --git a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.rs b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.rs
index 8877148bb56..a4529f98563 100644
--- a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.rs
+++ b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.rs
@@ -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>;
 
diff --git a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.stderr b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.stderr
index f86aea95aa7..ca47babd13d 100644
--- a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.stderr
+++ b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.stderr
@@ -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>`