Skip to content

rustup "Cheaper doc comments" #4755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ matrix:
fast_finish: true
include:
# Builds that are executed for every PR
- os: osx # run base tests on both platforms
- os: linux
- os: osx
if: branch IN (auto, try)
- os: windows
env: CARGO_INCREMENTAL=0 OS_WINDOWS=true

Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,11 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
}

for attr in attrs {
if attr.is_sugared_doc {
if attr.is_doc_comment() {
return;
}
if attr.style == AttrStyle::Outer {
if attr.tokens.is_empty() || !is_present_in_source(cx, attr.span) {
if attr.get_normal_item().tokens.is_empty() || !is_present_in_source(cx, attr.span) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet<String
let mut spans = vec![];

for attr in attrs {
if attr.is_sugared_doc {
if attr.is_doc_comment() {
if let Some(ref current) = attr.value_str() {
let current = current.to_string();
let (current, current_spans) = strip_doc_comment_decoration(&current, attr.span);
Expand Down
5 changes: 4 additions & 1 deletion clippy_lints/src/main_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ impl_lint_pass!(MainRecursion => [MAIN_RECURSION]);

impl LateLintPass<'_, '_> for MainRecursion {
fn check_crate(&mut self, _: &LateContext<'_, '_>, krate: &Crate) {
self.has_no_std_attr = krate.attrs.iter().any(|attr| attr.path == sym::no_std);
self.has_no_std_attr = krate
.attrs
.iter()
.any(|attr| !attr.is_doc_comment() && attr.get_normal_item().path == sym::no_std);
}

fn check_expr_post(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
Expand Down
76 changes: 40 additions & 36 deletions clippy_lints/src/utils/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,46 +57,50 @@ pub fn get_attr<'a>(
name: &'static str,
) -> impl Iterator<Item = &'a ast::Attribute> {
attrs.iter().filter(move |attr| {
let attr_segments = &attr.path.segments;
if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" {
if let Some(deprecation_status) =
BUILTIN_ATTRIBUTES
.iter()
.find_map(|(builtin_name, deprecation_status)| {
if *builtin_name == attr_segments[1].ident.to_string() {
Some(deprecation_status)
} else {
None
}
})
{
let mut db = sess.struct_span_err(attr_segments[1].ident.span, "Usage of deprecated attribute");
match *deprecation_status {
DeprecationStatus::Deprecated => {
db.emit();
false
},
DeprecationStatus::Replaced(new_name) => {
db.span_suggestion(
attr_segments[1].ident.span,
"consider using",
new_name.to_string(),
Applicability::MachineApplicable,
);
db.emit();
false
},
DeprecationStatus::None => {
db.cancel();
attr_segments[1].ident.to_string() == name
},
if attr.is_doc_comment() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i should split this closure to a separate function.

false
} else {
let attr_segments = &attr.get_normal_item().path.segments;
if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" {
if let Some(deprecation_status) =
BUILTIN_ATTRIBUTES
.iter()
.find_map(|(builtin_name, deprecation_status)| {
if *builtin_name == attr_segments[1].ident.to_string() {
Some(deprecation_status)
} else {
None
}
})
{
let mut db = sess.struct_span_err(attr_segments[1].ident.span, "Usage of deprecated attribute");
match *deprecation_status {
DeprecationStatus::Deprecated => {
db.emit();
false
},
DeprecationStatus::Replaced(new_name) => {
db.span_suggestion(
attr_segments[1].ident.span,
"consider using",
new_name.to_string(),
Applicability::MachineApplicable,
);
db.emit();
false
},
DeprecationStatus::None => {
db.cancel();
attr_segments[1].ident.to_string() == name
},
}
} else {
sess.span_err(attr_segments[1].ident.span, "Usage of unknown attribute");
false
}
} else {
sess.span_err(attr_segments[1].ident.span, "Usage of unknown attribute");
false
}
} else {
false
}
})
}
Expand Down