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

Don't infer closure signatures with late-bound type vars #108827

Conversation

compiler-errors
Copy link
Member

Fixes #108814

@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2023

r? @jackh726

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative labels Mar 6, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2023

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@@ -1,8 +1,6 @@
// Unit test for the "user substitutions" that are annotated on each
// node.

// compile-flags:-Zverbose
Copy link
Member Author

Choose a reason for hiding this comment

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

This test's output changes with the modification to how bound/placeholder tys print under -Zverbose, though arguably I could revert that change -- just made debug a bit easier for me.

@@ -760,7 +760,21 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
};

let trait_ref = self.closure_trait_ref_unnormalized(obligation, substs);
let mut nested = self.confirm_poly_trait_refs(obligation, trait_ref)?;

// FIXME(non_lifetime_binders): Perform the equivalent of a "leak check" here.
Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively, we could let this succeed, then error out during HIR typeck or something, though it would be harder to point to the source of the error.

@fmease
Copy link
Member

fmease commented Mar 6, 2023

As far as I can tell, this PR is closure & Fn* trait specific. Does this mean this code still ices w/ this PR? It ices on nightly for the same reason as #108814 but it doesn't use Fn* or closures (and it should be check-pass but I am not entirely sure).

@compiler-errors
Copy link
Member Author

@fmease: It ICEs with the same message, but for a different reason (the stacks have the same "head" but different "tails"). I can look into fixing that one too.

@fmease
Copy link
Member

fmease commented Mar 6, 2023

Ah, I see. Should I open a separate issue for it (unless you'd like to fix it in this PR of course)?

@compiler-errors
Copy link
Member Author

Sorry @fmease, forgot to respond. I opened #108836 for that.

};

// FIXME(non_lifetime_binders): Higher-ranked Fn trait candidates are not (yet) supported.
// Make sure that the inputs/output don't capture any placeholder types.
Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree with this. Canonicalization also maps ty::Param to a placeholder.

I generally think that this check should happen somewhere else 🤔

if inferred_sig.visit_with(&mut MentionsTy { expected_ty }).is_continue() {
// FIXME(non_lifetime_binder): Don't infer a signature with late-bound ty/ct vars
if inferred_sig.visit_with(&mut MentionsTy { expected_ty }).is_continue()
&& !inferred_sig.has_non_region_late_bound()
Copy link
Contributor

Choose a reason for hiding this comment

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

is this check not enough to prevent ICEs here? also, can you check that !inferred_sig.has_placeholders because inferring a closure signature to contain placeholders is wrong as the closure type is used outside of the binder which created them

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this just makes sure that we just don't eagerly deduce a closure signature from pending obligations.

We can still infer placeholders when we process pending obligations later, so we'd need to do something after typechecking to make sure that the closures don't capture any type placeholders.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that check here along with !inferred_sig.has_placeholders should be enough.
We keep getting ICE because of #109505 and probably because we're not using ty vars in the root universe.

@lcnr
Copy link
Contributor

lcnr commented Mar 7, 2023

r? @lcnr

@rustbot rustbot assigned lcnr and unassigned jackh726 Mar 7, 2023
@compiler-errors
Copy link
Member Author

Hmm... yeah, then this needs to go back to the drawing table then

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 14, 2023
@bors
Copy link
Contributor

bors commented Mar 21, 2023

☔ The latest upstream changes (presumably #109442) made this pull request unmergeable. Please resolve the merge conflicts.

@compiler-errors compiler-errors deleted the non_lifetime_binders-closure-infer branch August 11, 2023 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE “unexpected bound ty in binder” involving type binder, Fn-family trait and closure
7 participants