Skip to content

Commit

Permalink
Update clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jun 3, 2019
1 parent f9a5348 commit 73df096
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ semver = "0.9"
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}

[dev-dependencies]
cargo_metadata = "0.7.1"
cargo_metadata = "0.8.0"
compiletest_rs = { version = "0.3.22", features = ["tmp"] }
lazy_static = "1.0"
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
Expand Down
2 changes: 1 addition & 1 deletion clippy_dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Philipp Hansch <dev@phansch.net>"]
edition = "2018"

[dependencies]
clap = "~2.32"
clap = "2.33"
itertools = "0.8"
regex = "1"
lazy_static = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ keywords = ["clippy", "lint", "plugin"]
edition = "2018"

[dependencies]
cargo_metadata = "0.7.1"
cargo_metadata = "0.8.0"
itertools = "0.8"
lazy_static = "1.0.2"
matches = "0.1.7"
Expand Down
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
48 changes: 27 additions & 21 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,19 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```ignore
/// ```rust
/// let vec = vec!['a', 'b', 'c'];
/// for i in 0..vec.len() {
/// println!("{}", vec[i]);
/// }
/// ```
/// Could be written as:
/// ```rust
/// let vec = vec!['a', 'b', 'c'];
/// for i in vec {
/// println!("{}", i);
/// }
/// ```
pub NEEDLESS_RANGE_LOOP,
style,
"for-looping over a range of indices where an iterator over items would do"
Expand Down Expand Up @@ -1662,7 +1670,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 +1786,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 +1846,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 +2384,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
10 changes: 5 additions & 5 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,16 +594,16 @@ fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
fn in_attributes_expansion(expr: &Expr) -> bool {
expr.span
.ctxt()
.outer()
.expn_info()
.outer_expn_info()
.map_or(false, |info| matches!(info.format, ExpnFormat::MacroAttribute(_)))
}

/// 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
4 changes: 2 additions & 2 deletions clippy_lints/src/panic_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {

fn get_outer_span(expr: &Expr) -> Span {
if_chain! {
if let Some(first) = expr.span.ctxt().outer().expn_info();
if let Some(second) = first.call_site.ctxt().outer().expn_info();
if let Some(first) = expr.span.ctxt().outer_expn_info();
if let Some(second) = first.call_site.ctxt().outer_expn_info();
then {
second.call_site
} else {
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges {
then {
let span = expr.span
.ctxt()
.outer()
.expn_info()
.outer_expn_info()
.map_or(expr.span, |info| info.call_site);
span_lint_and_then(
cx,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/returns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn attr_is_cfg(attr: &ast::Attribute) -> bool {

// get the def site
fn get_def(span: Span) -> Option<Span> {
span.ctxt().outer().expn_info().and_then(|info| info.def_site)
span.ctxt().outer_expn_info().and_then(|info| info.def_site)
}

// is this expr a `()` unit?
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/utils/internal_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
// actual span that invoked `declare_tool_lint!`:
let lint_span = lint_span
.ctxt()
.outer()
.expn_info()
.outer_expn_info()
.map(|ei| ei.call_site)
.expect("unable to get call_site");

Expand Down
16 changes: 4 additions & 12 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {

/// Returns `true` if this `expn_info` was expanded by any macro or desugaring
pub fn in_macro_or_desugar(span: Span) -> bool {
span.ctxt().outer().expn_info().is_some()
span.ctxt().outer_expn_info().is_some()
}

/// Returns `true` if this `expn_info` was expanded by any macro.
pub fn in_macro(span: Span) -> bool {
if let Some(info) = span.ctxt().outer().expn_info() {
if let Some(info) = span.ctxt().outer_expn_info() {
if let ExpnFormat::CompilerDesugaring(..) = info.format {
false
} else {
Expand Down Expand Up @@ -691,11 +691,7 @@ pub fn is_adjusted(cx: &LateContext<'_, '_>, e: &Expr) -> bool {
/// See also `is_direct_expn_of`.
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
loop {
let span_name_span = span
.ctxt()
.outer()
.expn_info()
.map(|ei| (ei.format.name(), ei.call_site));
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.format.name(), ei.call_site));

match span_name_span {
Some((mac_name, new_span)) if mac_name.as_str() == name => return Some(new_span),
Expand All @@ -715,11 +711,7 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
/// `bar!` by
/// `is_direct_expn_of`.
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
let span_name_span = span
.ctxt()
.outer()
.expn_info()
.map(|ei| (ei.format.name(), ei.call_site));
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.format.name(), ei.call_site));

match span_name_span {
Some((mac_name, new_span)) if mac_name.as_str() == name => Some(new_span),
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
6 changes: 2 additions & 4 deletions clippy_lints/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec {
// report the error around the `vec!` not inside `<std macros>:`
let span = arg.span
.ctxt()
.outer()
.expn_info()
.outer_expn_info()
.map(|info| info.call_site)
.expect("unable to get call_site")
.ctxt()
.outer()
.expn_info()
.outer_expn_info()
.map(|info| info.call_site)
.expect("unable to get call_site");
check_vec_macro(cx, &vec_args, span);
Expand Down
6 changes: 3 additions & 3 deletions doc/adding_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ impl A {

// Default trait methods
trait B {
pub fn fo(&self) {}
pub fn foo(&self) {}
pub fn food(&self) {}
fn fo(&self) {}
fn foo(&self) {}
fn food(&self) {}
}

// Plain functions
Expand Down
9 changes: 6 additions & 3 deletions setup-toolchain.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/bash
# Set up the appropriate rustc toolchain

cd $(dirname $0)
cd "$(dirname "$0")"

if ! command -v rustup-toolchain-install-master > /dev/null; then
cargo install rustup-toolchain-install-master --debug
fi

cargo install rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed"
RUSTC_HASH=$(git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}')
rustup-toolchain-install-master -f -n master $RUSTC_HASH
rustup-toolchain-install-master -f -n master "$RUSTC_HASH"
rustup override set master

0 comments on commit 73df096

Please sign in to comment.