mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Merge branch 'master' into option_option_pr
This commit is contained in:
commit
ec60baa864
171 changed files with 516 additions and 42 deletions
70
clippy_lints/src/else_if_without_else.rs
Normal file
70
clippy_lints/src/else_if_without_else.rs
Normal file
|
@ -0,0 +1,70 @@
|
|||
//! lint on if expressions with an else if, but without a final else branch
|
||||
|
||||
use rustc::lint::*;
|
||||
use syntax::ast::*;
|
||||
|
||||
use utils::{in_external_macro, span_lint_and_sugg};
|
||||
|
||||
/// **What it does:** Checks for usage of if expressions with an `else if` branch,
|
||||
/// but without a final `else` branch.
|
||||
///
|
||||
/// **Why is this bad?** Some coding guidelines require this (e.g. MISRA-C:2004 Rule 14.10).
|
||||
///
|
||||
/// **Known problems:** None.
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// if x.is_positive() {
|
||||
/// a();
|
||||
/// } else if x.is_negative() {
|
||||
/// b();
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Could be written:
|
||||
///
|
||||
/// ```rust
|
||||
/// if x.is_positive() {
|
||||
/// a();
|
||||
/// } else if x.is_negative() {
|
||||
/// b();
|
||||
/// } else {
|
||||
/// // we don't care about zero
|
||||
/// }
|
||||
/// ```
|
||||
declare_restriction_lint! {
|
||||
pub ELSE_IF_WITHOUT_ELSE,
|
||||
"if expression with an `else if`, but without a final `else` branch"
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct ElseIfWithoutElse;
|
||||
|
||||
impl LintPass for ElseIfWithoutElse {
|
||||
fn get_lints(&self) -> LintArray {
|
||||
lint_array!(ELSE_IF_WITHOUT_ELSE)
|
||||
}
|
||||
}
|
||||
|
||||
impl EarlyLintPass for ElseIfWithoutElse {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, mut item: &Expr) {
|
||||
if in_external_macro(cx, item.span) {
|
||||
return;
|
||||
}
|
||||
|
||||
while let ExprKind::If(_, _, Some(ref els)) = item.node {
|
||||
if let ExprKind::If(_, _, None) = els.node {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
ELSE_IF_WITHOUT_ELSE,
|
||||
els.span,
|
||||
"if expression with an `else if`, but without a final `else`",
|
||||
"add an `else` block here",
|
||||
"".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
item = els;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -88,6 +88,7 @@ pub mod derive;
|
|||
pub mod doc;
|
||||
pub mod double_parens;
|
||||
pub mod drop_forget_ref;
|
||||
pub mod else_if_without_else;
|
||||
pub mod empty_enum;
|
||||
pub mod entry;
|
||||
pub mod enum_clike;
|
||||
|
@ -329,6 +330,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
|
|||
reg.register_early_lint_pass(box formatting::Formatting);
|
||||
reg.register_late_lint_pass(box swap::Swap);
|
||||
reg.register_early_lint_pass(box if_not_else::IfNotElse);
|
||||
reg.register_early_lint_pass(box else_if_without_else::ElseIfWithoutElse);
|
||||
reg.register_early_lint_pass(box int_plus_one::IntPlusOne);
|
||||
reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
|
||||
reg.register_late_lint_pass(box unused_label::UnusedLabel);
|
||||
|
@ -369,6 +371,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
|
|||
arithmetic::INTEGER_ARITHMETIC,
|
||||
array_indexing::INDEXING_SLICING,
|
||||
assign_ops::ASSIGN_OPS,
|
||||
else_if_without_else::ELSE_IF_WITHOUT_ELSE,
|
||||
misc::FLOAT_CMP_CONST,
|
||||
]);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ extern crate rustc_plugin;
|
|||
extern crate syntax;
|
||||
|
||||
use rustc_driver::{driver, Compilation, CompilerCalls, RustcDefaultCalls};
|
||||
use rustc::session::{config, CompileIncomplete, Session};
|
||||
use rustc::session::{config, Session};
|
||||
use rustc::session::config::{ErrorOutputType, Input};
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
@ -153,47 +153,44 @@ pub fn main() {
|
|||
})
|
||||
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
|
||||
|
||||
rustc_driver::in_rustc_thread(|| {
|
||||
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
|
||||
// We're invoking the compiler programmatically, so we ignore this/
|
||||
let mut orig_args: Vec<String> = env::args().collect();
|
||||
if orig_args.len() <= 1 {
|
||||
std::process::exit(1);
|
||||
}
|
||||
if orig_args[1] == "rustc" {
|
||||
// we still want to be able to invoke it normally though
|
||||
orig_args.remove(1);
|
||||
}
|
||||
// this conditional check for the --sysroot flag is there so users can call
|
||||
// `clippy_driver` directly
|
||||
// without having to pass --sysroot or anything
|
||||
let mut args: Vec<String> = if orig_args.iter().any(|s| s == "--sysroot") {
|
||||
orig_args.clone()
|
||||
} else {
|
||||
orig_args
|
||||
.clone()
|
||||
.into_iter()
|
||||
.chain(Some("--sysroot".to_owned()))
|
||||
.chain(Some(sys_root))
|
||||
.collect()
|
||||
};
|
||||
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
|
||||
// We're invoking the compiler programmatically, so we ignore this/
|
||||
let mut orig_args: Vec<String> = env::args().collect();
|
||||
if orig_args.len() <= 1 {
|
||||
std::process::exit(1);
|
||||
}
|
||||
if orig_args[1] == "rustc" {
|
||||
// we still want to be able to invoke it normally though
|
||||
orig_args.remove(1);
|
||||
}
|
||||
// this conditional check for the --sysroot flag is there so users can call
|
||||
// `clippy_driver` directly
|
||||
// without having to pass --sysroot or anything
|
||||
let mut args: Vec<String> = if orig_args.iter().any(|s| s == "--sysroot") {
|
||||
orig_args.clone()
|
||||
} else {
|
||||
orig_args
|
||||
.clone()
|
||||
.into_iter()
|
||||
.chain(Some("--sysroot".to_owned()))
|
||||
.chain(Some(sys_root))
|
||||
.collect()
|
||||
};
|
||||
|
||||
// this check ensures that dependencies are built but not linted and the final
|
||||
// crate is
|
||||
// linted but not built
|
||||
let clippy_enabled = env::var("CLIPPY_TESTS")
|
||||
.ok()
|
||||
.map_or(false, |val| val == "true")
|
||||
|| orig_args.iter().any(|s| s == "--emit=metadata");
|
||||
// this check ensures that dependencies are built but not linted and the final
|
||||
// crate is
|
||||
// linted but not built
|
||||
let clippy_enabled = env::var("CLIPPY_TESTS")
|
||||
.ok()
|
||||
.map_or(false, |val| val == "true")
|
||||
|| orig_args.iter().any(|s| s == "--emit=metadata");
|
||||
|
||||
if clippy_enabled {
|
||||
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);
|
||||
}
|
||||
if clippy_enabled {
|
||||
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);
|
||||
}
|
||||
|
||||
let mut ccc = ClippyCompilerCalls::new(clippy_enabled);
|
||||
let (result, _) = rustc_driver::run_compiler(&args, &mut ccc, None, None);
|
||||
if let Err(CompileIncomplete::Errored(_)) = result {
|
||||
std::process::exit(1);
|
||||
}
|
||||
}).expect("rustc_thread failed");
|
||||
let mut ccc = ClippyCompilerCalls::new(clippy_enabled);
|
||||
rustc_driver::run(move || {
|
||||
rustc_driver::run_compiler(&args, &mut ccc, None, None)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -46,7 +46,9 @@ fn config(dir: &'static str, mode: &'static str) -> compiletest::Config {
|
|||
config.target_rustcflags = Some(format!("-L {0} -L {0}/deps -Dwarnings", host_libs().display()));
|
||||
|
||||
config.mode = cfg_mode;
|
||||
config.build_base = {
|
||||
config.build_base = if rustc_test_suite().is_some() {
|
||||
PathBuf::from("/tmp/clippy_test_build_base")
|
||||
} else {
|
||||
let mut path = std::env::current_dir().unwrap();
|
||||
path.push("target/debug/test_build_base");
|
||||
path
|
||||
|
|
|
@ -143,3 +143,5 @@ error: <-comparison of unit values detected. This will always be false
|
|||
|
|
||||
= note: `-D unit-cmp` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 18 previous errors
|
||||
|
||||
|
|
|
@ -114,3 +114,5 @@ error: approximate value of `f{32, 64}::consts::SQRT_2` found. Consider using it
|
|||
55 | let my_sq2 = 1.4142;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 19 previous errors
|
||||
|
||||
|
|
|
@ -69,3 +69,5 @@ error: floating-point arithmetic detected
|
|||
29 | -f;
|
||||
| ^^
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
|
||||
|
|
|
@ -116,3 +116,5 @@ error: range is out of bounds
|
|||
44 | &empty[..4];
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 19 previous errors
|
||||
|
||||
|
|
|
@ -134,3 +134,5 @@ error: manual implementation of an assign operation
|
|||
40 | s = s + "bla";
|
||||
| ^^^^^^^^^^^^^ help: replace it with: `s += "bla"`
|
||||
|
||||
error: aborting due to 22 previous errors
|
||||
|
||||
|
|
|
@ -48,3 +48,5 @@ error: variable appears on both sides of an assignment operation
|
|||
15 | a &= a & 1;
|
||||
| ^^^^^^^^^^ help: replace it with: `a &= 1`
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
|
@ -20,3 +20,5 @@ error: the since field must contain a semver-compliant version
|
|||
30 | #[deprecated(since = "1")]
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
@ -106,3 +106,5 @@ error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared
|
|||
55 | x | 1 >= 8;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
|
||||
|
|
|
@ -84,3 +84,5 @@ error: use of a blacklisted/placeholder name `baz`
|
|||
35 | if let Some(ref mut baz) = Some(42) {}
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
|
|
@ -50,3 +50,5 @@ error: this boolean expression can be simplified
|
|||
|
|
||||
= note: `-D nonminimal-bool` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
@ -24,3 +24,5 @@ error: equality checks against false can be replaced by a negation
|
|||
10 | if false == x { "yes" } else { "no" };
|
||||
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
@ -175,3 +175,5 @@ error: this boolean expression can be simplified
|
|||
58 | let _ = !c ^ c || !a.is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `!c ^ c || a.is_none()`
|
||||
|
||||
error: aborting due to 21 previous errors
|
||||
|
||||
|
|
|
@ -28,3 +28,5 @@ error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
|||
22 | fn test4(a: &Box<bool>);
|
||||
| ^^^^^^^^^^ help: try: `&bool`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
@ -7,3 +7,5 @@ error: you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`
|
|||
= note: `-D box-vec` implied by `-D warnings`
|
||||
= help: `Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation.
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -17,3 +17,5 @@ error[E0308]: mismatched types
|
|||
= note: expected type `u32`
|
||||
found type `{integer}`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -22,3 +22,5 @@ error: You appear to be counting bytes the naive way
|
|||
22 | let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider using the bytecount crate: `bytecount::count(x, b + 1)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
@ -178,3 +178,5 @@ error: casting to the same type is unnecessary (`bool` -> `bool`)
|
|||
39 | false as bool;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 28 previous errors
|
||||
|
||||
|
|
|
@ -60,3 +60,5 @@ error: casting u32 to f64 may become silently lossy if types change
|
|||
14 | 1u32 as f64;
|
||||
| ^^^^^^^^^^^ help: try: `f64::from(1u32)`
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
@ -108,3 +108,5 @@ error: casting u32 to u64 may become silently lossy if types change
|
|||
23 | 1u32 as u64;
|
||||
| ^^^^^^^^^^^ help: try: `u64::from(1u32)`
|
||||
|
||||
error: aborting due to 18 previous errors
|
||||
|
||||
|
|
|
@ -120,3 +120,5 @@ error: casting i32 to usize may lose the sign of the value
|
|||
22 | 1i32 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 19 previous errors
|
||||
|
||||
|
|
|
@ -8,3 +8,5 @@ error: casting character literal to u8. `char`s are 4 bytes wide in rust, so cas
|
|||
= help: Consider using a byte literal instead:
|
||||
b'a'
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -72,3 +72,5 @@ error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead
|
|||
21 | y >= std::f64::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
|
||||
|
|
|
@ -12,3 +12,5 @@ error: Comparing with null is better expressed by the .is_null() method
|
|||
16 | if m == ptr::null_mut() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -36,3 +36,5 @@ error: this creates an owned instance just for comparison
|
|||
30 | self.to_owned() == *other
|
||||
| ^^^^^^^^^^^^^^^ try calling implementing the comparison without allocating
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
@ -240,3 +240,5 @@ help: try
|
|||
112 | }
|
||||
|
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
|
||||
|
|
|
@ -90,3 +90,5 @@ error: very complex type used. Consider factoring parts into `type` definitions
|
|||
40 | let _y: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
|
|||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
|
|||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
|
|||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
|
|||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
|
|||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
|
|||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -78,3 +78,5 @@ error: Constants have by default a `'static` lifetime
|
|||
24 | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
|
||||
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
|
||||
|
|
|
@ -33,3 +33,5 @@ error: This else block is redundant.
|
|||
}
|
||||
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -12,3 +12,5 @@ help: assign the `CString` to a variable to extend its lifetime
|
|||
7 | CString::new("foo").unwrap().as_ptr();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -269,3 +269,5 @@ error: the function has a cyclomatic complexity of 8
|
|||
|
|
||||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: aborting due to 20 previous errors
|
||||
|
||||
|
|
|
@ -13,3 +13,5 @@ error: the function has a cyclomatic complexity of 3
|
|||
= note: `-D cyclomatic-complexity` implied by `-D warnings`
|
||||
= help: you could split it up into multiple smaller functions
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -24,3 +24,5 @@ error: lint unstable_as_mut_slice has been removed: `Vec::as_mut_slice` has been
|
|||
10 | #[warn(unstable_as_mut_slice)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
@ -106,3 +106,5 @@ note: consider deriving `Clone` or removing `Copy`
|
|||
87 | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
@ -36,3 +36,5 @@ error: sub-expression diverges
|
|||
37 | _ => true || break,
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
@ -47,3 +47,5 @@ error: I see you're using a LinkedList! Perhaps you meant some other data struct
|
|||
|
|
||||
= help: a VecDeque might work
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
@ -180,3 +180,5 @@ error: you should put bare URLs between `<`/`>` or make a proper Markdown link
|
|||
168 | /// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 30 previous errors
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@ error: `--x` could be misinterpreted as pre-decrement by C programmers, is usual
|
|||
|
|
||||
= note: `-D double-neg` implied by `-D warnings`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -30,3 +30,5 @@ error: Consider removing unnecessary double parentheses
|
|||
32 | (())
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
@ -72,3 +72,5 @@ note: argument has type SomeStruct
|
|||
42 | forget(s4);
|
||||
| ^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
@ -216,3 +216,5 @@ note: argument has type &SomeStruct
|
|||
59 | std::mem::forget(&SomeStruct);
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 18 previous errors
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@ error: `darth` already exists, having another argument having almost the same na
|
|||
|
|
||||
= note: `-D duplicate-underscore-argument` implied by `-D warnings`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
50
tests/ui/else_if_without_else.rs
Normal file
50
tests/ui/else_if_without_else.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
#![warn(clippy)]
|
||||
#![warn(else_if_without_else)]
|
||||
|
||||
fn bla1() -> bool { unimplemented!() }
|
||||
fn bla2() -> bool { unimplemented!() }
|
||||
fn bla3() -> bool { unimplemented!() }
|
||||
|
||||
fn main() {
|
||||
if bla1() {
|
||||
println!("if");
|
||||
}
|
||||
|
||||
if bla1() {
|
||||
println!("if");
|
||||
} else {
|
||||
println!("else");
|
||||
}
|
||||
|
||||
if bla1() {
|
||||
println!("if");
|
||||
} else if bla2() {
|
||||
println!("else if");
|
||||
} else {
|
||||
println!("else")
|
||||
}
|
||||
|
||||
if bla1() {
|
||||
println!("if");
|
||||
} else if bla2() {
|
||||
println!("else if 1");
|
||||
} else if bla3() {
|
||||
println!("else if 2");
|
||||
} else {
|
||||
println!("else")
|
||||
}
|
||||
|
||||
if bla1() {
|
||||
println!("if");
|
||||
} else if bla2() { //~ ERROR else if without else
|
||||
println!("else if");
|
||||
}
|
||||
|
||||
if bla1() {
|
||||
println!("if");
|
||||
} else if bla2() {
|
||||
println!("else if 1");
|
||||
} else if bla3() { //~ ERROR else if without else
|
||||
println!("else if 2");
|
||||
}
|
||||
}
|
22
tests/ui/else_if_without_else.stderr
Normal file
22
tests/ui/else_if_without_else.stderr
Normal file
|
@ -0,0 +1,22 @@
|
|||
error: if expression with an `else if`, but without a final `else`
|
||||
--> $DIR/else_if_without_else.rs:39:12
|
||||
|
|
||||
39 | } else if bla2() { //~ ERROR else if without else
|
||||
| ____________^
|
||||
40 | | println!("else if");
|
||||
41 | | }
|
||||
| |_____^ help: add an `else` block here
|
||||
|
|
||||
= note: `-D else-if-without-else` implied by `-D warnings`
|
||||
|
||||
error: if expression with an `else if`, but without a final `else`
|
||||
--> $DIR/else_if_without_else.rs:47:12
|
||||
|
|
||||
47 | } else if bla3() { //~ ERROR else if without else
|
||||
| ____________^
|
||||
48 | | println!("else if 2");
|
||||
49 | | }
|
||||
| |_____^ help: add an `else` block here
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
@ -11,3 +11,5 @@ help: consider using the uninhabited type `!` or a wrapper around it
|
|||
7 | enum Empty {}
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -42,3 +42,5 @@ error: usage of `contains_key` followed by `insert` on a `BTreeMap`
|
|||
37 | if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `m.entry(k)`
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
@ -12,3 +12,5 @@ error: don't use glob imports for enum variants
|
|||
12 | use self::Enum::*;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -97,3 +97,5 @@ error: All variants have the same prefix: `With`
|
|||
= note: `-D pub-enum-variant-names` implied by `-D warnings`
|
||||
= help: remove the prefixes and use full paths to the variants instead of glob imports
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
@ -48,3 +48,5 @@ error: Clike enum variant discriminant is not portable to 32-bit targets
|
|||
37 | A = 0x1_0000_0000,
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
|
@ -204,3 +204,5 @@ error: taken reference of right operand
|
|||
|
|
||||
= note: `-D op-ref` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 33 previous errors
|
||||
|
||||
|
|
|
@ -18,3 +18,5 @@ error: this operation will always return zero. This is likely not the intended o
|
|||
11 | 0 / x;
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
@ -32,3 +32,5 @@ error: redundant closure found
|
|||
18 | let e = Some(1u8).map(|a| generic(a));
|
||||
| ^^^^^^^^^^^^^^ help: remove closure as shown: `generic`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
@ -47,3 +47,5 @@ note: whether read occurs before this write depends on evaluation order
|
|||
21 | x += { x = 20; 2 };
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
@ -36,3 +36,5 @@ error: use of `stderr().write_fmt(...).unwrap()`. Consider using `eprint!` inste
|
|||
21 | std::io::stderr().write_fmt(format_args!("test")).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
@ -89,3 +89,5 @@ note: potential failure(s)
|
|||
| ^^^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
@ -36,3 +36,5 @@ error: called `filter_map(p).map(q)` on an `Iterator`. This is more succinctly e
|
|||
25 | | .map(|x| x.checked_mul(2))
|
||||
| |__________________________________________________________^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
@ -95,3 +95,5 @@ note: std::f32::EPSILON and std::f64::EPSILON are available.
|
|||
57 | twice(x) != twice(ONE as f64);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
|
@ -83,3 +83,5 @@ note: std::f32::EPSILON and std::f64::EPSILON are available.
|
|||
25 | v != ONE;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
@ -565,3 +565,5 @@ error: it looks like you're manually copying between slices
|
|||
549 | | }
|
||||
| |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`
|
||||
|
||||
error: aborting due to 59 previous errors
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@ error: useless use of `format!`
|
|||
|
|
||||
= note: `-D useless-format` implied by `-D warnings`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -86,3 +86,5 @@ error: possibly missing a comma here
|
|||
|
|
||||
= note: to remove this lint, add a comma or write the expr in a single line
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
@ -75,3 +75,5 @@ error: this public function dereferences a raw pointer but is not marked `unsafe
|
|||
63 | unsafe { std::ptr::read(p) };
|
||||
| ^
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
|
||||
|
|
|
@ -60,3 +60,5 @@ error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and
|
|||
40 | *some_vecdeque.get_mut(0).unwrap() = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&mut some_vecdeque[0]`
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
@ -40,3 +40,5 @@ error: identical conversion
|
|||
39 | let _ = String::from("foo".to_string());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
@ -48,3 +48,5 @@ error: the operation is ineffective. Consider reducing it to `u`
|
|||
32 | u & 255;
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
|
@ -24,3 +24,5 @@ error: redundant pattern matching, consider using `is_some()`
|
|||
17 | if let Some(_) = Some(42) {
|
||||
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
@ -23,3 +23,5 @@ error: Unnecessary `!=` operation
|
|||
|
|
||||
= help: change to `==` and swap the blocks of the if/else
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -133,3 +133,5 @@ help: consider adding a type parameter
|
|||
78 | pub fn $name<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32, S>) {
|
||||
|
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
@ -39,3 +39,5 @@ error: digits grouped inconsistently by underscores
|
|||
|
|
||||
= help: consider: 1.234_567_8_f32
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
@ -96,3 +96,5 @@ error: possible infinite iteration detected
|
|||
30 | (0..).all(|x| x == 24); // maybe infinite iter
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
|
|
@ -40,3 +40,5 @@ help: change `>= y + 1` to `> y` as shown
|
|||
14 | y < x;
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
@ -47,3 +47,5 @@ error: reference to uninitialized memory
|
|||
|
|
||||
= help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
@ -162,3 +162,5 @@ error: because of the numeric bounds on `u8` prior to casting, this expression i
|
|||
78 | -5 >= (u8 as i32);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 27 previous errors
|
||||
|
||||
|
|
|
@ -69,3 +69,5 @@ error: This expression evaluates to the Unit type ()
|
|||
78 | let x3 = match None { Some(_) => {}, None => {}, };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
@ -12,3 +12,5 @@ error: adding items after statements is confusing, since items exist from the st
|
|||
17 | fn foo() { println!("foo"); }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -47,3 +47,5 @@ error: digit groups should be smaller
|
|||
|
|
||||
= help: consider: 123_456.123_456_f32
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
@ -66,3 +66,5 @@ help: consider boxing the large fields to reduce the total size of the enum
|
|||
49 | StructLikeLarge2 { x: Box<[i32; 8000]> },
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
@ -94,3 +94,5 @@ error: trait `DependsOnFoo` has a `len` method but no (possibly inherited) `is_e
|
|||
191 | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
|
||||
|
|
|
@ -46,3 +46,5 @@ error: `if _ { .. } else { .. }` is an expression
|
|||
|
|
||||
= note: you might not need `mut` at all
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
@ -23,3 +23,5 @@ note: this expression can be directly returned
|
|||
15 | let x = 5;
|
||||
| ^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -12,3 +12,5 @@ error: this let-binding has unit value. Consider omitting `let _a =`
|
|||
18 | let _a = ();
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -86,3 +86,5 @@ error: explicit lifetimes given in parameter types where they could be elided
|
|||
120 | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@ error: the lint `MISSING_LINT` is not added to any `LintPass`
|
|||
|
|
||||
= note: `-D lint-without-lint-pass` implied by `-D warnings`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -86,3 +86,5 @@ help: if you mean to use an octal constant, use `0o`
|
|||
30 | let fail8 = 0o123;
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
|
||||
|
|
|
@ -98,3 +98,5 @@ error: you seem to be using .map() to clone the contents of an Option, consider
|
|||
= help: try
|
||||
x.as_ref().cloned()
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
|
||||
|
|
|
@ -448,3 +448,5 @@ error: use as_mut() instead
|
|||
329 | | };
|
||||
| |_____^ help: try this: `mut_owned.as_mut()`
|
||||
|
||||
error: aborting due to 37 previous errors
|
||||
|
||||
|
|
|
@ -18,3 +18,5 @@ error: usage of mem::forget on Drop type
|
|||
24 | forgetSomething(eight);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
@ -501,3 +501,5 @@ error: used unwrap() on an Option value. If you don't want to handle the None ca
|
|||
|
|
||||
= note: `-D option-unwrap-used` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 66 previous errors
|
||||
|
||||
|
|
|
@ -42,3 +42,5 @@ error: this min/max combination leads to constant result
|
|||
30 | max(min(s, "Apple"), "Zoo");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
@ -264,3 +264,5 @@ error: missing documentation for a function
|
|||
191 | fn also_undocumented2() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 39 previous errors
|
||||
|
||||
|
|
|
@ -16,3 +16,5 @@ error: module has the same name as its containing module
|
|||
14 | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue