Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 60e8413

Browse files
committedNov 23, 2019
Auto merge of #4825 - Manishearth:rustup, r=flip1995
Rustup to rustc 1.41.0-nightly (35ef33a 2019-11-21) I don't have the right fix for the fmtstr tests, and I'm also hitting problems caused by messense/rustc-test#3 List of rustups: - rust-lang/rust#66271 (syntax: Keep string literals in ABIs and `asm!` more precisely) - rust-lang/rust#65355 (Stabilize `!` in Rust 1.41.0) - rust-lang/rust#66515 (Reduce size of `hir::Expr` by boxing more of `hir::InlineAsm`) - rust-lang/rust#66389 (Specific labels when referring to "expected" and "found" types) - rust-lang/rust#66074 ([mir-opt] Turn on the `ConstProp` pass by default) changelog: none
2 parents b4f1769 + 553db87 commit 60e8413

26 files changed

+132
-182
lines changed
 

‎.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ matrix:
6161
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6262
- env: INTEGRATION=rust-lang/cargo
6363
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
64-
- env: INTEGRATION=rust-lang-nursery/chalk
65-
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
64+
# FIXME: Output too large
65+
# - env: INTEGRATION=rust-lang-nursery/chalk
66+
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6667
- env: INTEGRATION=Geal/nom
6768
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6869
# FIXME blocked on https://github.com/rust-lang/rust-clippy/issues/4727
@@ -72,8 +73,9 @@ matrix:
7273
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7374
- env: INTEGRATION=bluss/rust-itertools
7475
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
75-
- env: INTEGRATION=serde-rs/serde
76-
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
76+
# FIXME: rustc ICE on `serde_test_suite`
77+
# - env: INTEGRATION=serde-rs/serde
78+
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7779
- env: INTEGRATION=rust-lang-nursery/stdsimd
7880
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7981
- env: INTEGRATION=rust-random/rand

‎Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
4141

4242
[dev-dependencies]
4343
cargo_metadata = "0.9.0"
44-
compiletest_rs = { version = "0.3.24", features = ["tmp"] }
44+
compiletest_rs = { version = "0.4.0", features = ["tmp"] }
45+
tester = "0.7"
4546
lazy_static = "1.0"
4647
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
4748
serde = { version = "1.0", features = ["derive"] }

‎clippy_lints/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#![feature(box_syntax)]
44
#![feature(box_patterns)]
5-
#![feature(never_type)]
65
#![feature(rustc_private)]
76
#![feature(slice_patterns)]
87
#![feature(stmt_expr_attributes)]

‎clippy_lints/src/loops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
720720
ExprKind::Struct(_, _, None)
721721
| ExprKind::Yield(_, _)
722722
| ExprKind::Closure(_, _, _, _, _)
723-
| ExprKind::InlineAsm(_, _, _)
723+
| ExprKind::InlineAsm(_)
724724
| ExprKind::Path(_)
725725
| ExprKind::Lit(_)
726726
| ExprKind::Err => NeverLoopResult::Otherwise,

