Repository navigation
Avoid inference constraints from opaque blanket impls - #160752
Conversation
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? @lcnr |
This comment has been minimized.
This comment has been minimized.
| // Blanket impls here only guide inference while the opaque hidden type | ||
| // is unknown. Do not let constraints from matching the impl itself | ||
| // constrain other inference variables. | ||
| Ok(ecx.make_ambiguous_response_no_constraints(maybe)) |
There was a problem hiding this comment.
that would also cause undesirable breakage, e.g I would like to use blanket impls for <impl Iterator<Item = u32> as IntoIterator>::Item. You should be able to construct a complete example from that by looking at the original PR/issue adding this hack for opaque types. I think that currently breaks with your PR
There was a problem hiding this comment.
now only reject the blanket impl if matching the impl itself constrains another trait argument and still allowing inference from the opaque bounds
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
876b69c to
530b635
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
| .args | ||
| .iter() | ||
| .skip(1) | ||
| .all(|arg| ecx.resolve_vars_if_possible(arg) == arg) |
There was a problem hiding this comment.
hmm, also feeling unsure about that you could imagine
?opaque = impl Trait<Assoc = u32>
?opaque: OtherTrait<?u>
impl<T: Trait<Assoc = U>, U> OtherTrait<U> for T {}sorry for not having much capacity to review this PR
There was a problem hiding this comment.
actually i was working on this pr meanwhile and yeah, that case works with the current check. I added it
| { | ||
| // Blanket impls may guide inference for not-yet-defined opaques, | ||
| // but must not constrain the other trait arguments while matching | ||
| // the impl itself. |
There was a problem hiding this comment.
hmm, this does work, feels brittle however as it relies on us not proving any of the added goals in consider_impl_candidate before calling the then closure 🤔
you could change this to just be goal_trait_ref .args .iter() .all(|arg| ecx.resolve_vars_if_possible(arg) == arg)
without the self type special case. hmm
the scary thing is that this can easily break and is subtly wrong wrt normalizing the impl header as these goals also only get evaluated in evaluate_added_goals_and_make_canonical_response 🤔
I am unsure. Your PR feels less wrong than currently nightly behavior. Still feels kinda iffy to me though. Can you keep a comment here that this is brittle and probably not quite what we want still, probably just keep the FIXME(trait-system-refactor-initiative#229) as this setup is still just kinda jank and I dislike it 😅
I would like to maybe do a larger change in the future where we instead eagerly replace opaque types with Placeholders, but that's still far off and has issues itself
There was a problem hiding this comment.
I think the tricky part is allowing inference from the opaque's bounds without letting the blanket impl itself constrain other inference variables
the check covers matching the impl header but normalization and added goals can introduce constraints later
that's probably the distinction we need to get right for #229 🤔
|
@rustbot author |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@bors r+ delegate can you manually rebase this PR and then approve it? unsure whether it'll cause merge conflicts given that it has been a while r=me |
|
@bors delegate+ |
|
This pull request was unapproved. |
Signed-off-by: Amirhossein Akhlaghpour <[email protected]>
Signed-off-by: Amirhossein Akhlaghpour <[email protected]>
Signed-off-by: Amirhossein Akhlaghpour <[email protected]>
4498357 to
e537e5c
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
patch is unchanged, thanks! @bors r=lcnr |
…ce, r=lcnr Avoid inference constraints from opaque blanket impls partially addresses trait system refactor initiative issue 229 this avoids constraining unrelated trait arguments when matching blanket impls for opaque types that are not yet defined while still allowing inference from their bounds
…uwer Rollup of 12 pull requests Successful merges: - #166340 (Revert "implement const Iterator for Range - #156216") - #165345 (Remove the 'eq', 'eq_trace', and 'goals_to_obligations' methods from 'At') - #165538 (Supertraits returns Unnormalized) - #165794 (`consider_impl_candidate` tweaks) - #160752 (Avoid inference constraints from opaque blanket impls) - #163187 (add `scalbn` and `ilogb` methods on floats) - #164541 (Add regression test for #152415) - #164543 (Add regression test for #151316) - #165920 (Introduce compute_abi helper and ComputeCallConv trait) - #166313 (Move `rustdoc-ui` tests in the right folder) - #166420 ([rustdoc] Fix search index generation: if crate content didn't change, it should generate the same search index) - #166485 (Allow passing `--exact-match` and `--purge` to `x perf`)
Rollup merge of #160752 - amirHdev:fix-opaque-blanket-guidance, r=lcnr Avoid inference constraints from opaque blanket impls partially addresses trait system refactor initiative issue 229 this avoids constraining unrelated trait arguments when matching blanket impls for opaque types that are not yet defined while still allowing inference from their bounds
…uwer Rollup of 12 pull requests Successful merges: - rust-lang/rust#166340 (Revert "implement const Iterator for Range - rust-lang/rust#156216") - rust-lang/rust#165345 (Remove the 'eq', 'eq_trace', and 'goals_to_obligations' methods from 'At') - rust-lang/rust#165538 (Supertraits returns Unnormalized) - rust-lang/rust#165794 (`consider_impl_candidate` tweaks) - rust-lang/rust#160752 (Avoid inference constraints from opaque blanket impls) - rust-lang/rust#163187 (add `scalbn` and `ilogb` methods on floats) - rust-lang/rust#164541 (Add regression test for rust-lang/rust#152415) - rust-lang/rust#164543 (Add regression test for rust-lang/rust#151316) - rust-lang/rust#165920 (Introduce compute_abi helper and ComputeCallConv trait) - rust-lang/rust#166313 (Move `rustdoc-ui` tests in the right folder) - rust-lang/rust#166420 ([rustdoc] Fix search index generation: if crate content didn't change, it should generate the same search index) - rust-lang/rust#166485 (Allow passing `--exact-match` and `--purge` to `x perf`)
…uwer Rollup of 12 pull requests Successful merges: - rust-lang/rust#166340 (Revert "implement const Iterator for Range - rust-lang/rust#156216") - rust-lang/rust#165345 (Remove the 'eq', 'eq_trace', and 'goals_to_obligations' methods from 'At') - rust-lang/rust#165538 (Supertraits returns Unnormalized) - rust-lang/rust#165794 (`consider_impl_candidate` tweaks) - rust-lang/rust#160752 (Avoid inference constraints from opaque blanket impls) - rust-lang/rust#163187 (add `scalbn` and `ilogb` methods on floats) - rust-lang/rust#164541 (Add regression test for rust-lang/rust#152415) - rust-lang/rust#164543 (Add regression test for rust-lang/rust#151316) - rust-lang/rust#165920 (Introduce compute_abi helper and ComputeCallConv trait) - rust-lang/rust#166313 (Move `rustdoc-ui` tests in the right folder) - rust-lang/rust#166420 ([rustdoc] Fix search index generation: if crate content didn't change, it should generate the same search index) - rust-lang/rust#166485 (Allow passing `--exact-match` and `--purge` to `x perf`)
View all comments
partially addresses trait system refactor initiative issue 229
this avoids constraining unrelated trait arguments when matching blanket impls for opaque types that are not yet defined while still allowing inference from their bounds