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 faed02c commit 8dc79e0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
let span = path.span;
match path.def {
Def::Existential(did) => {
// check for desugared impl trait
// Check for desugared impl trait.
assert!(ty::is_impl_trait_defn(tcx, did).is_none());
let item_segment = path.segments.split_last().unwrap();
self.prohibit_generics(item_segment.1);
Expand Down Expand Up @@ -1398,8 +1398,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
tcx.mk_ty_param(index, tcx.hir.name(node_id).as_interned_str())
}
Def::SelfTy(_, Some(def_id)) => {
// Self in impl (we know the concrete type).

// Self in impl. (We know the concrete type.)
assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments);

Expand Down
5 changes: 1 addition & 4 deletions src/librustc_typeck/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use rustc::infer::{Coercion, InferResult, InferOk};
use rustc::infer::type_variable::TypeVariableOrigin;
use rustc::traits::{self, ObligationCause, ObligationCauseCode};
use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
use rustc::ty::{self, TypeAndMut, Ty, ClosureSubsts};
use rustc::ty::{self, DefIdTree, TypeAndMut, Ty, ClosureSubsts};
use rustc::ty::fold::TypeFoldable;
use rustc::ty::error::TypeError;
use rustc::ty::relate::RelateResult;
Expand Down Expand Up @@ -537,9 +537,6 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
}
})?;

// Instantiate opaque type in tables.
self.fcx.instantiate_opaque_types_from_return_value(self., &coerce_source);

// Create the obligations for `Source` satisfying the target predicates.
let cause = ObligationCause::misc(self.cause.span, self.fcx.body_id);
let obligations = traits::predicates_for_generics(cause,
Expand Down
14 changes: 8 additions & 6 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
# check.rs
Within the check phase of type check, we check each item one at a time
Within the check phase of type checking, we check each item one at a time
(bodies of function expressions are checked as part of the containing
function). Inference is used to supply types wherever they are
unknown.
function). Inference is used to supply types wherever they are unknown.
By far the most complex case is checking the body of a function. This
can be broken down into several distinct phases:
Expand Down Expand Up @@ -1026,9 +1025,11 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
let mut fcx = FnCtxt::new(inherited, param_env, body.value.id);
*fcx.ps.borrow_mut() = UnsafetyState::function(fn_sig.unsafety, fn_id);

let fn_def_id = fcx.tcx.hir.local_def_id(fn_id);
let declared_ret_ty = fn_sig.output();
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
let revealed_ret_ty = fcx.instantiate_opaque_types_from_return_value(fn_id, &declared_ret_ty);
let revealed_ret_ty = fcx.instantiate_opaque_types_from_return_value(
fn_def_id, &declared_ret_ty);
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(revealed_ret_ty)));
fn_sig = fcx.tcx.mk_fn_sig(
fn_sig.inputs().iter().cloned(),
Expand Down Expand Up @@ -2248,10 +2249,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
/// `InferCtxt::instantiate_opaque_types` for more details.
fn instantiate_opaque_types_from_return_value<T: TypeFoldable<'tcx>>(
&self,
parent_id: ast::NodeId,
parent_def_id: DefId,
value: &T,
) -> T {
let parent_def_id = self.tcx.hir.local_def_id(parent_id);
debug!("instantiate_opaque_types_from_return_value(parent_def_id={:?}, value={:?})",
parent_def_id,
value);
Expand Down Expand Up @@ -5274,7 +5274,9 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if own_counts.types == 0 {
return;
}

// Make a vector of booleans initially false, set to true when used.
// FIXME: use `BitSet` here instead.
let mut types_used = vec![false; own_counts.types];

for leaf_ty in ty.walk() {
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ fn find_existential_constraints<'a, 'tcx>(
fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
intravisit::NestedVisitorMap::All(&self.tcx.hir)
}

fn visit_item(&mut self, it: &'tcx Item) {
let def_id = self.tcx.hir.local_def_id(it.id);
// The existential type itself or its children are not within its reveal scope.
Expand All @@ -1373,6 +1374,7 @@ fn find_existential_constraints<'a, 'tcx>(
intravisit::walk_item(self, it);
}
}

fn visit_impl_item(&mut self, it: &'tcx ImplItem) {
let def_id = self.tcx.hir.local_def_id(it.id);
// The existential type itself or its children are not within its reveal scope.
Expand All @@ -1381,6 +1383,7 @@ fn find_existential_constraints<'a, 'tcx>(
intravisit::walk_impl_item(self, it);
}
}

fn visit_trait_item(&mut self, it: &'tcx TraitItem) {
let def_id = self.tcx.hir.local_def_id(it.id);
self.check(def_id);
Expand Down

0 comments on commit 8dc79e0

Please sign in to comment.