Properly check the defining scope of existential types

Fixes #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.
This commit is contained in:
Aaron Hill 2019-07-28 17:57:04 -04:00
parent 023525dbda
commit 18bf9dd4b7
No known key found for this signature in database
GPG key ID: B4087E510E98B164
4 changed files with 58 additions and 9 deletions

View file

@ -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());
}

View file

@ -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