Skip to content

Commit 73df096

Browse files
committed
Update clippy
1 parent f9a5348 commit 73df096

16 files changed

+90
-67
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ semver = "0.9"
4545
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
4646

4747
[dev-dependencies]
48-
cargo_metadata = "0.7.1"
48+
cargo_metadata = "0.8.0"
4949
compiletest_rs = { version = "0.3.22", features = ["tmp"] }
5050
lazy_static = "1.0"
5151
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }

clippy_dev/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Philipp Hansch <[email protected]>"]
55
edition = "2018"
66

77
[dependencies]
8-
clap = "~2.32"
8+
clap = "2.33"
99
itertools = "0.8"
1010
regex = "1"
1111
lazy_static = "1.0"

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ keywords = ["clippy", "lint", "plugin"]
1717
edition = "2018"
1818

1919
[dependencies]
20-
cargo_metadata = "0.7.1"
20+
cargo_metadata = "0.8.0"
2121
itertools = "0.8"
2222
lazy_static = "1.0.2"
2323
matches = "0.1.7"

clippy_lints/src/escape.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
7979

8080
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
8181
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
82-
ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).consume_body(body);
82+
ExprUseVisitor::new(
83+
&mut v,
84+
cx.tcx,
85+
fn_def_id,
86+
cx.param_env,
87+
region_scope_tree,
88+
cx.tables,
89+
None,
90+
)
91+
.consume_body(body);
8392

