Skip to content

Commit 31a3bb5

Browse files
committed
Remove manual normalization in compare_projection_bounds
1 parent 83a9dc9 commit 31a3bb5

File tree

3 files changed

+25
-54
lines changed

3 files changed

+25
-54
lines changed

src/librustc_typeck/check/compare_method.rs

+3-50
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ use rustc_hir::{GenericParamKind, ImplItemKind, TraitItemKind};
66
use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
77
use rustc_middle::ty;
88
use rustc_middle::ty::error::{ExpectedFound, TypeError};
9-
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
9+
use rustc_middle::ty::subst::{InternalSubsts, Subst};
1010
use rustc_middle::ty::util::ExplicitSelf;
11-
use rustc_middle::ty::{GenericParamDefKind, ToPredicate, TyCtxt, WithConstness};
11+
use rustc_middle::ty::{GenericParamDefKind, ToPredicate, TyCtxt};
1212
use rustc_span::Span;
1313
use rustc_trait_selection::traits::error_reporting::InferCtxtExt;
1414
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode, Reveal};
1515

1616
use super::{potentially_plural_count, FnCtxt, Inherited};
17-
use std::iter;
1817

1918
/// Checks that a method from an impl conforms to the signature of
2019
/// the same method as declared in the trait.
@@ -1240,22 +1239,6 @@ fn compare_projection_bounds<'tcx>(
12401239
ty::ParamEnv::new(tcx.intern_predicates(&predicates), Reveal::UserFacing, None)
12411240
};
12421241

1243-
// Map the predicate from the trait to the corresponding one for the impl.
1244-
// For example:
1245-
//
1246-
// trait X<A> { type Y<'a>: PartialEq<A> } impl X for T { type Y<'a> = &'a S; }
1247-
// impl<'x> X<&'x u32> for () { type Y<'c> = &'c u32; }
1248-
//
1249-
// For the `for<'a> <<Self as X<A>>::Y<'a>: PartialEq<A>` bound, this
1250-
// function would translate and partially normalize
1251-
// `[<Self as X<A>>::Y<'a>, A]` to `[&'a u32, &'x u32]`.
1252-
let translate_predicate_substs = move |predicate_substs: SubstsRef<'tcx>| {
1253-
tcx.mk_substs(
1254-
iter::once(impl_ty_value.into())
1255-
.chain(predicate_substs[1..].iter().map(|s| s.subst(tcx, rebased_substs))),
1256-
)
1257-
};
1258-
12591242
tcx.infer_ctxt().enter(move |infcx| {
12601243
let inh = Inherited::new(infcx, impl_ty.def_id.expect_local());
12611244
let infcx = &inh.infcx;
@@ -1270,39 +1253,10 @@ fn compare_projection_bounds<'tcx>(
12701253
);
12711254

12721255
let predicates = tcx.projection_predicates(trait_ty.def_id);
1273-
12741256
debug!("compare_projection_bounds: projection_predicates={:?}", predicates);
12751257

12761258
for predicate in predicates {
1277-
let concrete_ty_predicate = match predicate.kind() {
1278-
ty::PredicateKind::Trait(poly_tr, c) => poly_tr
1279-
.map_bound(|tr| {
1280-
let trait_substs = translate_predicate_substs(tr.trait_ref.substs);
1281-
ty::TraitRef { def_id: tr.def_id(), substs: trait_substs }
1282-
})
1283-
.with_constness(*c)
1284-
.to_predicate(tcx),
1285-
ty::PredicateKind::Projection(poly_projection) => poly_projection
1286-
.map_bound(|projection| {
1287-
let projection_substs =
1288-
translate_predicate_substs(projection.projection_ty.substs);
1289-
ty::ProjectionPredicate {
1290-
projection_ty: ty::ProjectionTy {
1291-
substs: projection_substs,
1292-
item_def_id: projection.projection_ty.item_def_id,
1293-
},
1294-
ty: projection.ty.subst(tcx, rebased_substs),
1295-
}
1296-
})
1297-
.to_predicate(tcx),
1298-
ty::PredicateKind::TypeOutlives(poly_outlives) => poly_outlives
1299-
.map_bound(|outlives| {
1300-
ty::OutlivesPredicate(impl_ty_value, outlives.1.subst(tcx, rebased_substs))
1301-
})
1302-
.to_predicate(tcx),
1303-
_ => bug!("unexepected projection predicate kind: `{:?}`", predicate),
1304-
};
1305-
1259+
let concrete_ty_predicate = predicate.subst(tcx, rebased_substs);
13061260
debug!("compare_projection_bounds: concrete predicate = {:?}", concrete_ty_predicate);
13071261

13081262
let traits::Normalized { value: normalized_predicate, obligations } = traits::normalize(
@@ -1311,7 +1265,6 @@ fn compare_projection_bounds<'tcx>(
13111265
normalize_cause.clone(),
13121266
&concrete_ty_predicate,
13131267
);
1314-
13151268
debug!("compare_projection_bounds: normalized predicate = {:?}", normalized_predicate);
13161269

13171270
inh.register_predicates(obligations);

src/test/ui/generic-associated-types/unsatisfied-outlives-bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait ATy {
77

88
impl<'b> ATy for &'b () {
99
type Item<'a> = &'b ();
10-
//~^ ERROR does not fulfill the required lifetime
10+
//~^ ERROR cannot infer an appropriate lifetime
1111
}
1212

1313
trait StaticTy {

src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1-
error[E0477]: the type `&'b ()` does not fulfill the required lifetime
1+
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements
22
--> $DIR/unsatisfied-outlives-bound.rs:9:5
33
|
44
LL | type Item<'a> = &'b ();
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: type must outlive the lifetime `'a` as defined on the associated item at 9:15
7+
note: first, the lifetime cannot outlive the lifetime `'b` as defined on the impl at 8:6...
8+
--> $DIR/unsatisfied-outlives-bound.rs:8:6
9+
|
10+
LL | impl<'b> ATy for &'b () {
11+
| ^^
12+
note: ...so that the types are compatible
13+
--> $DIR/unsatisfied-outlives-bound.rs:9:5
14+
|
15+
LL | type Item<'a> = &'b ();
16+
| ^^^^^^^^^^^^^^^^^^^^^^^
17+
= note: expected `ATy`
18+
found `ATy`
19+
note: but, the lifetime must be valid for the lifetime `'a` as defined on the associated item at 9:15...
820
--> $DIR/unsatisfied-outlives-bound.rs:9:15
921
|
1022
LL | type Item<'a> = &'b ();
1123
| ^^
24+
note: ...so that the type `&()` will meet its required lifetime bounds
25+
--> $DIR/unsatisfied-outlives-bound.rs:9:5
26+
|
27+
LL | type Item<'a> = &'b ();
28+
| ^^^^^^^^^^^^^^^^^^^^^^^
1229

1330
error[E0477]: the type `&'a ()` does not fulfill the required lifetime
1431
--> $DIR/unsatisfied-outlives-bound.rs:18:5
@@ -20,4 +37,5 @@ LL | type Item<'a> = &'a ();
2037

2138
error: aborting due to 2 previous errors
2239

23-
For more information about this error, try `rustc --explain E0477`.
40+
Some errors have detailed explanations: E0477, E0495.
41+
For more information about an error, try `rustc --explain E0477`.

0 commit comments

Comments
 (0)