about summary refs log tree commit diff
diff options
context:
space:
mode:
authorflip1995 <hello@philkrones.com>2019-03-27 11:46:33 +0100
committerflip1995 <hello@philkrones.com>2019-04-01 20:37:05 +0200
commit6f01ecfefde7aee9a2cd62cd4b28e42dfe36410d (patch)
tree45acf65b1bb406a018cf877a1d7eff53ef97a3a5
parent3cff06a0eb27dc5b6d208eb24fb22016222ea9d8 (diff)
downloadrust-6f01ecfefde7aee9a2cd62cd4b28e42dfe36410d.tar.gz
rust-6f01ecfefde7aee9a2cd62cd4b28e42dfe36410d.zip
Fix question_mark lint+test
-rw-r--r--clippy_lints/src/utils/mod.rs9
-rw-r--r--tests/ui/question_mark.stderr63
2 files changed, 71 insertions, 1 deletions
diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs
index d70d3ff1239..1f4b0324700 100644
--- a/clippy_lints/src/utils/mod.rs
+++ b/clippy_lints/src/utils/mod.rs
@@ -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};
@@ -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)
     }
diff --git a/tests/ui/question_mark.stderr b/tests/ui/question_mark.stderr
index e69de29bb2d..522501d58c6 100644
--- a/tests/ui/question_mark.stderr
+++ b/tests/ui/question_mark.stderr
@@ -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
+