about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2022-06-02 14:06:54 -0700
committerEsteban Küber <esteban@kuber.com.ar>2022-06-02 15:29:20 -0700
commitcd8cfbfb098f8e1da086ee7d164af03e3fdde189 (patch)
treef7f5d26ddb2960c1bd9ccd916de7c84324e9afff
parentad63f907e987673fc99dce3e4d1437720705f5a8 (diff)
downloadrust-cd8cfbfb098f8e1da086ee7d164af03e3fdde189.tar.gz
rust-cd8cfbfb098f8e1da086ee7d164af03e3fdde189.zip
review comments
-rw-r--r--compiler/rustc_typeck/src/astconv/mod.rs50
-rw-r--r--src/test/ui/error-codes/E0109.stderr2
-rw-r--r--src/test/ui/error-codes/E0110.stderr2
-rw-r--r--src/test/ui/structs/struct-path-self.stderr4
-rw-r--r--src/test/ui/type/issue-91268.stderr2
-rw-r--r--src/test/ui/typeck/prim-with-args.stderr44
-rw-r--r--src/test/ui/usize-generic-argument-parent.stderr2
7 files changed, 47 insertions, 59 deletions
diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs
index 405acfc186c..bcff2ae5129 100644
--- a/compiler/rustc_typeck/src/astconv/mod.rs
+++ b/compiler/rustc_typeck/src/astconv/mod.rs
@@ -1816,7 +1816,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                                 // work for the `enum`, instead of just looking if it takes *any*.
                                 err.span_suggestion_verbose(
                                     args_span,
-                                    &format!("{type_name} doesn't have type parameters"),
+                                    &format!("{type_name} doesn't have generic parameters"),
                                     String::new(),
                                     Applicability::MachineApplicable,
                                 );
