forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't ICE on errors in function returning impl trait
Instead, report the error. This emits the errors on-demand, without special-casing `impl Trait`, so it should catch all ICEs of this kind, including ones that haven't been found yet. Since the error is emitted during type-checking there is less info about the error; see comments in the code for details. - Add test case for -> impl Trait - Add test for impl trait with alias - Move EmitIgnoredResolutionErrors to rustdoc This makes `fn typeck_item_bodies` public, which is not desired behavior. That change should be removed once rust-lang#74070 is merged. - Don't visit nested closures twice
- Loading branch information
Showing
7 changed files
with
162 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// edition:2018 | ||
#![feature(type_alias_impl_trait)] | ||
|
||
pub trait ValidTrait {} | ||
type ImplTrait = impl ValidTrait; | ||
|
||
/// This returns impl trait | ||
pub fn g() -> impl ValidTrait { | ||
error::_in::impl_trait() | ||
//~^ ERROR failed to resolve | ||
} | ||
|
||
/// This returns impl trait, but using a type alias | ||
pub fn h() -> ImplTrait { | ||
error::_in::impl_trait::alias(); | ||
//~^ ERROR failed to resolve | ||
(|| error::_in::impl_trait::alias::nested::closure())() | ||
//~^ ERROR failed to resolve | ||
} | ||
|
||
/// This used to work with ResolveBodyWithLoop. | ||
/// However now that we ignore type checking instead of modifying the function body, | ||
/// the return type is seen as `impl Future<Output = u32>`, not a `u32`. | ||
/// So it no longer allows errors in the function body. | ||
pub async fn a() -> u32 { | ||
error::_in::async_fn() | ||
//~^ ERROR failed to resolve | ||
} |
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,39 @@ | ||
error[E0433]: failed to resolve: could not resolve path `error::_in::impl_trait` | ||
--> $DIR/error-in-impl-trait.rs:9:5 | ||
| | ||
LL | error::_in::impl_trait() | ||
| ^^^^^^^^^^^^^^^^^^^^^^ could not resolve path `error::_in::impl_trait` | ||
| | ||
= note: this error was originally ignored because you are running `rustdoc` | ||
= note: try running again with `rustc` and you may get a more detailed error | ||
|
||
error[E0433]: failed to resolve: could not resolve path `error::_in::impl_trait::alias` | ||
--> $DIR/error-in-impl-trait.rs:15:5 | ||
| | ||
LL | error::_in::impl_trait::alias(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not resolve path `error::_in::impl_trait::alias` | ||
| | ||
= note: this error was originally ignored because you are running `rustdoc` | ||
= note: try running again with `rustc` and you may get a more detailed error | ||
|
||
error[E0433]: failed to resolve: could not resolve path `error::_in::impl_trait::alias::nested::closure` | ||
--> $DIR/error-in-impl-trait.rs:17:9 | ||
| | ||
LL | (|| error::_in::impl_trait::alias::nested::closure())() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not resolve path `error::_in::impl_trait::alias::nested::closure` | ||
| | ||
= note: this error was originally ignored because you are running `rustdoc` | ||
= note: try running again with `rustc` and you may get a more detailed error | ||
|
||
error[E0433]: failed to resolve: could not resolve path `error::_in::async_fn` | ||
--> $DIR/error-in-impl-trait.rs:26:5 | ||
| | ||
LL | error::_in::async_fn() | ||
| ^^^^^^^^^^^^^^^^^^^^ could not resolve path `error::_in::async_fn` | ||
| | ||
= note: this error was originally ignored because you are running `rustdoc` | ||
= note: try running again with `rustc` and you may get a more detailed error | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0433`. |
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,14 @@ | ||
#![feature(type_alias_impl_trait)] | ||
|
||
trait MyTrait {} | ||
impl MyTrait for i32 {} | ||
|
||
// @has impl_trait_alias/type.Foo.html 'Foo' | ||
/// debug type | ||
pub type Foo = impl MyTrait; | ||
|
||
// @has impl_trait_alias/fn.foo.html 'foo' | ||
/// debug function | ||
pub fn foo() -> Foo { | ||
1 | ||
} |