Fix question_mark lint+test

This commit is contained in:
flip1995 2019-03-27 11:46:33 +01:00
parent 3cff06a0eb
commit 6f01ecfefd
No known key found for this signature in database
GPG key ID: 693086869D506637
2 changed files with 71 additions and 1 deletions

View file

@ -27,7 +27,7 @@ use rustc::hir::def::Def;
use rustc::hir::def_id::CrateNum; use rustc::hir::def_id::CrateNum;
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; use rustc::hir::intravisit::{NestedVisitorMap, Visitor};
use rustc::hir::map::DisambiguatedDefPathData; use rustc::hir::map::{DefPathData, DisambiguatedDefPathData};
use rustc::hir::Node; use rustc::hir::Node;
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, Level, Lint, LintContext}; use rustc::lint::{LateContext, Level, Lint, LintContext};
@ -178,6 +178,13 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
disambiguated_data: &DisambiguatedDefPathData, disambiguated_data: &DisambiguatedDefPathData,
) -> Result<Self::Path, Self::Error> { ) -> Result<Self::Path, Self::Error> {
let mut path = print_prefix(self)?; 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()); path.push(disambiguated_data.data.as_interned_str().as_str());
Ok(path) Ok(path)
} }

View file

@ -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