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 check unsize goal in MIR validation when opaques remain #130989

Merged
merged 1 commit into from
Oct 16, 2024
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
11 changes: 11 additions & 0 deletions compiler/rustc_mir_transform/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
&self,
pred: impl Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>,
) -> bool {
let pred: ty::Predicate<'tcx> = pred.upcast(self.tcx);

// We sometimes have to use `defining_opaque_types` for predicates
// to succeed here and figuring out how exactly that should work
// is annoying. It is harmless enough to just not validate anything
// in that case. We still check this after analysis as all opaque
// types have been revealed at this point.
Comment on lines +600 to +604
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we not enforce this in some way?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't enforce it anyways for mir_assign_valid_types, so I don't see any reason to do so. I also don't think it would be easy to do.

if pred.has_opaque_types() {
return true;
}
Comment on lines +605 to +607
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm slightly concerned because we use predicate_must_hold_modulo_regions in several places that don't necessarily have additional later checks. Are there negative tests where we can cause compilation failures even when triggering this code-path?

Copy link
Member Author

Choose a reason for hiding this comment

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

Remember that this is just validation I added, and we validate MIR after opaques are revealed. I'm not totally certain if I understand the concern here.


let infcx = self.tcx.infer_ctxt().build();
let ocx = ObligationCtxt::new(&infcx);
ocx.register_obligation(Obligation::new(
Expand Down
10 changes: 0 additions & 10 deletions tests/crashes/130921.rs

This file was deleted.

12 changes: 12 additions & 0 deletions tests/ui/impl-trait/unsize-cast-validation-rpit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ check-pass
compiler-errors marked this conversation as resolved.
Show resolved Hide resolved
//@ compile-flags: -Zvalidate-mir

fn hello() -> &'static [impl Sized; 0] {
if false {
let x = hello();
let _: &[i32] = x;
}
&[]
}

fn main() {}
Loading