forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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 rust-lang#63093 - Aaron1011:fix/existential-closure, …
…r=cramertj 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
61 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
12 changes: 12 additions & 0 deletions
12
src/test/ui/existential-type/issue-52843-closure-constrain.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,12 @@ | ||
// Checks to ensure that we properly detect when a closure constrains an existential type | ||
#![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()); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/ui/existential-type/issue-52843-closure-constrain.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,20 @@ | ||
error: concrete type differs from previous defining existential type use | ||
--> $DIR/issue-52843-closure-constrain.rs:8:5 | ||
| | ||
LL | fn _unused() -> Existential { String::new() } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, got `std::string::String` | ||
| | ||
note: previous use here | ||
--> $DIR/issue-52843-closure-constrain.rs:6: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 | ||
|