Skip to content

Commit

Permalink
Normalize xform_ret_ty after constrained, bless tests
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Mar 14, 2024
1 parent f6eac07 commit 35d6003
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 32 deletions.
38 changes: 30 additions & 8 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1370,15 +1370,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 =
Expand Down Expand Up @@ -1420,11 +1427,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;
Expand All @@ -1447,8 +1462,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;
Expand Down
13 changes: 0 additions & 13 deletions compiler/rustc_trait_selection/src/traits/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ where

fn main() {
let mut list = RcNode::<i32>::new();
//~^ ERROR the size for values of type `Node<i32, RcFamily>` cannot be known at compilation time
//~^ ERROR the variant or associated item `new` exists for enum `Node<i32, RcFamily>`, but its trait bounds were not satisfied
}
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/issues/issue-62742.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::marker::PhantomData;
fn _alias_check() {
WrongImpl::foo(0i32);
//~^ ERROR the trait bound `RawImpl<_>: Raw<_>` is not satisfied
//~| ERROR the trait bound `RawImpl<_>: Raw<_>` is not satisfied
//~| ERROR the function or associated item `foo` exists for struct `SafeImpl<_, RawImpl<_>>`, but its trait bounds were not satisfied
WrongImpl::<()>::foo(0i32);
//~^ ERROR the trait bound `RawImpl<()>: Raw<()>` is not satisfied
//~| ERROR trait bounds were not satisfied
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/impl-trait/issues/issue-84073.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ where
}

fn main() {
Race::new(|race| race.when()); //~ ERROR overflow assigning `_` to `Option<_>`
Race::new(|race| race.when());
//~^ ERROR the method `when` exists for struct `RaceBuilder<_, Never<_>>`, but its trait bounds were not satisfied
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion tests/ui/issues/issue-57362-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ impl<'a> X for fn(&'a ()) {
}
}

// FIXME(@compiler-errors): This error message is less than helpful.
fn g() {
let x = <fn (&())>::make_g(); //~ ERROR the function
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
}

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-57362-2.stderr
Original file line number Diff line number Diff line change
@@ -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(&())`
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/nll/issue-57642-higher-ranked-subtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ impl<T> Y for fn(T) {
}

fn higher_ranked_region_has_lost_its_binder() {
let x = <fn (&())>::make_g(); //~ ERROR the function
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
}

fn magical() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/nll/issue-57642-higher-ranked-subtype.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LL | trait X {
| ^^^^^^^

error[E0599]: no function or associated item named `make_f` found for fn pointer `for<'a> fn(&'a ())` in the current scope
--> $DIR/issue-57642-higher-ranked-subtype.rs:35:25
--> $DIR/issue-57642-higher-ranked-subtype.rs:36:25
|
LL | let x = <fn (&())>::make_f();
| ^^^^^^ function or associated item not found in `fn(&())`
Expand Down

0 comments on commit 35d6003

Please sign in to comment.