Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Binder's field private and clean up its usage #50016

Merged
merged 2 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for ty::Binder<T>
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let ty::Binder(ref inner) = *self;
inner.hash_stable(hcx, hasher);
self.skip_binder().hash_stable(hcx, hasher);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/librustc/infer/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,16 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
Obligation::new(
cause.clone(),
param_env,
ty::Predicate::RegionOutlives(ty::Binder(ty::OutlivesPredicate(r1, r2))),
ty::Predicate::RegionOutlives(
ty::Binder::dummy(ty::OutlivesPredicate(r1, r2))),
),

UnpackedKind::Type(t1) =>
Obligation::new(
cause.clone(),
param_env,
ty::Predicate::TypeOutlives(ty::Binder(ty::OutlivesPredicate(t1, r2))),
ty::Predicate::TypeOutlives(
ty::Binder::dummy(ty::OutlivesPredicate(t1, r2))),
),
}
})) as Box<dyn Iterator<Item = _>>
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ struct Generalizer<'cx, 'gcx: 'cx+'tcx, 'tcx: 'cx> {

/// Result from a generalization operation. This includes
/// not only the generalized type, but also a bool flag
/// indicating whether further WF checks are needed.q
/// indicating whether further WF checks are needed.
struct Generalization<'tcx> {
ty: Ty<'tcx>,

Expand Down Expand Up @@ -351,7 +351,7 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
-> RelateResult<'tcx, ty::Binder<T>>
where T: Relate<'tcx>
{
Ok(ty::Binder(self.relate(a.skip_binder(), b.skip_binder())?))
Ok(ty::Binder::bind(self.relate(a.skip_binder(), b.skip_binder())?))
}

fn relate_item_substs(&mut self,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
};

if let (Some(def_id), Some(ret_ty)) = (def_id, ret_ty) {
if exp_is_struct && exp_found.expected == ret_ty.0 {
if exp_is_struct && &exp_found.expected == ret_ty.skip_binder() {
let message = format!(
"did you mean `{}(/* fields */)`?",
self.tcx.item_path_str(def_id)
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {

debug!("higher_ranked_sub: OK result={:?}", result);

Ok(ty::Binder(result))
Ok(ty::Binder::bind(result))
});
}

Expand Down Expand Up @@ -239,7 +239,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
b,
result1);

Ok(ty::Binder(result1))
Ok(ty::Binder::bind(result1))
});

fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
Expand Down Expand Up @@ -335,7 +335,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
b,
result1);

Ok(ty::Binder(result1))
Ok(ty::Binder::bind(result1))
});

fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
self.fields.trace.cause.clone(),
self.fields.param_env,
ty::Predicate::Subtype(
ty::Binder(ty::SubtypePredicate {
ty::Binder::dummy(ty::SubtypePredicate {
a_is_expected: self.a_is_expected,
a,
b,
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
&data.parent_trait_ref);
match self.get_parent_trait_ref(&data.parent_code) {
Some(t) => Some(t),
None => Some(format!("{}", parent_trait_ref.0.self_ty())),
None => Some(format!("{}", parent_trait_ref.skip_binder().self_ty())),
}
}
_ => None,
Expand Down Expand Up @@ -862,7 +862,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'tcx>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>) {
let ty::Binder(trait_ref) = trait_ref;
let trait_ref = trait_ref.skip_binder();
let span = obligation.cause.span;

if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) {
Expand Down Expand Up @@ -1102,7 +1102,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
::syntax::abi::Abi::Rust
)
};
format!("{}", ty::Binder(sig))
format!("{}", ty::Binder::bind(sig))
}

let argument_is_closure = expected_ref.skip_binder().substs.type_at(0).is_closure();
Expand Down Expand Up @@ -1436,7 +1436,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}
ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
let parent_trait_ref = self.resolve_type_vars_if_possible(&data.parent_trait_ref);
let ty = parent_trait_ref.0.self_ty();
let ty = parent_trait_ref.skip_binder().self_ty();
err.note(&format!("required because it appears within the type `{}`", ty));
obligated_types.push(ty);

