Skip to content

Commit 98cec39

Browse files
author
Alexander Regueiro
committed
Stuff works!
1 parent 8dc79e0 commit 98cec39

File tree

25 files changed

+162
-126
lines changed

25 files changed

+162
-126
lines changed

src/librustc/ich/impls_mir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ impl_stable_hash_for!(enum mir::CastKind {
453453
ReifyFnPointer,
454454
ClosureFnPointer,
455455
UnsafeFnPointer,
456+
Hide,
456457
Unsize
457458
});
458459

src/librustc/ich/impls_ty.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,8 @@ for ty::adjustment::Adjust<'gcx> {
183183
ty::adjustment::Adjust::UnsafeFnPointer |
184184
ty::adjustment::Adjust::ClosureFnPointer |
185185
ty::adjustment::Adjust::MutToConstPointer |
186+
ty::adjustment::Adjust::Hide |
186187
ty::adjustment::Adjust::Unsize => {}
187-
ty::adjustment::Adjust::Hide(ref revealed_ty) => {
188-
revealed_ty.hash_stable(hcx, hasher);
189-
}
190188
ty::adjustment::Adjust::Deref(ref overloaded) => {
191189
overloaded.hash_stable(hcx, hasher);
192190
}

src/librustc/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10571057
Substs::for_item(self.tcx, def_id, |param, _| self.var_for_def(span, param))
10581058
}
10591059

1060-
/// True if errors have been reported since this infcx was
1060+
/// Returns `true` if errors have been reported since this infcx was
10611061
/// created. This is sometimes used as a heuristic to skip
10621062
/// reporting errors that often occur as a result of earlier
10631063
/// errors, but where it's hard to be 100% sure (e.g., unresolved
@@ -1251,7 +1251,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12511251
value.fold_with(&mut r)
12521252
}
12531253

