review comments

This commit is contained in:
Esteban Küber 2022-06-02 14:06:54 -07:00
parent ad63f907e9
commit cd8cfbfb09
7 changed files with 47 additions and 59 deletions

View File

@ -1816,7 +1816,7 @@ pub fn associated_path_to_ty(
// 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 @@ pub fn prohibit_generics<'a>(
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 @@ pub fn prohibit_generics<'a>(
});
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 @@ pub fn res_to_ty(
);
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 @@ pub fn res_to_ty(
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,
);

View File

@ -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;

View File

@ -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;

View File

@ -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`

View File

@ -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

View File

@ -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;

View File

@ -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;