Skip to content

Commit 09ea3f9

Browse files
Fix obligation param and bless tests
1 parent 5f59b7f commit 09ea3f9

File tree

11 files changed

+64
-104
lines changed

11 files changed

+64
-104
lines changed

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+18-40
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::traits::{
2828
BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource,
2929
ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause, PolyTraitObligation,
3030
PredicateObligation, Selection, SelectionError, SignatureMismatch, TraitNotObjectSafe,
31-
Unimplemented,
31+
TraitObligation, Unimplemented,
3232
};
3333

3434
use super::BuiltinImplConditions;
@@ -693,12 +693,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
693693
)
694694
.map_bound(|(trait_ref, _)| trait_ref);
695695

696-
let mut nested = self.equate_trait_refs(
697-
&obligation.cause,
698-
obligation.param_env,
699-
placeholder_predicate.trait_ref,
700-
trait_ref,
701-
)?;
696+
let mut nested =
697+
self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?;
702698
let cause = obligation.derived_cause(BuiltinDerivedObligation);
703699

704700
// Confirm the `type Output: Sized;` bound that is present on `FnOnce`
@@ -764,9 +760,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
764760
);
765761

766762
let nested = self.equate_trait_refs(
767-
&obligation.cause,
768-
obligation.param_env,
769-
placeholder_predicate.trait_ref,
763+
obligation.with(self.tcx(), placeholder_predicate),
770764
ty::Binder::dummy(trait_ref),
771765
)?;
772766
debug!(?trait_ref, ?nested, "coroutine candidate obligations");
@@ -796,9 +790,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
796790
);
797791

798792
let nested = self.equate_trait_refs(
799-
&obligation.cause,
800-
obligation.param_env,
801-
placeholder_predicate.trait_ref,
793+
obligation.with(self.tcx(), placeholder_predicate),
802794
ty::Binder::dummy(trait_ref),
803795
)?;
804796
debug!(?trait_ref, ?nested, "future candidate obligations");
@@ -828,9 +820,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
828820
);
829821

830822
let nested = self.equate_trait_refs(
831-
&obligation.cause,
832-
obligation.param_env,
833-
placeholder_predicate.trait_ref,
823+
obligation.with(self.tcx(), placeholder_predicate),
834824
ty::Binder::dummy(trait_ref),
835825
)?;
836826
debug!(?trait_ref, ?nested, "iterator candidate obligations");
@@ -860,9 +850,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
860850
);
861851

862852
let nested = self.equate_trait_refs(
863-
&obligation.cause,
864-
obligation.param_env,
865-
placeholder_predicate.trait_ref,
853+
obligation.with(self.tcx(), placeholder_predicate),
866854
ty::Binder::dummy(trait_ref),
867855
)?;
868856
debug!(?trait_ref, ?nested, "iterator candidate obligations");
@@ -898,12 +886,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
898886
}
899887
};
900888

901-
self.equate_trait_refs(
902-
&obligation.cause,
903-
obligation.param_env,
904-
placeholder_predicate.trait_ref,
905-
trait_ref,
906-
)
889+
self.equate_trait_refs(obligation.with(self.tcx(), placeholder_predicate), trait_ref)
907890
}
908891

909892
#[instrument(skip(self), level = "debug")]
@@ -981,12 +964,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
981964
_ => bug!("expected callable type for AsyncFn candidate"),
982965
};
983966

984-
nested.extend(self.equate_trait_refs(
985-
&obligation.cause,
986-
obligation.param_env,
987-
placeholder_predicate.trait_ref,
988-
trait_ref,
989-
)?);
967+
nested.extend(
968+
self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?,
969+
);
990970

991971
let goal_kind =
992972
self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
@@ -1041,13 +1021,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10411021
#[instrument(skip(self), level = "trace")]
10421022
fn equate_trait_refs(
10431023
&mut self,
1044-
cause: &ObligationCause<'tcx>,
1045-
param_env: ty::ParamEnv<'tcx>,
1046-
obligation_trait_ref: ty::TraitRef<'tcx>,
1024+
obligation: TraitObligation<'tcx>,
10471025
found_trait_ref: ty::PolyTraitRef<'tcx>,
10481026
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
10491027
let found_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
1050-
cause.span,
1028+
obligation.cause.span,
10511029
HigherRankedType,
10521030
found_trait_ref,
10531031
);
@@ -1056,16 +1034,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10561034
ensure_sufficient_stack(|| {
10571035
normalize_with_depth(
10581036
self,
1059-
param_env,
1060-
cause.clone(),
1061-
0,
1062-
(obligation_trait_ref, found_trait_ref),
1037+
obligation.param_env,
1038+
obligation.cause.clone(),
1039+
obligation.recursion_depth + 1,
1040+
(obligation.predicate.trait_ref, found_trait_ref),
10631041
)
10641042
});
10651043

