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.
Properly check the defining scope of existential types
Fixes rust-lang#52632 Existential types (soon to be 'impl trait' aliases) can either be delcared at a top-level crate/module scope, or within another item such as an fn. Previously, we were handling the second case incorrectly when recursively searching for defining usages - we would check children of the item, but not the item itself. This lead to us missing closures that consituted a defining use of the existential type, as their opaque type instantiations are stored in the TypeckTables of their parent function. This commit ensures that we explicitly visit the defining item itself, not just its children.
- Loading branch information
Showing
4 changed files
with
58 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![feature(existential_type)] | ||
|
||
use std::fmt::Debug; | ||
|
||
fn main() { | ||
existential type Existential: Debug; | ||
fn _unused() -> Existential { String::new() } | ||
//~^ ERROR: concrete type differs from previous defining existential type use | ||
let null = || -> Existential { 0 }; | ||
println!("{:?}", null()); | ||
} |
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,20 @@ | ||
error: concrete type differs from previous defining existential type use | ||
--> $DIR/issue-52843.rs:7:5 | ||
| | ||
LL | fn _unused() -> Existential { String::new() } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, got `std::string::String` | ||
| | ||
note: previous use here | ||
--> $DIR/issue-52843.rs:5:1 | ||
| | ||
LL | / fn main() { | ||
LL | | existential type Existential: Debug; | ||
LL | | fn _unused() -> Existential { String::new() } | ||
LL | | | ||
LL | | let null = || -> Existential { 0 }; | ||
LL | | println!("{:?}", null()); | ||
LL | | } | ||
| |_^ | ||
|
||
error: aborting due to previous error | ||
|