Skip to content

Commit 3b68700

Browse files
Rollup merge of #98269 - compiler-errors:provide-more-segment-res, r=petrochenkov
Provide a `PathSegment.res` in more cases I find that in many cases, the `res` associated with a `PathSegment` is `Res::Err` even though the path was fully resolved. A few diagnostics use this `res` and their error messages suffer because of the lack of resolved segment. This fixes it a bit, but it's obviously not complete and I'm not exactly sure if it's correct.
2 parents 413e350 + f924e74 commit 3b68700

14 files changed

+116
-115
lines changed

compiler/rustc_resolve/src/ident.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,7 @@ impl<'a> Resolver<'a> {
15021502
return PathResult::NonModule(PartialRes::new(Res::Err));
15031503
} else if opt_ns.is_some() && (is_last || maybe_assoc) {
15041504
self.lint_if_path_starts_with_module(finalize, path, second_binding);
1505+
record_segment_res(self, res);
15051506
return PathResult::NonModule(PartialRes::with_unresolved_segments(
15061507
res,
15071508
path.len() - i - 1,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0109]: type arguments are not allowed on this type
1+
error[E0109]: type arguments are not allowed on builtin type `u32`
22
--> $DIR/E0109.rs:1:14
33
|
44
LL | type X = u32<i32>;
55
| --- ^^^ type argument not allowed
66
| |
7-
| not allowed on this type
7+
| not allowed on builtin type `u32`
88
|
99
help: primitive type `u32` doesn't have generic parameters
1010
|

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0109]: lifetime arguments are not allowed on this type
1+
error[E0109]: lifetime arguments are not allowed on builtin type `u32`
22
--> $DIR/E0110.rs:1:14
33
|
44
LL | type X = u32<'static>;
55
| --- ^^^^^^^ lifetime argument not allowed
66
| |
7-
| not allowed on this type
7+
| not allowed on builtin type `u32`
88
|
99
help: primitive type `u32` doesn't have generic parameters
1010
|

src/test/ui/inference/cannot-infer-closure-circular.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ fn main() {
44
// error handles this gracefully, and in particular doesn't generate an extra
55
// note about the `?` operator in the closure body, which isn't relevant to
66
// the inference.
7-
let x = |r| {
7+
let x = |r| { //~ ERROR type annotations needed for `Result<(), E>`
88
let v = r?;
99
Ok(v)
1010
};
1111

12-
let _ = x(x(Ok(()))); //~ ERROR type annotations needed for `Result<(), E>`
12+
let _ = x(x(Ok(())));
1313
}

src/test/ui/inference/cannot-infer-closure-circular.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0282]: type annotations needed for `Result<(), E>`
2-
--> $DIR/cannot-infer-closure-circular.rs:12:9
2+
--> $DIR/cannot-infer-closure-circular.rs:7:14
33
|
4-
LL | let _ = x(x(Ok(())));
5-
| ^
4+
LL | let x = |r| {
5+
| ^
66
|
7-
help: consider giving this pattern a type, where the type for type parameter `E` is specified
7+
help: consider giving this closure parameter an explicit type, where the type for type parameter `E` is specified
88
|
9-
LL | let _: Result<(), E> = x(x(Ok(())));
10-
| +++++++++++++++
9+
LL | let x = |r: Result<(), E>| {
10+
| +++++++++++++++
1111

1212
error: aborting due to previous error
1313

src/test/ui/type-alias-enum-variants/enum-variant-generic-args.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn main() {
5252
// Tuple struct variant
5353

5454
Enum::<()>::TSVariant::<()>(());
55-
//~^ ERROR type arguments are not allowed on this type [E0109]
55+
//~^ ERROR type arguments are not allowed on tuple variant `TSVariant` [E0109]
5656

5757
Alias::TSVariant::<()>(());
5858
//~^ ERROR type arguments are not allowed on this type [E0109]
@@ -70,7 +70,7 @@ fn main() {
7070
// Struct variant
7171

7272
Enum::<()>::SVariant::<()> { v: () };
73-
//~^ ERROR type arguments are not allowed on this type [E0109]
73+
//~^ ERROR type arguments are not allowed on variant `SVariant` [E0109]
7474

7575
Alias::SVariant::<()> { v: () };
7676
//~^ ERROR type arguments are not allowed on this type [E0109]
@@ -88,7 +88,7 @@ fn main() {
8888
// Unit variant
8989

9090
Enum::<()>::UVariant::<()>;
91-
//~^ ERROR type arguments are not allowed on this type [E0109]
91+
//~^ ERROR type arguments are not allowed on unit variant `UVariant` [E0109]
9292

9393
Alias::UVariant::<()>;
9494
//~^ ERROR type arguments are not allowed on this type [E0109]

src/test/ui/type-alias-enum-variants/enum-variant-generic-args.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ LL | Self::<()>::UVariant::<()>;
272272
| |
273273
| not allowed on this type
274274

275-
error[E0109]: type arguments are not allowed on this type
275+
error[E0109]: type arguments are not allowed on tuple variant `TSVariant`
276276
--> $DIR/enum-variant-generic-args.rs:54:29
277277
|
278278
LL | Enum::<()>::TSVariant::<()>(());
279279
| --------- ^^ type argument not allowed
280280
| |
281-
| not allowed on this type
281+
| not allowed on tuple variant `TSVariant`
282282

283283
error[E0109]: type arguments are not allowed on this type
284284
--> $DIR/enum-variant-generic-args.rs:57:24
@@ -340,13 +340,13 @@ LL | AliasFixed::<()>::TSVariant::<()>(());
340340
| |
341341
| not allowed on this type
342342

343-
error[E0109]: type arguments are not allowed on this type
343+
error[E0109]: type arguments are not allowed on variant `SVariant`
344344
--> $DIR/enum-variant-generic-args.rs:72:28
345345
|
346346
LL | Enum::<()>::SVariant::<()> { v: () };
347347
| -------- ^^ type argument not allowed
348348
| |
349-
| not allowed on this type
349+
| not allowed on variant `SVariant`
350350
|
351351
= note: enum variants can't have type parameters
352352

@@ -438,13 +438,13 @@ LL - AliasFixed::<()>::SVariant::<()> { v: () };
438438
LL + AliasFixed::<()>::SVariant { v: () };
439439
|
440440

441-
error[E0109]: type arguments are not allowed on this type
441+
error[E0109]: type arguments are not allowed on unit variant `UVariant`
442442
--> $DIR/enum-variant-generic-args.rs:90:28
443443
|
444444
LL | Enum::<()>::UVariant::<()>;
445445
| -------- ^^ type argument not allowed
446446
| |
447-
| not allowed on this type
447+
| not allowed on unit variant `UVariant`
448448

449449
error[E0109]: type arguments are not allowed on this type
450450
--> $DIR/enum-variant-generic-args.rs:93:23

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// error-pattern: this file contains an unclosed delimiter
22
// error-pattern: cannot find type `ţ` in this scope
33
// error-pattern: parenthesized type parameters may only be used with a `Fn` trait
4-
// error-pattern: type arguments are not allowed on this type
4+
// error-pattern: type arguments are not allowed on builtin type `u8`
55
// error-pattern: mismatched types
66
// ignore-tidy-trailing-newlines
77
// `ţ` must be the last character in this file, it cannot be followed by a newline

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ help: use angle brackets instead
3535
LL | 0: u8<ţ>
3636
| ~ +
3737

38-
error[E0109]: type arguments are not allowed on this type
38+
error[E0109]: type arguments are not allowed on builtin type `u8`
3939
--> $DIR/issue-91268.rs:9:11
4040
|
4141
LL | 0: u8(ţ
4242
| -- ^ type argument not allowed
4343
| |
44-
| not allowed on this type
44+
| not allowed on builtin type `u8`
4545
|
4646
help: primitive type `u8` doesn't have generic parameters
4747
|
+22-22
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
// run-rustfix
22
fn main() {
33

4-
let _x: isize; //~ ERROR type arguments are not allowed on this type
5-
let _x: i8; //~ ERROR type arguments are not allowed on this type
6-
let _x: i16; //~ ERROR type arguments are not allowed on this type
7-
let _x: i32; //~ ERROR type arguments are not allowed on this type
8-
let _x: i64; //~ ERROR type arguments are not allowed on this type
9-
let _x: usize; //~ ERROR type arguments are not allowed on this type
10-
let _x: u8; //~ ERROR type arguments are not allowed on this type
11-
let _x: u16; //~ ERROR type arguments are not allowed on this type
12-
let _x: u32; //~ ERROR type arguments are not allowed on this type
13-
let _x: u64; //~ ERROR type arguments are not allowed on this type
14-
let _x: char; //~ ERROR type arguments are not allowed on this type
4+
let _x: isize; //~ ERROR type arguments are not allowed on builtin type
5+
let _x: i8; //~ ERROR type arguments are not allowed on builtin type
6+
let _x: i16; //~ ERROR type arguments are not allowed on builtin type
7+
let _x: i32; //~ ERROR type arguments are not allowed on builtin type
8+
let _x: i64; //~ ERROR type arguments are not allowed on builtin type
9+
let _x: usize; //~ ERROR type arguments are not allowed on builtin type
10+
let _x: u8; //~ ERROR type arguments are not allowed on builtin type
11+
let _x: u16; //~ ERROR type arguments are not allowed on builtin type
12+
let _x: u32; //~ ERROR type arguments are not allowed on builtin type
13+
let _x: u64; //~ ERROR type arguments are not allowed on builtin type
14+
let _x: char; //~ ERROR type arguments are not allowed on builtin type
1515

16-
let _x: isize; //~ ERROR lifetime arguments are not allowed on this type
17-
let _x: i8; //~ ERROR lifetime arguments are not allowed on this type
18-
let _x: i16; //~ ERROR lifetime arguments are not allowed on this type
19-
let _x: i32; //~ ERROR lifetime arguments are not allowed on this type
20-
let _x: i64; //~ ERROR lifetime arguments are not allowed on this type
21-
let _x: usize; //~ ERROR lifetime arguments are not allowed on this type
22-
let _x: u8; //~ ERROR lifetime arguments are not allowed on this type
23-
let _x: u16; //~ ERROR lifetime arguments are not allowed on this type
24-
let _x: u32; //~ ERROR lifetime arguments are not allowed on this type
25-
let _x: u64; //~ ERROR lifetime arguments are not allowed on this type
26-
let _x: char; //~ ERROR lifetime arguments are not allowed on this type
16+
let _x: isize; //~ ERROR lifetime arguments are not allowed on builtin type
17+
let _x: i8; //~ ERROR lifetime arguments are not allowed on builtin type
18+
let _x: i16; //~ ERROR lifetime arguments are not allowed on builtin type
19+
let _x: i32; //~ ERROR lifetime arguments are not allowed on builtin type
20+
let _x: i64; //~ ERROR lifetime arguments are not allowed on builtin type
21+
let _x: usize; //~ ERROR lifetime arguments are not allowed on builtin type
22+
let _x: u8; //~ ERROR lifetime arguments are not allowed on builtin type
23+
let _x: u16; //~ ERROR lifetime arguments are not allowed on builtin type
24+
let _x: u32; //~ ERROR lifetime arguments are not allowed on builtin type
25+
let _x: u64; //~ ERROR lifetime arguments are not allowed on builtin type
26+
let _x: char; //~ ERROR lifetime arguments are not allowed on builtin type
2727

2828
}

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

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
// run-rustfix
22
fn main() {
33

4-
let _x: isize<isize>; //~ ERROR type arguments are not allowed on this type
5-
let _x: i8<isize>; //~ ERROR type arguments are not allowed on this type
6-
let _x: i16<isize>; //~ ERROR type arguments are not allowed on this type
7-
let _x: i32<isize>; //~ ERROR type arguments are not allowed on this type
8-
let _x: i64<isize>; //~ ERROR type arguments are not allowed on this type
9-
let _x: usize<isize>; //~ ERROR type arguments are not allowed on this type
10-
let _x: u8<isize>; //~ ERROR type arguments are not allowed on this type
11-
let _x: u16<isize>; //~ ERROR type arguments are not allowed on this type
12-
let _x: u32<isize>; //~ ERROR type arguments are not allowed on this type
13-
let _x: u64<isize>; //~ ERROR type arguments are not allowed on this type
14-
let _x: char<isize>; //~ ERROR type arguments are not allowed on this type
4+
let _x: isize<isize>; //~ ERROR type arguments are not allowed on builtin type
5+
let _x: i8<isize>; //~ ERROR type arguments are not allowed on builtin type
6+
let _x: i16<isize>; //~ ERROR type arguments are not allowed on builtin type
7+
let _x: i32<isize>; //~ ERROR type arguments are not allowed on builtin type
8+
let _x: i64<isize>; //~ ERROR type arguments are not allowed on builtin type
9+
let _x: usize<isize>; //~ ERROR type arguments are not allowed on builtin type
10+
let _x: u8<isize>; //~ ERROR type arguments are not allowed on builtin type
11+
let _x: u16<isize>; //~ ERROR type arguments are not allowed on builtin type
12+
let _x: u32<isize>; //~ ERROR type arguments are not allowed on builtin type
13+
let _x: u64<isize>; //~ ERROR type arguments are not allowed on builtin type
14+
let _x: char<isize>; //~ ERROR type arguments are not allowed on builtin type
1515

16-
let _x: isize<'static>; //~ ERROR lifetime arguments are not allowed on this type
17-
let _x: i8<'static>; //~ ERROR lifetime arguments are not allowed on this type
18-
let _x: i16<'static>; //~ ERROR lifetime arguments are not allowed on this type
19-
let _x: i32<'static>; //~ ERROR lifetime arguments are not allowed on this type
20-
let _x: i64<'static>; //~ ERROR lifetime arguments are not allowed on this type
21-
let _x: usize<'static>; //~ ERROR lifetime arguments are not allowed on this type
22-
let _x: u8<'static>; //~ ERROR lifetime arguments are not allowed on this type
23-
let _x: u16<'static>; //~ ERROR lifetime arguments are not allowed on this type
24-
let _x: u32<'static>; //~ ERROR lifetime arguments are not allowed on this type
25-
let _x: u64<'static>; //~ ERROR lifetime arguments are not allowed on this type
26-
let _x: char<'static>; //~ ERROR lifetime arguments are not allowed on this type
16+
let _x: isize<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
17+
let _x: i8<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
18+
let _x: i16<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
19+
let _x: i32<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
20+
let _x: i64<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
21+
let _x: usize<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
22+
let _x: u8<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
23+
let _x: u16<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
24+
let _x: u32<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
25+
let _x: u64<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
26+
let _x: char<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
2727

2828
}

0 commit comments

Comments
 (0)