Skip to content

Commit

Permalink
Fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Oct 6, 2020
1 parent e297652 commit d08ab94
Show file tree
Hide file tree
Showing 29 changed files with 121 additions and 201 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
| ty::PredicateAtom::Subtype(_)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => {
let (pred, _) = infcx.replace_bound_vars_with_placeholders(binder);
let pred = infcx.replace_bound_vars_with_placeholders(binder);
ProcessResult::Changed(mk_pending(vec![
obligation.with(pred.to_predicate(self.selcx.tcx())),
]))
Expand Down Expand Up @@ -673,7 +673,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
Ok(Ok(None)) => {
*stalled_on = trait_ref_infer_vars(
self.selcx,
project_obligation.predicate.to_poly_trait_ref(self.selcx.tcx()),
project_obligation.predicate.to_poly_trait_ref(tcx),
);
ProcessResult::Unchanged
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind;
pub use self::specialize::{specialization_graph, translate_substs, OverlapError};
pub use self::structural_match::search_for_structural_match_violation;
pub use self::structural_match::NonStructuralMatchTy;
pub use self::util::subst_assoc_item_bound;
pub use self::util::{elaborate_predicates, elaborate_trait_ref, elaborate_trait_refs};
pub use self::util::{expand_trait_aliases, TraitAliasExpander};
pub use self::util::{
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef};
use rustc_middle::ty::{self, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable};
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, WithConstness};
use rustc_span::symbol::sym;

use std::cell::{Cell, RefCell};
Expand Down
67 changes: 1 addition & 66 deletions compiler/rustc_trait_selection/src/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ use smallvec::SmallVec;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::subst::{GenericArg, Subst, SubstsRef};
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, WithConstness};

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

use std::iter;

///////////////////////////////////////////////////////////////////////////
// `TraitAliasExpander` iterator
///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -359,69 +357,6 @@ pub fn impl_item_is_final(tcx: TyCtxt<'_>, assoc_item: &ty::AssocItem) -> bool {
assoc_item.defaultness.is_final() && tcx.impl_defaultness(assoc_item.container.id()).is_final()
}

/// Map a bound from an associated item to apply to some other type.
/// For example, given the following trait
///
/// trait X<A> { type Y<'a>: PartialEq<A> }
///
/// Say that we know that `<() as X<B>>::Y<'c> = i32` and we need to check that
/// the `PartialEq` bound applies. We would then call this function with:
///
/// - `bound` = `<Self as X<A>>::Y<'a>: PartialEq`
/// - `normalized_projection_ty` = `i32`
/// - `assoc_item_substs` = `[(), B, 'c]`
///
/// This method would then return `i32: PartialEq<B>`.
pub fn subst_assoc_item_bound<'tcx>(
tcx: TyCtxt<'tcx>,
bound: ty::Predicate<'tcx>,
normalized_projection_ty: Ty<'tcx>,
assoc_item_substs: &[GenericArg<'tcx>],
) -> ty::Predicate<'tcx> {
// We're substituting these inside the closure passed to map_bound, so they
// can't have escaping bound regions.
assert!(!normalized_projection_ty.has_escaping_bound_vars());
assert!(!assoc_item_substs.iter().all(|arg| arg.has_escaping_bound_vars()));

let translate_predicate_substs = move |predicate_substs: SubstsRef<'tcx>| {
tcx.mk_substs(
iter::once(normalized_projection_ty.into())
.chain(predicate_substs[1..].iter().map(|s| s.subst(tcx, assoc_item_substs))),
)
};

match bound.kind() {
ty::PredicateKind::Trait(poly_tr, c) => poly_tr
.map_bound(|tr| {
let trait_substs = translate_predicate_substs(tr.trait_ref.substs);
ty::TraitRef { def_id: tr.def_id(), substs: trait_substs }
})
.with_constness(*c)
.to_predicate(tcx),
ty::PredicateKind::Projection(poly_projection) => poly_projection
.map_bound(|projection| {
let projection_substs = translate_predicate_substs(projection.projection_ty.substs);
ty::ProjectionPredicate {
projection_ty: ty::ProjectionTy {
substs: projection_substs,
item_def_id: projection.projection_ty.item_def_id,
},
ty: projection.ty.subst(tcx, assoc_item_substs),
}
})
.to_predicate(tcx),
ty::PredicateKind::TypeOutlives(poly_outlives) => poly_outlives
.map_bound(|outlives| {
ty::OutlivesPredicate(
normalized_projection_ty,
outlives.1.subst(tcx, assoc_item_substs),
)
})
.to_predicate(tcx),
_ => bug!("unexepected projection bound: `{:?}`", bound),
}
}

