From 6f01ecfefde7aee9a2cd62cd4b28e42dfe36410d Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 27 Mar 2019 11:46:33 +0100 Subject: [PATCH] Fix question_mark lint+test --- clippy_lints/src/utils/mod.rs | 9 ++++- tests/ui/question_mark.stderr | 63 +++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) 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 { 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 +