Skip to content

Commit b33ac52

Browse files
authoredSep 8, 2023
Rollup merge of #115630 - compiler-errors:dont-suggest-use-btw-use-and-attr, r=wesleywiser
Dont suggest use between `use` and cfg attr Fixes #115618
2 parents aa78b4c + 03bee1f commit b33ac52

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed
 

‎compiler/rustc_resolve/src/diagnostics.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2753,7 +2753,13 @@ fn search_for_any_use_in_items(items: &[P<ast::Item>]) -> Option<Span> {
27532753
for item in items {
27542754
if let ItemKind::Use(..) = item.kind {
27552755
if is_span_suitable_for_use_injection(item.span) {
2756-
return Some(item.span.shrink_to_lo());
2756+
let mut lo = item.span.lo();
2757+
for attr in &item.attrs {
2758+
if attr.span.eq_ctxt(item.span) {
2759+
lo = std::cmp::min(lo, attr.span.lo());
2760+
}
2761+
}
2762+
return Some(Span::new(lo, lo, item.span.ctxt(), item.span.parent()));
27572763
}
27582764
}
27592765
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// run-rustfix
2+
// compile-flags: --cfg=whatever -Aunused
3+
4+
use y::z;
5+
#[cfg(whatever)]
6+
use y::Whatever;
7+
8+
mod y {
9+
pub(crate) fn z() {}
10+
pub(crate) struct Whatever;
11+
}
12+
13+
fn main() {
14+
z();
15+
//~^ ERROR cannot find function `z` in this scope
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-rustfix
2+
// compile-flags: --cfg=whatever -Aunused
3+
4+
#[cfg(whatever)]
5+
use y::Whatever;
6+
7+
mod y {
8+
pub(crate) fn z() {}
9+
pub(crate) struct Whatever;
10+
}
11+
12+
fn main() {
13+
z();
14+
//~^ ERROR cannot find function `z` in this scope
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0425]: cannot find function `z` in this scope
2+
--> $DIR/suggest-import-without-clobbering-attrs.rs:13:5
3+
|
4+
LL | z();
5+
| ^ not found in this scope
6+
|
7+
help: consider importing this function
8+
|
9+
LL + use y::z;
10+
|
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)
Please sign in to comment.