Skip to content

Commit 74c6788

Browse files
committed
rustc: move liberate_late_bound_regions to rustc_typeck.
1 parent 6d4c214 commit 74c6788

File tree

7 files changed

+24
-74
lines changed

7 files changed

+24
-74
lines changed

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@
9696
//!
9797
//! - `fallthrough_ln`: a live node that represents a fallthrough
9898
//!
99-
//! - `no_ret_var`: a synthetic variable that is only 'read' from, the
100-
//! fallthrough node. This allows us to detect functions where we fail
101-
//! to return explicitly.
10299
//! - `clean_exit_var`: a synthetic variable that is only 'read' from the
103100
//! fallthrough node. It is only live if the function could converge
104101
//! via means other than an explicit `return` expression. That is, it is
@@ -111,8 +108,6 @@ use self::VarKind::*;
111108

112109
use hir::def::*;
113110
use ty::{self, TyCtxt};
114-
use traits::{self, Reveal};
115-
use ty::subst::Subst;
116111
use lint;
117112
use util::nodemap::NodeMap;
118113

@@ -256,7 +251,6 @@ struct LocalInfo {
256251
enum VarKind {
257252
Arg(NodeId, ast::Name),
258253
Local(LocalInfo),
259-
ImplicitRet,
260254
CleanExit
261255
}
262256

@@ -313,7 +307,7 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
313307
Local(LocalInfo { id: node_id, .. }) | Arg(node_id, _) => {
314308
self.variable_map.insert(node_id, v);
315309
},
316-
ImplicitRet | CleanExit => {}
310+
CleanExit => {}
317311
}
318312

319313
debug!("{:?} is {:?}", v, vk);
@@ -335,7 +329,6 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
335329
Local(LocalInfo { name, .. }) | Arg(_, name) => {
336330
name.to_string()
337331
},
338-
ImplicitRet => "<implicit-ret>".to_string(),
339332
CleanExit => "<clean-exit>".to_string()
340333
}
341334
}
@@ -382,7 +375,6 @@ fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'a, 'tcx>,
382375

383376
// check for various error conditions
384377
lsets.visit_body(body);
385-
lsets.check_ret(id, sp, entry_ln);
386378
lsets.warn_about_unused_args(body, entry_ln);
387379
}
388380

