Skip to content

Commit

Permalink
Fix obligation param and bless tests
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Mar 14, 2024
1 parent 5babe9f commit 0d9269f
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 104 deletions.
58 changes: 18 additions & 40 deletions compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::traits::{
BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource,
ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause, PolyTraitObligation,
PredicateObligation, Selection, SelectionError, SignatureMismatch, TraitNotObjectSafe,
Unimplemented,
TraitObligation, Unimplemented,
};

use super::BuiltinImplConditions;
Expand Down Expand Up @@ -691,12 +691,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
)
.map_bound(|(trait_ref, _)| trait_ref);

let mut nested = self.equate_trait_refs(
&obligation.cause,
obligation.param_env,
placeholder_predicate.trait_ref,
trait_ref,
)?;
let mut nested =
self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?;
let cause = obligation.derived_cause(BuiltinDerivedObligation);

// Confirm the `type Output: Sized;` bound that is present on `FnOnce`
Expand Down Expand Up @@ -762,9 +758,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
);

let nested = self.equate_trait_refs(
&obligation.cause,
obligation.param_env,
placeholder_predicate.trait_ref,
obligation.with(self.tcx(), placeholder_predicate),
ty::Binder::dummy(trait_ref),
)?;
debug!(?trait_ref, ?nested, "coroutine candidate obligations");
Expand Down Expand Up @@ -794,9 +788,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
);

let nested = self.equate_trait_refs(
&obligation.cause,
obligation.param_env,
placeholder_predicate.trait_ref,
obligation.with(self.tcx(), placeholder_predicate),
ty::Binder::dummy(trait_ref),
)?;
debug!(?trait_ref, ?nested, "future candidate obligations");
Expand Down Expand Up @@ -826,9 +818,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
);

let nested = self.equate_trait_refs(
&obligation.cause,
obligation.param_env,
placeholder_predicate.trait_ref,
obligation.with(self.tcx(), placeholder_predicate),
ty::Binder::dummy(trait_ref),
)?;
debug!(?trait_ref, ?nested, "iterator candidate obligations");
Expand Down Expand Up @@ -858,9 +848,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
);

let nested = self.equate_trait_refs(
&obligation.cause,
obligation.param_env,
placeholder_predicate.trait_ref,
obligation.with(self.tcx(), placeholder_predicate),
ty::Binder::dummy(trait_ref),
)?;
debug!(?trait_ref, ?nested, "iterator candidate obligations");
Expand Down Expand Up @@ -896,12 +884,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
};

self.equate_trait_refs(
&obligation.cause,
obligation.param_env,
placeholder_predicate.trait_ref,
trait_ref,
)
self.equate_trait_refs(obligation.with(self.tcx(), placeholder_predicate), trait_ref)
}

#[instrument(skip(self), level = "debug")]
Expand Down Expand Up @@ -979,12 +962,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
_ => bug!("expected callable type for AsyncFn candidate"),
};

nested.extend(self.equate_trait_refs(
&obligation.cause,
obligation.param_env,
placeholder_predicate.trait_ref,
trait_ref,
)?);
nested.extend(
self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?,
);

let goal_kind =
self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
Expand Down Expand Up @@ -1039,13 +1019,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
#[instrument(skip(self), level = "trace")]
fn equate_trait_refs(
&mut self,
cause: &ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>,
obligation_trait_ref: ty::TraitRef<'tcx>,
obligation: TraitObligation<'tcx>,
found_trait_ref: ty::PolyTraitRef<'tcx>,
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
let found_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
cause.span,
obligation.cause.span,
HigherRankedType,
found_trait_ref,
);
Expand All @@ -1054,16 +1032,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ensure_sufficient_stack(|| {
normalize_with_depth(
self,
param_env,
cause.clone(),
0,
(obligation_trait_ref, found_trait_ref),
obligation.param_env,
obligation.cause.clone(),
obligation.recursion_depth + 1,
(obligation.predicate.trait_ref, found_trait_ref),
)
});

// needed to define opaque types for tests/ui/type-alias-impl-trait/assoc-projection-ice.rs
self.infcx
.at(&cause, param_env)
.at(&obligation.cause, obligation.param_env)
.eq(DefineOpaqueTypes::Yes, obligation_trait_ref, found_trait_ref)
.map(|InferOk { mut obligations, .. }| {
obligations.extend(nested);
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/higher-ranked/builtin-closure-like-bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//@ compile-flags: -Zunstable-options
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
//@ check-pass

#![feature(unboxed_closures, gen_blocks)]

Expand Down Expand Up @@ -48,4 +49,4 @@ fn main() {

fn uwu<'a>(x: &'a ()) -> impl Fn(&'a ()) { |_| {} }
Closure(uwu).dispatch();
}
}
19 changes: 0 additions & 19 deletions tests/ui/higher-ranked/trait-bounds/fn-ptr.classic.stderr

This file was deleted.

19 changes: 0 additions & 19 deletions tests/ui/higher-ranked/trait-bounds/fn-ptr.current.stderr

This file was deleted.

3 changes: 1 addition & 2 deletions tests/ui/higher-ranked/trait-bounds/fn-ptr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
//@[next] check-pass
//@ check-pass

fn ice()
where
Expand All @@ -11,5 +11,4 @@ where

fn main() {
ice();
//[current]~^ ERROR expected a `Fn(&'w ())` closure, found `fn(&'w ())`
}
6 changes: 0 additions & 6 deletions tests/ui/higher-ranked/trait-bounds/future.classic.stderr

This file was deleted.

6 changes: 0 additions & 6 deletions tests/ui/higher-ranked/trait-bounds/future.current.stderr

This file was deleted.

9 changes: 1 addition & 8 deletions tests/ui/higher-ranked/trait-bounds/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
//@[next] check-pass
//@[current] known-bug: #112347
//@[current] build-fail
//@[current] failure-status: 101
//@[current] normalize-stderr-test "note: .*\n\n" -> ""
//@[current] normalize-stderr-test "thread 'rustc' panicked.*\n.*\n" -> ""
//@[current] normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
//@[current] rustc-env:RUST_BACKTRACE=0
//@ check-pass

#![feature(unboxed_closures)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lifetimes/issue-105675.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fn main() {
let f = | _ , y: &u32 , z | ();
thing(f);
//~^ ERROR implementation of `FnOnce` is not general enough
//~^^ ERROR implementation of `FnOnce` is not general enough
//~| ERROR implementation of `FnOnce` is not general enough
let f = | x, y: _ , z: u32 | ();
thing(f);
//~^ ERROR implementation of `FnOnce` is not general enough
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/lifetimes/lifetime-errors/issue_74400.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Regression test for #74400: Type mismatch in function arguments E0631, E0271 are falsely
//! recognized as E0308 mismatched types.
//! recognized as "implementation of `FnOnce` is not general enough".

use std::convert::identity;

Expand All @@ -13,6 +13,6 @@ fn g<T>(data: &[T]) {
//~^ ERROR the parameter type
//~| ERROR the parameter type
//~| ERROR the parameter type
//~| ERROR implementation of `FnOnce` is not general
//~| ERROR implementation of `FnOnce` is not general enough
//~| ERROR implementation of `Fn` is not general enough
}

0 comments on commit 0d9269f

Please sign in to comment.