Auto merge of #59058 - petrochenkov:assocrecov3, r=estebank

syntax: Better recovery for `$ty::AssocItem` and `ty!()::AssocItem`

This PR improves on https://github.com/rust-lang/rust/pull/46788 covering a few missing cases.

Fixes https://github.com/rust-lang/rust/issues/52307
Fixes https://github.com/rust-lang/rust/issues/53776
r? @estebank
This commit is contained in:
bors 2019-03-23 05:51:16 +00:00
commit d51a437e28
7 changed files with 217 additions and 92 deletions

View file

@ -18,3 +18,19 @@ fn main() {
10 + (u8)::clone(&0);
//~^ ERROR missing angle brackets in associated item path
}
macro_rules! expr {
($ty: ty) => ($ty::clone(&0))
//~^ ERROR missing angle brackets in associated item path
}
macro_rules! ty {
() => (u8)
}
fn check_macros() {
expr!(u8);
let _ = ty!()::clone(&0);
//~^ ERROR missing angle brackets in associated item path
ty!()::clone(&0);
//~^ ERROR missing angle brackets in associated item path
}

View file

@ -34,5 +34,26 @@ error: missing angle brackets in associated item path
LL | 10 + (u8)::clone(&0);
| ^^^^^^^^^^^ help: try: `<(u8)>::clone`
error: aborting due to 6 previous errors
error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:32:13
|
LL | let _ = ty!()::clone(&0);
| ^^^^^^^^^^^^ help: try: `<ty!()>::clone`
error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:34:5
|
LL | ty!()::clone(&0);
| ^^^^^^^^^^^^ help: try: `<ty!()>::clone`
error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:23:19
|
LL | ($ty: ty) => ($ty::clone(&0))
| ^^^^^^^^^^ help: try: `<$ty>::clone`
...
LL | expr!(u8);
| ---------- in this macro invocation
error: aborting due to 9 previous errors

View file

@ -16,3 +16,21 @@ fn main() {
//~| ERROR no associated item named `AssocItem` found for type `(u8,)` in the current scope
}
}
macro_rules! pat {
($ty: ty) => ($ty::AssocItem)
//~^ ERROR missing angle brackets in associated item path
//~| ERROR no associated item named `AssocItem` found for type `u8` in the current scope
}
macro_rules! ty {
() => (u8)
}
fn check_macros() {
match 0u8 {
pat!(u8) => {}
ty!()::AssocItem => {}
//~^ ERROR missing angle brackets in associated item path
//~| ERROR no associated item named `AssocItem` found for type `u8` in the current scope
}
}

View file

@ -22,6 +22,21 @@ error: missing angle brackets in associated item path
LL | &(u8,)::AssocItem => {}
| ^^^^^^^^^^^^^^^^ help: try: `<(u8,)>::AssocItem`
error: missing angle brackets in associated item path
--> $DIR/bad-assoc-pat.rs:32:9
|
LL | ty!()::AssocItem => {}
| ^^^^^^^^^^^^^^^^ help: try: `<ty!()>::AssocItem`
error: missing angle brackets in associated item path
--> $DIR/bad-assoc-pat.rs:21:19
|
LL | ($ty: ty) => ($ty::AssocItem)
| ^^^^^^^^^^^^^^ help: try: `<$ty>::AssocItem`
...
LL | pat!(u8) => {}
| -------- in this macro invocation
error[E0599]: no associated item named `AssocItem` found for type `[u8]` in the current scope
--> $DIR/bad-assoc-pat.rs:3:15
|
@ -54,6 +69,25 @@ LL | &(u8,)::AssocItem => {}
| |
| associated item not found in `(u8,)`
error: aborting due to 8 previous errors
error[E0599]: no associated item named `AssocItem` found for type `u8` in the current scope
--> $DIR/bad-assoc-pat.rs:21:24
|
LL | ($ty: ty) => ($ty::AssocItem)
| -----^^^^^^^^^
| |
| associated item not found in `u8`
...
LL | pat!(u8) => {}
| -------- in this macro invocation
error[E0599]: no associated item named `AssocItem` found for type `u8` in the current scope
--> $DIR/bad-assoc-pat.rs:32:16
|
LL | ty!()::AssocItem => {}
| -------^^^^^^^^^
| |
| associated item not found in `u8`
error: aborting due to 12 previous errors
For more information about this error, try `rustc --explain E0599`.

View file

@ -33,4 +33,16 @@ type G = 'static + (Send)::AssocTy;
type H = Fn(u8) -> (u8)::Output;
//~^ ERROR ambiguous associated type
macro_rules! ty {
($ty: ty) => ($ty::AssocTy);
//~^ ERROR missing angle brackets in associated item path
//~| ERROR ambiguous associated type
() => (u8);
}
type J = ty!(u8);
type I = ty!()::AssocTy;
//~^ ERROR missing angle brackets in associated item path
//~| ERROR ambiguous associated type
fn main() {}

View file

@ -38,7 +38,22 @@ error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:27:10
|
LL | type G = 'static + (Send)::AssocTy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `<'static + Send>::AssocTy`
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `<'static + (Send)>::AssocTy`
error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:44:10
|
LL | type I = ty!()::AssocTy;
| ^^^^^^^^^^^^^^ help: try: `<ty!()>::AssocTy`
error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:37:19
|
LL | ($ty: ty) => ($ty::AssocTy);
| ^^^^^^^^^^^^ help: try: `<$ty>::AssocTy`
...
LL | type J = ty!(u8);
| ------- in this macro invocation
error[E0223]: ambiguous associated type
--> $DIR/bad-assoc-ty.rs:1:10
@ -88,7 +103,22 @@ error[E0223]: ambiguous associated type
LL | type H = Fn(u8) -> (u8)::Output;
| ^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<(dyn std::ops::Fn(u8) -> u8 + 'static) as Trait>::Output`
error: aborting due to 15 previous errors
error[E0223]: ambiguous associated type
--> $DIR/bad-assoc-ty.rs:37:19
|
LL | ($ty: ty) => ($ty::AssocTy);
| ^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`
...
LL | type J = ty!(u8);
| ------- in this macro invocation
error[E0223]: ambiguous associated type
--> $DIR/bad-assoc-ty.rs:44:10
|
LL | type I = ty!()::AssocTy;
| ^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`
error: aborting due to 19 previous errors
Some errors occurred: E0121, E0223.
For more information about an error, try `rustc --explain E0121`.