From cd8cfbfb098f8e1da086ee7d164af03e3fdde189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 2 Jun 2022 14:06:54 -0700 Subject: [PATCH] review comments --- compiler/rustc_typeck/src/astconv/mod.rs | 50 +++++++------------ src/test/ui/error-codes/E0109.stderr | 2 +- src/test/ui/error-codes/E0110.stderr | 2 +- src/test/ui/structs/struct-path-self.stderr | 4 +- src/test/ui/type/issue-91268.stderr | 2 +- src/test/ui/typeck/prim-with-args.stderr | 44 ++++++++-------- .../ui/usize-generic-argument-parent.stderr | 2 +- 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 = 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 = 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; | | | 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; 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; | | | 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; LL + let _x: isize; @@ -20,7 +20,7 @@ LL | let _x: i8; | | | 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; LL + let _x: i8; @@ -34,7 +34,7 @@ LL | let _x: i16; | | | 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; LL + let _x: i16; @@ -48,7 +48,7 @@ LL | let _x: i32; | | | 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; LL + let _x: i32; @@ -62,7 +62,7 @@ LL | let _x: i64; | | | 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; LL + let _x: i64; @@ -76,7 +76,7 @@ LL | let _x: usize; | | | 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; LL + let _x: usize; @@ -90,7 +90,7 @@ LL | let _x: u8; | | | 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; LL + let _x: u8; @@ -104,7 +104,7 @@ LL | let _x: u16; | | | 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; LL + let _x: u16; @@ -118,7 +118,7 @@ LL | let _x: u32; | | | 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; LL + let _x: u32; @@ -132,7 +132,7 @@ LL | let _x: u64; | | | 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; LL + let _x: u64; @@ -146,7 +146,7 @@ LL | let _x: char; | | | 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; 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; | | | 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; LL + let x: usize;