Skip to content

Commit

Permalink
Don't check unsize goal in MIR validation when opaques remain
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Sep 28, 2024
1 parent e6eb451 commit 6a02453
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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.
if pred.has_opaque_types() {
return true;
}

let infcx = self.tcx.infer_ctxt().build();
let ocx = ObligationCtxt::new(&infcx);
ocx.register_obligation(Obligation::new(
Expand Down
11 changes: 11 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,11 @@
//@ check-pass

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

fn main() {}

0 comments on commit 6a02453

Please sign in to comment.