mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Merge remote-tracking branch 'origin/master' into laurent_master
This commit is contained in:
commit
561d47f338
15 changed files with 216 additions and 83 deletions
|
@ -1,6 +1,9 @@
|
|||
# Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## 0.0.170
|
||||
* Rustup to *rustc 1.23.0-nightly (d6b06c63a 2017-11-09)*
|
||||
|
||||
## 0.0.169
|
||||
* Rustup to *rustc 1.23.0-nightly (3b82e4c74 2017-11-05)*
|
||||
* New lints: [`just_underscores_and_digits`], [`result_map_unwrap_or_else`], [`transmute_bytes_to_str`]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "clippy"
|
||||
version = "0.0.169"
|
||||
version = "0.0.170"
|
||||
authors = [
|
||||
"Manish Goregaokar <manishsmail@gmail.com>",
|
||||
"Andre Bogus <bogusandre@gmail.com>",
|
||||
|
@ -37,12 +37,12 @@ path = "src/driver.rs"
|
|||
|
||||
[dependencies]
|
||||
# begin automatic update
|
||||
clippy_lints = { version = "0.0.169", path = "clippy_lints" }
|
||||
clippy_lints = { version = "0.0.170", path = "clippy_lints" }
|
||||
# end automatic update
|
||||
cargo_metadata = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
compiletest_rs = "0.2.7"
|
||||
compiletest_rs = "0.3"
|
||||
duct = "0.8.2"
|
||||
lazy_static = "0.2"
|
||||
regex = "0.2"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "clippy_lints"
|
||||
# begin automatic update
|
||||
version = "0.0.169"
|
||||
version = "0.0.170"
|
||||
# end automatic update
|
||||
authors = [
|
||||
"Manish Goregaokar <manishsmail@gmail.com>",
|
||||
|
|
|
@ -952,16 +952,17 @@ fn check_for_loop_range<'a, 'tcx>(
|
|||
let mut visitor = VarVisitor {
|
||||
cx: cx,
|
||||
var: canonical_id,
|
||||
indexed: HashMap::new(),
|
||||
indexed_mut: HashSet::new(),
|
||||
indexed_indirectly: HashMap::new(),
|
||||
indexed_directly: HashMap::new(),
|
||||
referenced: HashSet::new(),
|
||||
nonindex: false,
|
||||
prefer_mutable: false,
|
||||
};
|
||||
walk_expr(&mut visitor, body);
|
||||
|
||||
// linting condition: we only indexed one variable, and indexed it directly
|
||||
// (`indexed_directly` is subset of `indexed`)
|
||||
if visitor.indexed.len() == 1 && visitor.indexed_directly.len() == 1 {
|
||||
if visitor.indexed_indirectly.is_empty() && visitor.indexed_directly.len() == 1 {
|
||||
let (indexed, indexed_extent) = visitor
|
||||
.indexed_directly
|
||||
.into_iter()
|
||||
|
@ -1009,6 +1010,12 @@ fn check_for_loop_range<'a, 'tcx>(
|
|||
"".to_owned()
|
||||
};
|
||||
|
||||
let (ref_mut, method) = if visitor.indexed_mut.contains(&indexed) {
|
||||
("mut ", "iter_mut")
|
||||
} else {
|
||||
("", "iter")
|
||||
};
|
||||
|
||||
if visitor.nonindex {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
|
@ -1021,16 +1028,16 @@ fn check_for_loop_range<'a, 'tcx>(
|
|||
"consider using an iterator".to_string(),
|
||||
vec![
|
||||
(pat.span, format!("({}, <item>)", ident.node)),
|
||||
(arg.span, format!("{}.iter().enumerate(){}{}", indexed, take, skip)),
|
||||
(arg.span, format!("{}.{}().enumerate(){}{}", indexed, method, take, skip)),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
let repl = if starts_at_zero && take.is_empty() {
|
||||
format!("&{}", indexed)
|
||||
format!("&{}{}", ref_mut, indexed)
|
||||
} else {
|
||||
format!("{}.iter(){}{}", indexed, take, skip)
|
||||
format!("{}.{}(){}{}", indexed, method, take, skip)
|
||||
};
|
||||
|
||||
span_lint_and_then(
|
||||
|
@ -1537,8 +1544,10 @@ struct VarVisitor<'a, 'tcx: 'a> {
|
|||
cx: &'a LateContext<'a, 'tcx>,
|
||||
/// var name to look for as index
|
||||
var: ast::NodeId,
|
||||
/// indexed variables, the extend is `None` for global
|
||||
indexed: HashMap<Name, Option<region::Scope>>,
|
||||
/// indexed variables that are used mutably
|
||||
indexed_mut: HashSet<Name>,
|
||||
/// indirectly indexed variables (`v[(i + 4) % N]`), the extend is `None` for global
|
||||
indexed_indirectly: HashMap<Name, Option<region::Scope>>,
|
||||
/// subset of `indexed` of vars that are indexed directly: `v[i]`
|
||||
/// this will not contain cases like `v[calc_index(i)]` or `v[(i + 4) % N]`
|
||||
indexed_directly: HashMap<Name, Option<region::Scope>>,
|
||||
|
@ -1548,20 +1557,21 @@ struct VarVisitor<'a, 'tcx: 'a> {
|
|||
/// has the loop variable been used in expressions other than the index of
|
||||
/// an index op?
|
||||
nonindex: bool,
|
||||
/// Whether we are inside the `$` in `&mut $` or `$ = foo` or `$.bar`, where bar
|
||||
/// takes `&mut self`
|
||||
prefer_mutable: bool,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
||||
fn check(&mut self, idx: &'tcx Expr, seqexpr: &'tcx Expr, expr: &'tcx Expr) -> bool {
|
||||
if_chain! {
|
||||
// an index op
|
||||
if let ExprIndex(ref seqexpr, ref idx) = expr.node;
|
||||
// the indexed container is referenced by a name
|
||||
if let ExprPath(ref seqpath) = seqexpr.node;
|
||||
if let QPath::Resolved(None, ref seqvar) = *seqpath;
|
||||
if seqvar.segments.len() == 1;
|
||||
then {
|
||||
let index_used_directly = same_var(self.cx, idx, self.var);
|
||||
let index_used = index_used_directly || {
|
||||
let indexed_indirectly = {
|
||||
let mut used_visitor = LocalUsedVisitor {
|
||||
cx: self.cx,
|
||||
local: self.var,
|
||||
|
@ -1571,7 +1581,10 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
|||
used_visitor.used
|
||||
};
|
||||
|
||||
if index_used {
|
||||
if indexed_indirectly || index_used_directly {
|
||||
if self.prefer_mutable {
|
||||
self.indexed_mut.insert(seqvar.segments[0].name);
|
||||
}
|
||||
let def = self.cx.tables.qpath_def(seqpath, seqexpr.hir_id);
|
||||
match def {
|
||||
Def::Local(node_id) | Def::Upvar(node_id, ..) => {
|
||||
|
@ -1580,24 +1593,48 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
|||
let parent_id = self.cx.tcx.hir.get_parent(expr.id);
|
||||
let parent_def_id = self.cx.tcx.hir.local_def_id(parent_id);
|
||||
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
|
||||
self.indexed.insert(seqvar.segments[0].name, Some(extent));
|
||||
if indexed_indirectly {
|
||||
self.indexed_indirectly.insert(seqvar.segments[0].name, Some(extent));
|
||||
}
|
||||
if index_used_directly {
|
||||
self.indexed_directly.insert(seqvar.segments[0].name, Some(extent));
|
||||
}
|
||||
return; // no need to walk further *on the variable*
|
||||
return false; // no need to walk further *on the variable*
|
||||
}
|
||||
Def::Static(..) | Def::Const(..) => {
|
||||
self.indexed.insert(seqvar.segments[0].name, None);
|
||||
if indexed_indirectly {
|
||||
self.indexed_indirectly.insert(seqvar.segments[0].name, None);
|
||||
}
|
||||
if index_used_directly {
|
||||
self.indexed_directly.insert(seqvar.segments[0].name, None);
|
||||
}
|
||||
return; // no need to walk further *on the variable*
|
||||
return false; // no need to walk further *on the variable*
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
// a range index op
|
||||
if let ExprMethodCall(ref meth, _, ref args) = expr.node;
|
||||
if meth.name == "index" || meth.name == "index_mut";
|
||||
if !self.check(&args[1], &args[0], expr);
|
||||
then { return }
|
||||
}
|
||||
|
||||
if_chain! {
|
||||
// an index op
|
||||
if let ExprIndex(ref seqexpr, ref idx) = expr.node;
|
||||
if !self.check(idx, seqexpr, expr);
|
||||
then { return }
|
||||
}
|
||||
|
||||
if_chain! {
|
||||
// directly using a variable
|
||||
|
@ -1615,8 +1652,47 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
walk_expr(self, expr);
|
||||
let old = self.prefer_mutable;
|
||||
match expr.node {
|
||||
ExprAssignOp(_, ref lhs, ref rhs) |
|
||||
ExprAssign(ref lhs, ref rhs) => {
|
||||
self.prefer_mutable = true;
|
||||
self.visit_expr(lhs);
|
||||
self.prefer_mutable = false;
|
||||
self.visit_expr(rhs);
|
||||
},
|
||||
ExprAddrOf(mutbl, ref expr) => {
|
||||
if mutbl == MutMutable {
|
||||
self.prefer_mutable = true;
|
||||
}
|
||||
self.visit_expr(expr);
|
||||
},
|
||||
ExprCall(ref f, ref args) => {
|
||||
for (ty, expr) in self.cx.tables.expr_ty(f).fn_sig(self.cx.tcx).inputs().skip_binder().iter().zip(args) {
|
||||
self.prefer_mutable = false;
|
||||
if let ty::TyRef(_, mutbl) = ty.sty {
|
||||
if mutbl.mutbl == MutMutable {
|
||||
self.prefer_mutable = true;
|
||||
}
|
||||
}
|
||||
self.visit_expr(expr);
|
||||
}
|
||||
},
|
||||
ExprMethodCall(_, _, ref args) => {
|
||||
let def_id = self.cx.tables.type_dependent_defs()[expr.hir_id].def_id();
|
||||
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
|
||||
self.prefer_mutable = false;
|
||||
if let ty::TyRef(_, mutbl) = ty.sty {
|
||||
if mutbl.mutbl == MutMutable {
|
||||
self.prefer_mutable = true;
|
||||
}
|
||||
}
|
||||
self.visit_expr(expr);
|
||||
}
|
||||
},
|
||||
_ => walk_expr(self, expr),
|
||||
}
|
||||
self.prefer_mutable = old;
|
||||
}
|
||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
||||
NestedVisitorMap::None
|
||||
|
|
|
@ -888,9 +888,8 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir:
|
|||
}
|
||||
|
||||
// don't lint for constant values
|
||||
// FIXME: can we `expect` here instead of match?
|
||||
let owner_def = cx.tcx.hir.get_parent_did(arg.id);
|
||||
let promotable = cx.tcx.rvalue_promotable_map(owner_def)[&arg.hir_id.local_id];
|
||||
let promotable = cx.tcx.rvalue_promotable_map(owner_def).contains(&arg.hir_id.local_id);
|
||||
if promotable {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -620,14 +620,18 @@ where
|
|||
I: IntoIterator<Item = (Span, String)>,
|
||||
{
|
||||
let sugg = rustc_errors::CodeSuggestion {
|
||||
substitution_parts: sugg.into_iter()
|
||||
.map(|(span, sub)| {
|
||||
substitutions: vec![
|
||||
rustc_errors::Substitution {
|
||||
span: span,
|
||||
substitutions: vec![sub],
|
||||
parts: sugg.into_iter()
|
||||
.map(|(span, snippet)| {
|
||||
rustc_errors::SubstitutionPart {
|
||||
snippet,
|
||||
span,
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
],
|
||||
msg: help_msg,
|
||||
show_code_when_inline: true,
|
||||
};
|
||||
|
|
|
@ -22,7 +22,11 @@ fn run_mode(dir: &'static str, mode: &'static str) {
|
|||
}
|
||||
|
||||
config.mode = cfg_mode;
|
||||
config.build_base = PathBuf::from("target/debug/test_build_base");
|
||||
config.build_base = {
|
||||
let mut path = std::env::current_dir().unwrap();
|
||||
path.push("target/debug/test_build_base");
|
||||
path
|
||||
};
|
||||
config.src_base = PathBuf::from(format!("tests/{}", dir));
|
||||
config.rustc_path = clippy_driver_path();
|
||||
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
error: function is never used: `temporary_cstring`
|
||||
--> $DIR/cstring.rs:4:1
|
||||
|
|
||||
4 | fn temporary_cstring() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D dead-code` implied by `-D warnings`
|
||||
|
||||
error: you are getting the inner pointer of a temporary `CString`
|
||||
--> $DIR/cstring.rs:7:5
|
||||
|
|
||||
|
|
|
@ -82,7 +82,7 @@ error: the loop variable `i` is only used to index `vec`.
|
|||
help: consider using an iterator
|
||||
|
|
||||
86 | for <item> in &vec {
|
||||
| ^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
--> $DIR/for_loop.rs:95:5
|
||||
|
@ -95,7 +95,7 @@ error: the loop variable `i` is only used to index `vec`.
|
|||
help: consider using an iterator
|
||||
|
|
||||
95 | for <item> in &vec {
|
||||
| ^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `j` is only used to index `STATIC`.
|
||||
--> $DIR/for_loop.rs:100:5
|
||||
|
@ -108,7 +108,7 @@ error: the loop variable `j` is only used to index `STATIC`.
|
|||
help: consider using an iterator
|
||||
|
|
||||
100 | for <item> in STATIC.iter().take(4) {
|
||||
| ^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `j` is only used to index `CONST`.
|
||||
--> $DIR/for_loop.rs:104:5
|
||||
|
@ -121,7 +121,7 @@ error: the loop variable `j` is only used to index `CONST`.
|
|||
help: consider using an iterator
|
||||
|
|
||||
104 | for <item> in CONST.iter().take(4) {
|
||||
| ^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `i` is used to index `vec`
|
||||
--> $DIR/for_loop.rs:108:5
|
||||
|
@ -134,7 +134,7 @@ error: the loop variable `i` is used to index `vec`
|
|||
help: consider using an iterator
|
||||
|
|
||||
108 | for (i, <item>) in vec.iter().enumerate() {
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `i` is only used to index `vec2`.
|
||||
--> $DIR/for_loop.rs:116:5
|
||||
|
@ -147,7 +147,7 @@ error: the loop variable `i` is only used to index `vec2`.
|
|||
help: consider using an iterator
|
||||
|
|
||||
116 | for <item> in vec2.iter().take(vec.len()) {
|
||||
| ^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
--> $DIR/for_loop.rs:120:5
|
||||
|
@ -160,7 +160,7 @@ error: the loop variable `i` is only used to index `vec`.
|
|||
help: consider using an iterator
|
||||
|
|
||||
120 | for <item> in vec.iter().skip(5) {
|
||||
| ^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
--> $DIR/for_loop.rs:124:5
|
||||
|
@ -173,7 +173,7 @@ error: the loop variable `i` is only used to index `vec`.
|
|||
help: consider using an iterator
|
||||
|
|
||||
124 | for <item> in vec.iter().take(MAX_LEN) {
|
||||
| ^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
--> $DIR/for_loop.rs:128:5
|
||||
|
@ -186,7 +186,7 @@ error: the loop variable `i` is only used to index `vec`.
|
|||
help: consider using an iterator
|
||||
|
|
||||
128 | for <item> in vec.iter().take(MAX_LEN + 1) {
|
||||
| ^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
--> $DIR/for_loop.rs:132:5
|
||||
|
@ -199,7 +199,7 @@ error: the loop variable `i` is only used to index `vec`.
|
|||
help: consider using an iterator
|
||||
|
|
||||
132 | for <item> in vec.iter().take(10).skip(5) {
|
||||
| ^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
--> $DIR/for_loop.rs:136:5
|
||||
|
@ -212,7 +212,7 @@ error: the loop variable `i` is only used to index `vec`.
|
|||
help: consider using an iterator
|
||||
|
|
||||
136 | for <item> in vec.iter().take(10 + 1).skip(5) {
|
||||
| ^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `i` is used to index `vec`
|
||||
--> $DIR/for_loop.rs:140:5
|
||||
|
@ -225,7 +225,7 @@ error: the loop variable `i` is used to index `vec`
|
|||
help: consider using an iterator
|
||||
|
|
||||
140 | for (i, <item>) in vec.iter().enumerate().skip(5) {
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: the loop variable `i` is used to index `vec`
|
||||
--> $DIR/for_loop.rs:144:5
|
||||
|
@ -238,7 +238,7 @@ error: the loop variable `i` is used to index `vec`
|
|||
help: consider using an iterator
|
||||
|
|
||||
144 | for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: this range is empty so this for loop will never run
|
||||
--> $DIR/for_loop.rs:148:5
|
||||
|
@ -448,7 +448,7 @@ error: you seem to want to iterate on a map's values
|
|||
help: use the corresponding method
|
||||
|
|
||||
385 | for v in m.values() {
|
||||
| ^
|
||||
|
|
||||
|
||||
error: you seem to want to iterate on a map's values
|
||||
--> $DIR/for_loop.rs:390:5
|
||||
|
@ -464,7 +464,7 @@ error: you seem to want to iterate on a map's values
|
|||
help: use the corresponding method
|
||||
|
|
||||
390 | for v in (*m).values() {
|
||||
| ^
|
||||
|
|
||||
|
||||
error: you seem to want to iterate on a map's values
|
||||
--> $DIR/for_loop.rs:398:5
|
||||
|
@ -477,7 +477,7 @@ error: you seem to want to iterate on a map's values
|
|||
help: use the corresponding method
|
||||
|
|
||||
398 | for v in m.values_mut() {
|
||||
| ^
|
||||
|
|
||||
|
||||
error: you seem to want to iterate on a map's values
|
||||
--> $DIR/for_loop.rs:403:5
|
||||
|
@ -490,7 +490,7 @@ error: you seem to want to iterate on a map's values
|
|||
help: use the corresponding method
|
||||
|
|
||||
403 | for v in (*m).values_mut() {
|
||||
| ^
|
||||
|
|
||||
|
||||
error: you seem to want to iterate on a map's keys
|
||||
--> $DIR/for_loop.rs:409:5
|
||||
|
@ -503,7 +503,7 @@ error: you seem to want to iterate on a map's keys
|
|||
help: use the corresponding method
|
||||
|
|
||||
409 | for k in rm.keys() {
|
||||
| ^
|
||||
|
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/for_loop.rs:462:5
|
||||
|
|
|
@ -8,11 +8,11 @@ error: impl for `HashMap` should be generalized over different hashers
|
|||
help: consider adding a type parameter
|
||||
|
|
||||
11 | impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<i8> for HashMap<K, V, S> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: ...and use generic constructor
|
||||
|
|
||||
17 | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default()))
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: impl for `HashMap` should be generalized over different hashers
|
||||
--> $DIR/implicit_hasher.rs:20:36
|
||||
|
@ -23,11 +23,11 @@ error: impl for `HashMap` should be generalized over different hashers
|
|||
help: consider adding a type parameter
|
||||
|
|
||||
20 | impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<i8> for (HashMap<K, V, S>,) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: ...and use generic constructor
|
||||
|
|
||||
22 | ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),))
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: impl for `HashMap` should be generalized over different hashers
|
||||
--> $DIR/implicit_hasher.rs:25:19
|
||||
|
@ -38,11 +38,11 @@ error: impl for `HashMap` should be generalized over different hashers
|
|||
help: consider adding a type parameter
|
||||
|
|
||||
25 | impl<S: ::std::hash::BuildHasher + Default> Foo<i16> for HashMap<String, String, S> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: ...and use generic constructor
|
||||
|
|
||||
27 | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default()))
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: impl for `HashSet` should be generalized over different hashers
|
||||
--> $DIR/implicit_hasher.rs:43:32
|
||||
|
@ -53,11 +53,11 @@ error: impl for `HashSet` should be generalized over different hashers
|
|||
help: consider adding a type parameter
|
||||
|
|
||||
43 | impl<T: Hash + Eq, S: ::std::hash::BuildHasher + Default> Foo<i8> for HashSet<T, S> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: ...and use generic constructor
|
||||
|
|
||||
45 | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default()))
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: impl for `HashSet` should be generalized over different hashers
|
||||
--> $DIR/implicit_hasher.rs:48:19
|
||||
|
@ -68,11 +68,11 @@ error: impl for `HashSet` should be generalized over different hashers
|
|||
help: consider adding a type parameter
|
||||
|
|
||||
48 | impl<S: ::std::hash::BuildHasher + Default> Foo<i16> for HashSet<String, S> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: ...and use generic constructor
|
||||
|
|
||||
50 | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default()))
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: parameter of type `HashMap` should be generalized over different hashers
|
||||
--> $DIR/implicit_hasher.rs:65:23
|
||||
|
@ -83,7 +83,7 @@ error: parameter of type `HashMap` should be generalized over different hashers
|
|||
help: consider adding a type parameter
|
||||
|
|
||||
65 | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32, S>, _set: &mut HashSet<i32>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: parameter of type `HashSet` should be generalized over different hashers
|
||||
--> $DIR/implicit_hasher.rs:65:53
|
||||
|
@ -94,7 +94,7 @@ error: parameter of type `HashSet` should be generalized over different hashers
|
|||
help: consider adding a type parameter
|
||||
|
|
||||
65 | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32, S>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: impl for `HashMap` should be generalized over different hashers
|
||||
--> $DIR/implicit_hasher.rs:70:43
|
||||
|
@ -108,11 +108,11 @@ error: impl for `HashMap` should be generalized over different hashers
|
|||
help: consider adding a type parameter
|
||||
|
|
||||
70 | impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<u8> for HashMap<K, V, S> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: ...and use generic constructor
|
||||
|
|
||||
72 | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default()))
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: parameter of type `HashMap` should be generalized over different hashers
|
||||
--> $DIR/implicit_hasher.rs:78:33
|
||||
|
@ -126,7 +126,7 @@ error: parameter of type `HashMap` should be generalized over different hashers
|
|||
help: consider adding a type parameter
|
||||
|
|
||||
78 | pub fn $name<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32, S>, _set: &mut HashSet<i32>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: parameter of type `HashSet` should be generalized over different hashers
|
||||
--> $DIR/implicit_hasher.rs:78:63
|
||||
|
@ -140,5 +140,5 @@ error: parameter of type `HashSet` should be generalized over different hashers
|
|||
help: consider adding a type parameter
|
||||
|
|
||||
78 | pub fn $name<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32, S>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ error: you don't need to add `&` to all patterns
|
|||
help: instead of prefixing all patterns with `&`, you can dereference the expression
|
||||
|
|
||||
138 | match *v { .. }
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: you don't need to add `&` to all patterns
|
||||
--> $DIR/matches.rs:148:5
|
||||
|
@ -147,7 +147,7 @@ error: you don't need to add `&` to all patterns
|
|||
help: instead of prefixing all patterns with `&`, you can dereference the expression
|
||||
|
|
||||
148 | match *tup { .. }
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: you don't need to add `&` to both the expression and the patterns
|
||||
--> $DIR/matches.rs:154:5
|
||||
|
@ -169,7 +169,7 @@ error: you don't need to add `&` to all patterns
|
|||
help: instead of prefixing all patterns with `&`, you can dereference the expression
|
||||
|
|
||||
165 | if let .. = *a { .. }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: you don't need to add `&` to both the expression and the patterns
|
||||
--> $DIR/matches.rs:170:5
|
||||
|
|
|
@ -24,4 +24,32 @@ fn main() {
|
|||
for i in 3..10 {
|
||||
println!("{}", ns[calc_idx(i) % 4]);
|
||||
}
|
||||
|
||||
let mut ms = vec![1, 2, 3, 4, 5, 6];
|
||||
for i in 0..ms.len() {
|
||||
ms[i] *= 2;
|
||||
}
|
||||
assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]);
|
||||
|
||||
let mut ms = vec![1, 2, 3, 4, 5, 6];
|
||||
for i in 0..ms.len() {
|
||||
let x = &mut ms[i];
|
||||
*x *= 2;
|
||||
}
|
||||
assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]);
|
||||
|
||||
let g = vec![1, 2, 3, 4, 5, 6];
|
||||
let glen = g.len();
|
||||
for i in 0..glen {
|
||||
let x: u32 = g[i+1..].iter().sum();
|
||||
println!("{}", g[i] + x);
|
||||
}
|
||||
assert_eq!(g, vec![20, 18, 15, 11, 6, 0]);
|
||||
|
||||
let mut g = vec![1, 2, 3, 4, 5, 6];
|
||||
let glen = g.len();
|
||||
for i in 0..glen {
|
||||
g[i] = g[i+1..].iter().sum();
|
||||
}
|
||||
assert_eq!(g, vec![20, 18, 15, 11, 6, 0]);
|
||||
}
|
||||
|
|
|
@ -10,5 +10,32 @@ error: the loop variable `i` is only used to index `ns`.
|
|||
help: consider using an iterator
|
||||
|
|
||||
8 | for <item> in ns.iter().take(10).skip(3) {
|
||||
|
|
||||
|
||||
error: the loop variable `i` is only used to index `ms`.
|
||||
--> $DIR/needless_range_loop.rs:29:5
|
||||
|
|
||||
29 | / for i in 0..ms.len() {
|
||||
30 | | ms[i] *= 2;
|
||||
31 | | }
|
||||
| |_____^
|
||||
|
|
||||
help: consider using an iterator
|
||||
|
|
||||
29 | for <item> in &mut ms {
|
||||
| ^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `ms`.
|
||||
--> $DIR/needless_range_loop.rs:35:5
|
||||
|
|
||||
35 | / for i in 0..ms.len() {
|
||||
36 | | let x = &mut ms[i];
|
||||
37 | | *x *= 2;
|
||||
38 | | }
|
||||
| |_____^
|
||||
|
|
||||
help: consider using an iterator
|
||||
|
|
||||
35 | for <item> in &mut ms {
|
||||
| ^^^^^^
|
||||
|
||||
|
|
|
@ -8,5 +8,5 @@ error: needlessly taken reference of both operands
|
|||
help: use the values directly
|
||||
|
|
||||
13 | let foo = 5 - 6;
|
||||
| ^
|
||||
|
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ help: change `x.clone()` to
|
|||
help: change `x.clone()` to
|
||||
|
|
||||
46 | x.to_owned()
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: writing `&String` instead of `&str` involves a new object where a slice will do.
|
||||
--> $DIR/ptr_arg.rs:49:18
|
||||
|
@ -58,7 +58,7 @@ help: change `x.clone()` to
|
|||
help: change `x.clone()` to
|
||||
|
|
||||
56 | x.to_string()
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
|
||||
error: writing `&String` instead of `&str` involves a new object where a slice will do.
|
||||
--> $DIR/ptr_arg.rs:59:44
|
||||
|
|
Loading…
Reference in a new issue