Skip to content

Commit d08ab94

Browse files
committed
Fix rebase
1 parent e297652 commit d08ab94

29 files changed

+121
-201
lines changed

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
376376
| ty::PredicateAtom::Subtype(_)
377377
| ty::PredicateAtom::ConstEvaluatable(..)
378378
| ty::PredicateAtom::ConstEquate(..) => {
379-
let (pred, _) = infcx.replace_bound_vars_with_placeholders(binder);
379+
let pred = infcx.replace_bound_vars_with_placeholders(binder);
380380
ProcessResult::Changed(mk_pending(vec![
381381
obligation.with(pred.to_predicate(self.selcx.tcx())),
382382
]))
@@ -673,7 +673,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
673673
Ok(Ok(None)) => {
674674
*stalled_on = trait_ref_infer_vars(
675675
self.selcx,
676-
project_obligation.predicate.to_poly_trait_ref(self.selcx.tcx()),
676+
project_obligation.predicate.to_poly_trait_ref(tcx),
677677
);
678678
ProcessResult::Unchanged
679679
}

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind;
5959
pub use self::specialize::{specialization_graph, translate_substs, OverlapError};
6060
pub use self::structural_match::search_for_structural_match_violation;
6161
pub use self::structural_match::NonStructuralMatchTy;
62-
pub use self::util::subst_assoc_item_bound;
6362
pub use self::util::{elaborate_predicates, elaborate_trait_ref, elaborate_trait_refs};
6463
pub use self::util::{expand_trait_aliases, TraitAliasExpander};
6564
pub use self::util::{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
3838
use rustc_middle::ty::relate::TypeRelation;
3939
use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef};
4040
use rustc_middle::ty::{self, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
41-
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable};
41+
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, WithConstness};
4242
use rustc_span::symbol::sym;
4343

4444
use std::cell::{Cell, RefCell};

compiler/rustc_trait_selection/src/traits/util.rs

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ use smallvec::SmallVec;
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_hir::def_id::DefId;
88
use rustc_middle::ty::subst::{GenericArg, Subst, SubstsRef};
9-
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
9+
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, WithConstness};
1010

1111
use super::{Normalized, Obligation, ObligationCause, PredicateObligation, SelectionContext};
1212
pub use rustc_infer::traits::util::*;
1313

14-
use std::iter;
15-
1614
///////////////////////////////////////////////////////////////////////////
1715
// `TraitAliasExpander` iterator
1816
///////////////////////////////////////////////////////////////////////////
@@ -359,69 +357,6 @@ pub fn impl_item_is_final(tcx: TyCtxt<'_>, assoc_item: &ty::AssocItem) -> bool {
359357
assoc_item.defaultness.is_final() && tcx.impl_defaultness(assoc_item.container.id()).is_final()
360358
}
361359

