Skip to content

Refactor upvar mode inference #20432

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

Merged
merged 8 commits into from
Jan 3, 2015
10 changes: 3 additions & 7 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,15 +1612,11 @@ impl LintPass for MissingCopyImplementations {
}
_ => return,
};
let parameter_environment = ty::empty_parameter_environment();
if !ty::type_moves_by_default(cx.tcx,
ty,
&parameter_environment) {
let parameter_environment = ty::empty_parameter_environment(cx.tcx);
if !ty::type_moves_by_default(&parameter_environment, item.span, ty) {
return
}
if ty::can_type_implement_copy(cx.tcx,
ty,
&parameter_environment).is_ok() {
if ty::can_type_implement_copy(&parameter_environment, item.span, ty).is_ok() {
cx.span_lint(MISSING_COPY_IMPLEMENTATIONS,
item.span,
"type could implement `Copy`; consider adding `impl \
Expand Down
11 changes: 4 additions & 7 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'a> FromIterator<Vec<&'a Pat>> for Matrix<'a> {

pub struct MatchCheckCtxt<'a, 'tcx: 'a> {
pub tcx: &'a ty::ctxt<'tcx>,
pub param_env: ParameterEnvironment<'tcx>,
pub param_env: ParameterEnvironment<'a, 'tcx>,
}

#[deriving(Clone, PartialEq)]
Expand Down Expand Up @@ -148,7 +148,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MatchCheckCtxt<'a, 'tcx> {
pub fn check_crate(tcx: &ty::ctxt) {
visit::walk_crate(&mut MatchCheckCtxt {
tcx: tcx,
param_env: ty::empty_parameter_environment(),
param_env: ty::empty_parameter_environment(tcx),
}, tcx.map.krate());
tcx.sess.abort_if_errors();
}
Expand Down Expand Up @@ -1032,9 +1032,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
match p.node {
ast::PatIdent(ast::BindByValue(_), _, ref sub) => {
let pat_ty = ty::node_id_to_type(tcx, p.id);
if ty::type_moves_by_default(tcx,
pat_ty,
&cx.param_env) {
if ty::type_moves_by_default(&cx.param_env, pat.span, pat_ty) {
check_move(p, sub.as_ref().map(|p| &**p));
}
}
Expand Down Expand Up @@ -1063,8 +1061,7 @@ fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>,
cx: cx,
};
let mut visitor = ExprUseVisitor::new(&mut checker,
checker.cx.tcx,
&cx.param_env);
&checker.cx.param_env);
visitor.walk_expr(guard);
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/check_rvalues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> {
{
let param_env = ParameterEnvironment::for_item(self.tcx, fn_id);
let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: &param_env };
let mut euv = euv::ExprUseVisitor::new(&mut delegate, self.tcx, &param_env);
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &param_env);
euv.walk_fn(fd, b);
}
visit::walk_fn(self, fk, fd, b, s)
Expand All @@ -50,7 +50,7 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> {

struct RvalueContextDelegate<'a, 'tcx: 'a> {
tcx: &'a ty::ctxt<'tcx>,
param_env: &'a ty::ParameterEnvironment<'tcx>,
param_env: &'a ty::ParameterEnvironment<'a,'tcx>,
}

impl<'a, 'tcx> euv::Delegate<'tcx> for RvalueContextDelegate<'a, 'tcx> {
Expand All @@ -60,7 +60,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for RvalueContextDelegate<'a, 'tcx> {
cmt: mc::cmt<'tcx>,
_: euv::ConsumeMode) {
debug!("consume; cmt: {}; type: {}", *cmt, ty_to_string(self.tcx, cmt.ty));
if !ty::type_is_sized(self.tcx, cmt.ty, self.param_env) {
if !ty::type_is_sized(self.param_env, span, cmt.ty) {
span_err!(self.tcx.sess, span, E0161,
"cannot move a value of type {0}: the size of {0} cannot be statically determined",
ty_to_string(self.tcx, cmt.ty));
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/check_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct CheckStaticVisitor<'a, 'tcx: 'a> {
}

struct GlobalVisitor<'a,'b,'tcx:'a+'b>(
euv::ExprUseVisitor<'a,'b,'tcx,ty::ctxt<'tcx>>);
euv::ExprUseVisitor<'a,'b,'tcx,ty::ParameterEnvironment<'b,'tcx>>);
struct GlobalChecker {
static_consumptions: NodeSet,
const_borrows: NodeSet,
Expand All @@ -70,8 +70,8 @@ pub fn check_crate(tcx: &ty::ctxt) {
static_local_borrows: NodeSet::new(),
};
{
let param_env = ty::empty_parameter_environment();
let visitor = euv::ExprUseVisitor::new(&mut checker, tcx, &param_env);
let param_env = ty::empty_parameter_environment(tcx);
let visitor = euv::ExprUseVisitor::new(&mut checker, &param_env);
visit::walk_crate(&mut GlobalVisitor(visitor), tcx.map.krate());
}
visit::walk_crate(&mut CheckStaticVisitor {
Expand Down Expand Up @@ -121,8 +121,8 @@ impl<'a, 'tcx> CheckStaticVisitor<'a, 'tcx> {
let mut fulfill_cx = traits::FulfillmentContext::new();
let cause = traits::ObligationCause::new(e.span, e.id, traits::SharedStatic);
fulfill_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause);
let env = ty::empty_parameter_environment();
match fulfill_cx.select_all_or_error(&infcx, &env, self.tcx) {
let env = ty::empty_parameter_environment(self.tcx);
match fulfill_cx.select_all_or_error(&infcx, &env) {
Ok(()) => { },
Err(ref errors) => {
traits::report_fulfillment_errors(&infcx, errors);
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/middle/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ impl TraitItemKind {
}

impl Def {
pub fn local_node_id(&self) -> ast::NodeId {
let def_id = self.def_id();
assert_eq!(def_id.krate, ast::LOCAL_CRATE);
def_id.node
}

pub fn def_id(&self) -> ast::DefId {
match *self {
DefFn(id, _) | DefStaticMethod(id, _) | DefMod(id) |
Expand Down
Loading