@@ -500,7 +492,6 @@ fn invalid_users() -> Users {
500492
struct Specials {
501493
exit_ln: LiveNode,
502494
fallthrough_ln: LiveNode,
503-
no_ret_var: Variable,
504495
clean_exit_var: Variable
505496
}
506497

@@ -534,7 +525,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
534525
let specials = Specials {
535526
exit_ln: ir.add_live_node(ExitNode),
536527
fallthrough_ln: ir.add_live_node(ExitNode),
537-
no_ret_var: ir.add_variable(ImplicitRet),
538528
clean_exit_var: ir.add_variable(CleanExit)
539529
};
540530

@@ -1420,43 +1410,6 @@ fn check_expr<'a, 'tcx>(this: &mut Liveness<'a, 'tcx>, expr: &'tcx Expr) {
14201410
}
14211411

14221412
impl<'a, 'tcx> Liveness<'a, 'tcx> {
1423-
fn check_ret(&self,
1424-
id: NodeId,
1425-
sp: Span,
1426-
entry_ln: LiveNode)
1427-
{
1428-
let def_id = self.ir.tcx.hir.local_def_id(id);
1429-
let fn_ty = self.ir.tcx.type_of(def_id);
1430-
let fn_sig = match fn_ty.sty {
1431-
ty::TyClosure(closure_def_id, substs) => {
1432-
self.ir.tcx.closure_type(closure_def_id)
1433-
.subst(self.ir.tcx, substs.substs)
1434-
}
1435-
_ => fn_ty.fn_sig()
1436-
};
1437-
1438-
let fn_ret = fn_sig.output();
1439-
1440-
// within the fn body, late-bound regions are liberated
1441-
// and must outlive the *call-site* of the function.
1442-
let fn_ret =
1443-
self.ir.tcx.liberate_late_bound_regions(def_id, &fn_ret);
1444-
1445-
if !fn_ret.is_never() && self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
1446-
let param_env = self.ir.tcx.parameter_environment(def_id);
1447-
let t_ret_subst = fn_ret.subst(self.ir.tcx, &param_env.free_substs);
1448-
let is_nil = self.ir.tcx.infer_ctxt(param_env, Reveal::All).enter(|infcx| {
1449-
let cause = traits::ObligationCause::dummy();
1450-
traits::fully_normalize(&infcx, cause, &t_ret_subst).unwrap().is_nil()
1451-
});
1452-
1453-
// for nil return types, it is ok to not return a value expl.
1454-
if !is_nil {
1455-
span_bug!(sp, "not all control paths return a value");
1456-
}
1457-
}
1458-
}
1459-
14601413
fn check_lvalue(&mut self, expr: &'tcx Expr) {
14611414
match expr.node {
14621415
hir::ExprPath(hir::QPath::Resolved(_, ref path)) => {

src/librustc/ty/fold.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
//! These methods return true to indicate that the visitor has found what it is looking for
4040
//! and does not need to visit anything else.
4141
42-
use hir::def_id::DefId;
4342
use ty::subst::Substs;
4443
use ty::adjustment;
4544
use ty::{self, Binder, Ty, TyCtxt, TypeFlags};
@@ -326,23 +325,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
326325
(result, replacer.map)
327326
}
328327

329-
330-
/// Replace any late-bound regions bound in `value` with free variants attached to scope-id
331-
/// `scope_id`.
332-
pub fn liberate_late_bound_regions<T>(self,
333-
all_outlive_scope: DefId,
334-
value: &Binder<T>)
335-
-> T
336-
where T : TypeFoldable<'tcx>
337-
{
338-
self.replace_late_bound_regions(value, |br| {
339-
self.mk_region(ty::ReFree(ty::FreeRegion {
340-
scope: all_outlive_scope,
341-
bound_region: br
342-
}))
343-
}).0
344-
}
345-
346328
/// Flattens two binding levels into one. So `for<'a> for<'b> Foo`
347329
/// becomes `for<'a,'b> Foo`.
348330
pub fn flatten_late_bound_regions<T>(self, bound2_value: &Binder<Binder<T>>)

src/librustc/ty/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24172417
let tcx = self.global_tcx();
24182418
let generic_predicates = tcx.predicates_of(def_id);
24192419
let bounds = generic_predicates.instantiate(tcx, free_substs);
2420-
let bounds = tcx.liberate_late_bound_regions(def_id, &ty::Binder(bounds));
24212420
let predicates = bounds.predicates;
24222421

24232422
// Finally, we have to normalize the bounds in the environment, in

src/librustc_typeck/check/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
7373

7474
debug!("check_closure: expr.id={:?} closure_type={:?}", expr.id, closure_type);
7575

76-
let fn_sig = self.tcx.liberate_late_bound_regions(expr_def_id, &sig);
76+
let fn_sig = self.liberate_late_bound_regions(expr_def_id, &sig);
7777
let fn_sig = self.inh.normalize_associated_types_in(body.value.span,
7878
body.value.id, &fn_sig);
7979

src/librustc_typeck/check/compare_method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
282282
let impl_fty = tcx.mk_fn_ptr(ty::Binder(impl_sig));
283283
debug!("compare_impl_method: impl_fty={:?}", impl_fty);
284284

285-
let trait_sig = tcx.liberate_late_bound_regions(
285+
let trait_sig = inh.liberate_late_bound_regions(
286286
impl_m.def_id,
287287
&m_sig(trait_m));
288288
let trait_sig =

src/librustc_typeck/check/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,22 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
628628
obligations);
629629
InferOk { value, obligations }
630630
}
631+
632+
/// Replace any late-bound regions bound in `value` with
633+
/// free variants attached to `all_outlive_scope`.
634+
fn liberate_late_bound_regions<T>(&self,
635+
all_outlive_scope: DefId,
636+
value: &ty::Binder<T>)
637+
-> T
638+
where T: TypeFoldable<'tcx>
639+
{
640+
self.tcx.replace_late_bound_regions(value, |br| {
641+
self.tcx.mk_region(ty::ReFree(ty::FreeRegion {
642+
scope: all_outlive_scope,
643+
bound_region: br
644+
}))
645+
}).0
646+
}
631647
}
632648

633649
struct CheckItemTypesVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx> }
@@ -804,7 +820,7 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
804820
let fn_sig =
805821
fn_sig.subst(inh.tcx, &inh.parameter_environment.free_substs);
806822
let fn_sig =
807-
inh.tcx.liberate_late_bound_regions(def_id, &fn_sig);
823+
inh.liberate_late_bound_regions(def_id, &fn_sig);
808824
let fn_sig =
809825
inh.normalize_associated_types_in(body.value.span, body_id.node_id, &fn_sig);
810826

src/librustc_typeck/check/wfcheck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
427427
{
428428
let free_substs = &fcx.parameter_environment.free_substs;
429429
let sig = fcx.instantiate_type_scheme(span, free_substs, &sig);
430-
let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig);
430+
let sig = fcx.liberate_late_bound_regions(def_id, &sig);
431431

432432
for input_ty in sig.inputs() {
433433
fcx.register_wf_obligation(&input_ty, span, self.code.clone());
@@ -462,7 +462,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
462462
let free_substs = &fcx.parameter_environment.free_substs;
463463
let method_ty = fcx.tcx.type_of(method.def_id);
464464
let fty = fcx.instantiate_type_scheme(span, free_substs, &method_ty);
465-
let sig = fcx.tcx.liberate_late_bound_regions(method.def_id, &fty.fn_sig());
465+
let sig = fcx.liberate_late_bound_regions(method.def_id, &fty.fn_sig());
466466

467467
debug!("check_method_receiver: sig={:?}", sig);
468468

@@ -478,8 +478,8 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
478478
ExplicitSelf::ByBox => fcx.tcx.mk_box(self_ty)
479479
};
480480
let rcvr_ty = fcx.instantiate_type_scheme(span, free_substs, &rcvr_ty);
481-
let rcvr_ty = fcx.tcx.liberate_late_bound_regions(method.def_id,
482-
&ty::Binder(rcvr_ty));
481+
let rcvr_ty = fcx.liberate_late_bound_regions(method.def_id,
482+
&ty::Binder(rcvr_ty));
483483

484484
debug!("check_method_receiver: receiver ty = {:?}", rcvr_ty);
485485

0 commit comments

Comments
 (0)