362-
/// Map a bound from an associated item to apply to some other type.
363-
/// For example, given the following trait
364-
///
365-
/// trait X<A> { type Y<'a>: PartialEq<A> }
366-
///
367-
/// Say that we know that `<() as X<B>>::Y<'c> = i32` and we need to check that
368-
/// the `PartialEq` bound applies. We would then call this function with:
369-
///
370-
/// - `bound` = `<Self as X<A>>::Y<'a>: PartialEq`
371-
/// - `normalized_projection_ty` = `i32`
372-
/// - `assoc_item_substs` = `[(), B, 'c]`
373-
///
374-
/// This method would then return `i32: PartialEq<B>`.
375-
pub fn subst_assoc_item_bound<'tcx>(
376-
tcx: TyCtxt<'tcx>,
377-
bound: ty::Predicate<'tcx>,
378-
normalized_projection_ty: Ty<'tcx>,
379-
assoc_item_substs: &[GenericArg<'tcx>],
380-
) -> ty::Predicate<'tcx> {
381-
// We're substituting these inside the closure passed to map_bound, so they
382-
// can't have escaping bound regions.
383-
assert!(!normalized_projection_ty.has_escaping_bound_vars());
384-
assert!(!assoc_item_substs.iter().all(|arg| arg.has_escaping_bound_vars()));
385-
386-
let translate_predicate_substs = move |predicate_substs: SubstsRef<'tcx>| {
387-
tcx.mk_substs(
388-
iter::once(normalized_projection_ty.into())
389-
.chain(predicate_substs[1..].iter().map(|s| s.subst(tcx, assoc_item_substs))),
390-
)
391-
};
392-
393-
match bound.kind() {
394-
ty::PredicateKind::Trait(poly_tr, c) => poly_tr
395-
.map_bound(|tr| {
396-
let trait_substs = translate_predicate_substs(tr.trait_ref.substs);
397-
ty::TraitRef { def_id: tr.def_id(), substs: trait_substs }
398-
})
399-
.with_constness(*c)
400-
.to_predicate(tcx),
401-
ty::PredicateKind::Projection(poly_projection) => poly_projection
402-
.map_bound(|projection| {
403-
let projection_substs = translate_predicate_substs(projection.projection_ty.substs);
404-
ty::ProjectionPredicate {
405-
projection_ty: ty::ProjectionTy {
406-
substs: projection_substs,
407-
item_def_id: projection.projection_ty.item_def_id,
408-
},
409-
ty: projection.ty.subst(tcx, assoc_item_substs),
410-
}
411-
})
412-
.to_predicate(tcx),
413-
ty::PredicateKind::TypeOutlives(poly_outlives) => poly_outlives
414-
.map_bound(|outlives| {
415-
ty::OutlivesPredicate(
416-
normalized_projection_ty,
417-
outlives.1.subst(tcx, assoc_item_substs),
418-
)
419-
})
420-
.to_predicate(tcx),
421-
_ => bug!("unexepected projection bound: `{:?}`", bound),
422-
}
423-
}
424-
425360
pub enum TupleArgumentsFlag {
426361
Yes,
427362
No,

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
391391
cause.clone(),
392392
depth,
393393
param_env,
394-
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
394+
ty::PredicateAtom::WellFormed(arg).to_predicate(tcx),
395395
)
396396
}),
397397
);

compiler/rustc_traits/src/chalk/lowering.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -738,10 +738,10 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
738738
self,
739739
interner: &RustInterner<'tcx>,
740740
) -> Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>> {
741-
match &self.kind() {
742-
ty::PredicateKind::Trait(predicate, _) => {
741+
match self.bound_atom(interner.tcx).skip_binder() {
742+
ty::PredicateAtom::Trait(predicate, _) => {
743743
let (predicate, binders, _named_regions) =
744-
collect_bound_vars(interner, interner.tcx, predicate);
744+
collect_bound_vars(interner, interner.tcx, &ty::Binder::bind(predicate));
745745

746746
Some(chalk_ir::Binders::new(
747747
binders,
@@ -750,24 +750,24 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
750750
),
751751
))
752752
}
753-
ty::PredicateKind::Projection(predicate) => {
753+
ty::PredicateAtom::Projection(predicate) => {
754754
let (predicate, binders, _named_regions) =
755-
collect_bound_vars(interner, interner.tcx, predicate);
755+
collect_bound_vars(interner, interner.tcx, &ty::Binder::bind(predicate));
756756

757757
Some(chalk_ir::Binders::new(
758758
binders,
759759
chalk_solve::rust_ir::InlineBound::AliasEqBound(predicate.lower_into(interner)),
760760
))
761761
}
762-
ty::PredicateKind::TypeOutlives(_predicate) => None,
763-
ty::PredicateKind::WellFormed(_ty) => None,
764-
765-
ty::PredicateKind::RegionOutlives(..)
766-
| ty::PredicateKind::ObjectSafe(..)
767-
| ty::PredicateKind::ClosureKind(..)
768-
| ty::PredicateKind::Subtype(..)
769-
| ty::PredicateKind::ConstEvaluatable(..)
770-
| ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", &self),
762+
ty::PredicateAtom::TypeOutlives(_predicate) => None,
763+
ty::PredicateAtom::WellFormed(_ty) => None,
764+
765+
ty::PredicateAtom::RegionOutlives(..)
766+
| ty::PredicateAtom::ObjectSafe(..)
767+
| ty::PredicateAtom::ClosureKind(..)
768+
| ty::PredicateAtom::Subtype(..)
769+
| ty::PredicateAtom::ConstEvaluatable(..)
770+
| ty::PredicateAtom::ConstEquate(..) => bug!("unexpected predicate {}", &self),
771771
}
772772
}
773773
}

compiler/rustc_typeck/src/check/compare_method.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,36 +1225,35 @@ pub fn check_type_bounds<'tcx>(
12251225

12261226
let impl_ty_hir_id = tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local());
12271227
let normalize_cause = traits::ObligationCause::misc(impl_ty_span, impl_ty_hir_id);
1228-
let cause = ObligationCause::new(
1229-
impl_ty_span,
1230-
impl_ty_hir_id,
1231-
ObligationCauseCode::ItemObligation(trait_ty.def_id),
1232-
);
1228+
let mk_cause = |span| {
1229+
ObligationCause::new(
1230+
impl_ty_span,
1231+
impl_ty_hir_id,
1232+
ObligationCauseCode::BindingObligation(trait_ty.def_id, span),
1233+
)
1234+
};
12331235