8493
for node in v.set {
8594
span_lint(

clippy_lints/src/loops.rs

+27-21
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ declare_clippy_lint! {
6161
/// **Known problems:** None.
6262
///
6363
/// **Example:**
64-
/// ```ignore
64+
/// ```rust
65+
/// let vec = vec!['a', 'b', 'c'];
6566
/// for i in 0..vec.len() {
6667
/// println!("{}", vec[i]);
6768
/// }
6869
/// ```
70+
/// Could be written as:
71+
/// ```rust
72+
/// let vec = vec!['a', 'b', 'c'];
73+
/// for i in vec {
74+
/// println!("{}", i);
75+
/// }
76+
/// ```
6977
pub NEEDLESS_RANGE_LOOP,
7078
style,
7179
"for-looping over a range of indices where an iterator over items would do"
@@ -1662,7 +1670,16 @@ fn check_for_mutation(
16621670
};
16631671
let def_id = def_id::DefId::local(body.hir_id.owner);
16641672
let region_scope_tree = &cx.tcx.region_scope_tree(def_id);
1665-
ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).walk_expr(body);
1673+
ExprUseVisitor::new(
1674+
&mut delegate,
1675+
cx.tcx,
1676+
def_id,
1677+
cx.param_env,
1678+
region_scope_tree,
1679+
cx.tables,
1680+
None,
1681+
)
1682+
.walk_expr(body);
16661683
delegate.mutation_span()
16671684
}
16681685

@@ -1769,7 +1786,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
17691786
}
17701787
let res = self.cx.tables.qpath_res(seqpath, seqexpr.hir_id);
17711788
match res {
1772-
Res::Local(hir_id) | Res::Upvar(hir_id, ..) => {
1789+
Res::Local(hir_id) => {
17731790
let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
17741791
let parent_def_id = self.cx.tcx.hir().local_def_id_from_hir_id(parent_id);
17751792
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
@@ -1829,24 +1846,13 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18291846
if let QPath::Resolved(None, ref path) = *qpath;
18301847
if path.segments.len() == 1;
18311848
then {
1832-
match self.cx.tables.qpath_res(qpath, expr.hir_id) {
1833-
Res::Upvar(local_id, ..) => {
1834-
if local_id == self.var {
1835-
// we are not indexing anything, record that
1836-
self.nonindex = true;
1837-
}
1838-
}
1839-
Res::Local(local_id) =>
1840-
{
1841-
1842-
if local_id == self.var {
1843-
self.nonindex = true;
1844-
} else {
1845-
// not the correct variable, but still a variable
1846-
self.referenced.insert(path.segments[0].ident.name);
1847-
}
1849+
if let Res::Local(local_id) = self.cx.tables.qpath_res(qpath, expr.hir_id) {
1850+
if local_id == self.var {
1851+
self.nonindex = true;
1852+
} else {
1853+
// not the correct variable, but still a variable
1854+
self.referenced.insert(path.segments[0].ident.name);
18481855
}
1849-
_ => {}
18501856
}
18511857
}
18521858
}
@@ -2378,7 +2384,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
23782384
let res = self.cx.tables.qpath_res(qpath, ex.hir_id);
23792385
then {
23802386
match res {
2381-
Res::Local(node_id) | Res::Upvar(node_id, ..) => {
2387+
Res::Local(node_id) => {
23822388
self.ids.insert(node_id);
23832389
},
23842390
Res::Def(DefKind::Static, def_id) => {

clippy_lints/src/misc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -594,16 +594,16 @@ fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
594594
fn in_attributes_expansion(expr: &Expr) -> bool {
595595
expr.span
596596
.ctxt()
597-
.outer()
598-
.expn_info()
597+
.outer_expn_info()
599598
.map_or(false, |info| matches!(info.format, ExpnFormat::MacroAttribute(_)))
600599
}
601600

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

clippy_lints/src/needless_pass_by_value.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
137137
} = {
138138
let mut ctx = MovedVariablesCtxt::new(cx);
139139
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
140-
euv::ExprUseVisitor::new(&mut ctx, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None)
141-
.consume_body(body);
140+
euv::ExprUseVisitor::new(
141+
&mut ctx,
142+
cx.tcx,
143+
fn_def_id,
144+
cx.param_env,
145+
region_scope_tree,
146+
cx.tables,
147+
None,
148+
)
149+
.consume_body(body);
142150
ctx
143151
};
144152

clippy_lints/src/panic_unimplemented.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
6969

7070
fn get_outer_span(expr: &Expr) -> Span {
7171
if_chain! {
72-
if let Some(first) = expr.span.ctxt().outer().expn_info();
73-
if let Some(second) = first.call_site.ctxt().outer().expn_info();
72+
if let Some(first) = expr.span.ctxt().outer_expn_info();
73+
if let Some(second) = first.call_site.ctxt().outer_expn_info();
7474
then {
7575
second.call_site
7676
} else {

clippy_lints/src/ranges.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges {
148148
then {
149149
let span = expr.span
150150
.ctxt()
151-
.outer()
152-
.expn_info()
151+
.outer_expn_info()
153152
.map_or(expr.span, |info| info.call_site);
154153
span_lint_and_then(
155154
cx,

clippy_lints/src/returns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn attr_is_cfg(attr: &ast::Attribute) -> bool {
272272

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

278278
// is this expr a `()` unit?

clippy_lints/src/utils/internal_lints.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
156156
// actual span that invoked `declare_tool_lint!`:
157157
let lint_span = lint_span
158158
.ctxt()
159-
.outer()
160-
.expn_info()
159+
.outer_expn_info()
161160
.map(|ei| ei.call_site)
162161
.expect("unable to get call_site");
163162

clippy_lints/src/utils/mod.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
9494

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

100100
/// Returns `true` if this `expn_info` was expanded by any macro.
101101
pub fn in_macro(span: Span) -> bool {
102-
if let Some(info) = span.ctxt().outer().expn_info() {
102+
if let Some(info) = span.ctxt().outer_expn_info() {
103103
if let ExpnFormat::CompilerDesugaring(..) = info.format {
104104
false
105105
} else {
@@ -691,11 +691,7 @@ pub fn is_adjusted(cx: &LateContext<'_, '_>, e: &Expr) -> bool {
691691
/// See also `is_direct_expn_of`.
692692
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
693693
loop {
694-
let span_name_span = span
695-
.ctxt()
696-
.outer()
697-
.expn_info()
698-
.map(|ei| (ei.format.name(), ei.call_site));
694+
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.format.name(), ei.call_site));
699695

700696
match span_name_span {
701697
Some((mac_name, new_span)) if mac_name.as_str() == name => return Some(new_span),
@@ -715,11 +711,7 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
715711
/// `bar!` by
716712
/// `is_direct_expn_of`.
717713
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
718-
let span_name_span = span
719-
.ctxt()
720-
.outer()
721-
.expn_info()
722-
.map(|ei| (ei.format.name(), ei.call_site));
714+
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.format.name(), ei.call_site));
723715

724716
match span_name_span {
725717
Some((mac_name, new_span)) if mac_name.as_str() == name => Some(new_span),

clippy_lints/src/utils/usage.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ pub fn mutated_variables<'a, 'tcx: 'a>(expr: &'tcx Expr, cx: &'a LateContext<'a,
1616
};
1717
let def_id = def_id::DefId::local(expr.hir_id.owner);
1818
let region_scope_tree = &cx.tcx.region_scope_tree(def_id);
19-
ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).walk_expr(expr);
19+
ExprUseVisitor::new(
20+
&mut delegate,
21+
cx.tcx,
22+
def_id,
23+
cx.param_env,
24+
region_scope_tree,
25+
cx.tables,
26+
None,
27+
)
28+
.walk_expr(expr);
2029

2130
if delegate.skip {
2231
return None;
@@ -29,11 +38,11 @@ pub fn is_potentially_mutated<'a, 'tcx: 'a>(
2938
expr: &'tcx Expr,
3039
cx: &'a LateContext<'a, 'tcx>,
3140
) -> bool {
32-
let id = match variable.res {
33-
Res::Local(id) | Res::Upvar(id, ..) => id,
34-
_ => return true,
35-
};
36-
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id))
41+
if let Res::Local(id) = variable.res {
42+
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id))
43+
} else {
44+
return true;
45+
}
3746
}
3847

3948
struct MutVarsDelegate {

clippy_lints/src/vec.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec {
4949
// report the error around the `vec!` not inside `<std macros>:`
5050
let span = arg.span
5151
.ctxt()
52-
.outer()
53-
.expn_info()
52+
.outer_expn_info()
5453
.map(|info| info.call_site)
5554
.expect("unable to get call_site")
5655
.ctxt()
57-
.outer()
58-
.expn_info()
56+
.outer_expn_info()
5957
.map(|info| info.call_site)
6058
.expect("unable to get call_site");
6159
check_vec_macro(cx, &vec_args, span);

doc/adding_lints.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ impl A {
5757

5858
// Default trait methods
5959
trait B {
60-
pub fn fo(&self) {}
61-
pub fn foo(&self) {}
62-
pub fn food(&self) {}
60+
fn fo(&self) {}
61+
fn foo(&self) {}
62+
fn food(&self) {}
6363
}
6464

6565
// Plain functions

setup-toolchain.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/bin/bash
22
# Set up the appropriate rustc toolchain
33

4-
cd $(dirname $0)
4+
cd "$(dirname "$0")"
5+
6+
if ! command -v rustup-toolchain-install-master > /dev/null; then
7+
cargo install rustup-toolchain-install-master --debug
8+
fi
59

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

0 commit comments

Comments
 (0)