Skip to content
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

Lint multiline attributes properly #2473

merged 1 commit into from Feb 21, 2018
Show file tree
Hide file tree
Changes from all commits
File filter

Filter by extension

Filter by extension

Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions clippy_lints/src/
Expand Up @@ -271,18 +271,18 @@ fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) {

let attr_to_item_span = Span::new(attr.span.lo(), span.lo(), span.ctxt());
let begin_of_attr_to_item = Span::new(attr.span.lo(), span.lo(), span.ctxt());
let end_of_attr_to_item = Span::new(attr.span.hi(), span.lo(), span.ctxt());

if let Some(snippet) = snippet_opt(cx, attr_to_item_span) {
if let Some(snippet) = snippet_opt(cx, end_of_attr_to_item) {
let lines = snippet.split('\n').collect::<Vec<_>>();
if lines.iter().filter(|l| l.trim().is_empty()).count() > 1 {
if lines.iter().filter(|l| l.trim().is_empty()).count() > 2 {
"Found an empty line after an outer attribute. Perhaps you forgot to add a '!' to make it an inner attribute?"

Expand Down
9 changes: 9 additions & 0 deletions tests/ui/
Expand Up @@ -58,4 +58,13 @@ mod foo {
fn three_attributes() { assert!(true) }

// This should not produce a warning
#[doc = "
Returns the escaped value of the textual representation of

pub fn function() -> bool {

fn main() { }