Skip to content

Commit 6f01ecf

Browse files
committed
Fix question_mark lint+test
1 parent 3cff06a commit 6f01ecf

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

clippy_lints/src/utils/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc::hir::def::Def;
2727
use rustc::hir::def_id::CrateNum;
2828
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
2929
use rustc::hir::intravisit::{NestedVisitorMap, Visitor};
30-
use rustc::hir::map::DisambiguatedDefPathData;
30+
use rustc::hir::map::{DefPathData, DisambiguatedDefPathData};
3131
use rustc::hir::Node;
3232
use rustc::hir::*;
3333
use rustc::lint::{LateContext, Level, Lint, LintContext};
@@ -178,6 +178,13 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
178178
disambiguated_data: &DisambiguatedDefPathData,
179179
) -> Result<Self::Path, Self::Error> {
180180
let mut path = print_prefix(self)?;
181+
182+
// Skip `::{{constructor}}` on tuple/unit structs.
183+
match disambiguated_data.data {
184+
DefPathData::Ctor => return Ok(path),
185+
_ => {}
186+
}
187+
181188
path.push(disambiguated_data.data.as_interned_str().as_str());
182189
Ok(path)
183190
}

tests/ui/question_mark.stderr

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
error: this block may be rewritten with the `?` operator
2+
--> $DIR/question_mark.rs:2:5
3+
|
4+
LL | / if a.is_none() {
5+
LL | | return None;
6+
LL | | }
7+
| |_____^ help: replace_it_with: `a?;`
8+
|
9+
= note: `-D clippy::question-mark` implied by `-D warnings`
10+
11+
error: this block may be rewritten with the `?` operator
12+
--> $DIR/question_mark.rs:47:9
13+
|
14+
LL | / if (self.opt).is_none() {
15+
LL | | return None;
16+
LL | | }
17+
| |_________^ help: replace_it_with: `(self.opt)?;`
18+
19+
error: this block may be rewritten with the `?` operator
20+
--> $DIR/question_mark.rs:51:9
21+
|
22+
LL | / if self.opt.is_none() {
23+
LL | | return None
24+
LL | | }
25+
| |_________^ help: replace_it_with: `self.opt?;`
26+
27+
error: this block may be rewritten with the `?` operator
28+
--> $DIR/question_mark.rs:55:17
29+
|
30+
LL | let _ = if self.opt.is_none() {
31+
| _________________^
32+
LL | | return None;
33+
LL | | } else {
34+
LL | | self.opt
35+
LL | | };
36+
| |_________^ help: replace_it_with: `Some(self.opt?)`
37+
38+
error: this block may be rewritten with the `?` operator
39+
--> $DIR/question_mark.rs:72:9
40+
|
41+
LL | / if self.opt.is_none() {
42+
LL | | return None;
43+
LL | | }
44+
| |_________^ help: replace_it_with: `self.opt.as_ref()?;`
45+
46+
error: this block may be rewritten with the `?` operator
47+
--> $DIR/question_mark.rs:80:9
48+
|
49+
LL | / if self.opt.is_none() {
50+
LL | | return None;
51+
LL | | }
52+
| |_________^ help: replace_it_with: `self.opt.as_ref()?;`
53+
54+
error: this block may be rewritten with the `?` operator
55+
--> $DIR/question_mark.rs:88:9
56+
|
57+
LL | / if self.opt.is_none() {
58+
LL | | return None;
59+
LL | | }
60+
| |_________^ help: replace_it_with: `self.opt.as_ref()?;`
61+
62+
error: aborting due to 7 previous errors
63+

0 commit comments

Comments
 (0)