Skip to content

Commit

Permalink
Fix question_mark lint+test
Browse files Browse the repository at this point in the history
  • Loading branch information
flip1995 committed Mar 27, 2019
1 parent 6689fb0 commit 0294c95
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
9 changes: 8 additions & 1 deletion clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rustc::hir::def::Def;
use rustc::hir::def_id::CrateNum;
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc::hir::intravisit::{NestedVisitorMap, Visitor};
use rustc::hir::map::DisambiguatedDefPathData;
use rustc::hir::map::{DefPathData, DisambiguatedDefPathData};
use rustc::hir::Node;
use rustc::hir::*;
use rustc::lint::{LateContext, Level, Lint, LintContext};
Expand Down Expand Up @@ -178,6 +178,13 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
disambiguated_data: &DisambiguatedDefPathData,
) -> Result<Self::Path, Self::Error> {
let mut path = print_prefix(self)?;

// Skip `::{{constructor}}` on tuple/unit structs.
match disambiguated_data.data {
DefPathData::Ctor => return Ok(path),
_ => {}
}

path.push(disambiguated_data.data.as_interned_str().as_str());
Ok(path)
}
Expand Down
63 changes: 63 additions & 0 deletions tests/ui/question_mark.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:2:5
|
LL | / if a.is_none() {
LL | | return None;
LL | | }
| |_____^ help: replace_it_with: `a?;`
|
= note: `-D clippy::question-mark` implied by `-D warnings`

error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:47:9
|
LL | / if (self.opt).is_none() {
LL | | return None;
LL | | }
| |_________^ help: replace_it_with: `(self.opt)?;`

error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:51:9
|
LL | / if self.opt.is_none() {
LL | | return None
LL | | }
| |_________^ help: replace_it_with: `self.opt?;`

error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:55:17
|
LL | let _ = if self.opt.is_none() {
| _________________^
LL | | return None;
LL | | } else {
LL | | self.opt
LL | | };
| |_________^ help: replace_it_with: `Some(self.opt?)`

error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:72:9
|
LL | / if self.opt.is_none() {
LL | | return None;
LL | | }
| |_________^ help: replace_it_with: `self.opt.as_ref()?;`

error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:80:9
|
LL | / if self.opt.is_none() {
LL | | return None;
LL | | }
| |_________^ help: replace_it_with: `self.opt.as_ref()?;`

error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:88:9
|
LL | / if self.opt.is_none() {
LL | | return None;
LL | | }
| |_________^ help: replace_it_with: `self.opt.as_ref()?;`

error: aborting due to 7 previous errors

0 comments on commit 0294c95

Please sign in to comment.