pub enum TupleArgumentsFlag {
Yes,
No,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
cause.clone(),
depth,
param_env,
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
ty::PredicateAtom::WellFormed(arg).to_predicate(tcx),
)
}),
);
Expand Down
28 changes: 14 additions & 14 deletions compiler/rustc_traits/src/chalk/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,10 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
self,
interner: &RustInterner<'tcx>,
) -> Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>> {
match &self.kind() {
ty::PredicateKind::Trait(predicate, _) => {
match self.bound_atom(interner.tcx).skip_binder() {
ty::PredicateAtom::Trait(predicate, _) => {
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, predicate);
collect_bound_vars(interner, interner.tcx, &ty::Binder::bind(predicate));

Some(chalk_ir::Binders::new(
binders,
Expand All @@ -750,24 +750,24 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
),
))
}
ty::PredicateKind::Projection(predicate) => {
ty::PredicateAtom::Projection(predicate) => {
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, predicate);
collect_bound_vars(interner, interner.tcx, &ty::Binder::bind(predicate));

Some(chalk_ir::Binders::new(
binders,
chalk_solve::rust_ir::InlineBound::AliasEqBound(predicate.lower_into(interner)),
))
}
ty::PredicateKind::TypeOutlives(_predicate) => None,
ty::PredicateKind::WellFormed(_ty) => None,

ty::PredicateKind::RegionOutlives(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", &self),
ty::PredicateAtom::TypeOutlives(_predicate) => None,
ty::PredicateAtom::WellFormed(_ty) => None,

ty::PredicateAtom::RegionOutlives(..)
| ty::PredicateAtom::ObjectSafe(..)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => bug!("unexpected predicate {}", &self),
}
}
}
Expand Down
23 changes: 11 additions & 12 deletions compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,36 +1225,35 @@ pub fn check_type_bounds<'tcx>(

let impl_ty_hir_id = tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local());
let normalize_cause = traits::ObligationCause::misc(impl_ty_span, impl_ty_hir_id);
let cause = ObligationCause::new(
impl_ty_span,
impl_ty_hir_id,
ObligationCauseCode::ItemObligation(trait_ty.def_id),
);
let mk_cause = |span| {
ObligationCause::new(
impl_ty_span,
impl_ty_hir_id,
ObligationCauseCode::BindingObligation(trait_ty.def_id, span),
)
};