12341236
let obligations = tcx
12351237
.explicit_item_bounds(trait_ty.def_id)
12361238
.iter()
12371239
.map(|&(bound, span)| {
1238-
let concrete_ty_bound =
1239-
traits::subst_assoc_item_bound(tcx, bound, impl_ty_value, rebased_substs);
1240+
let concrete_ty_bound = bound.subst(tcx, rebased_substs);
12401241
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
12411242

12421243
traits::Obligation::new(mk_cause(span), param_env, concrete_ty_bound)
12431244
})
12441245
.collect();
12451246
debug!("check_type_bounds: item_bounds={:?}", obligations);
12461247

1247-
for obligation in util::elaborate_obligations(tcx, obligations) {
1248-
let concrete_ty_predicate = predicate.subst(tcx, rebased_substs);
1249-
debug!("compare_projection_bounds: concrete predicate = {:?}", concrete_ty_predicate);
1250-
1248+
for mut obligation in util::elaborate_obligations(tcx, obligations) {
12511249
let traits::Normalized { value: normalized_predicate, obligations } = traits::normalize(
12521250
&mut selcx,
12531251
normalize_param_env,
12541252
normalize_cause.clone(),
1255-
&concrete_ty_predicate,
1253+
&obligation.predicate,
12561254
);
12571255
debug!("compare_projection_bounds: normalized predicate = {:?}", normalized_predicate);
1256+
obligation.predicate = normalized_predicate;
12581257

12591258
inh.register_predicates(obligations);
12601259
inh.register_predicate(obligation);

compiler/rustc_typeck/src/collect.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,8 +2137,8 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
21372137
// associated type:
21382138
// * It must use the identity substs of the item.
21392139
// * Since any generic parameters on the item are not in scope,
2140-
// this means that the item is not a GAT, and its identity substs
2141-
// are the same as the trait's.
2140+
// this means that the item is not a GAT, and its identity
2141+
// substs are the same as the trait's.
21422142
// * It must be an associated type for this trait (*not* a
21432143
// supertrait).
21442144
if let ty::Projection(projection) = ty.kind {
@@ -2158,14 +2158,12 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
21582158
.predicates
21592159
.iter()
21602160
.copied()
2161-
.filter(|(pred, _)| match pred.kind() {
2162-
ty::PredicateKind::Trait(tr, _) => !is_assoc_item_ty(tr.skip_binder().self_ty()),
2163-
ty::PredicateKind::Projection(proj) => {
2164-
!is_assoc_item_ty(proj.skip_binder().projection_ty.self_ty())
2165-
}
2166-
ty::PredicateKind::TypeOutlives(outlives) => {
2167-
!is_assoc_item_ty(outlives.skip_binder().0)
2161+
.filter(|(pred, _)| match pred.skip_binders() {
2162+
ty::PredicateAtom::Trait(tr, _) => !is_assoc_item_ty(tr.self_ty()),
2163+
ty::PredicateAtom::Projection(proj) => {
2164+
!is_assoc_item_ty(proj.projection_ty.self_ty())
21682165
}
2166+
ty::PredicateAtom::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0),
21692167
_ => true,
21702168
})
21712169
.collect();

compiler/rustc_typeck/src/collect/item_bounds.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ fn associated_type_bounds<'tcx>(
3737
let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id.expect_local());
3838

3939
let bounds_from_parent =
40-
trait_predicates.predicates.iter().copied().filter(|(pred, _)| match pred.kind() {
41-
ty::PredicateKind::Trait(tr, _) => tr.skip_binder().self_ty() == item_ty,
42-
ty::PredicateKind::Projection(proj) => {
43-
proj.skip_binder().projection_ty.self_ty() == item_ty
44-
}
45-
ty::PredicateKind::TypeOutlives(outlives) => outlives.skip_binder().0 == item_ty,
40+
trait_predicates.predicates.iter().copied().filter(|(pred, _)| match pred.skip_binders() {
41+
ty::PredicateAtom::Trait(tr, _) => tr.self_ty() == item_ty,
42+
ty::PredicateAtom::Projection(proj) => proj.projection_ty.self_ty() == item_ty,
43+
ty::PredicateAtom::TypeOutlives(outlives) => outlives.0 == item_ty,
4644
_ => false,
4745
});
4846

src/test/ui/associated-type-bounds/bounds-on-assoc-in-trait.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0277]: `<<Self as Case1>::A as std::iter::Iterator>::Item` doesn't implem
44
LL | type A: Iterator<Item: Debug>;
55
| ^^^^^ `<<Self as Case1>::A as std::iter::Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
66
|
7-
::: $SRC_DIR/libcore/fmt/mod.rs:LL:COL
7+
::: $SRC_DIR/core/src/fmt/mod.rs:LL:COL
88
|
99
LL | pub trait Debug {
1010
| --------------- required by this bound in `std::fmt::Debug`
@@ -21,7 +21,7 @@ error[E0277]: the trait bound `<<Self as Foo>::Out as Baz>::Assoc: std::default:
2121
LL | pub trait Foo { type Out: Baz<Assoc: Default>; }
2222
| ^^^^^^^ the trait `std::default::Default` is not implemented for `<<Self as Foo>::Out as Baz>::Assoc`
2323
|
24-
::: $SRC_DIR/libcore/default.rs:LL:COL
24+
::: $SRC_DIR/core/src/default.rs:LL:COL
2525
|
2626
LL | pub trait Default: Sized {
2727
| ------------------------ required by this bound in `std::default::Default`

src/test/ui/associated-types/defaults-suitability.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ trait C where
4545
bool: IsU8<Self::Assoc>,
4646
{
4747
type Assoc = u8;
48-
//~^ ERROR the trait bound `u8: IsU8<<Self as C>::Assoc>` is not satisfied
4948
}
5049

5150
// Test that we get all expected errors if that default is unsuitable
@@ -55,7 +54,7 @@ trait D where
5554
bool: IsU8<Self::Assoc>,
5655
{
5756
type Assoc = NotClone;
58-
//~^ ERROR the trait bound `NotClone: IsU8<<Self as D>::Assoc>` is not satisfied
57+
//~^ ERROR the trait bound `NotClone: IsU8<NotClone>` is not satisfied
5958
}
6059

6160
// Test behavior of the check when defaults refer to other defaults:

src/test/ui/associated-types/defaults-suitability.stderr

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,8 @@ LL | type Assoc: Foo<Self> = ();
4242
| | required by this bound in `Bar::Assoc`
4343
| the trait `Foo<Self>` is not implemented for `()`
4444

45-
error[E0277]: the trait bound `u8: IsU8<<Self as C>::Assoc>` is not satisfied
46-
--> $DIR/defaults-suitability.rs:44:5
47-
|
48-
LL | Self::Assoc: IsU8<Self::Assoc>,
49-
| ----------------- required by this bound in `C::Assoc`
50-
...
51-
LL | type Assoc = u8;
52-
| ^^^^^-----^^^^^^
53-
| | |
54-
| | required by a bound in this
55-
| the trait `IsU8<<Self as C>::Assoc>` is not implemented for `u8`
56-
57-
error[E0277]: the trait bound `NotClone: IsU8<<Self as D>::Assoc>` is not satisfied
58-
--> $DIR/defaults-suitability.rs:54:5
45+
error[E0277]: the trait bound `NotClone: IsU8<NotClone>` is not satisfied
46+
--> $DIR/defaults-suitability.rs:53:5
5947
|
6048
LL | Self::Assoc: IsU8<Self::Assoc>,
6149
| ----------------- required by this bound in `D::Assoc`
@@ -64,10 +52,10 @@ LL | type Assoc = NotClone;
6452
| ^^^^^-----^^^^^^^^^^^^
6553
| | |
6654
| | required by a bound in this
67-
| the trait `IsU8<<Self as D>::Assoc>` is not implemented for `NotClone`
55+
| the trait `IsU8<NotClone>` is not implemented for `NotClone`
6856

6957
error[E0277]: the trait bound `<Self as Foo2<T>>::Baz: std::clone::Clone` is not satisfied
70-
--> $DIR/defaults-suitability.rs:63:5
58+
--> $DIR/defaults-suitability.rs:62:5
7159
|
7260
LL | type Bar: Clone = Vec<Self::Baz>;
7361
| ^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^
@@ -82,7 +70,7 @@ LL | trait Foo2<T> where <Self as Foo2<T>>::Baz: Clone {
8270
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8371

8472
error[E0277]: the trait bound `<Self as Foo25<T>>::Baz: std::clone::Clone` is not satisfied
85-
--> $DIR/defaults-suitability.rs:72:5
73+
--> $DIR/defaults-suitability.rs:71:5
8674
|
8775
LL | type Bar: Clone = Vec<Self::Baz>;
8876
| ^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^
@@ -97,7 +85,7 @@ LL | trait Foo25<T: Clone> where <Self as Foo25<T>>::Baz: Clone {
9785
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9886

9987
error[E0277]: the trait bound `T: std::clone::Clone` is not satisfied
100-
--> $DIR/defaults-suitability.rs:84:5
88+
--> $DIR/defaults-suitability.rs:83:5
10189
|
10290
LL | Self::Baz: Clone,
10391
| ----- required by this bound in `Foo3::Baz`
@@ -113,6 +101,6 @@ help: consider further restricting type parameter `T`
113101
LL | Self::Baz: Clone, T: Clone
114102
| ^^^^^^^^^^
115103

116-
error: aborting due to 9 previous errors
104+
error: aborting due to 8 previous errors
117105

118106
For more information about this error, try `rustc --explain E0277`.

src/test/ui/associated-types/defaults-wf.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation
44
LL | type Ty = Vec<[u8]>;
55
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
66
|
7-
::: $SRC_DIR/liballoc/vec.rs:LL:COL
7+
::: $SRC_DIR/alloc/src/vec.rs:LL:COL
88
|
99
LL | pub struct Vec<T> {
1010
| - required by this bound in `std::vec::Vec`

src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ error[E0277]: the trait bound `<<Self as _Tr3>::A as std::iter::Iterator>::Item:
145145
LL | type A: Iterator<Item: Copy>;
146146
| ^^^^ the trait `std::marker::Copy` is not implemented for `<<Self as _Tr3>::A as std::iter::Iterator>::Item`
147147
|
148-
::: $SRC_DIR/libcore/marker.rs:LL:COL
148+
::: $SRC_DIR/core/src/marker.rs:LL:COL
149149
|
150150
LL | pub trait Copy: Clone {
151151
| --------------------- required by this bound in `std::marker::Copy`

src/test/ui/feature-gates/feature-gate-generic_associated_types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl PointerFamily<u32> for Foo {
1515
//~^ ERROR generic associated types are unstable
1616
type Pointer2<U32> = Box<U32>;
1717
//~^ ERROR generic associated types are unstable
18+
//~| ERROR the trait bound `U32: std::clone::Clone` is not satisfied
1819
}
1920

2021
trait Bar {

0 commit comments

Comments
 (0)