Skip to content
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

Normalize closure signature after construction #101708

Merged
merged 1 commit into from
Sep 23, 2022
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 compiler/rustc_typeck/src/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
),
bound_vars,
);
// Astconv can't normalize inputs or outputs with escaping bound vars,
// so normalize them here, after we've wrapped them in a binder.
let result = self.normalize_associated_types_in(self.tcx.hir().span(hir_id), result);

let c_result = self.inh.infcx.canonicalize_response(result);
self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result);
Expand Down
36 changes: 36 additions & 0 deletions src/test/ui/closures/issue-101696.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// check-pass

use std::marker::PhantomData;

#[derive(Default)]
struct MyType<'a> {
field: usize,
_phantom: PhantomData<&'a ()>,
}

#[derive(Default)]
struct MyTypeVariant<'a> {
field: usize,
_phantom: PhantomData<&'a ()>,
}

trait AsVariantTrait {
type Type;
}

impl<'a> AsVariantTrait for MyType<'a> {
type Type = MyTypeVariant<'a>;
}

type Variant<G> = <G as AsVariantTrait>::Type;

fn foo<T: Default, F: FnOnce(T)>(f: F) {
let input = T::default();
f(input);
}

fn main() {
foo(|a: <MyType as AsVariantTrait>::Type| {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding another test for the notation that tries to use the type alias Variant instead?

fn main() {
    foo(|a: Variant<MyType>| { 
        a.field;
    });
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I can just change this test to use that. I only changed this to the associated type syntax to make sure it wasn't a bug with type aliases.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just throw both call-sites into main and call it a day. 😆

The type alias notation is what I was originally trying to use when I found the ICE.

a.field;
});
}