Skip to content

MIR typeck needed more normalize #65099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
};

let place_ty = place.ty(body, tcx).ty;
let place_ty = self.normalize(place_ty, location);
let rv_ty = rv.ty(body, tcx);
let rv_ty = self.normalize(rv_ty, location);
if let Err(terr) =
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
{
Expand Down Expand Up @@ -1654,6 +1656,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
match *destination {
Some((ref dest, _target_block)) => {
let dest_ty = dest.ty(body, tcx).ty;
let dest_ty = self.normalize(dest_ty, term_location);
let category = match *dest {
Place {
base: PlaceBase::Local(RETURN_PLACE),
Expand Down
34 changes: 34 additions & 0 deletions src/test/ui/nll/issue-63154-normalize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Regression test for rust-lang/rust#63154
//
// Before, we would ICE after failing to normalize the destination type
// when checking call destinations and also when checking MIR
// assignment statements.

// check-pass

trait HasAssocType {
type Inner;
}

impl HasAssocType for () {
type Inner = ();
}

trait Tr<I, T>: Fn(I) -> Option<T> {}
impl<I, T, Q: Fn(I) -> Option<T>> Tr<I, T> for Q {}

fn f<T: HasAssocType>() -> impl Tr<T, T::Inner> {
|_| None
}

fn g<T, Y>(f: impl Tr<T, Y>) -> impl Tr<T, Y> {
f
}

fn h() {
g(f())(());
}

fn main() {
h();
}