Skip to content

Commit cd8cfbf

Browse files
committed
review comments
1 parent ad63f90 commit cd8cfbf

File tree

7 files changed

+47
-59
lines changed

7 files changed

+47
-59
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

+19-31
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18161816
// work for the `enum`, instead of just looking if it takes *any*.
18171817
err.span_suggestion_verbose(
18181818
args_span,
1819-
&format!("{type_name} doesn't have type parameters"),
1819+
&format!("{type_name} doesn't have generic parameters"),
18201820
String::new(),
18211821
Applicability::MachineApplicable,
18221822
);
@@ -2115,20 +2115,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21152115
if segment.args().args.is_empty() {
21162116
None
21172117
} else {
2118-
let mut desc = res.descr();
2119-
if desc == "unresolved item" {
2120-
desc = "this type";
2121-
};
2122-
2123-
let name = match res {
2124-
Res::PrimTy(ty) => Some(ty.name()),
2125-
Res::Def(_, def_id) => self.tcx().opt_item_name(def_id),
2126-
_ => None,
2127-
};
21282118
Some((
2129-
match name {
2130-
Some(ty) => format!("{desc} `{ty}`"),
2131-
None => desc.to_string(),
2119+
match res {
2120+
Res::PrimTy(ty) => format!("{} `{}`", res.descr(), ty.name()),
2121+
Res::Def(_, def_id)
2122+
if let Some(name) = self.tcx().opt_item_name(def_id) => {
2123+
format!("{} `{name}`", res.descr())
2124+
}
2125+
Res::Err => "this type".to_string(),
2126+
_ => res.descr().to_string(),
21322127
},
21332128
segment.ident.span,
21342129
))
@@ -2158,33 +2153,26 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21582153
});
21592154
let mut emitted = false;
21602155
if lt || ty || ct || inf {
2161-
let arg_spans: Vec<Span> = args
2162-
.map(|arg| match arg {
2163-
hir::GenericArg::Lifetime(lt) => lt.span,
2164-
hir::GenericArg::Type(ty) => ty.span,
2165-
hir::GenericArg::Const(ct) => ct.span,
2166-
hir::GenericArg::Infer(inf) => inf.span,
2167-
})
2168-
.collect();
2156+
let arg_spans: Vec<Span> = args.map(|arg| arg.span()).collect();
21692157

2170-
let mut types = Vec::with_capacity(4);
2158+
let mut kinds = Vec::with_capacity(4);
21712159
if lt {
2172-
types.push("lifetime");
2160+
kinds.push("lifetime");
21732161
}
21742162
if ty {
2175-
types.push("type");
2163+
kinds.push("type");
21762164
}
21772165
if ct {
2178-
types.push("const");
2166+
kinds.push("const");
21792167
}
21802168
if inf {
2181-
types.push("generic");
2169+
kinds.push("generic");
21822170
}
2183-
let (kind, s) = match types[..] {
2171+
let (kind, s) = match kinds[..] {
21842172
[.., _, last] => (
21852173
format!(
21862174
"{} and {last}",
2187-
types[..types.len() - 1]
2175+
kinds[..kinds.len() - 1]
21882176
.iter()
21892177
.map(|&x| x)
21902178
.intersperse(", ")
@@ -2464,7 +2452,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24642452
);
24652453
let mut postfix = "";
24662454
if generics == 0 {
2467-
postfix = ", which doesn't have type parameters";
2455+
postfix = ", which doesn't have generic parameters";
24682456
}
24692457
span.push_span_label(
24702458
t_sp,
@@ -2557,7 +2545,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
25572545
if let Some(args) = segment.args {
25582546
err.span_suggestion_verbose(
25592547
segment.ident.span.shrink_to_hi().to(args.span_ext),
2560-
&format!("primitive type `{name}` doesn't have type parameters"),
2548+
&format!("primitive type `{name}` doesn't have generic parameters"),
25612549
String::new(),
25622550
Applicability::MaybeIncorrect,
25632551
);

src/test/ui/error-codes/E0109.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | type X = u32<i32>;
66
| |
77
| not allowed on this
88
|
9-
help: primitive type `u32` doesn't have type parameters
9+
help: primitive type `u32` doesn't have generic parameters
1010
|
1111
LL - type X = u32<i32>;
1212
LL + type X = u32;

src/test/ui/error-codes/E0110.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | type X = u32<'static>;
66
| |
77
| not allowed on this
88
|
9-
help: primitive type `u32` doesn't have type parameters
9+
help: primitive type `u32` doesn't have generic parameters
1010
|
1111
LL - type X = u32<'static>;
1212
LL + type X = u32;

src/test/ui/structs/struct-path-self.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ note: `Self` is of type `S`
4242
--> $DIR/struct-path-self.rs:1:8
4343
|
4444
LL | struct S;
45-
| ^ `Self` corresponds to this type, which doesn't have type parameters
45+
| ^ `Self` corresponds to this type, which doesn't have generic parameters
4646
...
4747
LL | impl Tr for S {
4848
| ------------- `Self` is on type `S` in this `impl`
@@ -64,7 +64,7 @@ note: `Self` is of type `S`
6464
--> $DIR/struct-path-self.rs:1:8
6565
|
6666
LL | struct S;
67-
| ^ `Self` corresponds to this type, which doesn't have type parameters
67+
| ^ `Self` corresponds to this type, which doesn't have generic parameters
6868
...
6969
LL | impl S {
7070
| ------ `Self` is on type `S` in this `impl`

src/test/ui/type/issue-91268.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ LL | 0: u8(ţ
3838
| |
3939
| not allowed on this
4040
|
41-
help: primitive type `u8` doesn't have type parameters
41+
help: primitive type `u8` doesn't have generic parameters
4242
|
4343
LL - 0: u8(ţ
4444
LL + 0: u8

src/test/ui/typeck/prim-with-args.stderr

+22-22
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let _x: isize<isize>;
66
| |
77
| not allowed on this
88
|
9-
help: primitive type `isize` doesn't have type parameters
9+
help: primitive type `isize` doesn't have generic parameters
1010
|
1111
LL - let _x: isize<isize>;
1212
LL + let _x: isize;
@@ -20,7 +20,7 @@ LL | let _x: i8<isize>;
2020
| |
2121
| not allowed on this
2222
|
23-
help: primitive type `i8` doesn't have type parameters
23+
help: primitive type `i8` doesn't have generic parameters
2424
|
2525
LL - let _x: i8<isize>;
2626
LL + let _x: i8;
@@ -34,7 +34,7 @@ LL | let _x: i16<isize>;
3434
| |
3535
| not allowed on this
3636
|
37-
help: primitive type `i16` doesn't have type parameters
37+
help: primitive type `i16` doesn't have generic parameters
3838
|
3939
LL - let _x: i16<isize>;
4040
LL + let _x: i16;
@@ -48,7 +48,7 @@ LL | let _x: i32<isize>;
4848
| |
4949
| not allowed on this
5050
|
51-
help: primitive type `i32` doesn't have type parameters
51+
help: primitive type `i32` doesn't have generic parameters
5252
|
5353
LL - let _x: i32<isize>;
5454
LL + let _x: i32;
@@ -62,7 +62,7 @@ LL | let _x: i64<isize>;
6262
| |
6363
| not allowed on this
6464
|
65-
help: primitive type `i64` doesn't have type parameters
65+
help: primitive type `i64` doesn't have generic parameters
6666
|
6767
LL - let _x: i64<isize>;
6868
LL + let _x: i64;
@@ -76,7 +76,7 @@ LL | let _x: usize<isize>;
7676
| |
7777
| not allowed on this
7878
|
79-
help: primitive type `usize` doesn't have type parameters
79+
help: primitive type `usize` doesn't have generic parameters
8080
|
8181
LL - let _x: usize<isize>;
8282
LL + let _x: usize;
@@ -90,7 +90,7 @@ LL | let _x: u8<isize>;
9090
| |
9191
| not allowed on this
9292
|
93-
help: primitive type `u8` doesn't have type parameters
93+
help: primitive type `u8` doesn't have generic parameters
9494
|
9595
LL - let _x: u8<isize>;
9696
LL + let _x: u8;
@@ -104,7 +104,7 @@ LL | let _x: u16<isize>;
104104
| |
105105
| not allowed on this
106106
|
107-
help: primitive type `u16` doesn't have type parameters
107+
help: primitive type `u16` doesn't have generic parameters
108108
|
109109
LL - let _x: u16<isize>;
110110
LL + let _x: u16;
@@ -118,7 +118,7 @@ LL | let _x: u32<isize>;
118118
| |
119119
| not allowed on this
120120
|
121-
help: primitive type `u32` doesn't have type parameters
121+
help: primitive type `u32` doesn't have generic parameters
122122
|
123123
LL - let _x: u32<isize>;
124124
LL + let _x: u32;
@@ -132,7 +132,7 @@ LL | let _x: u64<isize>;
132132
| |
133133
| not allowed on this
134134
|
135-
help: primitive type `u64` doesn't have type parameters
135+
help: primitive type `u64` doesn't have generic parameters
136136
|
137137
LL - let _x: u64<isize>;
138138
LL + let _x: u64;
@@ -146,7 +146,7 @@ LL | let _x: char<isize>;
146146
| |
147147
| not allowed on this
148148
|
149-
help: primitive type `char` doesn't have type parameters
149+
help: primitive type `char` doesn't have generic parameters
150150
|
151151
LL - let _x: char<isize>;
152152
LL + let _x: char;
@@ -160,7 +160,7 @@ LL | let _x: isize<'static>;
160160
| |
161161
| not allowed on this
162162
|
163-
help: primitive type `isize` doesn't have type parameters
163+
help: primitive type `isize` doesn't have generic parameters
164164
|
165165
LL - let _x: isize<'static>;
166166
LL + let _x: isize;
@@ -174,7 +174,7 @@ LL | let _x: i8<'static>;
174174
| |
175175
| not allowed on this
176176
|
177-
help: primitive type `i8` doesn't have type parameters
177+
help: primitive type `i8` doesn't have generic parameters
178178
|
179179
LL - let _x: i8<'static>;
180180
LL + let _x: i8;
@@ -188,7 +188,7 @@ LL | let _x: i16<'static>;
188188
| |
189189
| not allowed on this
190190
|
191-
help: primitive type `i16` doesn't have type parameters
191+
help: primitive type `i16` doesn't have generic parameters
192192
|
193193
LL - let _x: i16<'static>;
194194
LL + let _x: i16;
@@ -202,7 +202,7 @@ LL | let _x: i32<'static>;
202202
| |
203203
| not allowed on this
204204
|
205-
help: primitive type `i32` doesn't have type parameters
205+
help: primitive type `i32` doesn't have generic parameters
206206
|
207207
LL - let _x: i32<'static>;
208208
LL + let _x: i32;
@@ -216,7 +216,7 @@ LL | let _x: i64<'static>;
216216
| |
217217
| not allowed on this
218218
|
219-
help: primitive type `i64` doesn't have type parameters
219+
help: primitive type `i64` doesn't have generic parameters
220220
|
221221
LL - let _x: i64<'static>;
222222
LL + let _x: i64;
@@ -230,7 +230,7 @@ LL | let _x: usize<'static>;
230230
| |
231231
| not allowed on this
232232
|
233-
help: primitive type `usize` doesn't have type parameters
233+
help: primitive type `usize` doesn't have generic parameters
234234
|
235235
LL - let _x: usize<'static>;
236236
LL + let _x: usize;
@@ -244,7 +244,7 @@ LL | let _x: u8<'static>;
244244
| |
245245
| not allowed on this
246246
|
247-
help: primitive type `u8` doesn't have type parameters
247+
help: primitive type `u8` doesn't have generic parameters
248248
|
249249
LL - let _x: u8<'static>;
250250
LL + let _x: u8;
@@ -258,7 +258,7 @@ LL | let _x: u16<'static>;
258258
| |
259259
| not allowed on this
260260
|
261-
help: primitive type `u16` doesn't have type parameters
261+
help: primitive type `u16` doesn't have generic parameters
262262
|
263263
LL - let _x: u16<'static>;
264264
LL + let _x: u16;
@@ -272,7 +272,7 @@ LL | let _x: u32<'static>;
272272
| |
273273
| not allowed on this
274274
|
275-
help: primitive type `u32` doesn't have type parameters
275+
help: primitive type `u32` doesn't have generic parameters
276276
|
277277
LL - let _x: u32<'static>;
278278
LL + let _x: u32;
@@ -286,7 +286,7 @@ LL | let _x: u64<'static>;
286286
| |
287287
| not allowed on this
288288
|
289-
help: primitive type `u64` doesn't have type parameters
289+
help: primitive type `u64` doesn't have generic parameters
290290
|
291291
LL - let _x: u64<'static>;
292292
LL + let _x: u64;
@@ -300,7 +300,7 @@ LL | let _x: char<'static>;
300300
| |
301301
| not allowed on this
302302
|
303-
help: primitive type `char` doesn't have type parameters
303+
help: primitive type `char` doesn't have generic parameters
304304
|
305305
LL - let _x: char<'static>;
306306
LL + let _x: char;

src/test/ui/usize-generic-argument-parent.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let x: usize<foo>;
66
| |
77
| not allowed on this
88
|
9-
help: primitive type `usize` doesn't have type parameters
9+
help: primitive type `usize` doesn't have generic parameters
1010
|
1111
LL - let x: usize<foo>;
1212
LL + let x: usize;

0 commit comments

Comments
 (0)