From 652df0fb79666dc976bed3a08d0db7f454014951 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 7 Nov 2017 14:41:54 +0100 Subject: [PATCH 1/5] Differentiate between mutable iteration and immutable iteration in `needless_range_loop` --- clippy_lints/src/loops.rs | 65 ++++++++++++++++++++++++++--- tests/ui/needless_range_loop.rs | 13 ++++++ tests/ui/needless_range_loop.stderr | 27 ++++++++++++ 3 files changed, 100 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 80aa7892a26..ecaa64c8724 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -952,10 +952,12 @@ fn check_for_loop_range<'a, 'tcx>( let mut visitor = VarVisitor { cx: cx, var: canonical_id, + indexed_mut: HashSet::new(), indexed: HashMap::new(), indexed_directly: HashMap::new(), referenced: HashSet::new(), nonindex: false, + prefer_mutable: false, }; walk_expr(&mut visitor, body); @@ -1009,6 +1011,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 +1029,16 @@ fn check_for_loop_range<'a, 'tcx>( "consider using an iterator".to_string(), vec![ (pat.span, format!("({}, )", 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,6 +1545,8 @@ struct VarVisitor<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, /// var name to look for as index var: ast::NodeId, + /// indexed variables that are used mutably + indexed_mut: HashSet, /// indexed variables, the extend is `None` for global indexed: HashMap>, /// subset of `indexed` of vars that are indexed directly: `v[i]` @@ -1548,6 +1558,9 @@ 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> { @@ -1572,6 +1585,9 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { }; if index_used { + 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, ..) => { @@ -1615,8 +1631,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 diff --git a/tests/ui/needless_range_loop.rs b/tests/ui/needless_range_loop.rs index b960e3990c1..6f1e5f53ce2 100644 --- a/tests/ui/needless_range_loop.rs +++ b/tests/ui/needless_range_loop.rs @@ -24,4 +24,17 @@ 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]); } diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr index e2c3e18e821..9b6be856b85 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -12,3 +12,30 @@ help: consider using an iterator 8 | for 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 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 in &mut ms { + | ^^^^^^ + From 1b323b9f355c0b3cdf0729f57880240ade00d56f Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 7 Nov 2017 15:32:52 +0100 Subject: [PATCH 2/5] Don't lint mixed slice indexing and usize indexing in `needless_range_loop` --- clippy_lints/src/loops.rs | 51 +++++++++++++++++++++++---------- tests/ui/needless_range_loop.rs | 15 ++++++++++ 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index ecaa64c8724..babf3d3cc16 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -953,7 +953,7 @@ fn check_for_loop_range<'a, 'tcx>( cx: cx, var: canonical_id, indexed_mut: HashSet::new(), - indexed: HashMap::new(), + indexed_indirectly: HashMap::new(), indexed_directly: HashMap::new(), referenced: HashSet::new(), nonindex: false, @@ -962,8 +962,7 @@ fn check_for_loop_range<'a, 'tcx>( 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() @@ -1547,8 +1546,8 @@ struct VarVisitor<'a, 'tcx: 'a> { var: ast::NodeId, /// indexed variables that are used mutably indexed_mut: HashSet, - /// indexed variables, the extend is `None` for global - indexed: HashMap>, + /// indirectly indexed variables (`v[(i + 4) % N]`), the extend is `None` for global + indexed_indirectly: HashMap>, /// 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>, @@ -1563,18 +1562,16 @@ struct VarVisitor<'a, 'tcx: 'a> { 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, @@ -1584,7 +1581,7 @@ 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); } @@ -1596,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 diff --git a/tests/ui/needless_range_loop.rs b/tests/ui/needless_range_loop.rs index 6f1e5f53ce2..30613f98f2b 100644 --- a/tests/ui/needless_range_loop.rs +++ b/tests/ui/needless_range_loop.rs @@ -37,4 +37,19 @@ fn main() { *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]); } From 5c0b99820b6f7d4e35cc8c8a73f60f7de4001e73 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Thu, 9 Nov 2017 11:05:49 +0900 Subject: [PATCH 3/5] Use compiletest 0.3 --- Cargo.toml | 2 +- tests/compile-test.rs | 4 +++- tests/ui/cstring.stderr | 8 -------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 047d966be66..2fbf6d17ce4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ clippy_lints = { version = "0.0.169", path = "clippy_lints" } 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" diff --git a/tests/compile-test.rs b/tests/compile-test.rs index be8793215dc..cda3a586546 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -22,7 +22,9 @@ 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 = PathBuf::from("target/debug/test_build_base") + .canonicalize() + .unwrap(); config.src_base = PathBuf::from(format!("tests/{}", dir)); config.rustc_path = clippy_driver_path(); diff --git a/tests/ui/cstring.stderr b/tests/ui/cstring.stderr index ddb74ce9cac..c3dd9cf83f6 100644 --- a/tests/ui/cstring.stderr +++ b/tests/ui/cstring.stderr @@ -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 | From b17899878f3efe6802bc6604b922822c7d9ab309 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Thu, 9 Nov 2017 14:47:14 +0900 Subject: [PATCH 4/5] Build path from current_dir --- tests/compile-test.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index cda3a586546..bd968cc6009 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -22,9 +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") - .canonicalize() - .unwrap(); + 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(); From 299f1270a6d0dfa9b77ab0c61b1f25f257a9b692 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 10 Nov 2017 08:58:54 +0100 Subject: [PATCH 5/5] Rustup --- CHANGELOG.md | 3 +++ Cargo.toml | 4 ++-- clippy_lints/Cargo.toml | 2 +- clippy_lints/src/methods.rs | 3 +-- clippy_lints/src/utils/mod.rs | 20 +++++++++------- tests/ui/for_loop.stderr | 36 ++++++++++++++--------------- tests/ui/implicit_hasher.stderr | 32 ++++++++++++------------- tests/ui/matches.stderr | 6 ++--- tests/ui/needless_range_loop.stderr | 2 +- tests/ui/op_ref.stderr | 2 +- tests/ui/ptr_arg.stderr | 4 ++-- 11 files changed, 60 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df19e84a194..4603c27e266 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`] diff --git a/Cargo.toml b/Cargo.toml index 2fbf6d17ce4..157a0d18a99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.169" +version = "0.0.170" authors = [ "Manish Goregaokar ", "Andre Bogus ", @@ -37,7 +37,7 @@ 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" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 41803b6ee3e..e2b8d654682 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -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 ", diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 251c4ac3a11..ee61920b489 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -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; } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index c557e856bf4..a0323df1f62 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -620,14 +620,18 @@ where I: IntoIterator, { let sugg = rustc_errors::CodeSuggestion { - substitution_parts: sugg.into_iter() - .map(|(span, sub)| { - rustc_errors::Substitution { - span: span, - substitutions: vec![sub], - } - }) - .collect(), + substitutions: vec![ + rustc_errors::Substitution { + parts: sugg.into_iter() + .map(|(span, snippet)| { + rustc_errors::SubstitutionPart { + snippet, + span, + } + }) + .collect(), + } + ], msg: help_msg, show_code_when_inline: true, }; diff --git a/tests/ui/for_loop.stderr b/tests/ui/for_loop.stderr index 620c32b6ab5..f968e088866 100644 --- a/tests/ui/for_loop.stderr +++ b/tests/ui/for_loop.stderr @@ -82,7 +82,7 @@ error: the loop variable `i` is only used to index `vec`. help: consider using an iterator | 86 | for 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 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 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 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, ) 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 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 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 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 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 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 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, ) 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, ) 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 diff --git a/tests/ui/implicit_hasher.stderr b/tests/ui/implicit_hasher.stderr index 27d6e2cec08..52b686bf8ae 100644 --- a/tests/ui/implicit_hasher.stderr +++ b/tests/ui/implicit_hasher.stderr @@ -8,11 +8,11 @@ error: impl for `HashMap` should be generalized over different hashers help: consider adding a type parameter | 11 | impl Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | 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 Foo for (HashMap,) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | 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 Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | 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 Foo for HashSet { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | 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 Foo for HashSet { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | 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(_map: &mut HashMap, _set: &mut HashSet) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | 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(_map: &mut HashMap, _set: &mut HashSet) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | 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 Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | 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(_map: &mut HashMap, _set: &mut HashSet) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | 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(_map: &mut HashMap, _set: &mut HashSet) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | diff --git a/tests/ui/matches.stderr b/tests/ui/matches.stderr index 1c2452c46ce..7ff38a35341 100644 --- a/tests/ui/matches.stderr +++ b/tests/ui/matches.stderr @@ -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 diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr index e2c3e18e821..e54c0e7d011 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -10,5 +10,5 @@ error: the loop variable `i` is only used to index `ns`. help: consider using an iterator | 8 | for in ns.iter().take(10).skip(3) { - | ^^^^^^ + | diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr index dbe53933fd5..32596944570 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -8,5 +8,5 @@ error: needlessly taken reference of both operands help: use the values directly | 13 | let foo = 5 - 6; - | ^ + | diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr index 13be68d4cd4..9c6804cd9a0 100644 --- a/tests/ui/ptr_arg.stderr +++ b/tests/ui/ptr_arg.stderr @@ -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