Skip to content

Commit df6932a

Browse files
committed
rustup "Cheaper doc comments"
1 parent 43a3796 commit df6932a

File tree

4 files changed

+47
-40
lines changed

4 files changed

+47
-40
lines changed

clippy_lints/src/attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,11 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
417417
}
418418

419419
for attr in attrs {
420-
if attr.is_sugared_doc {
420+
if attr.is_doc_comment() {
421421
return;
422422
}
423423
if attr.style == AttrStyle::Outer {
424-
if attr.tokens.is_empty() || !is_present_in_source(cx, attr.span) {
424+
if attr.get_normal_item().tokens.is_empty() || !is_present_in_source(cx, attr.span) {
425425
return;
426426
}
427427

clippy_lints/src/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet<String
247247
let mut spans = vec![];
248248

249249
for attr in attrs {
250-
if attr.is_sugared_doc {
250+
if attr.is_doc_comment() {
251251
if let Some(ref current) = attr.value_str() {
252252
let current = current.to_string();
253253
let (current, current_spans) = strip_doc_comment_decoration(&current, attr.span);

clippy_lints/src/main_recursion.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ impl_lint_pass!(MainRecursion => [MAIN_RECURSION]);
3434

3535
impl LateLintPass<'_, '_> for MainRecursion {
3636
fn check_crate(&mut self, _: &LateContext<'_, '_>, krate: &Crate) {
37-
self.has_no_std_attr = krate.attrs.iter().any(|attr| attr.path == sym::no_std);
37+
self.has_no_std_attr = krate
38+
.attrs
39+
.iter()
40+
.any(|attr| !attr.is_doc_comment() && attr.get_normal_item().path == sym::no_std);
3841
}
3942

4043
fn check_expr_post(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {

clippy_lints/src/utils/attrs.rs

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,46 +57,50 @@ pub fn get_attr<'a>(
5757
name: &'static str,
5858
) -> impl Iterator<Item = &'a ast::Attribute> {
5959
attrs.iter().filter(move |attr| {
60-
let attr_segments = &attr.path.segments;
61-
if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" {
62-
if let Some(deprecation_status) =
63-
BUILTIN_ATTRIBUTES
64-
.iter()
65-
.find_map(|(builtin_name, deprecation_status)| {
66-
if *builtin_name == attr_segments[1].ident.to_string() {
67-
Some(deprecation_status)
68-
} else {
69-
None
70-
}
71-
})
72-
{
73-
let mut db = sess.struct_span_err(attr_segments[1].ident.span, "Usage of deprecated attribute");
74-
match *deprecation_status {
75-
DeprecationStatus::Deprecated => {
76-
db.emit();
77-
false
78-
},
79-
DeprecationStatus::Replaced(new_name) => {
80-
db.span_suggestion(
81-
attr_segments[1].ident.span,
82-
"consider using",
83-
new_name.to_string(),
84-
Applicability::MachineApplicable,
85-
);
86-
db.emit();
87-
false
88-
},
89-
DeprecationStatus::None => {
90-
db.cancel();
91-
attr_segments[1].ident.to_string() == name
92-
},
60+
if attr.is_doc_comment() {
61+
false
62+
} else {
63+
let attr_segments = &attr.get_normal_item().path.segments;
64+
if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" {
65+
if let Some(deprecation_status) =
66+
BUILTIN_ATTRIBUTES
67+
.iter()
68+
.find_map(|(builtin_name, deprecation_status)| {
69+
if *builtin_name == attr_segments[1].ident.to_string() {
70+
Some(deprecation_status)
71+
} else {
72+
None
73+
}
74+
})
75+
{
76+
let mut db = sess.struct_span_err(attr_segments[1].ident.span, "Usage of deprecated attribute");
77+
match *deprecation_status {
78+
DeprecationStatus::Deprecated => {
79+
db.emit();
80+
false
81+
},
82+
DeprecationStatus::Replaced(new_name) => {
83+
db.span_suggestion(
84+
attr_segments[1].ident.span,
85+
"consider using",
86+
new_name.to_string(),
87+
Applicability::MachineApplicable,
88+
);
89+
db.emit();
90+
false
91+
},
92+
DeprecationStatus::None => {
93+
db.cancel();
94+
attr_segments[1].ident.to_string() == name
95+
},
96+
}
97+
} else {
98+
sess.span_err(attr_segments[1].ident.span, "Usage of unknown attribute");
99+
false
93100
}
94101
} else {
95-
sess.span_err(attr_segments[1].ident.span, "Usage of unknown attribute");
96102
false
97103
}
98-
} else {
99-
false
100104
}
101105
})
102106
}

0 commit comments

Comments
 (0)