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:
parent
023525dbda
commit
18bf9dd4b7
4 changed files with 58 additions and 9 deletions
11
src/test/ui/existential-type/issue-52843.rs
Normal file
11
src/test/ui/existential-type/issue-52843.rs
Normal 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());
|
||||
}
|
||||
20
src/test/ui/existential-type/issue-52843.stderr
Normal file
20
src/test/ui/existential-type/issue-52843.stderr
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue