Skip to content

Commit

Permalink
Rollup merge of rust-lang#98269 - compiler-errors:provide-more-segmen…
Browse files Browse the repository at this point in the history
…t-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.
  • Loading branch information
compiler-errors authored Jun 23, 2022
2 parents d9d9899 + f924e74 commit e71ac92
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 115 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@ impl<'a> Resolver<'a> {
return PathResult::NonModule(PartialRes::new(Res::Err));
} else if opt_ns.is_some() && (is_last || maybe_assoc) {
self.lint_if_path_starts_with_module(finalize, path, second_binding);
record_segment_res(self, res);
return PathResult::NonModule(PartialRes::with_unresolved_segments(
res,
path.len() - i - 1,
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0109.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0109]: type arguments are not allowed on this type
error[E0109]: type arguments are not allowed on builtin type `u32`
--> $DIR/E0109.rs:1:14
|
LL | type X = u32<i32>;
| --- ^^^ type argument not allowed
| |
| not allowed on this type
| not allowed on builtin type `u32`
|
help: primitive type `u32` doesn't have generic parameters
|
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0110.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0109]: lifetime arguments are not allowed on this type
error[E0109]: lifetime arguments are not allowed on builtin type `u32`
--> $DIR/E0110.rs:1:14
|
LL | type X = u32<'static>;
| --- ^^^^^^^ lifetime argument not allowed
| |
| not allowed on this type
| not allowed on builtin type `u32`
|
help: primitive type `u32` doesn't have generic parameters
|
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/inference/cannot-infer-closure-circular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ fn main() {
// error handles this gracefully, and in particular doesn't generate an extra
// note about the `?` operator in the closure body, which isn't relevant to
// the inference.
let x = |r| {
let x = |r| { //~ ERROR type annotations needed for `Result<(), E>`
let v = r?;
Ok(v)
};

let _ = x(x(Ok(()))); //~ ERROR type annotations needed for `Result<(), E>`
let _ = x(x(Ok(())));
}
12 changes: 6 additions & 6 deletions src/test/ui/inference/cannot-infer-closure-circular.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0282]: type annotations needed for `Result<(), E>`
--> $DIR/cannot-infer-closure-circular.rs:12:9
--> $DIR/cannot-infer-closure-circular.rs:7:14
|
LL | let _ = x(x(Ok(())));
| ^
LL | let x = |r| {
| ^
|
help: consider giving this pattern a type, where the type for type parameter `E` is specified
help: consider giving this closure parameter an explicit type, where the type for type parameter `E` is specified
|
LL | let _: Result<(), E> = x(x(Ok(())));
| +++++++++++++++
LL | let x = |r: Result<(), E>| {
| +++++++++++++++

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() {
// Tuple struct variant

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

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

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

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

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

Alias::UVariant::<()>;
//~^ ERROR type arguments are not allowed on this type [E0109]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ LL | Self::<()>::UVariant::<()>;
| |
| not allowed on this type

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

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

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

Expand Down Expand Up @@ -438,13 +438,13 @@ LL - AliasFixed::<()>::SVariant::<()> { v: () };
LL + AliasFixed::<()>::SVariant { v: () };
|

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

error[E0109]: type arguments are not allowed on this type
--> $DIR/enum-variant-generic-args.rs:93:23
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/type/issue-91268.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// error-pattern: this file contains an unclosed delimiter
// error-pattern: cannot find type `ţ` in this scope
// error-pattern: parenthesized type parameters may only be used with a `Fn` trait
// error-pattern: type arguments are not allowed on this type
// error-pattern: type arguments are not allowed on builtin type `u8`
// error-pattern: mismatched types
// ignore-tidy-trailing-newlines
// `ţ` must be the last character in this file, it cannot be followed by a newline
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/type/issue-91268.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ help: use angle brackets instead
LL | 0: u8<ţ>
| ~ +

error[E0109]: type arguments are not allowed on this type
error[E0109]: type arguments are not allowed on builtin type `u8`
--> $DIR/issue-91268.rs:9:11
|
LL | 0: u8(ţ
| -- ^ type argument not allowed
| |
| not allowed on this type
| not allowed on builtin type `u8`
|
help: primitive type `u8` doesn't have generic parameters
|
Expand Down
44 changes: 22 additions & 22 deletions src/test/ui/typeck/prim-with-args.fixed
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
// run-rustfix
fn main() {

let _x: isize; //~ ERROR type arguments are not allowed on this type
let _x: i8; //~ ERROR type arguments are not allowed on this type
let _x: i16; //~ ERROR type arguments are not allowed on this type
let _x: i32; //~ ERROR type arguments are not allowed on this type
let _x: i64; //~ ERROR type arguments are not allowed on this type
let _x: usize; //~ ERROR type arguments are not allowed on this type
let _x: u8; //~ ERROR type arguments are not allowed on this type
let _x: u16; //~ ERROR type arguments are not allowed on this type
let _x: u32; //~ ERROR type arguments are not allowed on this type
let _x: u64; //~ ERROR type arguments are not allowed on this type
let _x: char; //~ ERROR type arguments are not allowed on this type
let _x: isize; //~ ERROR type arguments are not allowed on builtin type
let _x: i8; //~ ERROR type arguments are not allowed on builtin type
let _x: i16; //~ ERROR type arguments are not allowed on builtin type
let _x: i32; //~ ERROR type arguments are not allowed on builtin type
let _x: i64; //~ ERROR type arguments are not allowed on builtin type
let _x: usize; //~ ERROR type arguments are not allowed on builtin type
let _x: u8; //~ ERROR type arguments are not allowed on builtin type
let _x: u16; //~ ERROR type arguments are not allowed on builtin type
let _x: u32; //~ ERROR type arguments are not allowed on builtin type
let _x: u64; //~ ERROR type arguments are not allowed on builtin type
let _x: char; //~ ERROR type arguments are not allowed on builtin type

let _x: isize; //~ ERROR lifetime arguments are not allowed on this type
let _x: i8; //~ ERROR lifetime arguments are not allowed on this type
let _x: i16; //~ ERROR lifetime arguments are not allowed on this type
let _x: i32; //~ ERROR lifetime arguments are not allowed on this type
let _x: i64; //~ ERROR lifetime arguments are not allowed on this type
let _x: usize; //~ ERROR lifetime arguments are not allowed on this type
let _x: u8; //~ ERROR lifetime arguments are not allowed on this type
let _x: u16; //~ ERROR lifetime arguments are not allowed on this type
let _x: u32; //~ ERROR lifetime arguments are not allowed on this type
let _x: u64; //~ ERROR lifetime arguments are not allowed on this type
let _x: char; //~ ERROR lifetime arguments are not allowed on this type
let _x: isize; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: i8; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: i16; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: i32; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: i64; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: usize; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: u8; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: u16; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: u32; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: u64; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: char; //~ ERROR lifetime arguments are not allowed on builtin type

}
44 changes: 22 additions & 22 deletions src/test/ui/typeck/prim-with-args.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
// run-rustfix
fn main() {

let _x: isize<isize>; //~ ERROR type arguments are not allowed on this type
let _x: i8<isize>; //~ ERROR type arguments are not allowed on this type
let _x: i16<isize>; //~ ERROR type arguments are not allowed on this type
let _x: i32<isize>; //~ ERROR type arguments are not allowed on this type
let _x: i64<isize>; //~ ERROR type arguments are not allowed on this type
let _x: usize<isize>; //~ ERROR type arguments are not allowed on this type
let _x: u8<isize>; //~ ERROR type arguments are not allowed on this type
let _x: u16<isize>; //~ ERROR type arguments are not allowed on this type
let _x: u32<isize>; //~ ERROR type arguments are not allowed on this type
let _x: u64<isize>; //~ ERROR type arguments are not allowed on this type
let _x: char<isize>; //~ ERROR type arguments are not allowed on this type
let _x: isize<isize>; //~ ERROR type arguments are not allowed on builtin type
let _x: i8<isize>; //~ ERROR type arguments are not allowed on builtin type
let _x: i16<isize>; //~ ERROR type arguments are not allowed on builtin type
let _x: i32<isize>; //~ ERROR type arguments are not allowed on builtin type
let _x: i64<isize>; //~ ERROR type arguments are not allowed on builtin type
let _x: usize<isize>; //~ ERROR type arguments are not allowed on builtin type
let _x: u8<isize>; //~ ERROR type arguments are not allowed on builtin type
let _x: u16<isize>; //~ ERROR type arguments are not allowed on builtin type
let _x: u32<isize>; //~ ERROR type arguments are not allowed on builtin type
let _x: u64<isize>; //~ ERROR type arguments are not allowed on builtin type
let _x: char<isize>; //~ ERROR type arguments are not allowed on builtin type

let _x: isize<'static>; //~ ERROR lifetime arguments are not allowed on this type
let _x: i8<'static>; //~ ERROR lifetime arguments are not allowed on this type
let _x: i16<'static>; //~ ERROR lifetime arguments are not allowed on this type
let _x: i32<'static>; //~ ERROR lifetime arguments are not allowed on this type
let _x: i64<'static>; //~ ERROR lifetime arguments are not allowed on this type
let _x: usize<'static>; //~ ERROR lifetime arguments are not allowed on this type
let _x: u8<'static>; //~ ERROR lifetime arguments are not allowed on this type
let _x: u16<'static>; //~ ERROR lifetime arguments are not allowed on this type
let _x: u32<'static>; //~ ERROR lifetime arguments are not allowed on this type
let _x: u64<'static>; //~ ERROR lifetime arguments are not allowed on this type
let _x: char<'static>; //~ ERROR lifetime arguments are not allowed on this type
let _x: isize<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: i8<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: i16<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: i32<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: i64<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: usize<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: u8<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: u16<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: u32<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: u64<'static>; //~ ERROR lifetime arguments are not allowed on builtin type
let _x: char<'static>; //~ ERROR lifetime arguments are not allowed on builtin type

}
Loading

0 comments on commit e71ac92

Please sign in to comment.