Expand All @@ -1453,7 +1453,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err.note(
&format!("required because of the requirements on the impl of `{}` for `{}`",
parent_trait_ref,
parent_trait_ref.0.self_ty()));
parent_trait_ref.skip_binder().self_ty()));
let parent_predicate = parent_trait_ref.to_predicate();
self.note_obligation_cause_code(err,
&parent_predicate,
Expand Down Expand Up @@ -1484,7 +1484,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = cause_code {
let parent_trait_ref = self.resolve_type_vars_if_possible(&data.parent_trait_ref);
for obligated_type in obligated_types {
if obligated_type == &parent_trait_ref.0.self_ty() {
if obligated_type == &parent_trait_ref.skip_binder().self_ty() {
return true;
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,16 +855,19 @@ fn vtable_methods<'a, 'tcx>(

// the method may have some early-bound lifetimes, add
// regions for those
let substs = Substs::for_item(tcx, def_id,
|_, _| tcx.types.re_erased,
|def, _| trait_ref.substs().type_for_def(def));
let substs = trait_ref.map_bound(|trait_ref| {
Substs::for_item(
tcx, def_id,
|_, _| tcx.types.re_erased,
|def, _| trait_ref.substs.type_for_def(def))
});

// the trait type may have higher-ranked lifetimes in it;
// so erase them if they appear, so that we get the type
// at some particular call site
let substs = tcx.normalize_erasing_late_bound_regions(
ty::ParamEnv::reveal_all(),
&ty::Binder(substs),
&substs
);

// It's possible that the method relies on where clauses that
Expand Down Expand Up @@ -997,7 +1000,7 @@ impl<'tcx> FulfillmentError<'tcx> {

impl<'tcx> TraitObligation<'tcx> {
fn self_ty(&self) -> ty::Binder<Ty<'tcx>> {
ty::Binder(self.predicate.skip_binder().self_ty())
self.predicate.map_bound(|p| p.self_ty())
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
trait_def_id: DefId,
supertraits_only: bool) -> bool
{
let trait_ref = ty::Binder(ty::TraitRef {
let trait_ref = ty::Binder::dummy(ty::TraitRef {
def_id: trait_def_id,
substs: Substs::identity_for_item(self, trait_def_id)
});
Expand Down Expand Up @@ -199,7 +199,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
.any(|predicate| {
match predicate {
ty::Predicate::Trait(ref trait_pred) if trait_pred.def_id() == sized_def_id => {
trait_pred.0.self_ty().is_self()
trait_pred.skip_binder().self_ty().is_self()
}
ty::Predicate::Projection(..) |
ty::Predicate::Trait(..) |
Expand Down Expand Up @@ -352,7 +352,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

// Compute supertraits of current trait lazily.
if supertraits.is_none() {
let trait_ref = ty::Binder(ty::TraitRef {
let trait_ref = ty::Binder::bind(ty::TraitRef {
def_id: trait_def_id,
substs: Substs::identity_for_item(self, trait_def_id)
});
Expand All @@ -367,7 +367,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// direct equality here because all of these types
// are part of the formal parameter listing, and
// hence there should be no inference variables.
let projection_trait_ref = ty::Binder(data.trait_ref(self));
let projection_trait_ref = ty::Binder::bind(data.trait_ref(self));
let is_supertrait_of_current_trait =
supertraits.as_ref().unwrap().contains(&projection_trait_ref);

Expand Down
69 changes: 34 additions & 35 deletions src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ pub fn normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
let def_id = projection_ty.item_def_id;
let ty_var = selcx.infcx().next_ty_var(
TypeVariableOrigin::NormalizeProjectionType(tcx.def_span(def_id)));
let projection = ty::Binder(ty::ProjectionPredicate {
let projection = ty::Binder::dummy(ty::ProjectionPredicate {
projection_ty,
ty: ty_var
});
Expand Down Expand Up @@ -982,8 +982,7 @@ fn assemble_candidates_from_predicates<'cx, 'gcx, 'tcx, I>(
predicate);
match predicate {
ty::Predicate::Projection(data) => {
let same_def_id =
data.0.projection_ty.item_def_id == obligation.predicate.item_def_id;
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;

let is_match = same_def_id && infcx.probe(|_| {
let data_poly_trait_ref =
Expand Down Expand Up @@ -1241,7 +1240,7 @@ fn confirm_object_candidate<'cx, 'gcx, 'tcx>(
// item with the correct name
let env_predicates = env_predicates.filter_map(|p| match p {
ty::Predicate::Projection(data) =>
if data.0.projection_ty.item_def_id == obligation.predicate.item_def_id {
if data.projection_def_id() == obligation.predicate.item_def_id {
Some(data)
} else {
None
Expand Down Expand Up @@ -1302,28 +1301,28 @@ fn confirm_generator_candidate<'cx, 'gcx, 'tcx>(

let gen_def_id = tcx.lang_items().gen_trait().unwrap();

// Note: we unwrap the binder here but re-create it below (1)
let ty::Binder((trait_ref, yield_ty, return_ty)) =
let predicate =
tcx.generator_trait_ref_and_outputs(gen_def_id,
obligation.predicate.self_ty(),
gen_sig);

let name = tcx.associated_item(obligation.predicate.item_def_id).name;
let ty = if name == Symbol::intern("Return") {
return_ty
} else if name == Symbol::intern("Yield") {
yield_ty
} else {
bug!()
};
gen_sig)
.map_bound(|(trait_ref, yield_ty, return_ty)| {
let name = tcx.associated_item(obligation.predicate.item_def_id).name;
let ty = if name == Symbol::intern("Return") {
return_ty
} else if name == Symbol::intern("Yield") {
yield_ty
} else {
bug!()
};

let predicate = ty::Binder(ty::ProjectionPredicate { // (1) recreate binder here
projection_ty: ty::ProjectionTy {
substs: trait_ref.substs,
item_def_id: obligation.predicate.item_def_id,
},
ty: ty
});
ty::ProjectionPredicate {
projection_ty: ty::ProjectionTy {
substs: trait_ref.substs,
item_def_id: obligation.predicate.item_def_id,
},
ty: ty
}
});

confirm_param_env_candidate(selcx, obligation, predicate)
.with_addl_obligations(vtable.nested)
Expand Down Expand Up @@ -1400,21 +1399,21 @@ fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
// the `Output` associated type is declared on `FnOnce`
let fn_once_def_id = tcx.lang_items().fn_once_trait().unwrap();

// Note: we unwrap the binder here but re-create it below (1)
let ty::Binder((trait_ref, ret_type)) =
let predicate =
tcx.closure_trait_ref_and_return_type(fn_once_def_id,
obligation.predicate.self_ty(),
fn_sig,
flag);

let predicate = ty::Binder(ty::ProjectionPredicate { // (1) recreate binder here
projection_ty: ty::ProjectionTy::from_ref_and_name(
tcx,
trait_ref,
Symbol::intern(FN_OUTPUT_NAME),
),
ty: ret_type
});
flag)
.map_bound(|(trait_ref, ret_type)| {
ty::ProjectionPredicate {
projection_ty: ty::ProjectionTy::from_ref_and_name(
tcx,
trait_ref,
Symbol::intern(FN_OUTPUT_NAME),
),
ty: ret_type
}
});

confirm_param_env_candidate(selcx, obligation, predicate)
}
Expand Down
Loading