Normalize xform_ret_ty after constrained

This commit is contained in:
Michael Goulet 2024-03-14 14:51:55 -04:00
parent ff4653a08f
commit d9fec1321a
11 changed files with 35 additions and 45 deletions

View File

@ -1375,15 +1375,22 @@ fn consider_probe(
(xform_self_ty, xform_ret_ty) =
self.xform_self_ty(probe.item, impl_ty, impl_args);
xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
// FIXME: Weirdly, we normalize the ret ty in this candidate, but no other candidates.
xform_ret_ty = ocx.normalize(cause, self.param_env, xform_ret_ty);
match ocx.eq_no_opaques(cause, self.param_env, xform_self_ty, self_ty) {
Ok(()) => {}
// FIXME: Make this `ocx.eq` once we define opaques more eagerly.
match self.at(cause, self.param_env).eq(
DefineOpaqueTypes::No,
xform_self_ty,
self_ty,
) {
Ok(infer_ok) => {
ocx.register_infer_ok_obligations(infer_ok);
}
Err(err) => {
debug!("--> cannot relate self-types {:?}", err);
return ProbeResult::NoMatch;
}
}
// FIXME: Weirdly, we normalize the ret ty in this candidate, but no other candidates.
xform_ret_ty = ocx.normalize(cause, self.param_env, xform_ret_ty);
// Check whether the impl imposes obligations we have to worry about.
let impl_def_id = probe.item.container_id(self.tcx);
let impl_bounds =
@ -1425,11 +1432,19 @@ fn consider_probe(
infer::FnCall,
poly_trait_ref,
);
let trait_ref = ocx.normalize(cause, self.param_env, trait_ref);
(xform_self_ty, xform_ret_ty) =
self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
match ocx.eq_no_opaques(cause, self.param_env, xform_self_ty, self_ty) {
Ok(()) => {}
// FIXME: Make this `ocx.eq` once we define opaques more eagerly.
match self.at(cause, self.param_env).eq(
DefineOpaqueTypes::No,
xform_self_ty,
self_ty,
) {
Ok(infer_ok) => {
ocx.register_infer_ok_obligations(infer_ok);
}
Err(err) => {
debug!("--> cannot relate self-types {:?}", err);
return ProbeResult::NoMatch;
@ -1452,8 +1467,15 @@ fn consider_probe(
(xform_self_ty, xform_ret_ty) =
self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
match ocx.eq_no_opaques(cause, self.param_env, xform_self_ty, self_ty) {
Ok(()) => {}
// FIXME: Make this `ocx.eq` once we define opaques more eagerly.
match self.at(cause, self.param_env).eq(
DefineOpaqueTypes::No,
xform_self_ty,
self_ty,
) {
Ok(infer_ok) => {
ocx.register_infer_ok_obligations(infer_ok);
}
Err(err) => {
debug!("--> cannot relate self-types {:?}", err);
return ProbeResult::NoMatch;

View File

@ -129,19 +129,6 @@ pub fn eq<T: ToTrace<'tcx>>(
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
}
pub fn eq_no_opaques<T: ToTrace<'tcx>>(
&self,
cause: &ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>,
expected: T,
actual: T,
) -> Result<(), TypeError<'tcx>> {
self.infcx
.at(cause, param_env)
.eq(DefineOpaqueTypes::No, expected, actual)
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
}
/// Checks whether `expected` is a subtype of `actual`: `expected <: actual`.
pub fn sub<T: ToTrace<'tcx>>(
&self,

View File

@ -29,5 +29,5 @@ fn new() -> P::Pointer<Self> {
fn main() {
let mut list = RcNode::<i32>::new();
//~^ ERROR trait bounds were not satisfied
//~^ ERROR the variant or associated item `new` exists for enum `Node<i32, RcFamily>`, but its trait bounds were not satisfied
}

View File

@ -6,7 +6,6 @@ LL | let _result = &Some(42).as_deref();
|
= note: the following trait bounds were not satisfied:
`{integer}: Deref`
which is required by `<{integer} as Deref>::Target = _`
error: aborting due to 1 previous error

View File

@ -6,7 +6,6 @@ LL | let _result = &mut Some(42).as_deref_mut();
|
= note: the following trait bounds were not satisfied:
`{integer}: Deref`
which is required by `<{integer} as Deref>::Target = _`
error: aborting due to 1 previous error

View File

@ -6,7 +6,6 @@ LL | let _result = &Ok(42).as_deref();
|
= note: the following trait bounds were not satisfied:
`{integer}: Deref`
which is required by `<{integer} as Deref>::Target = _`
error: aborting due to 1 previous error

View File

@ -6,7 +6,6 @@ LL | let _result = &mut Ok(42).as_deref_mut();
|
= note: the following trait bounds were not satisfied:
`{integer}: Deref`
which is required by `<{integer} as Deref>::Target = _`
error: aborting due to 1 previous error

View File

@ -18,6 +18,7 @@ fn make_g() -> Self::G {
}
}
// FIXME(@compiler-errors): This error message is less than helpful.
fn g() {
let x = <fn (&())>::make_g();
//~^ ERROR no function or associated item named `make_g` found for fn pointer `for<'a> fn(&'a ())` in the current scope

View File

@ -1,5 +1,5 @@
error[E0599]: no function or associated item named `make_g` found for fn pointer `for<'a> fn(&'a ())` in the current scope
--> $DIR/issue-57362-2.rs:22:25
--> $DIR/issue-57362-2.rs:23:25
|
LL | let x = <fn (&())>::make_g();
| ^^^^^^ function or associated item not found in `fn(&())`

View File

@ -1,3 +1,5 @@
//@ check-pass
// Some trait with a function that returns a slice:
pub trait AsSlice {
type Element;
@ -22,7 +24,6 @@ pub fn failing<Coef>(&self)
Self: AsSlice<Element = Coef>,
{
self.as_ref_a().as_ref_a();
//~^ ERROR no method named `as_ref_a` found for struct `A<&[Coef]>` in the current scope
}
pub fn as_ref_a<Coef>(&self) -> A<&[<Self as AsSlice>::Element]>

View File

@ -1,17 +0,0 @@
error[E0599]: no method named `as_ref_a` found for struct `A<&[Coef]>` in the current scope
--> $DIR/issue-85671.rs:24:25
|
LL | pub struct A<Cont>(Cont);
| ------------------ method `as_ref_a` not found for this struct
...
LL | self.as_ref_a().as_ref_a();
| ---- ^^^^^^^^ method not found in `A<&[Coef]>`
| |
| method `as_ref_a` is available on `&A<Cont>`
|
= note: the method was found for
- `A<Cont>`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0599`.