From d9fec1321acf9c397781ca0dd6f130b4d100fe0b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 14 Mar 2024 14:51:55 -0400 Subject: [PATCH] Normalize xform_ret_ty after constrained --- compiler/rustc_hir_typeck/src/method/probe.rs | 38 +++++++++++++++---- .../src/traits/engine.rs | 13 ------- ...ied-gat-bound-during-assoc-ty-selection.rs | 2 +- .../option-as_deref.stderr | 1 - .../option-as_deref_mut.stderr | 1 - .../result-as_deref.stderr | 1 - .../result-as_deref_mut.stderr | 1 - tests/ui/nll/issue-57362-2.rs | 1 + tests/ui/nll/issue-57362-2.stderr | 2 +- tests/ui/resolve/issue-85671.rs | 3 +- tests/ui/resolve/issue-85671.stderr | 17 --------- 11 files changed, 35 insertions(+), 45 deletions(-) delete mode 100644 tests/ui/resolve/issue-85671.stderr diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index c31b54c642d..49210209520 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1375,15 +1375,22 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { (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 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { (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; diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index 68c76dcf297..9fbec174ce8 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -129,19 +129,6 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> { .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } - pub fn eq_no_opaques>( - &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>( &self, diff --git a/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs b/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs index 86da6ebfaaa..d7dff329df1 100644 --- a/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs +++ b/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs @@ -29,5 +29,5 @@ where fn main() { let mut list = RcNode::::new(); - //~^ ERROR trait bounds were not satisfied + //~^ ERROR the variant or associated item `new` exists for enum `Node`, but its trait bounds were not satisfied } diff --git a/tests/ui/issues/issue-50264-inner-deref-trait/option-as_deref.stderr b/tests/ui/issues/issue-50264-inner-deref-trait/option-as_deref.stderr index 0468e0522d1..84247a42704 100644 --- a/tests/ui/issues/issue-50264-inner-deref-trait/option-as_deref.stderr +++ b/tests/ui/issues/issue-50264-inner-deref-trait/option-as_deref.stderr @@ -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 diff --git a/tests/ui/issues/issue-50264-inner-deref-trait/option-as_deref_mut.stderr b/tests/ui/issues/issue-50264-inner-deref-trait/option-as_deref_mut.stderr index cf4e866901c..bf05ab5665c 100644 --- a/tests/ui/issues/issue-50264-inner-deref-trait/option-as_deref_mut.stderr +++ b/tests/ui/issues/issue-50264-inner-deref-trait/option-as_deref_mut.stderr @@ -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 diff --git a/tests/ui/issues/issue-50264-inner-deref-trait/result-as_deref.stderr b/tests/ui/issues/issue-50264-inner-deref-trait/result-as_deref.stderr index 0e3e7999044..ac744a6d3b6 100644 --- a/tests/ui/issues/issue-50264-inner-deref-trait/result-as_deref.stderr +++ b/tests/ui/issues/issue-50264-inner-deref-trait/result-as_deref.stderr @@ -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 diff --git a/tests/ui/issues/issue-50264-inner-deref-trait/result-as_deref_mut.stderr b/tests/ui/issues/issue-50264-inner-deref-trait/result-as_deref_mut.stderr index 43143db0da7..688d2cf3486 100644 --- a/tests/ui/issues/issue-50264-inner-deref-trait/result-as_deref_mut.stderr +++ b/tests/ui/issues/issue-50264-inner-deref-trait/result-as_deref_mut.stderr @@ -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 diff --git a/tests/ui/nll/issue-57362-2.rs b/tests/ui/nll/issue-57362-2.rs index bc0d0f5291f..664cdf89a38 100644 --- a/tests/ui/nll/issue-57362-2.rs +++ b/tests/ui/nll/issue-57362-2.rs @@ -18,6 +18,7 @@ impl<'a> X for fn(&'a ()) { } } +// FIXME(@compiler-errors): This error message is less than helpful. fn g() { let x = ::make_g(); //~^ ERROR no function or associated item named `make_g` found for fn pointer `for<'a> fn(&'a ())` in the current scope diff --git a/tests/ui/nll/issue-57362-2.stderr b/tests/ui/nll/issue-57362-2.stderr index a78c96dbd0d..24787b990e3 100644 --- a/tests/ui/nll/issue-57362-2.stderr +++ b/tests/ui/nll/issue-57362-2.stderr @@ -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 = ::make_g(); | ^^^^^^ function or associated item not found in `fn(&())` diff --git a/tests/ui/resolve/issue-85671.rs b/tests/ui/resolve/issue-85671.rs index ac001cebda7..54db03f774e 100644 --- a/tests/ui/resolve/issue-85671.rs +++ b/tests/ui/resolve/issue-85671.rs @@ -1,3 +1,5 @@ +//@ check-pass + // Some trait with a function that returns a slice: pub trait AsSlice { type Element; @@ -22,7 +24,6 @@ impl A { Self: AsSlice, { 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(&self) -> A<&[::Element]> diff --git a/tests/ui/resolve/issue-85671.stderr b/tests/ui/resolve/issue-85671.stderr deleted file mode 100644 index 0571e600197..00000000000 --- a/tests/ui/resolve/issue-85671.stderr +++ /dev/null @@ -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); - | ------------------ 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` - | - = note: the method was found for - - `A` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0599`.