-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #58608 - pnkfelix:warning-period-for-detecting-nested-i…
…mpl-trait, r=zoxc Warning period for detecting nested impl trait Here is some proposed code for making a warning period for the new checking of nested impl trait. It undoes some of the corrective effects of PR #57730, by using boolean flags to track parts of the analysis that were previously skipped prior to PRs #57730 and #57981 landing. Cc #57979
- Loading branch information
Showing
11 changed files
with
345 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/ui/impl-trait/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// rust-lang/rust#57979 : the initial support for `impl Trait` didn't | ||
// properly check syntax hidden behind an associated type projection, | ||
// but it did catch *some cases*. This is checking that we continue to | ||
// properly emit errors for those, even with the new | ||
// future-incompatibility warnings. | ||
// | ||
// issue-57979-nested-impl-trait-in-assoc-proj.rs shows the main case | ||
// that we were previously failing to catch. | ||
|
||
struct Deeper<T>(T); | ||
|
||
mod allowed { | ||
#![allow(nested_impl_trait)] | ||
|
||
pub trait Foo<T> { } | ||
pub trait Bar { } | ||
pub trait Quux { type Assoc; } | ||
pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { } | ||
//~^ ERROR nested `impl Trait` is not allowed | ||
} | ||
|
||
mod warned { | ||
#![warn(nested_impl_trait)] | ||
|
||
pub trait Foo<T> { } | ||
pub trait Bar { } | ||
pub trait Quux { type Assoc; } | ||
pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { } | ||
//~^ ERROR nested `impl Trait` is not allowed | ||
} | ||
|
||
mod denied { | ||
#![deny(nested_impl_trait)] | ||
|
||
pub trait Foo<T> { } | ||
pub trait Bar { } | ||
pub trait Quux { type Assoc; } | ||
pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { } | ||
//~^ ERROR nested `impl Trait` is not allowed | ||
} | ||
|
||
fn main() { } |
30 changes: 30 additions & 0 deletions
30
src/test/ui/impl-trait/issue-57979-deeply-nested-impl-trait-in-assoc-proj.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
error[E0666]: nested `impl Trait` is not allowed | ||
--> $DIR/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs:18:59 | ||
| | ||
LL | pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { } | ||
| ---------^^^^^^^^- | ||
| | | | ||
| | nested `impl Trait` here | ||
| outer `impl Trait` | ||
|
||
error[E0666]: nested `impl Trait` is not allowed | ||
--> $DIR/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs:28:59 | ||
| | ||
LL | pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { } | ||
| ---------^^^^^^^^- | ||
| | | | ||
| | nested `impl Trait` here | ||
| outer `impl Trait` | ||
|
||
error[E0666]: nested `impl Trait` is not allowed | ||
--> $DIR/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs:38:59 | ||
| | ||
LL | pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { } | ||
| ---------^^^^^^^^- | ||
| | | | ||
| | nested `impl Trait` here | ||
| outer `impl Trait` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0666`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// rust-lang/rust#57979 : the initial support for `impl Trait` didn't | ||
// properly check syntax hidden behind an associated type projection. | ||
// Here we test behavior of occurrences of `impl Trait` within a path | ||
// component in that context. | ||
|
||
mod allowed { | ||
#![allow(nested_impl_trait)] | ||
|
||
pub trait Bar { } | ||
pub trait Quux<T> { type Assoc; } | ||
pub fn demo(_: impl Quux<(), Assoc=<() as Quux<impl Bar>>::Assoc>) { } | ||
impl<T> Quux<T> for () { type Assoc = u32; } | ||
} | ||
|
||
mod warned { | ||
#![warn(nested_impl_trait)] | ||
|
||
pub trait Bar { } | ||
pub trait Quux<T> { type Assoc; } | ||
pub fn demo(_: impl Quux<(), Assoc=<() as Quux<impl Bar>>::Assoc>) { } | ||
//~^ WARN `impl Trait` is not allowed in path parameters | ||
//~| WARN will become a hard error in a future release! | ||
impl<T> Quux<T> for () { type Assoc = u32; } | ||
} | ||
|
||
mod denied { | ||
#![deny(nested_impl_trait)] | ||
|
||
pub trait Bar { } | ||
pub trait Quux<T> { type Assoc; } | ||
pub fn demo(_: impl Quux<(), Assoc=<() as Quux<impl Bar>>::Assoc>) { } | ||
//~^ ERROR `impl Trait` is not allowed in path parameters | ||
//~| WARN will become a hard error in a future release! | ||
impl<T> Quux<T> for () { type Assoc = u32; } | ||
} | ||
|
||
fn main() { } |
Oops, something went wrong.