Skip to content

Commit 122fb29

Browse files
committed
Auto merge of rust-lang#136011 - compiler-errors:query-norm-vaniquishes-us, r=jackh726
Revert rust-lang#135914: Remove usages of `QueryNormalizer` in the compiler Reverts rust-lang#135914. r? jackh726
2 parents aeba3c6 + 4e3e915 commit 122fb29

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use rustc_span::{DUMMY_SP, Span};
66
use tracing::{debug, instrument};
77

88
use crate::traits::query::NoSolution;
9-
use crate::traits::{ObligationCause, ObligationCtxt};
9+
use crate::traits::query::normalize::QueryNormalizeExt;
10+
use crate::traits::{Normalized, ObligationCause, ObligationCtxt};
1011

1112
/// This returns true if the type `ty` is "trivial" for
1213
/// dropck-outlives -- that is, if it doesn't require any types to
@@ -172,31 +173,26 @@ pub fn compute_dropck_outlives_inner<'tcx>(
172173
// do not themselves define a destructor", more or less. We have
173174
// to push them onto the stack to be expanded.
174175
for ty in constraints.dtorck_types.drain(..) {
175-
let normalized_ty = ocx.normalize(&cause, param_env, ty);
176+
let Normalized { value: ty, obligations } =
177+
ocx.infcx.at(&cause, param_env).query_normalize(ty)?;
178+
ocx.register_obligations(obligations);
176179

177-
let errors = ocx.select_where_possible();
178-
if !errors.is_empty() {
179-
debug!("failed to normalize dtorck type: {ty} ~> {errors:#?}");
180-
return Err(NoSolution);
181-
}
182-
183-
let normalized_ty = ocx.infcx.resolve_vars_if_possible(normalized_ty);
184-
debug!("dropck_outlives: ty from dtorck_types = {:?}", normalized_ty);
180+
debug!("dropck_outlives: ty from dtorck_types = {:?}", ty);
185181

186-
match normalized_ty.kind() {
182+
match ty.kind() {
187183
// All parameters live for the duration of the
188184
// function.
189185
ty::Param(..) => {}
190186

191187
// A projection that we couldn't resolve - it
192188
// might have a destructor.
193189
ty::Alias(..) => {
194-
result.kinds.push(normalized_ty.into());
190+
result.kinds.push(ty.into());
195191
}
196192

197193
_ => {
198-
if ty_set.insert(normalized_ty) {
199-
ty_stack.push((normalized_ty, depth + 1));
194+
if ty_set.insert(ty) {
195+
ty_stack.push((ty, depth + 1));
200196
}
201197
}
202198
}

compiler/rustc_traits/src/type_op.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ use rustc_middle::traits::query::NoSolution;
77
use rustc_middle::ty::{Clause, FnSig, ParamEnvAnd, PolyFnSig, Ty, TyCtxt, TypeFoldable};
88
use rustc_span::DUMMY_SP;
99
use rustc_trait_selection::infer::InferCtxtBuilderExt;
10+
use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
1011
use rustc_trait_selection::traits::query::type_op::ascribe_user_type::{
1112
AscribeUserType, type_op_ascribe_user_type_with_span,
1213
};
1314
use rustc_trait_selection::traits::query::type_op::normalize::Normalize;
1415
use rustc_trait_selection::traits::query::type_op::prove_predicate::ProvePredicate;
15-
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
16+
use rustc_trait_selection::traits::{Normalized, Obligation, ObligationCause, ObligationCtxt};
1617

1718
pub(crate) fn provide(p: &mut Providers) {
1819
*p = Providers {
@@ -43,7 +44,10 @@ where
4344
T: fmt::Debug + TypeFoldable<TyCtxt<'tcx>>,
4445
{
4546
let (param_env, Normalize { value }) = key.into_parts();
46-
Ok(ocx.normalize(&ObligationCause::dummy(), param_env, value))
47+
let Normalized { value, obligations } =
48+
ocx.infcx.at(&ObligationCause::dummy(), param_env).query_normalize(value)?;
49+
ocx.register_obligations(obligations);
50+
Ok(value)
4751
}
4852

4953
fn type_op_normalize_ty<'tcx>(

tests/ui/higher-ranked/trait-bounds/normalize-under-binder/issue-71955.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ fn main() {
4343
}
4444

4545
foo(bar, "string", |s| s.len() == 5);
46-
//~^ ERROR implementation of `Parser` is not general enough
47-
//~| ERROR implementation of `Parser` is not general enough
46+
//~^ ERROR implementation of `FnOnce` is not general enough
47+
//~| ERROR implementation of `FnOnce` is not general enough
4848
foo(baz, "string", |s| s.0.len() == 5);
49-
//~^ ERROR implementation of `Parser` is not general enough
50-
//~| ERROR implementation of `Parser` is not general enough
49+
//~^ ERROR implementation of `FnOnce` is not general enough
50+
//~| ERROR implementation of `FnOnce` is not general enough
5151
}

tests/ui/higher-ranked/trait-bounds/normalize-under-binder/issue-71955.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
error: implementation of `Parser` is not general enough
1+
error: implementation of `FnOnce` is not general enough
22
--> $DIR/issue-71955.rs:45:5
33
|
44
LL | foo(bar, "string", |s| s.len() == 5);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Parser` is not general enough
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
66
|
7-
= note: `for<'a> fn(&'a str) -> (&'a str, &'a str) {bar}` must implement `Parser<'0>`, for any lifetime `'0`...
8-
= note: ...but it actually implements `Parser<'1>`, for some specific lifetime `'1`
7+
= note: closure with signature `for<'a> fn(&'a &'2 str) -> bool` must implement `FnOnce<(&&'1 str,)>`, for any lifetime `'1`...
8+
= note: ...but it actually implements `FnOnce<(&&'2 str,)>`, for some specific lifetime `'2`
99

10-
error: implementation of `Parser` is not general enough
10+
error: implementation of `FnOnce` is not general enough
1111
--> $DIR/issue-71955.rs:45:5
1212
|
1313
LL | foo(bar, "string", |s| s.len() == 5);
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Parser` is not general enough
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
1515
|
16-
= note: `for<'a> fn(&'a str) -> (&'a str, &'a str) {bar}` must implement `Parser<'0>`, for any lifetime `'0`...
17-
= note: ...but it actually implements `Parser<'1>`, for some specific lifetime `'1`
16+
= note: closure with signature `for<'a> fn(&'a &'2 str) -> bool` must implement `FnOnce<(&&'1 str,)>`, for any lifetime `'1`...
17+
= note: ...but it actually implements `FnOnce<(&&'2 str,)>`, for some specific lifetime `'2`
1818
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1919