10661044
// needed to define opaque types for tests/ui/type-alias-impl-trait/assoc-projection-ice.rs
10671045
self.infcx
1068-
.at(&cause, param_env)
1046+
.at(&obligation.cause, obligation.param_env)
10691047
.eq(DefineOpaqueTypes::Yes, obligation_trait_ref, found_trait_ref)
10701048
.map(|InferOk { mut obligations, .. }| {
10711049
obligations.extend(nested);

tests/ui/higher-ranked/builtin-closure-like-bounds.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
//@ compile-flags: -Zunstable-options
33
//@ revisions: current next
44
//@[next] compile-flags: -Znext-solver
5+
//@ check-pass
6+
7+
// Makes sure that we support closure/coroutine goals where the signature of
8+
// the item references higher-ranked lifetimes from the *predicate* binder,
9+
// not its own internal signature binder.
10+
//
11+
// This was fixed in <https://github.com/rust-lang/rust/pull/122267>.
512

613
#![feature(unboxed_closures, gen_blocks)]
714

@@ -48,4 +55,4 @@ fn main() {
4855

4956
fn uwu<'a>(x: &'a ()) -> impl Fn(&'a ()) { |_| {} }
5057
Closure(uwu).dispatch();
51-
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//@ revisions: current next
2+
//@[next] compile-flags: -Znext-solver
3+
//@ build-pass
4+
5+
// Regression test for incomplete handling of Fn-trait goals,
6+
// fixed in #122267.
7+
8+
trait Trait {
9+
type Assoc<'a>: FnOnce(&'a ());
10+
}
11+
12+
impl Trait for () {
13+
type Assoc<'a> = fn(&'a ());
14+
}
15+
16+
trait Indir {
17+
fn break_me() {}
18+
}
19+
20+
impl<F: Trait> Indir for F
21+
where
22+
for<'a> F::Assoc<'a>: FnOnce(&'a ()),
23+
{
24+
fn break_me() {}
25+
}
26+
27+
fn foo<F: Trait>() {
28+
F::break_me()
29+
}
30+
31+
fn main() {
32+
foo::<()>();
33+
}

tests/ui/higher-ranked/trait-bounds/fn-ptr.classic.stderr

-19
This file was deleted.

tests/ui/higher-ranked/trait-bounds/fn-ptr.current.stderr

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ revisions: current next
22
//@ ignore-compare-mode-next-solver (explicit revisions)
33
//@[next] compile-flags: -Znext-solver
4-
//@[next] check-pass
4+
//@ check-pass
55

66
fn ice()
77
where
@@ -11,5 +11,4 @@ where
1111

1212
fn main() {
1313
ice();
14-
//[current]~^ ERROR expected a `Fn(&'w ())` closure, found `fn(&'w ())`
1514
}

tests/ui/higher-ranked/trait-bounds/future.classic.stderr

-6
This file was deleted.

tests/ui/higher-ranked/trait-bounds/future.current.stderr

-6
This file was deleted.

tests/ui/higher-ranked/trait-bounds/future.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
//@ revisions: current next
44
//@ ignore-compare-mode-next-solver (explicit revisions)
55
//@[next] compile-flags: -Znext-solver
6-
//@[next] check-pass
7-
//@[current] known-bug: #112347
8-
//@[current] build-fail
9-
//@[current] failure-status: 101
10-
//@[current] normalize-stderr-test "note: .*\n\n" -> ""
11-
//@[current] normalize-stderr-test "thread 'rustc' panicked.*\n.*\n" -> ""
12-
//@[current] normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
13-
//@[current] rustc-env:RUST_BACKTRACE=0
6+
//@ check-pass
147

158
#![feature(unboxed_closures)]
169

tests/ui/lifetimes/issue-105675.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn main() {
44
let f = | _ , y: &u32 , z | ();
55
thing(f);
66
//~^ ERROR implementation of `FnOnce` is not general enough
7-
//~^^ ERROR implementation of `FnOnce` is not general enough
7+
//~| ERROR implementation of `FnOnce` is not general enough
88
let f = | x, y: _ , z: u32 | ();
99
thing(f);
1010
//~^ ERROR implementation of `FnOnce` is not general enough

tests/ui/lifetimes/lifetime-errors/issue_74400.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Regression test for #74400: Type mismatch in function arguments E0631, E0271 are falsely
2-
//! recognized as E0308 mismatched types.
2+
//! recognized as "implementation of `FnOnce` is not general enough".
33
44
use std::convert::identity;
55

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

0 commit comments

Comments
 (0)