Skip to content
Closed
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
9 changes: 7 additions & 2 deletions compiler/rustc_mir_transform/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
crate::util::relate_types(self.tcx, self.typing_env, variance, src, dest)
}

/// Check that the given predicate definitely holds in the param-env of this MIR body.
/// Check that the given predicate is not provably false in the param-env of this MIR body.
///
/// We deliberately accept ambiguous and cycle results, such as post-monomorphization cycles,
/// mirroring the behavior of `impossible_clauses` which also only rejects definite failures.
/// See <https://github.com/rust-lang/rust/issues/155538>.
fn predicate_must_hold_modulo_regions(
&self,
pred: impl Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>,
Expand All @@ -622,7 +626,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
param_env,
pred,
));
ocx.evaluate_obligations_error_on_ambiguity().no_errors()
let errors = ocx.try_evaluate_obligations();
errors.as_slice().iter().all(|error| !error.is_true_error())
}
}

Expand Down
27 changes: 27 additions & 0 deletions tests/ui/mir/validate/validate-unsize-cast-cycle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Regression test for <https://github.com/rust-lang/rust/issues/155538>.
//
// This must be a full build test: `check-pass` only emits metadata and
// therefore does not run the post-mono MIR validator that this ICEs in.
//@ build-pass

trait Apply {
type Output<T: Trait>: Trait;
}
struct Identity;
impl Apply for Identity {
type Output<T: Trait> = T;
}

struct Thing<A: Apply>(A);

trait Trait {}

impl<A: Apply> Trait for Thing<A> where <A as Apply>::Output<Self>: Trait {}

fn weird<A: Apply>(x: A) -> impl Trait {
Thing(x)
}

fn main() {
let _ = Box::new(weird(Identity)) as Box<dyn Trait>;
}
Loading