Skip to content

Commit fdde66a

Browse files
Process alias-relate obligations when proving receiver_is_valid
1 parent 11dd90f commit fdde66a

File tree

8 files changed

+38
-50
lines changed

8 files changed

+38
-50
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,15 @@ fn receiver_is_valid<'tcx>(
17121712
let cause =
17131713
ObligationCause::new(span, wfcx.body_def_id, traits::ObligationCauseCode::MethodReceiver);
17141714

1715-
let can_eq_self = |ty| infcx.can_eq(wfcx.param_env, self_ty, ty);
1715+
let can_eq_self = |ty| {
1716+
wfcx.infcx.probe(|_| {
1717+
let ocx = ObligationCtxt::new(wfcx.infcx);
1718+
let Ok(()) = ocx.eq(&ObligationCause::dummy(), wfcx.param_env, self_ty, ty) else {
1719+
return false;
1720+
};
1721+
ocx.select_where_possible().is_empty()
1722+
})
1723+
};
17161724

17171725
// `self: Self` is always valid.
17181726
if can_eq_self(receiver_ty) {

compiler/rustc_infer/src/infer/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ impl<'tcx> InferCtxt<'tcx> {
767767
.collect()
768768
}
769769

770+
// FIXME(-Znext-solver): Get rid of this method, it's never correct. Either that,
771+
// or we need to process the obligations.
770772
pub fn can_sub<T>(&self, param_env: ty::ParamEnv<'tcx>, expected: T, actual: T) -> bool
771773
where
772774
T: at::ToTrace<'tcx>,
@@ -779,6 +781,8 @@ impl<'tcx> InferCtxt<'tcx> {
779781
})
780782
}
781783

784+
// FIXME(-Znext-solver): Get rid of this method, it's never correct. Either that,
785+
// or we need to process the obligations.
782786
pub fn can_eq<T>(&self, param_env: ty::ParamEnv<'tcx>, a: T, b: T) -> bool
783787
where
784788
T: at::ToTrace<'tcx>,

tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.nn.stderr

-12
This file was deleted.

tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.ny.stderr

-12
This file was deleted.

tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@ revisions: nn ny yn yy
2-
//@ known-bug: #110395
32
//@ compile-flags: -Znext-solver
3+
//@ check-pass
4+
45
#![allow(incomplete_features)]
56
#![feature(const_trait_impl, effects, associated_type_defaults, const_mut_refs)]
67

tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.yn.stderr

-12
This file was deleted.

tests/ui/rfcs/rfc-2632-const-trait-impl/issue-100222.yy.stderr

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
// Fixes a regression in `receiver_is_valid` in wfcheck where we were using
5+
// `InferCtxt::can_eq` instead of processing alias-relate goals, leading to false
6+
// positives, not deref'ing enough steps to check the receiver is valid.
7+
8+
trait Mirror {
9+
type Mirror: ?Sized;
10+
}
11+
impl<T: ?Sized> Mirror for T {
12+
type Mirror = T;
13+
}
14+
15+
trait Foo {
16+
fn foo(&self) {}
17+
}
18+
19+
impl Foo for <() as Mirror>::Mirror {
20+
fn foo(&self) {}
21+
}
22+
23+
fn main() {}

0 commit comments

Comments
 (0)