preserve overflow in builtin Field candidates - #162332
Conversation
This comment has been minimized.
This comment has been minimized.
b1a0cdc to
907d8f7
Compare
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Thanks for fixing this, I also figured out the solution in the zulip thread and I think our code looks pretty much the same, except for early return style vs bigger if. my solution fn consider_builtin_field_candidate(
ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, Self>,
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
if goal.predicate.polarity != ty::ClausePolarity::Positive {
return Err(NoSolution.into());
}
if let ty::Adt(def, args) = goal.predicate.self_ty().kind()
&& let Some(FieldInfo { base, ty, .. }) =
def.field_representing_type_info(ecx.cx(), args)
&& match base.kind() {
ty::Adt(def, _) => def.is_struct() && !def.is_packed(),
ty::Tuple(..) => true,
_ => false,
}
{
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
let cx = ecx.cx();
let sized_trait = ecx.cx().require_trait_lang_item(SolverTraitLangItem::Sized);
// FIXME: add better support for builtin impls of traits that check for the bounds
// on the trait definition in std.
// NOTE: these bounds have to be kept in sync with the definition of the `Field`
// trait in `library/core/src/field.rs` as well as the old trait solver `fn
// assemble_candidates_for_field_trait` in
// `compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs`.
ecx.add_goal(
GoalSource::ImplWhereBound,
goal.with(cx, ty::TraitRef::new(ecx.cx(), sized_trait, [base])),
)?;
ecx.add_goal(
GoalSource::ImplWhereBound,
goal.with(cx, TraitRef::new(ecx.cx(), sized_trait, [ty])),
)?;
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
})
} else {
Err(NoSolution.into())
}
}Maybe @lcnr would make for a better reviewer? |
|
Closing this since I realized @BennoLossin had already worked it out :) I missed that in the Zulip thread |
|
Ah no worries, I was glad that I didn't have to spin up a PR :) so feel free to reopen this one |
|
@amirHdev do you want to finish this work? if so, just reopen the PR |
|
Reopening as suggested thanks Benno :) I'll finish this up here And thanks for the earlier Zulip investigation as well |
|
@rustbot reroll |
| match base.kind() { | ||
| ty::Adt(def, _) if def.is_struct() && !def.is_packed() => {} | ||
| ty::Tuple(..) => {} | ||
| _ => return Err(NoSolution.into()), |
There was a problem hiding this comment.
what if that's an infer var @BennoLossin, is that possible?
There was a problem hiding this comment.
base comes from args.type_at(0)
it can still be an infer var here.
I'll move this check back inside the probe
There was a problem hiding this comment.
yeah that sounds correct
There was a problem hiding this comment.
actually, if the field representing type info exists, then base is always an adt or tuple, so I don't think htis needs to be moved in
There was a problem hiding this comment.
yeah, this should handle infer vars then 😁 and we should get a test where that happens, maybe by makig this match ICE on ty::Infer and then getting a test to panic.
also, what are other allowed base types here. Could we make this match exhaustive/unreachable! in the catch all?
There was a problem hiding this comment.
I don't understand why we need to handle infer vars here. the type should be concrete... what would an example of ty::Infer be? something like this?
#![feature(field_projections)]
use std::field::field_of;
fn main() {
let _: field_of!(_, field);
}error: cannot use `_` in this position
--> src/main.rs:4:22
|
4 | let _: field_of!(_, field);
|
There was a problem hiding this comment.
didn't read your second message in depth 😅
okay, then this should be an unreachable!. That's also fine with me
There was a problem hiding this comment.
as field_representing_type_info only gives us an ADT or tuple here we can keep the other ADT cases as NoSolution and made everything else unreachable!()
|
@rustbot author |
|
@bors r+ rollup |
|
❌ Commit 8bd4b8a has been unapproved due to PR CI failure. Reapprove it with |
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
8bd4b8a to
01ad9b7
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. |
|
@lcnr lol. the CI failure was stale stderr after the recent diagnostic span change |
|
@bors r+ rollup |
…uwer Rollup of 9 pull requests Successful merges: - #163655 (explicitly handle tests that pass with -Znext-solver) - #159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc) - #163572 (Update the minimum external LLVM to 22) - #129822 (Docs - type guarantees update) - #157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules) - #162332 (preserve overflow in builtin Field candidates) - #163574 (intrinsics: Rename `abort` to `abort_immediate`) - #163638 (avoid trivial `fn map_bound` validations) - #163660 (yeet compare-mode-coherence)
…uwer Rollup of 9 pull requests Successful merges: - #163655 (explicitly handle tests that pass with -Znext-solver) - #159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc) - #163572 (Update the minimum external LLVM to 22) - #129822 (Docs - type guarantees update) - #157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules) - #162332 (preserve overflow in builtin Field candidates) - #163574 (intrinsics: Rename `abort` to `abort_immediate`) - #163638 (avoid trivial `fn map_bound` validations) - #163660 (yeet compare-mode-coherence)
Rollup merge of #162332 - amirHdev:fix-field-projection-overflow, r=lcnr preserve overflow in builtin Field candidates preserve overflow from the builtin Field candidate instead of treating it as `NoSolution` the Sized requirements are now evaluated inside the candidate probe and coherence correctly rejects overlapping impls when evaluation overflows. fixes #162125
…uwer Rollup of 9 pull requests Successful merges: - rust-lang/rust#163655 (explicitly handle tests that pass with -Znext-solver) - rust-lang/rust#159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc) - rust-lang/rust#163572 (Update the minimum external LLVM to 22) - rust-lang/rust#129822 (Docs - type guarantees update) - rust-lang/rust#157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules) - rust-lang/rust#162332 (preserve overflow in builtin Field candidates) - rust-lang/rust#163574 (intrinsics: Rename `abort` to `abort_immediate`) - rust-lang/rust#163638 (avoid trivial `fn map_bound` validations) - rust-lang/rust#163660 (yeet compare-mode-coherence)
…uwer Rollup of 9 pull requests Successful merges: - rust-lang/rust#163655 (explicitly handle tests that pass with -Znext-solver) - rust-lang/rust#159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc) - rust-lang/rust#163572 (Update the minimum external LLVM to 22) - rust-lang/rust#129822 (Docs - type guarantees update) - rust-lang/rust#157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules) - rust-lang/rust#162332 (preserve overflow in builtin Field candidates) - rust-lang/rust#163574 (intrinsics: Rename `abort` to `abort_immediate`) - rust-lang/rust#163638 (avoid trivial `fn map_bound` validations) - rust-lang/rust#163660 (yeet compare-mode-coherence)
…uwer Rollup of 9 pull requests Successful merges: - rust-lang/rust#163655 (explicitly handle tests that pass with -Znext-solver) - rust-lang/rust#159924 (Send -fno-lto when linker plugin LTO is not requested to avoid having GCC do LTO when using rustc_codegen_gcc) - rust-lang/rust#163572 (Update the minimum external LLVM to 22) - rust-lang/rust#129822 (Docs - type guarantees update) - rust-lang/rust#157973 (Distinguish `repr(C)` ZSTs from others in ABI compatibility rules) - rust-lang/rust#162332 (preserve overflow in builtin Field candidates) - rust-lang/rust#163574 (intrinsics: Rename `abort` to `abort_immediate`) - rust-lang/rust#163638 (avoid trivial `fn map_bound` validations) - rust-lang/rust#163660 (yeet compare-mode-coherence)
View all comments
preserve overflow from the builtin Field candidate instead of treating it as
NoSolutionthe Sized requirements are now evaluated inside the candidate probe and coherence correctly rejects overlapping impls when evaluation overflows.
fixes #162125