Skip to content

Commit

Permalink
Make output more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jun 2, 2022
1 parent 196a30e commit ad63f90
Show file tree
Hide file tree
Showing 28 changed files with 391 additions and 217 deletions.
47 changes: 45 additions & 2 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,46 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
extend: impl Fn(&mut DiagnosticBuilder<'tcx, ErrorGuaranteed>),
) -> bool {
let args = segments.clone().flat_map(|segment| segment.args().args);
let types_and_spans: Vec<_> = segments
.clone()
.flat_map(|segment| {
segment.res.and_then(|res| {
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(),
},
segment.ident.span,
))
}
})
})
.collect();
let this_type = match &types_and_spans[..] {
[.., _, (last, _)] => format!(
"{} and {last}",
types_and_spans[..types_and_spans.len() - 1]
.iter()
.map(|(x, _)| x.as_str())
.intersperse(&", ")
.collect::<String>()
),
[(only, _)] => only.to_string(),
[] => "this type".to_string(),
};

let (lt, ty, ct, inf) =
args.clone().fold((false, false, false, false), |(lt, ty, ct, inf), arg| match arg {
Expand Down Expand Up @@ -2143,7 +2183,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let (kind, s) = match types[..] {
[.., _, last] => (
format!(
"{} and `{last}`",
"{} and {last}",
types[..types.len() - 1]
.iter()
.map(|&x| x)
Expand All @@ -2161,9 +2201,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.tcx().sess,
span,
E0109,
"{kind} arguments are not allowed for this type",
"{kind} arguments are not allowed on {this_type}",
);
err.span_label(last_span, format!("{kind} argument{s} not allowed"));
for (_, span) in types_and_spans {
err.span_label(span, "not allowed on this");
}
extend(&mut err);
err.emit();
emitted = true;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/derives/issue-97343.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Debug;

#[derive(Debug)]
pub struct Irrelevant<Irrelevant> { //~ ERROR type arguments are not allowed for this type
pub struct Irrelevant<Irrelevant> { //~ ERROR type arguments are not allowed on type parameter
irrelevant: Irrelevant,
}

Expand Down
7 changes: 5 additions & 2 deletions src/test/ui/derives/issue-97343.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on type parameter `Irrelevant`
--> $DIR/issue-97343.rs:4:23
|
LL | #[derive(Debug)]
| ----- in this derive macro expansion
| -----
| |
| not allowed on this
| in this derive macro expansion
LL | pub struct Irrelevant<Irrelevant> {
| ^^^^^^^^^^ type argument not allowed
|
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/error-codes/E0109.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on this type
--> $DIR/E0109.rs:1:14
|
LL | type X = u32<i32>;
| ^^^ type argument not allowed
| --- ^^^ type argument not allowed
| |
| not allowed on this
|
help: primitive type `u32` doesn't have type parameters
|
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/error-codes/E0110.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0109]: lifetime arguments are not allowed for this type
error[E0109]: lifetime arguments are not allowed on this type
--> $DIR/E0110.rs:1:14
|
LL | type X = u32<'static>;
| ^^^^^^^ lifetime argument not allowed
| --- ^^^^^^^ lifetime argument not allowed
| |
| not allowed on this
|
help: primitive type `u32` doesn't have type parameters
|
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-22706.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn is_copy<T: ::std::marker<i32>::Copy>() {}
//~^ ERROR type arguments are not allowed for this type [E0109]
//~^ ERROR type arguments are not allowed on module `marker` [E0109]
fn main() {}
6 changes: 4 additions & 2 deletions src/test/ui/issues/issue-22706.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on module `marker`
--> $DIR/issue-22706.rs:1:29
|
LL | fn is_copy<T: ::std::marker<i32>::Copy>() {}
| ^^^ type argument not allowed
| ------ ^^^ type argument not allowed
| |
| not allowed on this

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-57924.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Gcm<E>(E);
impl<E> Gcm<E> {
pub fn crash(e: E) -> Self {
Self::<E>(e)
//~^ ERROR type arguments are not allowed for this type
//~^ ERROR type arguments are not allowed on self constructor
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/issues/issue-57924.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on self constructor
--> $DIR/issue-57924.rs:5:16
|
LL | Self::<E>(e)
| ^ type argument not allowed
| ---- ^ type argument not allowed
| |
| not allowed on this

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-60989.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ impl From<A> for B {
fn main() {
let c1 = ();
c1::<()>;
//~^ ERROR type arguments are not allowed for this type
//~^ ERROR type arguments are not allowed on local variable

let c1 = A {};
c1::<dyn Into<B>>;
//~^ ERROR type arguments are not allowed for this type
//~^ ERROR type arguments are not allowed on local variable
}
12 changes: 8 additions & 4 deletions src/test/ui/issues/issue-60989.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on local variable
--> $DIR/issue-60989.rs:12:10
|
LL | c1::<()>;
| ^^ type argument not allowed
| -- ^^ type argument not allowed
| |
| not allowed on this

error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on local variable
--> $DIR/issue-60989.rs:16:10
|
LL | c1::<dyn Into<B>>;
| ^^^^^^^^^^^ type argument not allowed
| -- ^^^^^^^^^^^ type argument not allowed
| |
| not allowed on this

error: aborting due to 2 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/mod-subitem-as-enum-variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ mod Mod {
fn main() {
Mod::FakeVariant::<i32>(0);
Mod::<i32>::FakeVariant(0);
//~^ ERROR type arguments are not allowed for this type [E0109]
//~^ ERROR type arguments are not allowed on module `Mod` [E0109]
}
6 changes: 4 additions & 2 deletions src/test/ui/mod-subitem-as-enum-variant.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on module `Mod`
--> $DIR/mod-subitem-as-enum-variant.rs:7:11
|
LL | Mod::<i32>::FakeVariant(0);
| ^^^ type argument not allowed
| --- ^^^ type argument not allowed
| |
| not allowed on this

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/structs/struct-path-associated-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn f<T: Tr>() {
//~^ ERROR expected struct, variant or union type, found associated type
let z = T::A::<u8> {};
//~^ ERROR expected struct, variant or union type, found associated type
//~| ERROR type arguments are not allowed for this type
//~| ERROR type arguments are not allowed on this type
match S {
T::A {} => {}
//~^ ERROR expected struct, variant or union type, found associated type
Expand All @@ -22,7 +22,7 @@ fn f<T: Tr>() {

fn g<T: Tr<A = S>>() {
let s = T::A {}; // OK
let z = T::A::<u8> {}; //~ ERROR type arguments are not allowed for this type
let z = T::A::<u8> {}; //~ ERROR type arguments are not allowed on this type
match S {
T::A {} => {} // OK
}
Expand Down
12 changes: 8 additions & 4 deletions src/test/ui/structs/struct-path-associated-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ error[E0071]: expected struct, variant or union type, found associated type
LL | let s = T::A {};
| ^^^^ not a struct

error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on this type
--> $DIR/struct-path-associated-type.rs:14:20
|
LL | let z = T::A::<u8> {};
| ^^ type argument not allowed
| - ^^ type argument not allowed
| |
| not allowed on this

error[E0071]: expected struct, variant or union type, found associated type
--> $DIR/struct-path-associated-type.rs:14:13
Expand All @@ -22,11 +24,13 @@ error[E0071]: expected struct, variant or union type, found associated type
LL | T::A {} => {}
| ^^^^ not a struct

error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on this type
--> $DIR/struct-path-associated-type.rs:25:20
|
LL | let z = T::A::<u8> {};
| ^^ type argument not allowed
| - ^^ type argument not allowed
| |
| not allowed on this

error[E0223]: ambiguous associated type
--> $DIR/struct-path-associated-type.rs:32:13
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/structs/struct-path-self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ trait Tr {
//~^ ERROR expected struct, variant or union type, found type parameter
let z = Self::<u8> {};
//~^ ERROR expected struct, variant or union type, found type parameter
//~| ERROR type arguments are not allowed for this type
//~| ERROR type arguments are not allowed on self type
match s {
Self { .. } => {}
//~^ ERROR expected struct, variant or union type, found type parameter
Expand All @@ -17,7 +17,7 @@ trait Tr {
impl Tr for S {
fn f() {
let s = Self {}; // OK
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed for this type
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed on self type
match s {
Self { .. } => {} // OK
}
Expand All @@ -27,7 +27,7 @@ impl Tr for S {
impl S {
fn g() {
let s = Self {}; // OK
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed for this type
let z = Self::<u8> {}; //~ ERROR type arguments are not allowed on self type
match s {
Self { .. } => {} // OK
}
Expand Down
18 changes: 12 additions & 6 deletions src/test/ui/structs/struct-path-self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ error[E0071]: expected struct, variant or union type, found type parameter `Self
LL | let s = Self {};
| ^^^^ not a struct

error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on self type
--> $DIR/struct-path-self.rs:7:24
|
LL | let z = Self::<u8> {};
| ^^ type argument not allowed
| ---- ^^ type argument not allowed
| |
| not allowed on this
|
help: the `Self` type doesn't accept type parameters
|
Expand All @@ -28,11 +30,13 @@ error[E0071]: expected struct, variant or union type, found type parameter `Self
LL | Self { .. } => {}
| ^^^^ not a struct

error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on self type
--> $DIR/struct-path-self.rs:20:24
|
LL | let z = Self::<u8> {};
| ^^ type argument not allowed
| ---- ^^ type argument not allowed
| |
| not allowed on this
|
note: `Self` is of type `S`
--> $DIR/struct-path-self.rs:1:8
Expand All @@ -48,11 +52,13 @@ LL - let z = Self::<u8> {};
LL + let z = Self {};
|

error[E0109]: type arguments are not allowed for this type
error[E0109]: type arguments are not allowed on self type
--> $DIR/struct-path-self.rs:30:24
|
LL | let z = Self::<u8> {};
| ^^ type argument not allowed
| ---- ^^ type argument not allowed
| |
| not allowed on this
|
note: `Self` is of type `S`
--> $DIR/struct-path-self.rs:1:8
Expand Down
Loading

0 comments on commit ad63f90

Please sign in to comment.