Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jun 2, 2022
1 parent ad63f90 commit cd8cfbf
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 59 deletions.
50 changes: 19 additions & 31 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
))
Expand Down Expand Up @@ -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(", ")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0109.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0110.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/structs/struct-path-self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/type/issue-91268.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 22 additions & 22 deletions src/test/ui/typeck/prim-with-args.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/usize-generic-argument-parent.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cd8cfbf

Please sign in to comment.