1254-
/// Returns true if `T` contains unresolved type variables. In the
1254+
/// Returns `true` if `T` contains unresolved type variables. In the
12551255
/// process of visiting `T`, this will resolve (where possible)
12561256
/// type variables in `T`, but it never constructs the final,
12571257
/// resolved type, so it's more efficient than

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +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(_) |
724+
adjustment::Adjust::Hide |
725725
adjustment::Adjust::Unsize => {
726726
// Creating a closure/fn-pointer or unsizing consumes
727727
// the input and stores it into the resulting rvalue.

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +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(_) |
634+
adjustment::Adjust::Hide |
635635
adjustment::Adjust::Unsize => {
636636
// Result is an rvalue.
637637
Ok(self.cat_rvalue_node(expr.hir_id, expr.span, target))

src/librustc/mir/mod.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -2128,16 +2128,16 @@ impl<'tcx> Operand<'tcx> {
21282128
21292129
#[derive(Clone, RustcEncodable, RustcDecodable)]
21302130
pub enum Rvalue<'tcx> {
2131-
/// x (either a move or copy, depending on type of x)
2131+
/// `x` (either a move or copy, depending on type of `x`)
21322132
Use(Operand<'tcx>),
21332133

2134-
/// [x; 32]
2134+
/// `[x; 32]`
21352135
Repeat(Operand<'tcx>, u64),
21362136

2137-
/// &x or &mut x
2137+
/// `&x` or `&mut x`
21382138
Ref(Region<'tcx>, BorrowKind, Place<'tcx>),
21392139

2140-
/// length of a [X] or [X;n] value
2140+
/// length of a `[X]` or `[X;n]` value
21412141
Len(Place<'tcx>),
21422142

21432143
Cast(CastKind, Operand<'tcx>, Ty<'tcx>),
@@ -2166,15 +2166,19 @@ pub enum Rvalue<'tcx> {
21662166
pub enum CastKind {
21672167
Misc,
21682168

2169-
/// Convert unique, zero-sized type for a fn to fn()
2169+
/// Convert a unique, zero-sized type for a fn to `fn()`
21702170
ReifyFnPointer,
21712171

2172-
/// Convert non capturing closure to fn()
2172+
/// Convert a non capturing closure to `fn()`
21732173
ClosureFnPointer,
21742174

2175-
/// Convert safe fn() to unsafe fn()
2175+
/// Convert a safe fn() to unsafe `fn()`
21762176
UnsafeFnPointer,
21772177

2178+
// "Hide" -- convert a value to an opaque type, i.e. `impl Trait`,
2179+
// thus hiding information about its conrete type.
2180+
Hide,
2181+
21782182
/// "Unsize" -- convert a thin-or-fat pointer to a fat pointer.
21792183
/// codegen must figure out the details once full monomorphization
21802184
/// is known. For example, this could be used to cast from a
@@ -2185,7 +2189,7 @@ pub enum CastKind {
21852189

21862190
#[derive(Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
21872191
pub enum AggregateKind<'tcx> {
2188-
/// The type is of the element
2192+
/// The type is of the element.
21892193
Array(Ty<'tcx>),
21902194
Tuple,
21912195

src/librustc/ty/adjustment.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use hir::def_id::DefId;
1313
use ty::{self, Ty, TyCtxt};
1414
use ty::subst::Substs;
1515

16-
1716
/// Represents coercing a value to a different type of value.
1817
///
1918
/// We transform values by following a number of `Adjust` steps in order.
@@ -84,7 +83,7 @@ pub enum Adjust<'tcx> {
8483
Borrow(AutoBorrow<'tcx>),
8584

8685
/// Hide a value with an opaque type.
87-
Hide(Ty<'tcx>),
86+
Hide,
8887

8988
/// Unsize a pointer/reference value, e.g. `&[T; n]` to
9089
/// `&[T]`. Note that the source could be a thin or fat pointer.

src/librustc/ty/structural_impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -346,8 +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),
349+
ty::adjustment::Adjust::Hide =>
350+
Some(ty::adjustment::Adjust::Hide),
351351
ty::adjustment::Adjust::Unsize =>
352352
Some(ty::adjustment::Adjust::Unsize),
353353
ty::adjustment::Adjust::Deref(ref overloaded) => {
@@ -883,7 +883,7 @@ EnumTypeFoldableImpl! {
883883
(ty::adjustment::Adjust::UnsafeFnPointer),
884884
(ty::adjustment::Adjust::ClosureFnPointer),
885885
(ty::adjustment::Adjust::MutToConstPointer),
886-
(ty::adjustment::Adjust::Hide)(a),
886+
(ty::adjustment::Adjust::Hide),
887887
(ty::adjustment::Adjust::Unsize),
888888
(ty::adjustment::Adjust::Deref)(a),
889889
(ty::adjustment::Adjust::Borrow)(a),

src/librustc_codegen_llvm/mir/rvalue.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ impl FunctionCx<'a, 'll, 'tcx> {
240240
}
241241
}
242242
mir::CastKind::UnsafeFnPointer => {
243-
// this is a no-op at the LLVM level
243+
// This is a no-op at the LLVM level.
244+
operand.val
245+
}
246+
mir::CastKind::Hide => {
247+
// This is a no-op at the LLVM level.
244248
operand.val
245249
}
246250
mir::CastKind::Unsize => {

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+33-14
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
973973
locations: Locations,
974974
category: ConstraintCategory,
975975
) -> Fallible<()> {
976+
// FIXME(alexreg): see issue #54600.
976977
if let Err(terr) = self.sub_types(sub, sup, locations, category) {
977978
if let TyKind::Opaque(..) = sup.sty {
978979
// When you have `let x: impl Foo = ...` in a closure,
@@ -1059,17 +1060,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10591060

10601061
fn eq_opaque_type_and_type(
10611062
&mut self,
1062-
revealed_ty: Ty<'tcx>,
1063-
anon_ty: Ty<'tcx>,
1064-
anon_owner_def_id: DefId,
1063+
concrete_ty: Ty<'tcx>,
1064+
opaque_ty: Ty<'tcx>,
1065+
parent_def_id: DefId,
10651066
locations: Locations,
10661067
category: ConstraintCategory,
10671068
) -> Fallible<()> {
10681069
debug!(
10691070
"eq_opaque_type_and_type( \
1070-
revealed_ty={:?}, \
1071-
anon_ty={:?})",
1072-
revealed_ty, anon_ty
1071+
concrete_ty={:?}, \
1072+
opaque_ty={:?})",
1073+
concrete_ty, opaque_ty
10731074
);
10741075
let infcx = self.infcx;
10751076
let tcx = infcx.tcx;
@@ -1085,21 +1086,21 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10851086
let dummy_body_id = ObligationCause::dummy().body_id;
10861087
let (output_ty, opaque_type_map) =
10871088
obligations.add(infcx.instantiate_opaque_types(
1088-
anon_owner_def_id,
1089+
parent_def_id,
10891090
dummy_body_id,
10901091
param_env,
1091-
&anon_ty,
1092+
&opaque_ty,
10921093
));
10931094
debug!(
10941095
"eq_opaque_type_and_type: \
10951096
instantiated output_ty={:?} \
10961097
opaque_type_map={:#?} \
1097-
revealed_ty={:?}",
1098-
output_ty, opaque_type_map, revealed_ty
1098+
concrete_ty={:?}",
1099+
output_ty, opaque_type_map, concrete_ty
10991100
);
11001101
obligations.add(infcx
11011102
.at(&ObligationCause::dummy(), param_env)
1102-
.eq(output_ty, revealed_ty)?);
1103+
.eq(output_ty, concrete_ty)?);
11031104

11041105
for (&opaque_def_id, opaque_decl) in &opaque_type_map {
11051106
let opaque_defn_ty = tcx.type_of(opaque_def_id);
@@ -1524,7 +1525,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
15241525
}
15251526
}
15261527
None => {
1527-
// FIXME(canndrew): This is_never should probably be an is_uninhabited
1528+
// FIXME(canndrew): this `is_never` should probably be an `is_uninhabited`.
15281529
if !sig.output().is_never() {
15291530
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
15301531
}
@@ -1910,6 +1911,25 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
19101911
}
19111912
}
19121913

1914+
CastKind::Hide => {
1915+
let predicates = match ty.sty {
1916+
ty::Opaque(def_id, substs) => {
1917+
let bounds = tcx.predicates_of(def_id);
1918+
let result = bounds.instantiate(tcx, substs);
1919+
// TODO: do I need to normalize associated types here somehow.
1920+
// as is done in coercion.rs?
1921+
result
1922+
}
1923+
_ => bug!(),
1924+
};
1925+
1926+
self.prove_predicates(
1927+
predicates.predicates,
1928+
location.to_locations(),
1929+
ConstraintCategory::Cast,
1930+
);
1931+
}
1932+
19131933
CastKind::Unsize => {
19141934
let &ty = ty;
19151935
let trait_ref = ty::TraitRef {
@@ -1932,7 +1952,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
19321952
self.add_reborrow_constraint(location, region, borrowed_place);
19331953
}
19341954

1935-
// FIXME: These other cases have to be implemented in future PRs
1955+
// FIXME: these other cases have to be implemented in future PRs.
19361956
Rvalue::Use(..)
19371957
| Rvalue::Len(..)
19381958
| Rvalue::BinaryOp(..)
@@ -2164,7 +2184,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
21642184
}
21652185

21662186
// For closures, we have some **extra requirements** we
2167-
//
21682187
// have to check. In particular, in their upvars and
21692188
// signatures, closures often reference various regions
21702189
// from the surrounding function -- we call those the

src/librustc_mir/build/expr/as_place.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
189189
| ExprKind::ReifyFnPointer { .. }
190190
| ExprKind::ClosureFnPointer { .. }
191191
| ExprKind::UnsafeFnPointer { .. }
192+
| ExprKind::Hide { .. }
192193
| ExprKind::Unsize { .. }
193194
| ExprKind::Repeat { .. }
194195
| ExprKind::Borrow { .. }
@@ -205,7 +206,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
205206
| ExprKind::InlineAsm { .. }
206207
| ExprKind::Yield { .. }
207208
| ExprKind::Call { .. } => {
208-
// these are not places, so we need to make a temporary.
209+
// These are not places, so we need to make a temporary.
209210
debug_assert!(match Category::of(&expr.kind) {
210211
Some(Category::Place) => false,
211212
_ => true,

src/librustc_mir/build/expr/as_rvalue.rs

+6
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
174174
let source = unpack!(block = this.as_operand(block, scope, source));
175175
block.and(Rvalue::Cast(CastKind::ClosureFnPointer, source, expr.ty))
176176
}
177+
ExprKind::Hide { source } => {
178+
let source = this.hir.mirror(source);
179+
180+
let source = unpack!(block = this.as_operand(block, scope, source));
181+
block.and(Rvalue::Cast(CastKind::Hide, source, expr.ty))
182+
}
177183
ExprKind::Unsize { source } => {
178184
let source = unpack!(block = this.as_operand(block, scope, source));
179185
block.and(Rvalue::Cast(CastKind::Unsize, source, expr.ty))

src/librustc_mir/build/expr/category.rs

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl Category {
7272
| ExprKind::ReifyFnPointer { .. }
7373
| ExprKind::ClosureFnPointer { .. }
7474
| ExprKind::UnsafeFnPointer { .. }
75+
| ExprKind::Hide { .. }
7576
| ExprKind::Unsize { .. }
7677
| ExprKind::Repeat { .. }
7778
| ExprKind::Borrow { .. }

src/librustc_mir/build/expr/into.rs

+1
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
399399
| ExprKind::ReifyFnPointer { .. }
400400
| ExprKind::ClosureFnPointer { .. }
401401
| ExprKind::UnsafeFnPointer { .. }
402+
| ExprKind::Hide { .. }
402403
| ExprKind::Unsize { .. }
403404
| ExprKind::Repeat { .. }
404405
| ExprKind::Borrow { .. }

0 commit comments

Comments
 (0)