Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Regueiro committed Nov 11, 2018
1 parent 653da4f commit faed02c
Showing 18 changed files with 218 additions and 162 deletions.
3 changes: 3 additions & 0 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
@@ -184,6 +184,9 @@ for ty::adjustment::Adjust<'gcx> {
ty::adjustment::Adjust::ClosureFnPointer |
ty::adjustment::Adjust::MutToConstPointer |
ty::adjustment::Adjust::Unsize => {}
ty::adjustment::Adjust::Hide(ref revealed_ty) => {
revealed_ty.hash_stable(hcx, hasher);
}
ty::adjustment::Adjust::Deref(ref overloaded) => {
overloaded.hash_stable(hcx, hasher);
}
1 change: 1 addition & 0 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
@@ -721,6 +721,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
adjustment::Adjust::UnsafeFnPointer |
adjustment::Adjust::ClosureFnPointer |
adjustment::Adjust::MutToConstPointer |
adjustment::Adjust::Hide(_) |
adjustment::Adjust::Unsize => {
// Creating a closure/fn-pointer or unsizing consumes
// the input and stores it into the resulting rvalue.
1 change: 1 addition & 0 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
@@ -631,6 +631,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
adjustment::Adjust::ClosureFnPointer |
adjustment::Adjust::MutToConstPointer |
adjustment::Adjust::Borrow(_) |
adjustment::Adjust::Hide(_) |
adjustment::Adjust::Unsize => {
// Result is an rvalue.
Ok(self.cat_rvalue_node(expr.hir_id, expr.span, target))
4 changes: 2 additions & 2 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ pub enum TraitQueryMode {
Canonical,
}

/// An `Obligation` represents some trait reference (e.g. `int:Eq`) for
/// An `Obligation` represents some trait reference (e.g. `int: Eq`) for
/// which the vtable must be found. The process of finding a vtable is
/// called "resolving" the `Obligation`. This process consists of
/// either identifying an `impl` (e.g., `impl Eq for int`) that
@@ -1015,7 +1015,7 @@ fn vtable_methods<'a, 'tcx>(
)
}

impl<'tcx,O> Obligation<'tcx,O> {
impl<'tcx, O> Obligation<'tcx, O> {
pub fn new(cause: ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>,
predicate: O)
2 changes: 1 addition & 1 deletion src/librustc/traits/util.rs
Original file line number Diff line number Diff line change
@@ -393,7 +393,7 @@ pub fn impl_trait_ref_and_oblig<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a,
(impl_trait_ref, impl_obligations)
}

/// See `super::obligations_for_generics`
/// See `super::predicates_for_generics`.
pub fn predicates_for_generics<'tcx>(cause: ObligationCause<'tcx>,
recursion_depth: usize,
param_env: ty::ParamEnv<'tcx>,
3 changes: 3 additions & 0 deletions src/librustc/ty/adjustment.rs
Original file line number Diff line number Diff line change
@@ -83,6 +83,9 @@ pub enum Adjust<'tcx> {
/// Take the address and produce either a `&` or `*` pointer.
Borrow(AutoBorrow<'tcx>),

/// Hide a value with an opaque type.
Hide(Ty<'tcx>),

/// Unsize a pointer/reference value, e.g. `&[T; n]` to
/// `&[T]`. Note that the source could be a thin or fat pointer.
/// This will do things like convert thin pointers to fat
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -993,6 +993,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
self.instantiate_into(tcx, &mut instantiated, substs);
instantiated
}

pub fn instantiate_own(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, substs: &Substs<'tcx>)
-> InstantiatedPredicates<'tcx> {
InstantiatedPredicates {
@@ -1028,8 +1029,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {

pub fn instantiate_supertrait(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
poly_trait_ref: &ty::PolyTraitRef<'tcx>)
-> InstantiatedPredicates<'tcx>
{
-> InstantiatedPredicates<'tcx> {
assert_eq!(self.parent, None);
InstantiatedPredicates {
predicates: self.predicates.iter().map(|(pred, _)| {
3 changes: 3 additions & 0 deletions src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
@@ -346,6 +346,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
Some(ty::adjustment::Adjust::ClosureFnPointer),
ty::adjustment::Adjust::MutToConstPointer =>
Some(ty::adjustment::Adjust::MutToConstPointer),
ty::adjustment::Adjust::Hide(ref revealed_ty) =>
tcx.lift(revealed_ty).map(ty::adjustment::Adjust::Hide),
ty::adjustment::Adjust::Unsize =>
Some(ty::adjustment::Adjust::Unsize),
ty::adjustment::Adjust::Deref(ref overloaded) => {
@@ -881,6 +883,7 @@ EnumTypeFoldableImpl! {
(ty::adjustment::Adjust::UnsafeFnPointer),
(ty::adjustment::Adjust::ClosureFnPointer),
(ty::adjustment::Adjust::MutToConstPointer),
(ty::adjustment::Adjust::Hide)(a),
(ty::adjustment::Adjust::Unsize),
(ty::adjustment::Adjust::Deref)(a),
(ty::adjustment::Adjust::Borrow)(a),
10 changes: 5 additions & 5 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
@@ -190,8 +190,8 @@ pub enum TyKind<'tcx> {

/// Opaque (`impl Trait`) type found in a return type.
/// The `DefId` comes either from
/// * the `impl Trait` ast::Ty node,
/// * or the `existential type` declaration
/// * the `impl Trait` `ast::Ty` node,
/// * the `existential type` declaration.
/// The substitutions are for the generics of the function in question.
/// After typeck, the concrete type can be found in the `types` map.
Opaque(DefId, &'tcx Substs<'tcx>),
@@ -582,7 +582,7 @@ impl<'tcx> List<ExistentialPredicate<'tcx>> {

#[inline]
pub fn projection_bounds<'a>(&'a self) ->
impl Iterator<Item=ExistentialProjection<'tcx>> + 'a {
impl Iterator<Item = ExistentialProjection<'tcx>> + 'a {
self.iter().filter_map(|predicate| {
match *predicate {
ExistentialPredicate::Projection(p) => Some(p),
@@ -592,7 +592,7 @@ impl<'tcx> List<ExistentialPredicate<'tcx>> {
}

#[inline]
pub fn auto_traits<'a>(&'a self) -> impl Iterator<Item=DefId> + 'a {
pub fn auto_traits<'a>(&'a self) -> impl Iterator<Item = DefId> + 'a {
self.iter().filter_map(|predicate| {
match *predicate {
ExistentialPredicate::AutoTrait(d) => Some(d),
@@ -619,7 +619,7 @@ impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> {
}

pub fn iter<'a>(&'a self)
-> impl DoubleEndedIterator<Item=Binder<ExistentialPredicate<'tcx>>> + 'tcx {
-> impl DoubleEndedIterator<Item = Binder<ExistentialPredicate<'tcx>>> + 'tcx {
self.skip_binder().iter().cloned().map(Binder::bind)
}
}
14 changes: 13 additions & 1 deletion src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
@@ -206,8 +206,20 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
// since they get rid of a borrow implicitly.
ExprKind::Use { source: cast_expr.to_ref() }
}
Adjust::Hide(revealed_ty) => {
// See the above comment for Adjust::Deref.
if let ExprKind::Block { body } = expr.kind {
if let Some(ref last_expr) = body.expr {
span = last_expr.span;
expr.span = span;
}
}
expr.ty = revealed_ty;
debug!("hide: {:?} {:?}", expr, revealed_ty);
ExprKind::Cast { source: expr.to_ref() }
}
Adjust::Unsize => {
// See the above comment for Adjust::Deref
// See the above comment for Adjust::Deref.
if let ExprKind::Block { body } = expr.kind {
if let Some(ref last_expr) = body.expr {
span = last_expr.span;
3 changes: 3 additions & 0 deletions src/librustc_mir/hair/mod.rs
Original file line number Diff line number Diff line change
@@ -193,6 +193,9 @@ pub enum ExprKind<'tcx> {
UnsafeFnPointer {
source: ExprRef<'tcx>,
},
// Hide {
// source: ExprRef<'tcx>,
// },
Unsize {
source: ExprRef<'tcx>,
},
1 change: 1 addition & 0 deletions src/librustc_passes/rvalue_promotion.rs
Original file line number Diff line number Diff line change
@@ -615,6 +615,7 @@ fn check_adjustments<'a, 'tcx>(
Adjust::ClosureFnPointer |
Adjust::MutToConstPointer |
Adjust::Borrow(_) |
Adjust::Hide(_) |
Adjust::Unsize => {}

Adjust::Deref(_) => {
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
@@ -234,7 +234,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
.pat_binding_modes_mut()
.insert(pat.hir_id, bm);
debug!("check_pat_walk: pat.hir_id={:?} bm={:?}", pat.hir_id, bm);
let local_ty = self.local_ty(pat.span, pat.id).decl_ty;
let local_ty = self.local_ty(pat.span, pat.id);
match bm {
ty::BindByReference(mutbl) => {
// if the binding is like
@@ -261,7 +261,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// if there are multiple arms, make sure they all agree on
// what the type of the binding `x` ought to be
if var_id != pat.id {
let vt = self.local_ty(pat.span, var_id).decl_ty;
let vt = self.local_ty(pat.span, var_id);
self.demand_eqtype(pat.span, vt, local_ty);
}

Loading

0 comments on commit faed02c

Please sign in to comment.