let obligations = tcx
.explicit_item_bounds(trait_ty.def_id)
.iter()
.map(|&(bound, span)| {
let concrete_ty_bound =
traits::subst_assoc_item_bound(tcx, bound, impl_ty_value, rebased_substs);
let concrete_ty_bound = bound.subst(tcx, rebased_substs);
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);

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

for obligation in util::elaborate_obligations(tcx, obligations) {
let concrete_ty_predicate = predicate.subst(tcx, rebased_substs);
debug!("compare_projection_bounds: concrete predicate = {:?}", concrete_ty_predicate);

for mut obligation in util::elaborate_obligations(tcx, obligations) {
let traits::Normalized { value: normalized_predicate, obligations } = traits::normalize(
&mut selcx,
normalize_param_env,
normalize_cause.clone(),
&concrete_ty_predicate,
&obligation.predicate,
);
debug!("compare_projection_bounds: normalized predicate = {:?}", normalized_predicate);
obligation.predicate = normalized_predicate;

inh.register_predicates(obligations);
inh.register_predicate(obligation);
Expand Down
16 changes: 7 additions & 9 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2137,8 +2137,8 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
// associated type:
// * It must use the identity substs of the item.
// * Since any generic parameters on the item are not in scope,
// this means that the item is not a GAT, and its identity substs
// are the same as the trait's.
// this means that the item is not a GAT, and its identity
// substs are the same as the trait's.
// * It must be an associated type for this trait (*not* a
// supertrait).
if let ty::Projection(projection) = ty.kind {
Expand All @@ -2158,14 +2158,12 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
.predicates
.iter()
.copied()
.filter(|(pred, _)| match pred.kind() {
ty::PredicateKind::Trait(tr, _) => !is_assoc_item_ty(tr.skip_binder().self_ty()),
ty::PredicateKind::Projection(proj) => {
!is_assoc_item_ty(proj.skip_binder().projection_ty.self_ty())
}
ty::PredicateKind::TypeOutlives(outlives) => {
!is_assoc_item_ty(outlives.skip_binder().0)
.filter(|(pred, _)| match pred.skip_binders() {
ty::PredicateAtom::Trait(tr, _) => !is_assoc_item_ty(tr.self_ty()),
ty::PredicateAtom::Projection(proj) => {
!is_assoc_item_ty(proj.projection_ty.self_ty())
}
ty::PredicateAtom::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0),
_ => true,
})
.collect();
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_typeck/src/collect/item_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ fn associated_type_bounds<'tcx>(
let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id.expect_local());

let bounds_from_parent =
trait_predicates.predicates.iter().copied().filter(|(pred, _)| match pred.kind() {
ty::PredicateKind::Trait(tr, _) => tr.skip_binder().self_ty() == item_ty,
ty::PredicateKind::Projection(proj) => {
proj.skip_binder().projection_ty.self_ty() == item_ty
}
ty::PredicateKind::TypeOutlives(outlives) => outlives.skip_binder().0 == item_ty,
trait_predicates.predicates.iter().copied().filter(|(pred, _)| match pred.skip_binders() {
ty::PredicateAtom::Trait(tr, _) => tr.self_ty() == item_ty,
ty::PredicateAtom::Projection(proj) => proj.projection_ty.self_ty() == item_ty,
ty::PredicateAtom::TypeOutlives(outlives) => outlives.0 == item_ty,
_ => false,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0277]: `<<Self as Case1>::A as std::iter::Iterator>::Item` doesn't implem
LL | type A: Iterator<Item: Debug>;
| ^^^^^ `<<Self as Case1>::A as std::iter::Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
::: $SRC_DIR/libcore/fmt/mod.rs:LL:COL
::: $SRC_DIR/core/src/fmt/mod.rs:LL:COL
|
LL | pub trait Debug {
| --------------- required by this bound in `std::fmt::Debug`
Expand All @@ -21,7 +21,7 @@ error[E0277]: the trait bound `<<Self as Foo>::Out as Baz>::Assoc: std::default:
LL | pub trait Foo { type Out: Baz<Assoc: Default>; }
| ^^^^^^^ the trait `std::default::Default` is not implemented for `<<Self as Foo>::Out as Baz>::Assoc`
|
::: $SRC_DIR/libcore/default.rs:LL:COL
::: $SRC_DIR/core/src/default.rs:LL:COL
|
LL | pub trait Default: Sized {
| ------------------------ required by this bound in `std::default::Default`
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/associated-types/defaults-suitability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ trait C where
bool: IsU8<Self::Assoc>,
{
type Assoc = u8;
//~^ ERROR the trait bound `u8: IsU8<<Self as C>::Assoc>` is not satisfied
}

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

// Test behavior of the check when defaults refer to other defaults:
Expand Down
26 changes: 7 additions & 19 deletions src/test/ui/associated-types/defaults-suitability.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,8 @@ LL | type Assoc: Foo<Self> = ();
| | required by this bound in `Bar::Assoc`
| the trait `Foo<Self>` is not implemented for `()`

error[E0277]: the trait bound `u8: IsU8<<Self as C>::Assoc>` is not satisfied
--> $DIR/defaults-suitability.rs:44:5
|
LL | Self::Assoc: IsU8<Self::Assoc>,
| ----------------- required by this bound in `C::Assoc`
...
LL | type Assoc = u8;
| ^^^^^-----^^^^^^
| | |
| | required by a bound in this
| the trait `IsU8<<Self as C>::Assoc>` is not implemented for `u8`

error[E0277]: the trait bound `NotClone: IsU8<<Self as D>::Assoc>` is not satisfied
--> $DIR/defaults-suitability.rs:54:5
error[E0277]: the trait bound `NotClone: IsU8<NotClone>` is not satisfied
--> $DIR/defaults-suitability.rs:53:5
|
LL | Self::Assoc: IsU8<Self::Assoc>,
| ----------------- required by this bound in `D::Assoc`
Expand All @@ -64,10 +52,10 @@ LL | type Assoc = NotClone;
| ^^^^^-----^^^^^^^^^^^^
| | |
| | required by a bound in this
| the trait `IsU8<<Self as D>::Assoc>` is not implemented for `NotClone`
| the trait `IsU8<NotClone>` is not implemented for `NotClone`

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

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

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

error: aborting due to 9 previous errors
error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0277`.
2 changes: 1 addition & 1 deletion src/test/ui/associated-types/defaults-wf.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation
LL | type Ty = Vec<[u8]>;
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
::: $SRC_DIR/liballoc/vec.rs:LL:COL
::: $SRC_DIR/alloc/src/vec.rs:LL:COL
|
LL | pub struct Vec<T> {
| - required by this bound in `std::vec::Vec`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ error[E0277]: the trait bound `<<Self as _Tr3>::A as std::iter::Iterator>::Item:
LL | type A: Iterator<Item: Copy>;
| ^^^^ the trait `std::marker::Copy` is not implemented for `<<Self as _Tr3>::A as std::iter::Iterator>::Item`
|
::: $SRC_DIR/libcore/marker.rs:LL:COL
::: $SRC_DIR/core/src/marker.rs:LL:COL
|
LL | pub trait Copy: Clone {
| --------------------- required by this bound in `std::marker::Copy`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ impl PointerFamily<u32> for Foo {
//~^ ERROR generic associated types are unstable
type Pointer2<U32> = Box<U32>;
//~^ ERROR generic associated types are unstable
//~| ERROR the trait bound `U32: std::clone::Clone` is not satisfied
}

trait Bar {
Expand Down
Loading

0 comments on commit d08ab94

Please sign in to comment.