@@ -2115,20 +2115,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                     if segment.args().args.is_empty() {
                         None
                     } else {
-                        let mut desc = res.descr();
-                        if desc == "unresolved item" {
-                            desc = "this type";
-                        };
-
-                        let name = match res {
-                            Res::PrimTy(ty) => Some(ty.name()),
-                            Res::Def(_, def_id) => self.tcx().opt_item_name(def_id),
-                            _ => None,
-                        };
                         Some((
-                            match name {
-                                Some(ty) => format!("{desc} `{ty}`"),
-                                None => desc.to_string(),
+                            match res {
+                                Res::PrimTy(ty) => format!("{} `{}`", res.descr(), ty.name()),
+                                Res::Def(_, def_id)
+                                if let Some(name) = self.tcx().opt_item_name(def_id) => {
+                                    format!("{} `{name}`", res.descr())
+                                }
+                                Res::Err => "this type".to_string(),
+                                _ => res.descr().to_string(),
                             },
                             segment.ident.span,
                         ))
@@ -2158,33 +2153,26 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
             });
         let mut emitted = false;
         if lt || ty || ct || inf {
-            let arg_spans: Vec<Span> = args
-                .map(|arg| match arg {
-                    hir::GenericArg::Lifetime(lt) => lt.span,
-                    hir::GenericArg::Type(ty) => ty.span,
-                    hir::GenericArg::Const(ct) => ct.span,
-                    hir::GenericArg::Infer(inf) => inf.span,
-                })
-                .collect();
+            let arg_spans: Vec<Span> = args.map(|arg| arg.span()).collect();
 
-            let mut types = Vec::with_capacity(4);
+            let mut kinds = Vec::with_capacity(4);
             if lt {
-                types.push("lifetime");
+                kinds.push("lifetime");
             }
             if ty {
-                types.push("type");
+                kinds.push("type");
             }
             if ct {
-                types.push("const");
+                kinds.push("const");
             }
             if inf {
-                types.push("generic");
+                kinds.push("generic");
             }
-            let (kind, s) = match types[..] {
+            let (kind, s) = match kinds[..] {
                 [.., _, last] => (
                     format!(
                         "{} and {last}",
-                        types[..types.len() - 1]
+                        kinds[..kinds.len() - 1]
                             .iter()
                             .map(|&x| x)
                             .intersperse(", ")
@@ -2464,7 +2452,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                         );
                         let mut postfix = "";
                         if generics == 0 {
-                            postfix = ", which doesn't have type parameters";
+                            postfix = ", which doesn't have generic parameters";
                         }
                         span.push_span_label(
                             t_sp,
@@ -2557,7 +2545,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                         if let Some(args) = segment.args {
                             err.span_suggestion_verbose(
                                 segment.ident.span.shrink_to_hi().to(args.span_ext),
-                                &format!("primitive type `{name}` doesn't have type parameters"),
+                                &format!("primitive type `{name}` doesn't have generic parameters"),
                                 String::new(),
                                 Applicability::MaybeIncorrect,
                             );
diff --git a/src/test/ui/error-codes/E0109.stderr b/src/test/ui/error-codes/E0109.stderr
index e91c74151b3..e0e437e18ae 100644
--- a/src/test/ui/error-codes/E0109.stderr
+++ b/src/test/ui/error-codes/E0109.stderr
@@ -6,7 +6,7 @@ LL | type X = u32<i32>;
    |          |
    |          not allowed on this
    |
-help: primitive type `u32` doesn't have type parameters
+help: primitive type `u32` doesn't have generic parameters
    |
 LL - type X = u32<i32>;
 LL + type X = u32;
diff --git a/src/test/ui/error-codes/E0110.stderr b/src/test/ui/error-codes/E0110.stderr
index 4425d87e2b0..15e1b959193 100644
--- a/src/test/ui/error-codes/E0110.stderr
+++ b/src/test/ui/error-codes/E0110.stderr
@@ -6,7 +6,7 @@ LL | type X = u32<'static>;
    |          |
    |          not allowed on this
    |
-help: primitive type `u32` doesn't have type parameters
+help: primitive type `u32` doesn't have generic parameters
    |
 LL - type X = u32<'static>;
 LL + type X = u32;
diff --git a/src/test/ui/structs/struct-path-self.stderr b/src/test/ui/structs/struct-path-self.stderr
index 3a4baeb9f6c..cccdd7b0f02 100644
--- a/src/test/ui/structs/struct-path-self.stderr
+++ b/src/test/ui/structs/struct-path-self.stderr
@@ -42,7 +42,7 @@ note: `Self` is of type `S`
   --> $DIR/struct-path-self.rs:1:8
    |
 LL | struct S;
-   |        ^ `Self` corresponds to this type, which doesn't have type parameters
+   |        ^ `Self` corresponds to this type, which doesn't have generic parameters
 ...
 LL | impl Tr for S {
    | ------------- `Self` is on type `S` in this `impl`
@@ -64,7 +64,7 @@ note: `Self` is of type `S`
   --> $DIR/struct-path-self.rs:1:8
    |
 LL | struct S;
-   |        ^ `Self` corresponds to this type, which doesn't have type parameters
+   |        ^ `Self` corresponds to this type, which doesn't have generic parameters
 ...
 LL | impl S {
    | ------ `Self` is on type `S` in this `impl`
diff --git a/src/test/ui/type/issue-91268.stderr b/src/test/ui/type/issue-91268.stderr
index b8900b02180..199fd6a23f7 100644
--- a/src/test/ui/type/issue-91268.stderr
+++ b/src/test/ui/type/issue-91268.stderr
@@ -38,7 +38,7 @@ LL |     0: u8(ţ
    |        |
    |        not allowed on this
    |
-help: primitive type `u8` doesn't have type parameters
+help: primitive type `u8` doesn't have generic parameters
    |
 LL -     0: u8(ţ
 LL +     0: u8
diff --git a/src/test/ui/typeck/prim-with-args.stderr b/src/test/ui/typeck/prim-with-args.stderr
index 1728757c808..7e7bc580b3b 100644
--- a/src/test/ui/typeck/prim-with-args.stderr
+++ b/src/test/ui/typeck/prim-with-args.stderr
@@ -6,7 +6,7 @@ LL | let _x: isize<isize>;
    |         |
    |         not allowed on this
    |
-help: primitive type `isize` doesn't have type parameters
+help: primitive type `isize` doesn't have generic parameters
    |
 LL - let _x: isize<isize>;
 LL + let _x: isize;
@@ -20,7 +20,7 @@ LL | let _x: i8<isize>;
    |         |
    |         not allowed on this
    |
-help: primitive type `i8` doesn't have type parameters
+help: primitive type `i8` doesn't have generic parameters
    |
 LL - let _x: i8<isize>;
 LL + let _x: i8;
@@ -34,7 +34,7 @@ LL | let _x: i16<isize>;
    |         |
    |         not allowed on this
    |
-help: primitive type `i16` doesn't have type parameters
+help: primitive type `i16` doesn't have generic parameters
    |
 LL - let _x: i16<isize>;
 LL + let _x: i16;
@@ -48,7 +48,7 @@ LL | let _x: i32<isize>;
    |         |
    |         not allowed on this
    |
-help: primitive type `i32` doesn't have type parameters
+help: primitive type `i32` doesn't have generic parameters
    |
 LL - let _x: i32<isize>;
 LL + let _x: i32;
@@ -62,7 +62,7 @@ LL | let _x: i64<isize>;
    |         |
    |         not allowed on this
    |
-help: primitive type `i64` doesn't have type parameters
+help: primitive type `i64` doesn't have generic parameters
    |
 LL - let _x: i64<isize>;
 LL + let _x: i64;
@@ -76,7 +76,7 @@ LL | let _x: usize<isize>;
    |         |
    |         not allowed on this
    |
-help: primitive type `usize` doesn't have type parameters
+help: primitive type `usize` doesn't have generic parameters
    |
 LL - let _x: usize<isize>;
 LL + let _x: usize;
@@ -90,7 +90,7 @@ LL | let _x: u8<isize>;
    |         |
    |         not allowed on this
    |
-help: primitive type `u8` doesn't have type parameters
+help: primitive type `u8` doesn't have generic parameters
    |
 LL - let _x: u8<isize>;
 LL + let _x: u8;
@@ -104,7 +104,7 @@ LL | let _x: u16<isize>;
    |         |
    |         not allowed on this
    |
-help: primitive type `u16` doesn't have type parameters
+help: primitive type `u16` doesn't have generic parameters
    |
 LL - let _x: u16<isize>;
 LL + let _x: u16;
@@ -118,7 +118,7 @@ LL | let _x: u32<isize>;
    |         |
    |         not allowed on this
    |
-help: primitive type `u32` doesn't have type parameters
+help: primitive type `u32` doesn't have generic parameters
    |
 LL - let _x: u32<isize>;
 LL + let _x: u32;
@@ -132,7 +132,7 @@ LL | let _x: u64<isize>;
    |         |
    |         not allowed on this
    |
-help: primitive type `u64` doesn't have type parameters
+help: primitive type `u64` doesn't have generic parameters
    |
 LL - let _x: u64<isize>;
 LL + let _x: u64;
@@ -146,7 +146,7 @@ LL | let _x: char<isize>;
    |         |
    |         not allowed on this
    |
-help: primitive type `char` doesn't have type parameters
+help: primitive type `char` doesn't have generic parameters
    |
 LL - let _x: char<isize>;
 LL + let _x: char;
@@ -160,7 +160,7 @@ LL | let _x: isize<'static>;
    |         |
    |         not allowed on this
    |
-help: primitive type `isize` doesn't have type parameters
+help: primitive type `isize` doesn't have generic parameters
    |
 LL - let _x: isize<'static>;
 LL + let _x: isize;
@@ -174,7 +174,7 @@ LL | let _x: i8<'static>;
    |         |
    |         not allowed on this
    |
-help: primitive type `i8` doesn't have type parameters
+help: primitive type `i8` doesn't have generic parameters
    |
 LL - let _x: i8<'static>;
 LL + let _x: i8;
@@ -188,7 +188,7 @@ LL | let _x: i16<'static>;
    |         |
    |         not allowed on this
    |
-help: primitive type `i16` doesn't have type parameters
+help: primitive type `i16` doesn't have generic parameters
    |
 LL - let _x: i16<'static>;
 LL + let _x: i16;
@@ -202,7 +202,7 @@ LL | let _x: i32<'static>;
    |         |
    |         not allowed on this
    |
-help: primitive type `i32` doesn't have type parameters
+help: primitive type `i32` doesn't have generic parameters
    |
 LL - let _x: i32<'static>;
 LL + let _x: i32;
@@ -216,7 +216,7 @@ LL | let _x: i64<'static>;
    |         |
    |         not allowed on this
    |
-help: primitive type `i64` doesn't have type parameters
+help: primitive type `i64` doesn't have generic parameters
    |
 LL - let _x: i64<'static>;
 LL + let _x: i64;
@@ -230,7 +230,7 @@ LL | let _x: usize<'static>;
    |         |
    |         not allowed on this
    |
-help: primitive type `usize` doesn't have type parameters
+help: primitive type `usize` doesn't have generic parameters
    |
 LL - let _x: usize<'static>;
 LL + let _x: usize;
@@ -244,7 +244,7 @@ LL | let _x: u8<'static>;
    |         |
    |         not allowed on this
    |
-help: primitive type `u8` doesn't have type parameters
+help: primitive type `u8` doesn't have generic parameters
    |
 LL - let _x: u8<'static>;
 LL + let _x: u8;
@@ -258,7 +258,7 @@ LL | let _x: u16<'static>;
    |         |
    |         not allowed on this
    |
-help: primitive type `u16` doesn't have type parameters
+help: primitive type `u16` doesn't have generic parameters
    |
 LL - let _x: u16<'static>;
 LL + let _x: u16;
@@ -272,7 +272,7 @@ LL | let _x: u32<'static>;
    |         |
    |         not allowed on this
    |
-help: primitive type `u32` doesn't have type parameters
+help: primitive type `u32` doesn't have generic parameters
    |
 LL - let _x: u32<'static>;
 LL + let _x: u32;
@@ -286,7 +286,7 @@ LL | let _x: u64<'static>;
    |         |
    |         not allowed on this
    |
-help: primitive type `u64` doesn't have type parameters
+help: primitive type `u64` doesn't have generic parameters
    |
 LL - let _x: u64<'static>;
 LL + let _x: u64;
@@ -300,7 +300,7 @@ LL | let _x: char<'static>;
    |         |
    |         not allowed on this
    |
-help: primitive type `char` doesn't have type parameters
+help: primitive type `char` doesn't have generic parameters
    |
 LL - let _x: char<'static>;
 LL + let _x: char;
diff --git a/src/test/ui/usize-generic-argument-parent.stderr b/src/test/ui/usize-generic-argument-parent.stderr
index e47de289d1e..c657f0faa0b 100644
--- a/src/test/ui/usize-generic-argument-parent.stderr
+++ b/src/test/ui/usize-generic-argument-parent.stderr
@@ -6,7 +6,7 @@ LL |     let x: usize<foo>;
    |            |
    |            not allowed on this
    |
-help: primitive type `usize` doesn't have type parameters
+help: primitive type `usize` doesn't have generic parameters
    |
 LL -     let x: usize<foo>;
 LL +     let x: usize;