20-
error: implementation of `Parser` is not general enough
20+
error: implementation of `FnOnce` is not general enough
2121
--> $DIR/issue-71955.rs:48:5
2222
|
2323
LL | foo(baz, "string", |s| s.0.len() == 5);
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Parser` is not general enough
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
2525
|
26-
= note: `for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz}` must implement `Parser<'0>`, for any lifetime `'0`...
27-
= note: ...but it actually implements `Parser<'1>`, for some specific lifetime `'1`
26+
= note: closure with signature `for<'a> fn(&'a Wrapper<'2>) -> bool` must implement `FnOnce<(&Wrapper<'1>,)>`, for any lifetime `'1`...
27+
= note: ...but it actually implements `FnOnce<(&Wrapper<'2>,)>`, for some specific lifetime `'2`
2828

29-
error: implementation of `Parser` is not general enough
29+
error: implementation of `FnOnce` is not general enough
3030
--> $DIR/issue-71955.rs:48:5
3131
|
3232
LL | foo(baz, "string", |s| s.0.len() == 5);
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Parser` is not general enough
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
3434
|
35-
= note: `for<'a> fn(&'a str) -> (&'a str, Wrapper<'a>) {baz}` must implement `Parser<'0>`, for any lifetime `'0`...
36-
= note: ...but it actually implements `Parser<'1>`, for some specific lifetime `'1`
35+
= note: closure with signature `for<'a> fn(&'a Wrapper<'2>) -> bool` must implement `FnOnce<(&Wrapper<'1>,)>`, for any lifetime `'1`...
36+
= note: ...but it actually implements `FnOnce<(&Wrapper<'2>,)>`, for some specific lifetime `'2`
3737
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3838

3939
error: aborting due to 4 previous errors

0 commit comments

Comments
 (0)