Skip to content

Rustup for https://github.com/rust-lang/rust/pull/61276 #4166

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 2 commits into from
Jun 2, 2019
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
11 changes: 10 additions & 1 deletion clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {

let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).consume_body(body);
ExprUseVisitor::new(
&mut v,
cx.tcx,
fn_def_id,
cx.param_env,
region_scope_tree,
cx.tables,
None,
)
.consume_body(body);

for node in v.set {
span_lint(
Expand Down
38 changes: 18 additions & 20 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,16 @@ fn check_for_mutation(
};
let def_id = def_id::DefId::local(body.hir_id.owner);
let region_scope_tree = &cx.tcx.region_scope_tree(def_id);
ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).walk_expr(body);
ExprUseVisitor::new(
&mut delegate,
cx.tcx,
def_id,
cx.param_env,
region_scope_tree,
cx.tables,
None,
)
.walk_expr(body);
delegate.mutation_span()
}

Expand Down Expand Up @@ -1769,7 +1778,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
}
let res = self.cx.tables.qpath_res(seqpath, seqexpr.hir_id);
match res {
Res::Local(hir_id) | Res::Upvar(hir_id, ..) => {
Res::Local(hir_id) => {
let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
let parent_def_id = self.cx.tcx.hir().local_def_id_from_hir_id(parent_id);
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
Expand Down Expand Up @@ -1829,24 +1838,13 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
if let QPath::Resolved(None, ref path) = *qpath;
if path.segments.len() == 1;
then {
match self.cx.tables.qpath_res(qpath, expr.hir_id) {
Res::Upvar(local_id, ..) => {
if local_id == self.var {
// we are not indexing anything, record that
self.nonindex = true;
}
}
Res::Local(local_id) =>
{

if local_id == self.var {
self.nonindex = true;
} else {
// not the correct variable, but still a variable
self.referenced.insert(path.segments[0].ident.name);
}
if let Res::Local(local_id) = self.cx.tables.qpath_res(qpath, expr.hir_id) {
if local_id == self.var {
self.nonindex = true;
} else {
// not the correct variable, but still a variable
self.referenced.insert(path.segments[0].ident.name);
}
_ => {}
}
}
}
Expand Down Expand Up @@ -2378,7 +2376,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
let res = self.cx.tables.qpath_res(qpath, ex.hir_id);
then {
match res {
Res::Local(node_id) | Res::Upvar(node_id, ..) => {
Res::Local(node_id) => {
self.ids.insert(node_id);
},
Res::Def(DefKind::Static, def_id) => {
Expand Down
7 changes: 4 additions & 3 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,10 @@ fn in_attributes_expansion(expr: &Expr) -> bool {

/// Tests whether `res` is a variable defined outside a macro.
fn non_macro_local(cx: &LateContext<'_, '_>, res: def::Res) -> bool {
match res {
def::Res::Local(id) | def::Res::Upvar(id, ..) => !in_macro_or_desugar(cx.tcx.hir().span_by_hir_id(id)),
_ => false,
if let def::Res::Local(id) = res {
!in_macro_or_desugar(cx.tcx.hir().span_by_hir_id(id))
} else {
false
}
}

Expand Down
12 changes: 10 additions & 2 deletions clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
} = {
let mut ctx = MovedVariablesCtxt::new(cx);
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
euv::ExprUseVisitor::new(&mut ctx, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None)
.consume_body(body);
euv::ExprUseVisitor::new(
&mut ctx,
cx.tcx,
fn_def_id,
cx.param_env,
region_scope_tree,
cx.tables,
None,
)
.consume_body(body);
ctx
};

Expand Down
21 changes: 15 additions & 6 deletions clippy_lints/src/utils/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ pub fn mutated_variables<'a, 'tcx: 'a>(expr: &'tcx Expr, cx: &'a LateContext<'a,
};
let def_id = def_id::DefId::local(expr.hir_id.owner);
let region_scope_tree = &cx.tcx.region_scope_tree(def_id);
ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).walk_expr(expr);
ExprUseVisitor::new(
&mut delegate,
cx.tcx,
def_id,
cx.param_env,
region_scope_tree,
cx.tables,
None,
)
.walk_expr(expr);

if delegate.skip {
return None;
Expand All @@ -29,11 +38,11 @@ pub fn is_potentially_mutated<'a, 'tcx: 'a>(
expr: &'tcx Expr,
cx: &'a LateContext<'a, 'tcx>,
) -> bool {
let id = match variable.res {
Res::Local(id) | Res::Upvar(id, ..) => id,
_ => return true,
};
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id))
if let Res::Local(id) = variable.res {
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id))
} else {
return true;
}
}

struct MutVarsDelegate {
Expand Down