-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #132214 - fmease:mv-impl-trait-val-paths, r=compiler-…
…errors Cleanup: Move an impl-Trait check from AST validation to AST lowering Namely the one that rejects `impl Trait` in qself types and non-final path segments. There's no good reason to perform this during AST validation. We have better infrastructure in place in the AST lowerer (`ImplTraitContext`). This shaves off a lot of code. We now lower `impl Trait` in bad positions to `{type error}` which allows us to remove a special case from HIR ty lowering. Coincidentally fixes #126725. Well, it only *masks* it by passing `{type error}` to HIR analysis instead of a "bad" opaque. I was able to find a new reproducer for it. See the issue.
- Loading branch information
Showing
13 changed files
with
78 additions
and
153 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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,35 @@ | ||
error[E0667]: `impl Trait` is not allowed in path parameters | ||
error[E0562]: `impl Trait` is not allowed in paths | ||
--> $DIR/impl_trait_projections.rs:12:51 | ||
| | ||
LL | fn projection_is_disallowed(x: impl Iterator) -> <impl Iterator>::Item { | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: `impl Trait` is only allowed in arguments and return types of functions and methods | ||
|
||
error[E0667]: `impl Trait` is not allowed in path parameters | ||
--> $DIR/impl_trait_projections.rs:19:9 | ||
error[E0562]: `impl Trait` is not allowed in paths | ||
--> $DIR/impl_trait_projections.rs:18:9 | ||
| | ||
LL | -> <impl Iterator as Iterator>::Item | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: `impl Trait` is only allowed in arguments and return types of functions and methods | ||
|
||
error[E0667]: `impl Trait` is not allowed in path parameters | ||
--> $DIR/impl_trait_projections.rs:26:27 | ||
error[E0562]: `impl Trait` is not allowed in paths | ||
--> $DIR/impl_trait_projections.rs:25:27 | ||
| | ||
LL | -> <::std::ops::Range<impl Debug> as Iterator>::Item | ||
| ^^^^^^^^^^ | ||
| | ||
= note: `impl Trait` is only allowed in arguments and return types of functions and methods | ||
|
||
error[E0667]: `impl Trait` is not allowed in path parameters | ||
--> $DIR/impl_trait_projections.rs:35:29 | ||
error[E0562]: `impl Trait` is not allowed in paths | ||
--> $DIR/impl_trait_projections.rs:32:29 | ||
| | ||
LL | -> <dyn Iterator<Item = impl Debug> as Iterator>::Item | ||
| ^^^^^^^^^^ | ||
|
||
error[E0667]: `impl Trait` is not allowed in path parameters | ||
--> $DIR/impl_trait_projections.rs:12:51 | ||
| | ||
LL | fn projection_is_disallowed(x: impl Iterator) -> <impl Iterator>::Item { | ||
| ^^^^^^^^^^^^^ | ||
|
||
error[E0277]: the trait bound `impl Debug: Step` is not satisfied | ||
--> $DIR/impl_trait_projections.rs:26:8 | ||
| | ||
LL | -> <::std::ops::Range<impl Debug> as Iterator>::Item | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Step` is not implemented for `impl Debug`, which is required by `std::ops::Range<impl Debug>: Iterator` | ||
| | ||
= help: the following other types implement trait `Step`: | ||
Char | ||
Ipv4Addr | ||
Ipv6Addr | ||
char | ||
i128 | ||
i16 | ||
i32 | ||
i64 | ||
and 8 others | ||
= note: required for `std::ops::Range<impl Debug>` to implement `Iterator` | ||
|
||
error[E0277]: the trait bound `impl Debug: Step` is not satisfied | ||
--> $DIR/impl_trait_projections.rs:29:1 | ||
| | ||
LL | / { | ||
LL | | | ||
LL | | (1i32..100).next().unwrap() | ||
LL | | } | ||
| |_^ the trait `Step` is not implemented for `impl Debug`, which is required by `std::ops::Range<impl Debug>: Iterator` | ||
| | ||
= help: the following other types implement trait `Step`: | ||
Char | ||
Ipv4Addr | ||
Ipv6Addr | ||
char | ||
i128 | ||
i16 | ||
i32 | ||
i64 | ||
and 8 others | ||
= note: required for `std::ops::Range<impl Debug>` to implement `Iterator` | ||
= note: `impl Trait` is only allowed in arguments and return types of functions and methods | ||
|
||
error: aborting due to 7 previous errors | ||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0277, E0667. | ||
For more information about an error, try `rustc --explain E0277`. | ||
For more information about this error, try `rustc --explain E0562`. |
22 changes: 22 additions & 0 deletions
22
tests/ui/impl-trait/in-trait/bad-projection-from-opaque.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,22 @@ | ||
// issue: rust-lang/rust#126725 | ||
|
||
trait Foo { | ||
fn foo<'a>() -> <&'a impl Sized as Bar>::Output; | ||
//~^ ERROR `impl Trait` is not allowed in paths | ||
} | ||
|
||
trait Bar { | ||
type Output; | ||
} | ||
|
||
impl<'a> Bar for &'a () { | ||
type Output = &'a i32; | ||
} | ||
|
||
impl Foo for () { | ||
fn foo<'a>() -> <&'a Self as Bar>::Output { | ||
&0 | ||
} | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
tests/ui/impl-trait/in-trait/bad-projection-from-opaque.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,11 @@ | ||
error[E0562]: `impl Trait` is not allowed in paths | ||
--> $DIR/bad-projection-from-opaque.rs:4:26 | ||
| | ||
LL | fn foo<'a>() -> <&'a impl Sized as Bar>::Output; | ||
| ^^^^^^^^^^ | ||
| | ||
= note: `impl Trait` is only allowed in arguments and return types of functions and methods | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0562`. |
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
6 changes: 4 additions & 2 deletions
6
tests/ui/impl-trait/issues/issue-57979-impl-trait-in-path.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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
error[E0667]: `impl Trait` is not allowed in path parameters | ||
error[E0562]: `impl Trait` is not allowed in paths | ||
--> $DIR/issue-57979-impl-trait-in-path.rs:8:48 | ||
| | ||
LL | pub fn demo(_: impl Quux<(), Assoc=<() as Quux<impl Bar>>::Assoc>) { } | ||
| ^^^^^^^^ | ||
| | ||
= note: `impl Trait` is only allowed in arguments and return types of functions and methods | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0667`. | ||
For more information about this error, try `rustc --explain E0562`. |