Skip to content

Commit

Permalink
Corrected tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bengsparks committed Dec 27, 2020
1 parent 57a9cf4 commit bbe49d1
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 36 deletions.
8 changes: 4 additions & 4 deletions clippy_lints/src/needless_question_mark.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_errors::Applicability;
use rustc_hir::*;
use rustc_hir::{Body, Expr, ExprKind, LangItem, MatchSource, Path, QPath};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};

Expand Down Expand Up @@ -86,7 +86,7 @@ impl LateLintPass<'_> for NeedlessQuestionMark {
};

if let Some(ok_some_call) = is_some_or_ok_call(cx, e) {
emit_lint(cx, ok_some_call);
emit_lint(cx, &ok_some_call);
}
}

Expand All @@ -103,13 +103,13 @@ impl LateLintPass<'_> for NeedlessQuestionMark {
if let Some(expr) = expr_opt;
if let Some(ok_some_call) = is_some_or_ok_call(cx, expr);
then {
emit_lint(cx, ok_some_call);
emit_lint(cx, &ok_some_call);
}
};
}
}

fn emit_lint(cx: &LateContext<'_>, expr: SomeOkCall<'_>) {
fn emit_lint(cx: &LateContext<'_>, expr: &SomeOkCall<'_>) {
let (entire_expr, inner_expr) = match expr {
SomeOkCall::OkCall(outer, inner) | SomeOkCall::SomeCall(outer, inner) => (outer, inner),
};
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/needless_question_mark.fixed
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// run-rustfix

#![warn(clippy::needless_question_mark)]
#![allow(clippy::needless_return)]
#![allow(clippy::needless_return, clippy::unnecessary_unwrap, dead_code)]
struct TO {
magic: Option<usize>,
}
Expand Down Expand Up @@ -71,12 +71,12 @@ fn simple_result_bad5(tr: Result<TR, bool>) -> Result<usize, bool> {
})
}

fn just_bad_code_really(tr: Result<TR, bool>) -> Result<usize, bool> {
return tr.and_then(|t| t.magic);

// Dead code
let t = tr.unwrap();
return t.magic;
fn also_bad(tr: Result<TR, bool>) -> Result<usize, bool> {
if tr.is_ok() {
let t = tr.unwrap();
return t.magic;
}
Err(false)
}

fn main() {}
14 changes: 7 additions & 7 deletions tests/ui/needless_question_mark.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// run-rustfix

#![warn(clippy::needless_question_mark)]
#![allow(clippy::needless_return)]
#![allow(clippy::needless_return, clippy::unnecessary_unwrap, dead_code)]
struct TO {
magic: Option<usize>,
}
Expand Down Expand Up @@ -71,12 +71,12 @@ fn simple_result_bad5(tr: Result<TR, bool>) -> Result<usize, bool> {
})
}

fn just_bad_code_really(tr: Result<TR, bool>) -> Result<usize, bool> {
return tr.and_then(|t| Ok(t.magic?));

// Dead code
let t = tr.unwrap();
return Ok(t.magic?);
fn also_bad(tr: Result<TR, bool>) -> Result<usize, bool> {
if tr.is_ok() {
let t = tr.unwrap();
return Ok(t.magic?);
}
Err(false)
}

fn main() {}
14 changes: 4 additions & 10 deletions tests/ui/needless_question_mark.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,10 @@ LL | Ok(t.magic?)
| ^^^^^^^^^^^^ help: try: `t.magic`

error: Question mark operator is useless here
--> $DIR/needless_question_mark.rs:75:28
--> $DIR/needless_question_mark.rs:77:16
|
LL | return tr.and_then(|t| Ok(t.magic?));
| ^^^^^^^^^^^^ help: try: `t.magic`
LL | return Ok(t.magic?);
| ^^^^^^^^^^^^ help: try: `t.magic`

error: Question mark operator is useless here
--> $DIR/needless_question_mark.rs:79:12
|
LL | return Ok(t.magic?);
| ^^^^^^^^^^^^ help: try: `t.magic`

error: aborting due to 12 previous errors
error: aborting due to 11 previous errors

2 changes: 1 addition & 1 deletion tests/ui/try_err.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// aux-build:macro_rules.rs

#![deny(clippy::try_err)]
#![allow(clippy::unnecessary_wraps)]
#![allow(clippy::unnecessary_wraps, clippy::needless_question_mark)]

#[macro_use]
extern crate macro_rules;
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/try_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// aux-build:macro_rules.rs

#![deny(clippy::try_err)]
#![allow(clippy::unnecessary_wraps)]
#![allow(clippy::needless-question-mark)]
#![allow(clippy::unnecessary_wraps, clippy::needless_question_mark)]

#[macro_use]
extern crate macro_rules;
Expand Down
80 changes: 75 additions & 5 deletions tests/ui/try_err.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,78 @@
error: expected one of `(`, `,`, `::`, or `=`, found `-`
--> $DIR/try_err.rs:6:26
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:19:9
|
LL | #![allow(clippy::needless-question-mark)]
| ^ expected one of `(`, `,`, `::`, or `=`
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err)`
|
note: the lint level is defined here
--> $DIR/try_err.rs:4:9
|
LL | #![deny(clippy::try_err)]
| ^^^^^^^^^^^^^^^

error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:29:9
|
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err.into())`

error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:49:17
|
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err)`

error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:68:17
|
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err.into())`

error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:87:23
|
LL | Err(_) => Err(1)?,
| ^^^^^^^ help: try this: `return Err(1)`
...
LL | try_validation!(Ok::<_, i32>(5));
| --------------------------------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:102:23
|
LL | Err(_) => Err(ret_one!())?,
| ^^^^^^^^^^^^^^^^ help: try this: `return Err(ret_one!())`
...
LL | try_validation_in_macro!(Ok::<_, i32>(5));
| ------------------------------------------ in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:141:9
|
LL | Err(foo!())?;
| ^^^^^^^^^^^^ help: try this: `return Err(foo!())`

error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:148:9
|
LL | Err(io::ErrorKind::WriteZero)?
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))`

error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:150:9
|
LL | Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))?
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error")))`

error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:158:9
|
LL | Err(io::ErrorKind::NotFound)?
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into())))`

error: aborting due to previous error
error: aborting due to 10 previous errors

0 comments on commit bbe49d1

Please sign in to comment.