‎clippy_lints/src/utils/author.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
458458
println!("Ret(None) = {};", current);
459459
}
460460
},
461-
ExprKind::InlineAsm(_, ref _input, ref _output) => {
462-
println!("InlineAsm(_, ref input, ref output) = {};", current);
461+
ExprKind::InlineAsm(_) => {
462+
println!("InlineAsm(_) = {};", current);
463463
println!(" // unimplemented: `ExprKind::InlineAsm` is not further destructured at the moment");
464464
},
465465
ExprKind::Struct(ref path, ref fields, ref opt_base) => {

‎clippy_lints/src/utils/inspector.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,16 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) {
282282
print_expr(cx, e, indent + 1);
283283
}
284284
},
285-
hir::ExprKind::InlineAsm(_, ref input, ref output) => {
285+
hir::ExprKind::InlineAsm(ref asm) => {
286+
let inputs = &asm.inputs_exprs;
287+
let outputs = &asm.outputs_exprs;
286288
println!("{}InlineAsm", ind);
287289
println!("{}inputs:", ind);
288-
for e in input {
290+
for e in inputs.iter() {
289291
print_expr(cx, e, indent + 1);
290292
}
291293
println!("{}outputs:", ind);
292-
for e in output {
294+
for e in outputs.iter() {
293295
print_expr(cx, e, indent + 1);
294296
}
295297
},

‎clippy_lints/src/write.rs

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_errors::Applicability;
88
use rustc_lexer::unescape::{self, EscapeError};
99
use rustc_parse::parser;
1010
use syntax::ast::*;
11+
use syntax::symbol::Symbol;
1112
use syntax::token;
1213
use syntax::tokenstream::TokenStream;
1314
use syntax_pos::{BytePos, Span};
@@ -190,7 +191,7 @@ impl EarlyLintPass for Write {
190191
if mac.path == sym!(println) {
191192
span_lint(cx, PRINT_STDOUT, mac.span, "use of `println!`");
192193
if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, false) {
193-
if fmt_str.contents.is_empty() {
194+
if fmt_str.symbol == Symbol::intern("") {
194195
span_lint_and_sugg(
195196
cx,
196197
PRINTLN_EMPTY_STRING,
@@ -205,7 +206,7 @@ impl EarlyLintPass for Write {
205206
} else if mac.path == sym!(print) {
206207
span_lint(cx, PRINT_STDOUT, mac.span, "use of `print!`");
207208
if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, false) {
208-
if check_newlines(&fmt_str.contents, fmt_str.style) {
209+
if check_newlines(&fmt_str) {
209210
span_lint_and_then(
210211
cx,
211212
PRINT_WITH_NEWLINE,
@@ -216,7 +217,7 @@ impl EarlyLintPass for Write {
216217
"use `println!` instead",
217218
vec![
218219
(mac.path.span, String::from("println")),
219-
(fmt_str.newline_span(), String::new()),
220+
(newline_span(&fmt_str), String::new()),
220221
],
221222
Applicability::MachineApplicable,
222223
);
@@ -226,7 +227,7 @@ impl EarlyLintPass for Write {
226227
}
227228
} else if mac.path == sym!(write) {
228229
if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, true) {
229-
if check_newlines(&fmt_str.contents, fmt_str.style) {
230+
if check_newlines(&fmt_str) {
230231
span_lint_and_then(
231232
cx,
232233
WRITE_WITH_NEWLINE,
@@ -237,7 +238,7 @@ impl EarlyLintPass for Write {
237238
"use `writeln!()` instead",
238239
vec![
239240
(mac.path.span, String::from("writeln")),
240-
(fmt_str.newline_span(), String::new()),
241+
(newline_span(&fmt_str), String::new()),
241242
],
242243
Applicability::MachineApplicable,
243244
);
@@ -247,7 +248,7 @@ impl EarlyLintPass for Write {
247248
}
248249
} else if mac.path == sym!(writeln) {
249250
if let (Some(fmt_str), expr) = check_tts(cx, &mac.tts, true) {
250-
if fmt_str.contents.is_empty() {
251+
if fmt_str.symbol == Symbol::intern("") {
251252
let mut applicability = Applicability::MachineApplicable;
252253
let suggestion = expr.map_or_else(
253254
move || {
@@ -272,37 +273,27 @@ impl EarlyLintPass for Write {
272273
}
273274
}
274275

275-
/// The arguments of a `print[ln]!` or `write[ln]!` invocation.
276-
struct FmtStr {
277-
/// The contents of the format string (inside the quotes).
278-
contents: String,
279-
style: StrStyle,
280-
/// The span of the format string, including quotes, the raw marker, and any raw hashes.
281-
span: Span,
282-
}
283-
284-
impl FmtStr {
285-
/// Given a format string that ends in a newline and its span, calculates the span of the
286-
/// newline.
287-
fn newline_span(&self) -> Span {
288-
let sp = self.span;
276+
/// Given a format string that ends in a newline and its span, calculates the span of the
277+
/// newline.
278+
fn newline_span(fmtstr: &StrLit) -> Span {
279+
let sp = fmtstr.span;
280+
let contents = &fmtstr.symbol.as_str();
289281

290-
let newline_sp_hi = sp.hi()
291-
- match self.style {
292-
StrStyle::Cooked => BytePos(1),
293-
StrStyle::Raw(hashes) => BytePos((1 + hashes).into()),
294-
};
295-
296-
let newline_sp_len = if self.contents.ends_with('\n') {
297-
BytePos(1)
298-
} else if self.contents.ends_with(r"\n") {
299-
BytePos(2)
300-
} else {
301-
panic!("expected format string to contain a newline");
282+
let newline_sp_hi = sp.hi()
283+
- match fmtstr.style {
284+
StrStyle::Cooked => BytePos(1),
285+
StrStyle::Raw(hashes) => BytePos((1 + hashes).into()),
302286
};
303287

304-
sp.with_lo(newline_sp_hi - newline_sp_len).with_hi(newline_sp_hi)
305-
}
288+
let newline_sp_len = if contents.ends_with('\n') {
289+
BytePos(1)
290+
} else if contents.ends_with(r"\n") {
291+
BytePos(2)
292+
} else {
293+
panic!("expected format string to contain a newline");
294+
};
295+
296+
sp.with_lo(newline_sp_hi - newline_sp_len).with_hi(newline_sp_hi)
306297
}
307298

308299
/// Checks the arguments of `print[ln]!` and `write[ln]!` calls. It will return a tuple of two
@@ -325,7 +316,7 @@ impl FmtStr {
325316
/// (Some("string to write: {}"), Some(buf))
326317
/// ```
327318
#[allow(clippy::too_many_lines)]
328-
fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (Option<FmtStr>, Option<Expr>) {
319+
fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (Option<StrLit>, Option<Expr>) {
329320
use fmt_macros::*;
330321
let tts = tts.clone();
331322

@@ -342,12 +333,11 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (O
342333
}
343334
}
344335

345-
let (fmtstr, fmtstyle) = match parser.parse_str().map_err(|mut err| err.cancel()) {
346-
Ok((fmtstr, fmtstyle)) => (fmtstr.to_string(), fmtstyle),
336+
let fmtstr = match parser.parse_str_lit() {
337+
Ok(fmtstr) => fmtstr,
347338
Err(_) => return (None, expr),
348339
};
349-
let fmtspan = parser.prev_span;
350-
let tmp = fmtstr.clone();
340+
let tmp = fmtstr.symbol.as_str();
351341
let mut args = vec![];
352342
let mut fmt_parser = Parser::new(&tmp, None, Vec::new(), false);
353343
while let Some(piece) = fmt_parser.next() {
@@ -377,26 +367,12 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (O
377367
ty_span: None,
378368
};
379369
if !parser.eat(&token::Comma) {
380-
return (
381-
Some(FmtStr {
382-
contents: fmtstr,
383-
style: fmtstyle,
384-
span: fmtspan,
385-
}),
386-
expr,
387-
);
370+
return (Some(fmtstr), expr);
388371
}
389372
let token_expr = if let Ok(expr) = parser.parse_expr().map_err(|mut err| err.cancel()) {
390373
expr
391374
} else {
392-
return (
393-
Some(FmtStr {
394-
contents: fmtstr,
395-
style: fmtstyle,
396-
span: fmtspan,
397-
}),
398-
None,
399-
);
375+
return (Some(fmtstr), None);
400376
};
401377
match &token_expr.kind {
402378
ExprKind::Lit(_) => {
@@ -448,11 +424,13 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (O
448424
/// Checks if the format string contains a single newline that terminates it.
449425
///
450426
/// Literal and escaped newlines are both checked (only literal for raw strings).
451-
fn check_newlines(contents: &str, style: StrStyle) -> bool {
427+
fn check_newlines(fmtstr: &StrLit) -> bool {
452428
let mut has_internal_newline = false;
453429
let mut last_was_cr = false;
454430
let mut should_lint = false;
455431

432+
let contents = &fmtstr.symbol.as_str();
433+
456434
let mut cb = |r: Range<usize>, c: Result<char, EscapeError>| {
457435
let c = c.unwrap();
458436

@@ -466,7 +444,7 @@ fn check_newlines(contents: &str, style: StrStyle) -> bool {
466444
}
467445
};
468446

469-
match style {
447+
match fmtstr.style {
470448
StrStyle::Cooked => unescape::unescape_str(contents, &mut cb),
471449
StrStyle::Raw(_) => unescape::unescape_raw_str(contents, &mut cb),
472450
}

‎src/driver.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
7575
clippy_lints::register_pre_expansion_lints(&mut lint_store, &conf);
7676
clippy_lints::register_renamed(&mut lint_store);
7777
}));
78+
79+
// FIXME: #4825; This is required, because Clippy lints that are based on MIR have to be
80+
// run on the unoptimized MIR. On the other hand this results in some false negatives. If
81+
// MIR passes can be enabled / disabled separately, we should figure out, what passes to
82+
// use for Clippy.
83+
config.opts.debugging_opts.mir_opt_level = 0;
7884
}
7985
}
8086

‎tests/compile-test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(test)]
22

33
use compiletest_rs as compiletest;
4-
extern crate test;
4+
extern crate tester as test;
55

66
use std::env::{set_var, var};
77
use std::ffi::OsStr;

‎tests/ui/builtin-type-shadow.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ LL | fn foo<u32>(a: u32) -> u32 {
1616
LL | 42
1717
| ^^ expected type parameter `u32`, found integer
1818
|
19-
= note: expected type `u32`
20-
found type `{integer}`
19+
= note: expected type parameter `u32`
20+
found type `{integer}`
2121
= help: type parameters must be constrained to match other types
2222
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
2323

‎tests/ui/diverging_sub_expression.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(never_type)]
21
#![warn(clippy::diverging_sub_expression)]
32
#![allow(clippy::match_same_arms, clippy::logic_bug)]
43

‎tests/ui/diverging_sub_expression.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
error: sub-expression diverges
2-
--> $DIR/diverging_sub_expression.rs:21:10
2+
--> $DIR/diverging_sub_expression.rs:20:10
33
|
44
LL | b || diverge();
55
| ^^^^^^^^^
66
|
77
= note: `-D clippy::diverging-sub-expression` implied by `-D warnings`
88

99
error: sub-expression diverges
10-
--> $DIR/diverging_sub_expression.rs:22:10
10+
--> $DIR/diverging_sub_expression.rs:21:10
1111
|
1212
LL | b || A.foo();
1313
| ^^^^^^^
1414

1515
error: sub-expression diverges
16-
--> $DIR/diverging_sub_expression.rs:31:26
16+
--> $DIR/diverging_sub_expression.rs:30:26
1717
|
1818
LL | 6 => true || return,
1919
| ^^^^^^
2020

2121
error: sub-expression diverges
22-
--> $DIR/diverging_sub_expression.rs:32:26
22+
--> $DIR/diverging_sub_expression.rs:31:26
2323
|
2424
LL | 7 => true || continue,
2525
| ^^^^^^^^
2626

2727
error: sub-expression diverges
28-
--> $DIR/diverging_sub_expression.rs:35:26
28+
--> $DIR/diverging_sub_expression.rs:34:26
2929
|
3030
LL | 3 => true || diverge(),
3131
| ^^^^^^^^^
3232

3333
error: sub-expression diverges
34-
--> $DIR/diverging_sub_expression.rs:40:26
34+
--> $DIR/diverging_sub_expression.rs:39:26
3535
|
3636
LL | _ => true || break,
3737
| ^^^^^

‎tests/ui/indexing_slicing.stderr

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
error: index out of bounds: the len is 4 but the index is 4
2-
--> $DIR/indexing_slicing.rs:18:5
3-
|
4-
LL | x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
5-
| ^^^^
6-
|
7-
= note: `#[deny(const_err)]` on by default
8-
9-
error: index out of bounds: the len is 4 but the index is 8
10-
--> $DIR/indexing_slicing.rs:19:5
11-
|
12-
LL | x[1 << 3]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
13-
| ^^^^^^^^^
14-
15-
error: index out of bounds: the len is 4 but the index is 15
16-
--> $DIR/indexing_slicing.rs:54:5
17-
|
18-
LL | x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
19-
| ^^^^
20-
211
error: indexing may panic.
222
--> $DIR/indexing_slicing.rs:13:5
233
|
@@ -209,5 +189,5 @@ LL | v[M];
209189
|
210190
= help: Consider using `.get(n)` or `.get_mut(n)` instead
211191

212-
error: aborting due to 27 previous errors
192+
error: aborting due to 24 previous errors
213193

‎tests/ui/infallible_destructuring_match.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![feature(exhaustive_patterns, never_type)]
2+
#![feature(exhaustive_patterns)]
33
#![allow(dead_code, unreachable_code, unused_variables)]
44
#![allow(clippy::let_and_return)]
55

‎tests/ui/infallible_destructuring_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![feature(exhaustive_patterns, never_type)]
2+
#![feature(exhaustive_patterns)]
33
#![allow(dead_code, unreachable_code, unused_variables)]
44
#![allow(clippy::let_and_return)]
55

‎tests/ui/must_use_candidates.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// run-rustfix
2-
#![feature(never_type)]
32
#![allow(unused_mut)]
43
#![warn(clippy::must_use_candidate)]
54
use std::rc::Rc;

‎tests/ui/must_use_candidates.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// run-rustfix
2-
#![feature(never_type)]
32
#![allow(unused_mut)]
43
#![warn(clippy::must_use_candidate)]
54
use std::rc::Rc;

‎tests/ui/must_use_candidates.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
error: this function could have a `#[must_use]` attribute
2-
--> $DIR/must_use_candidates.rs:12:1
2+
--> $DIR/must_use_candidates.rs:11:1
33
|
44
LL | pub fn pure(i: u8) -> u8 {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8`
66
|
77
= note: `-D clippy::must-use-candidate` implied by `-D warnings`
88

99
error: this method could have a `#[must_use]` attribute
10-
--> $DIR/must_use_candidates.rs:17:5
10+
--> $DIR/must_use_candidates.rs:16:5
1111
|
1212
LL | pub fn inherent_pure(&self) -> u8 {
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn inherent_pure(&self) -> u8`
1414

1515
error: this function could have a `#[must_use]` attribute
16-
--> $DIR/must_use_candidates.rs:48:1
16+
--> $DIR/must_use_candidates.rs:47:1
1717
|
1818
LL | pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool {
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool`
2020

2121
error: this function could have a `#[must_use]` attribute
22-
--> $DIR/must_use_candidates.rs:60:1
22+
--> $DIR/must_use_candidates.rs:59:1
2323
|
2424
LL | pub fn rcd(_x: Rc<u32>) -> bool {
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn rcd(_x: Rc<u32>) -> bool`
2626

2727
error: this function could have a `#[must_use]` attribute
28-
--> $DIR/must_use_candidates.rs:68:1
28+
--> $DIR/must_use_candidates.rs:67:1
2929
|
3030
LL | pub fn arcd(_x: Arc<u32>) -> bool {
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc<u32>) -> bool`

‎tests/ui/redundant_clone.fixed

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22
// rustfix-only-machine-applicable
3+
34
use std::ffi::OsString;
45
use std::path::Path;
56

@@ -17,11 +18,11 @@ fn main() {
1718

1819
let _s = Path::new("/a/b/").join("c");
1920

20-
let _s = Path::new("/a/b/").join("c");
21+
let _s = Path::new("/a/b/").join("c").to_path_buf();
2122

2223
let _s = OsString::new();
2324

24-
let _s = OsString::new();
25+
let _s = OsString::new().to_os_string();
2526

2627
// Check that lint level works
2728
#[allow(clippy::redundant_clone)]
@@ -46,6 +47,7 @@ fn main() {
4647
let _ = Some(String::new()).unwrap_or_else(|| x.0.clone()); // ok; closure borrows `x`
4748

4849
with_branch(Alpha, true);
50+
cannot_double_move(Alpha);
4951
cannot_move_from_type_with_drop();
5052
borrower_propagation();
5153
}
@@ -60,6 +62,10 @@ fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) {
6062
}
6163
}
6264

65+
fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) {
66+
(a.clone(), a)
67+
}
68+
6369
struct TypeWithDrop {
6470
x: String,
6571
}

‎tests/ui/redundant_clone.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22
// rustfix-only-machine-applicable
3+
34
use std::ffi::OsString;
45
use std::path::Path;
56

@@ -46,6 +47,7 @@ fn main() {
4647
let _ = Some(String::new()).unwrap_or_else(|| x.0.clone()); // ok; closure borrows `x`
4748

4849
with_branch(Alpha, true);
50+
cannot_double_move(Alpha);
4951
cannot_move_from_type_with_drop();
5052
borrower_propagation();
5153
}
@@ -60,6 +62,10 @@ fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) {
6062
}
6163
}
6264

65+
fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) {
66+
(a.clone(), a)
67+
}
68+
6369
struct TypeWithDrop {
6470
x: String,
6571
}

‎tests/ui/redundant_clone.stderr

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,135 @@
11
error: redundant clone
2-
--> $DIR/redundant_clone.rs:7:42
2+
--> $DIR/redundant_clone.rs:8:42
33
|
44
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
55
| ^^^^^^^^^^^^ help: remove this
66
|
77
= note: `-D clippy::redundant-clone` implied by `-D warnings`
88
note: this value is dropped without further use
9-
--> $DIR/redundant_clone.rs:7:14
9+
--> $DIR/redundant_clone.rs:8:14
1010
|
1111
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
1212
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1313

1414
error: redundant clone
15-
--> $DIR/redundant_clone.rs:10:15
15+
--> $DIR/redundant_clone.rs:11:15
1616
|
1717
LL | let _s = s.clone();
1818
| ^^^^^^^^ help: remove this
1919
|
2020
note: this value is dropped without further use
21-
--> $DIR/redundant_clone.rs:10:14
21+
--> $DIR/redundant_clone.rs:11:14
2222
|
2323
LL | let _s = s.clone();
2424
| ^
2525

2626
error: redundant clone
27-
--> $DIR/redundant_clone.rs:13:15
27+
--> $DIR/redundant_clone.rs:14:15
2828
|
2929
LL | let _s = s.to_string();
3030
| ^^^^^^^^^^^^ help: remove this
3131
|
3232
note: this value is dropped without further use
33-
--> $DIR/redundant_clone.rs:13:14
33+
--> $DIR/redundant_clone.rs:14:14
3434
|
3535
LL | let _s = s.to_string();
3636
| ^
3737

3838
error: redundant clone
39-
--> $DIR/redundant_clone.rs:16:15
39+
--> $DIR/redundant_clone.rs:17:15
4040
|
4141
LL | let _s = s.to_owned();
4242
| ^^^^^^^^^^^ help: remove this
4343
|
4444
note: this value is dropped without further use
45-
--> $DIR/redundant_clone.rs:16:14
45+
--> $DIR/redundant_clone.rs:17:14
4646
|
4747
LL | let _s = s.to_owned();
4848
| ^
4949

5050
error: redundant clone
51-
--> $DIR/redundant_clone.rs:18:42
51+
--> $DIR/redundant_clone.rs:19:42
5252
|
5353
LL | let _s = Path::new("/a/b/").join("c").to_owned();
5454
| ^^^^^^^^^^^ help: remove this
5555
|
5656
note: this value is dropped without further use
57-
--> $DIR/redundant_clone.rs:18:14
57+
--> $DIR/redundant_clone.rs:19:14
5858
|
5959
LL | let _s = Path::new("/a/b/").join("c").to_owned();
6060
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6161

6262
error: redundant clone
63-
--> $DIR/redundant_clone.rs:20:42
64-
|
65-
LL | let _s = Path::new("/a/b/").join("c").to_path_buf();
66-
| ^^^^^^^^^^^^^^ help: remove this
67-
|
68-
note: this value is dropped without further use
69-
--> $DIR/redundant_clone.rs:20:14
70-
|
71-
LL | let _s = Path::new("/a/b/").join("c").to_path_buf();
72-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73-
74-
error: redundant clone
75-
--> $DIR/redundant_clone.rs:22:29
63+
--> $DIR/redundant_clone.rs:23:29
7664
|
7765
LL | let _s = OsString::new().to_owned();
7866
| ^^^^^^^^^^^ help: remove this
7967
|
8068
note: this value is dropped without further use
81-
--> $DIR/redundant_clone.rs:22:14
69+
--> $DIR/redundant_clone.rs:23:14
8270
|
8371
LL | let _s = OsString::new().to_owned();
8472
| ^^^^^^^^^^^^^^^
8573

8674
error: redundant clone
87-
--> $DIR/redundant_clone.rs:24:29
88-
|
89-
LL | let _s = OsString::new().to_os_string();
90-
| ^^^^^^^^^^^^^^^ help: remove this
91-
|
92-
note: this value is dropped without further use
93-
--> $DIR/redundant_clone.rs:24:14
94-
|
95-
LL | let _s = OsString::new().to_os_string();
96-
| ^^^^^^^^^^^^^^^
97-
98-
error: redundant clone
99-
--> $DIR/redundant_clone.rs:31:19
75+
--> $DIR/redundant_clone.rs:32:19
10076
|
10177
LL | let _t = tup.0.clone();
10278
| ^^^^^^^^ help: remove this
10379
|
10480
note: this value is dropped without further use
105-
--> $DIR/redundant_clone.rs:31:14
81+
--> $DIR/redundant_clone.rs:32:14
10682
|
10783
LL | let _t = tup.0.clone();
10884
| ^^^^^
10985

11086
error: redundant clone
111-
--> $DIR/redundant_clone.rs:57:22
87+
--> $DIR/redundant_clone.rs:59:22
11288
|
11389
LL | (a.clone(), a.clone())
11490
| ^^^^^^^^ help: remove this
11591
|
11692
note: this value is dropped without further use
117-
--> $DIR/redundant_clone.rs:57:21
93+
--> $DIR/redundant_clone.rs:59:21
11894
|
11995
LL | (a.clone(), a.clone())
12096
| ^
12197

12298
error: redundant clone
123-
--> $DIR/redundant_clone.rs:113:15
99+
--> $DIR/redundant_clone.rs:119:15
124100
|
125101
LL | let _s = s.clone();
126102
| ^^^^^^^^ help: remove this
127103
|
128104
note: this value is dropped without further use
129-
--> $DIR/redundant_clone.rs:113:14
105+
--> $DIR/redundant_clone.rs:119:14
130106
|
131107
LL | let _s = s.clone();
132108
| ^
133109

134110
error: redundant clone
135-
--> $DIR/redundant_clone.rs:114:15
111+
--> $DIR/redundant_clone.rs:120:15
136112
|
137113
LL | let _t = t.clone();
138114
| ^^^^^^^^ help: remove this
139115
|
140116
note: this value is dropped without further use
141-
--> $DIR/redundant_clone.rs:114:14
117+
--> $DIR/redundant_clone.rs:120:14
142118
|
143119
LL | let _t = t.clone();
144120
| ^
145121

146122
error: redundant clone
147-
--> $DIR/redundant_clone.rs:124:19
123+
--> $DIR/redundant_clone.rs:130:19
148124
|
149125
LL | let _f = f.clone();
150126
| ^^^^^^^^ help: remove this
151127
|
152128
note: this value is dropped without further use
153-
--> $DIR/redundant_clone.rs:124:18
129+
--> $DIR/redundant_clone.rs:130:18
154130
|
155131
LL | let _f = f.clone();
156132
| ^
157133

158-
error: aborting due to 13 previous errors
134+
error: aborting due to 11 previous errors
159135

‎tests/ui/result_map_unit_fn_fixable.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-rustfix
22

3-
#![feature(never_type)]
43
#![warn(clippy::result_map_unit_fn)]
54
#![allow(unused)]
65

‎tests/ui/result_map_unit_fn_fixable.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-rustfix
22

3-
#![feature(never_type)]
43
#![warn(clippy::result_map_unit_fn)]
54
#![allow(unused)]
65

‎tests/ui/result_map_unit_fn_fixable.stderr

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: called `map(f)` on an Result value where `f` is a unit function
2-
--> $DIR/result_map_unit_fn_fixable.rs:36:5
2+
--> $DIR/result_map_unit_fn_fixable.rs:35:5
33
|
44
LL | x.field.map(do_nothing);
55
| ^^^^^^^^^^^^^^^^^^^^^^^-
@@ -9,127 +9,127 @@ LL | x.field.map(do_nothing);
99
= note: `-D clippy::result-map-unit-fn` implied by `-D warnings`
1010

1111
error: called `map(f)` on an Result value where `f` is a unit function
12-
--> $DIR/result_map_unit_fn_fixable.rs:38:5
12+
--> $DIR/result_map_unit_fn_fixable.rs:37:5
1313
|
1414
LL | x.field.map(do_nothing);
1515
| ^^^^^^^^^^^^^^^^^^^^^^^-
1616
| |
1717
| help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }`
1818

1919
error: called `map(f)` on an Result value where `f` is a unit function
20-
--> $DIR/result_map_unit_fn_fixable.rs:40:5
20+
--> $DIR/result_map_unit_fn_fixable.rs:39:5
2121
|
2222
LL | x.field.map(diverge);
2323
| ^^^^^^^^^^^^^^^^^^^^-
2424
| |
2525
| help: try this: `if let Ok(x_field) = x.field { diverge(x_field) }`
2626

2727
error: called `map(f)` on an Result value where `f` is a unit closure
28-
--> $DIR/result_map_unit_fn_fixable.rs:46:5
28+
--> $DIR/result_map_unit_fn_fixable.rs:45:5
2929
|
3030
LL | x.field.map(|value| x.do_result_nothing(value + captured));
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
3232
| |
3333
| help: try this: `if let Ok(value) = x.field { x.do_result_nothing(value + captured) }`
3434

3535
error: called `map(f)` on an Result value where `f` is a unit closure
36-
--> $DIR/result_map_unit_fn_fixable.rs:48:5
36+
--> $DIR/result_map_unit_fn_fixable.rs:47:5
3737
|
3838
LL | x.field.map(|value| { x.do_result_plus_one(value + captured); });
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
4040
| |
4141
| help: try this: `if let Ok(value) = x.field { x.do_result_plus_one(value + captured); }`
4242

4343
error: called `map(f)` on an Result value where `f` is a unit closure
44-
--> $DIR/result_map_unit_fn_fixable.rs:51:5
44+
--> $DIR/result_map_unit_fn_fixable.rs:50:5
4545
|
4646
LL | x.field.map(|value| do_nothing(value + captured));
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
4848
| |
4949
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }`
5050

5151
error: called `map(f)` on an Result value where `f` is a unit closure
52-
--> $DIR/result_map_unit_fn_fixable.rs:53:5
52+
--> $DIR/result_map_unit_fn_fixable.rs:52:5
5353
|
5454
LL | x.field.map(|value| { do_nothing(value + captured) });
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
5656
| |
5757
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }`
5858

5959
error: called `map(f)` on an Result value where `f` is a unit closure
60-
--> $DIR/result_map_unit_fn_fixable.rs:55:5
60+
--> $DIR/result_map_unit_fn_fixable.rs:54:5
6161
|
6262
LL | x.field.map(|value| { do_nothing(value + captured); });
6363
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
6464
| |
6565
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }`
6666

6767
error: called `map(f)` on an Result value where `f` is a unit closure
68-
--> $DIR/result_map_unit_fn_fixable.rs:57:5
68+
--> $DIR/result_map_unit_fn_fixable.rs:56:5
6969
|
7070
LL | x.field.map(|value| { { do_nothing(value + captured); } });
7171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
7272
| |
7373
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }`
7474

7575
error: called `map(f)` on an Result value where `f` is a unit closure
76-
--> $DIR/result_map_unit_fn_fixable.rs:60:5
76+
--> $DIR/result_map_unit_fn_fixable.rs:59:5
7777
|
7878
LL | x.field.map(|value| diverge(value + captured));
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
8080
| |
8181
| help: try this: `if let Ok(value) = x.field { diverge(value + captured) }`
8282

8383
error: called `map(f)` on an Result value where `f` is a unit closure
84-
--> $DIR/result_map_unit_fn_fixable.rs:62:5
84+
--> $DIR/result_map_unit_fn_fixable.rs:61:5
8585
|
8686
LL | x.field.map(|value| { diverge(value + captured) });
8787
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
8888
| |
8989
| help: try this: `if let Ok(value) = x.field { diverge(value + captured) }`
9090

9191
error: called `map(f)` on an Result value where `f` is a unit closure
92-
--> $DIR/result_map_unit_fn_fixable.rs:64:5
92+
--> $DIR/result_map_unit_fn_fixable.rs:63:5
9393
|
9494
LL | x.field.map(|value| { diverge(value + captured); });
9595
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
9696
| |
9797
| help: try this: `if let Ok(value) = x.field { diverge(value + captured); }`
9898

9999
error: called `map(f)` on an Result value where `f` is a unit closure
100-
--> $DIR/result_map_unit_fn_fixable.rs:66:5
100+
--> $DIR/result_map_unit_fn_fixable.rs:65:5
101101
|
102102
LL | x.field.map(|value| { { diverge(value + captured); } });
103103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
104104
| |
105105
| help: try this: `if let Ok(value) = x.field { diverge(value + captured); }`
106106

107107
error: called `map(f)` on an Result value where `f` is a unit closure
108-
--> $DIR/result_map_unit_fn_fixable.rs:71:5
108+
--> $DIR/result_map_unit_fn_fixable.rs:70:5
109109
|
110110
LL | x.field.map(|value| { let y = plus_one(value + captured); });
111111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
112112
| |
113113
| help: try this: `if let Ok(value) = x.field { let y = plus_one(value + captured); }`
114114

115115
error: called `map(f)` on an Result value where `f` is a unit closure
116-
--> $DIR/result_map_unit_fn_fixable.rs:73:5
116+
--> $DIR/result_map_unit_fn_fixable.rs:72:5
117117
|
118118
LL | x.field.map(|value| { plus_one(value + captured); });
119119
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
120120
| |
121121
| help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }`
122122

123123
error: called `map(f)` on an Result value where `f` is a unit closure
124-
--> $DIR/result_map_unit_fn_fixable.rs:75:5
124+
--> $DIR/result_map_unit_fn_fixable.rs:74:5
125125
|
126126
LL | x.field.map(|value| { { plus_one(value + captured); } });
127127
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
128128
| |
129129
| help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }`
130130

131131
error: called `map(f)` on an Result value where `f` is a unit closure
132-
--> $DIR/result_map_unit_fn_fixable.rs:78:5
132+
--> $DIR/result_map_unit_fn_fixable.rs:77:5
133133
|
134134
LL | x.field.map(|ref value| { do_nothing(value + captured) });
135135
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-

‎tests/ui/result_map_unit_fn_unfixable.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(never_type)]
21
#![warn(clippy::result_map_unit_fn)]
32
#![allow(unused)]
43

‎tests/ui/result_map_unit_fn_unfixable.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error[E0425]: cannot find value `x` in this scope
2-
--> $DIR/result_map_unit_fn_unfixable.rs:17:5
2+
--> $DIR/result_map_unit_fn_unfixable.rs:16:5
33
|
44
LL | x.field.map(|value| { do_nothing(value); do_nothing(value) });
55
| ^ not found in this scope
66

77
error[E0425]: cannot find value `x` in this scope
8-
--> $DIR/result_map_unit_fn_unfixable.rs:19:5
8+
--> $DIR/result_map_unit_fn_unfixable.rs:18:5
99
|
1010
LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) });
1111
| ^ not found in this scope
1212

1313
error[E0425]: cannot find value `x` in this scope
14-
--> $DIR/result_map_unit_fn_unfixable.rs:23:5
14+
--> $DIR/result_map_unit_fn_unfixable.rs:22:5
1515
|
1616
LL | x.field.map(|value| {
1717
| ^ not found in this scope
1818

1919
error[E0425]: cannot find value `x` in this scope
20-
--> $DIR/result_map_unit_fn_unfixable.rs:27:5
20+
--> $DIR/result_map_unit_fn_unfixable.rs:26:5
2121
|
2222
LL | x.field.map(|value| { do_nothing(value); do_nothing(value); });
2323
| ^ not found in this scope

0 commit comments

Comments
 (0)
Please sign in to comment.