Skip to content

Commit a4571f9

Browse files
committed
add @compile-flags to [mixed_attributes_style]'s test;
turns out not linting in test mod is not a FN.
1 parent 1c71163 commit a4571f9

File tree

4 files changed

+84
-67
lines changed

4 files changed

+84
-67
lines changed

clippy_lints/src/attrs/mixed_attributes_style.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use clippy_utils::diagnostics::span_lint;
33
use rustc_ast::{AttrKind, AttrStyle, Attribute};
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_lint::{LateContext, LintContext};
6-
use rustc_span::{Span, Symbol};
6+
use rustc_span::source_map::SourceMap;
7+
use rustc_span::{SourceFile, Span, Symbol};
78
use std::sync::Arc;
89

910
#[derive(Hash, PartialEq, Eq)]
@@ -35,8 +36,11 @@ pub(super) fn check(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute])
3536
let mut inner_attr_kind: FxHashSet<SimpleAttrKind> = FxHashSet::default();
3637
let mut outer_attr_kind: FxHashSet<SimpleAttrKind> = FxHashSet::default();
3738

39+
let source_map = cx.sess().source_map();
40+
let item_src = source_map.lookup_source_file(item_span.lo());
41+
3842
for attr in attrs {
39-
if attr.span.from_expansion() || !attr_in_same_src_as_item(cx, attr.span, item_span) {
43+
if attr.span.from_expansion() || !attr_in_same_src_as_item(source_map, &item_src, item_span) {
4044
continue;
4145
}
4246

@@ -75,9 +79,7 @@ fn lint_mixed_attrs(cx: &LateContext<'_>, attrs: &[Attribute]) {
7579
);
7680
}
7781

78-
fn attr_in_same_src_as_item(cx: &LateContext<'_>, attr_span: Span, item_span: Span) -> bool {
79-
let source_map = cx.sess().source_map();
80-
let item_src = source_map.lookup_source_file(item_span.lo());
82+
fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Arc<SourceFile>, attr_span: Span) -> bool {
8183
let attr_src = source_map.lookup_source_file(attr_span.lo());
82-
Arc::ptr_eq(&attr_src, &item_src)
84+
Arc::ptr_eq(item_src, &attr_src)
8385
}

tests/ui/mixed_attributes_style.rs

+36-37
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//@aux-build:proc_macro_attr.rs
2+
//@compile-flags: --test --cfg dummy_cfg
23
#![feature(custom_inner_attributes)]
34
#![warn(clippy::mixed_attributes_style)]
45
#![allow(clippy::duplicated_attributes)]
56

6-
use proc_macro_attr::dummy;
7+
#[macro_use]
8+
extern crate proc_macro_attr;
79

810
#[allow(unused)] //~ ERROR: item has both inner and outer attributes
911
fn foo1() {
@@ -58,44 +60,41 @@ mod quz {
5860
#![allow(unused)]
5961
}
6062

61-
// issue #12530, don't lint different attributes entirely
62-
#[cfg(test)]
63-
mod tests {
64-
#![allow(clippy::unreadable_literal)]
65-
}
66-
#[cfg(unix)]
67-
mod another_mod {
68-
#![allow(clippy::question_mark)]
69-
}
70-
/// Nested mod - Good
71-
mod nested_mod {
72-
#[allow(dead_code)] //~ ERROR: item has both inner and outer attributes
73-
mod inner_mod {
74-
#![allow(dead_code)]
75-
}
76-
}
77-
/// Nested mod - Good //~ ERROR: item has both inner and outer attributes
78-
#[allow(unused)]
79-
mod nest_mod_2 {
80-
#![allow(unused)]
63+
mod issue_12530 {
64+
// don't lint different attributes entirely
65+
#[cfg(test)]
66+
mod tests {
67+
#![allow(clippy::unreadable_literal)]
8168

82-
#[allow(dead_code)] //~ ERROR: item has both inner and outer attributes
83-
mod inner_mod {
84-
#![allow(dead_code)]
69+
#[allow(dead_code)] //~ ERROR: item has both inner and outer attributes
70+
mod inner_mod {
71+
#![allow(dead_code)]
72+
}
8573
}
86-
}
87-
/// Nested mod - Possible FN
88-
#[cfg(test)]
89-
mod nested_mod_false_nagative {
90-
#![allow(unused)]
74+
#[cfg(dummy_cfg)]
75+
mod another_mod {
76+
#![allow(clippy::question_mark)]
77+
}
78+
/// Nested mod
79+
mod nested_mod {
80+
#[allow(dead_code)] //~ ERROR: item has both inner and outer attributes
81+
mod inner_mod {
82+
#![allow(dead_code)]
83+
}
84+
}
85+
/// Nested mod //~ ERROR: item has both inner and outer attributes
86+
#[allow(unused)]
87+
mod nest_mod_2 {
88+
#![allow(unused)]
9189

92-
#[allow(dead_code)] // This should lint but it does not, removing the `#[cfg(test)]` solves the problem.
93-
mod inner_mod {
94-
#![allow(dead_code)]
90+
#[allow(dead_code)] //~ ERROR: item has both inner and outer attributes
91+
mod inner_mod {
92+
#![allow(dead_code)]
93+
}
94+
}
95+
// Different path symbols - Known FN
96+
#[dummy]
97+
fn use_dummy() {
98+
#![proc_macro_attr::dummy]
9599
}
96-
}
97-
// Different path symbols - Known FN
98-
#[dummy]
99-
fn use_dummy() {
100-
#![proc_macro_attr::dummy]
101100
}
+28-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: item has both inner and outer attributes
2-
--> tests/ui/mixed_attributes_style.rs:8:1
2+
--> tests/ui/mixed_attributes_style.rs:10:1
33
|
44
LL | / #[allow(unused)]
55
LL | | fn foo1() {
@@ -10,7 +10,7 @@ LL | | #![allow(unused)]
1010
= help: to override `-D warnings` add `#[allow(clippy::mixed_attributes_style)]`
1111

1212
error: item has both inner and outer attributes
13-
--> tests/ui/mixed_attributes_style.rs:22:1
13+
--> tests/ui/mixed_attributes_style.rs:24:1
1414
|
1515
LL | / /// linux
1616
LL | |
@@ -19,37 +19,45 @@ LL | | //! windows
1919
| |_______________^
2020

2121
error: item has both inner and outer attributes
22-
--> tests/ui/mixed_attributes_style.rs:37:1
22+
--> tests/ui/mixed_attributes_style.rs:39:1
2323
|
2424
LL | / #[allow(unused)]
2525
LL | | mod bar {
2626
LL | | #![allow(unused)]
2727
| |_____________________^
2828

2929
error: item has both inner and outer attributes
30-
--> tests/ui/mixed_attributes_style.rs:72:5
30+
--> tests/ui/mixed_attributes_style.rs:69:9
3131
|
32-
LL | / #[allow(dead_code)]
33-
LL | | mod inner_mod {
34-
LL | | #![allow(dead_code)]
35-
| |____________________________^
32+
LL | / #[allow(dead_code)]
33+
LL | | mod inner_mod {
34+
LL | | #![allow(dead_code)]
35+
| |________________________________^
3636

3737
error: item has both inner and outer attributes
38-
--> tests/ui/mixed_attributes_style.rs:77:1
38+
--> tests/ui/mixed_attributes_style.rs:80:9
3939
|
40-
LL | / /// Nested mod - Good
41-
LL | | #[allow(unused)]
42-
LL | | mod nest_mod_2 {
43-
LL | | #![allow(unused)]
44-
| |_____________________^
40+
LL | / #[allow(dead_code)]
41+
LL | | mod inner_mod {
42+
LL | | #![allow(dead_code)]
43+
| |________________________________^
44+
45+
error: item has both inner and outer attributes
46+
--> tests/ui/mixed_attributes_style.rs:85:5
47+
|
48+
LL | / /// Nested mod
49+
LL | | #[allow(unused)]
50+
LL | | mod nest_mod_2 {
51+
LL | | #![allow(unused)]
52+
| |_________________________^
4553

4654
error: item has both inner and outer attributes
47-
--> tests/ui/mixed_attributes_style.rs:82:5
55+
--> tests/ui/mixed_attributes_style.rs:90:9
4856
|
49-
LL | / #[allow(dead_code)]
50-
LL | | mod inner_mod {
51-
LL | | #![allow(dead_code)]
52-
| |____________________________^
57+
LL | / #[allow(dead_code)]
58+
LL | | mod inner_mod {
59+
LL | | #![allow(dead_code)]
60+
| |________________________________^
5361

54-
error: aborting due to 6 previous errors
62+
error: aborting due to 7 previous errors
5563

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
error: item has both inner and outer attributes
2+
--> tests/ui/mixed_attributes_style/mod_declaration.rs:1:1
3+
|
4+
LL | / #[path = "auxiliary/submodule.rs"] // don't lint.
5+
LL | | /// This doc comment should not lint, it could be used to add context to the original module doc
6+
LL | | mod submodule;
7+
| |____________________^
8+
|
9+
= note: `-D clippy::mixed-attributes-style` implied by `-D warnings`
10+
= help: to override `-D warnings` add `#[allow(clippy::mixed_attributes_style)]`
11+
112
error: item has both inner and outer attributes
213
--> tests/ui/mixed_attributes_style/auxiliary/submodule.rs:5:1
314
|
@@ -6,9 +17,6 @@ LL | |
617
LL | | mod foo {
718
LL | | #![allow(dead_code)]
819
| |________________________^
9-
|
10-
= note: `-D clippy::mixed-attributes-style` implied by `-D warnings`
11-
= help: to override `-D warnings` add `#[allow(clippy::mixed_attributes_style)]`
1220

13-
error: aborting due to 1 previous error
21+
error: aborting due to 2 previous errors
1422

0 commit comments

Comments
 (0)