Skip to content

Commit faed02c

Browse files
author
Alexander Regueiro
committed
WIP
1 parent 653da4f commit faed02c

File tree

18 files changed

+218
-162
lines changed

18 files changed

+218
-162
lines changed

src/librustc/ich/impls_ty.rs

+3
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ for ty::adjustment::Adjust<'gcx> {
184184
ty::adjustment::Adjust::ClosureFnPointer |
185185
ty::adjustment::Adjust::MutToConstPointer |
186186
ty::adjustment::Adjust::Unsize => {}
187+
ty::adjustment::Adjust::Hide(ref revealed_ty) => {
188+
revealed_ty.hash_stable(hcx, hasher);
189+
}
187190
ty::adjustment::Adjust::Deref(ref overloaded) => {
188191
overloaded.hash_stable(hcx, hasher);
189192
}

src/librustc/middle/expr_use_visitor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
721721
adjustment::Adjust::UnsafeFnPointer |
722722
adjustment::Adjust::ClosureFnPointer |
723723
adjustment::Adjust::MutToConstPointer |
724+
adjustment::Adjust::Hide(_) |
724725
adjustment::Adjust::Unsize => {
725726
// Creating a closure/fn-pointer or unsizing consumes
726727
// the input and stores it into the resulting rvalue.

src/librustc/middle/mem_categorization.rs

+1
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
631631
adjustment::Adjust::ClosureFnPointer |
632632
adjustment::Adjust::MutToConstPointer |
633633
adjustment::Adjust::Borrow(_) |
634+
adjustment::Adjust::Hide(_) |
634635
adjustment::Adjust::Unsize => {
635636
// Result is an rvalue.
636637
Ok(self.cat_rvalue_node(expr.hir_id, expr.span, target))

src/librustc/traits/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub enum TraitQueryMode {
9494
Canonical,
9595
}
9696

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

1018-
impl<'tcx,O> Obligation<'tcx,O> {
1018+
impl<'tcx, O> Obligation<'tcx, O> {
10191019
pub fn new(cause: ObligationCause<'tcx>,
10201020
param_env: ty::ParamEnv<'tcx>,
10211021
predicate: O)

src/librustc/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ pub fn impl_trait_ref_and_oblig<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a,
393393
(impl_trait_ref, impl_obligations)
394394
}
395395

396-
/// See `super::obligations_for_generics`
396+
/// See `super::predicates_for_generics`.
397397
pub fn predicates_for_generics<'tcx>(cause: ObligationCause<'tcx>,
398398
recursion_depth: usize,
399399
param_env: ty::ParamEnv<'tcx>,

src/librustc/ty/adjustment.rs

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ pub enum Adjust<'tcx> {
8383
/// Take the address and produce either a `&` or `*` pointer.
8484
Borrow(AutoBorrow<'tcx>),
8585

86+
/// Hide a value with an opaque type.
87+
Hide(Ty<'tcx>),
88+
8689
/// Unsize a pointer/reference value, e.g. `&[T; n]` to
8790
/// `&[T]`. Note that the source could be a thin or fat pointer.
8891
/// This will do things like convert thin pointers to fat

src/librustc/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
993993
self.instantiate_into(tcx, &mut instantiated, substs);
994994
instantiated
995995
}
996+
996997
pub fn instantiate_own(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, substs: &Substs<'tcx>)
997998
-> InstantiatedPredicates<'tcx> {
998999
InstantiatedPredicates {
@@ -1028,8 +1029,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
10281029

10291030
pub fn instantiate_supertrait(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
10301031
poly_trait_ref: &ty::PolyTraitRef<'tcx>)
1031-
-> InstantiatedPredicates<'tcx>
1032-
{
1032+
-> InstantiatedPredicates<'tcx> {
10331033
assert_eq!(self.parent, None);
10341034
InstantiatedPredicates {
10351035
predicates: self.predicates.iter().map(|(pred, _)| {

src/librustc/ty/structural_impls.rs

+3
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
346346
Some(ty::adjustment::Adjust::ClosureFnPointer),
347347
ty::adjustment::Adjust::MutToConstPointer =>
348348
Some(ty::adjustment::Adjust::MutToConstPointer),
349+
ty::adjustment::Adjust::Hide(ref revealed_ty) =>
350+
tcx.lift(revealed_ty).map(ty::adjustment::Adjust::Hide),
349351
ty::adjustment::Adjust::Unsize =>
350352
Some(ty::adjustment::Adjust::Unsize),
351353
ty::adjustment::Adjust::Deref(ref overloaded) => {
@@ -881,6 +883,7 @@ EnumTypeFoldableImpl! {
881883
(ty::adjustment::Adjust::UnsafeFnPointer),
882884
(ty::adjustment::Adjust::ClosureFnPointer),
883885
(ty::adjustment::Adjust::MutToConstPointer),
886+
(ty::adjustment::Adjust::Hide)(a),
884887
(ty::adjustment::Adjust::Unsize),
885888
(ty::adjustment::Adjust::Deref)(a),
886889
(ty::adjustment::Adjust::Borrow)(a),

src/librustc/ty/sty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ pub enum TyKind<'tcx> {
190190

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

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

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

621621
pub fn iter<'a>(&'a self)
622-
-> impl DoubleEndedIterator<Item=Binder<ExistentialPredicate<'tcx>>> + 'tcx {
622+
-> impl DoubleEndedIterator<Item = Binder<ExistentialPredicate<'tcx>>> + 'tcx {
623623
self.skip_binder().iter().cloned().map(Binder::bind)
624624
}
625625
}

src/librustc_mir/hair/cx/expr.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,20 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
206206
// since they get rid of a borrow implicitly.
207207
ExprKind::Use { source: cast_expr.to_ref() }
208208
}
209+
Adjust::Hide(revealed_ty) => {
210+
// See the above comment for Adjust::Deref.
211+
if let ExprKind::Block { body } = expr.kind {
212+
if let Some(ref last_expr) = body.expr {
213+
span = last_expr.span;
214+
expr.span = span;
215+
}
216+
}
217+
expr.ty = revealed_ty;
218+
debug!("hide: {:?} {:?}", expr, revealed_ty);
219+
ExprKind::Cast { source: expr.to_ref() }
220+
}
209221
Adjust::Unsize => {
210-
// See the above comment for Adjust::Deref
222+
// See the above comment for Adjust::Deref.
211223
if let ExprKind::Block { body } = expr.kind {
212224
if let Some(ref last_expr) = body.expr {
213225
span = last_expr.span;

src/librustc_mir/hair/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ pub enum ExprKind<'tcx> {
193193
UnsafeFnPointer {
194194
source: ExprRef<'tcx>,
195195
},
196+
// Hide {
197+
// source: ExprRef<'tcx>,
198+
// },
196199
Unsize {
197200
source: ExprRef<'tcx>,
198201
},

src/librustc_passes/rvalue_promotion.rs

+1
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ fn check_adjustments<'a, 'tcx>(
615615
Adjust::ClosureFnPointer |
616616
Adjust::MutToConstPointer |
617617
Adjust::Borrow(_) |
618+
Adjust::Hide(_) |
618619
Adjust::Unsize => {}
619620

620621
Adjust::Deref(_) => {

src/librustc_typeck/check/_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
234234
.pat_binding_modes_mut()
235235
.insert(pat.hir_id, bm);
236236
debug!("check_pat_walk: pat.hir_id={:?} bm={:?}", pat.hir_id, bm);
237-
let local_ty = self.local_ty(pat.span, pat.id).decl_ty;
237+
let local_ty = self.local_ty(pat.span, pat.id);
238238
match bm {
239239
ty::BindByReference(mutbl) => {
240240
// if the binding is like
@@ -261,7 +261,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
261261
// if there are multiple arms, make sure they all agree on
262262
// what the type of the binding `x` ought to be
263263
if var_id != pat.id {
264-
let vt = self.local_ty(pat.span, var_id).decl_ty;
264+
let vt = self.local_ty(pat.span, var_id);
265265
self.demand_eqtype(pat.span, vt, local_ty);
266266
}
267267

0 commit comments

Comments
 (0)