Skip to content

Commit

Permalink
Unrolled build for rust-lang#115630
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#115630 - compiler-errors:dont-suggest-use-btw-use-and-attr, r=wesleywiser

Dont suggest use between `use` and cfg attr

Fixes rust-lang#115618
  • Loading branch information
rust-timer authored Sep 9, 2023
2 parents 62ebe3a + 03bee1f commit e3fd415
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2753,7 +2753,13 @@ fn search_for_any_use_in_items(items: &[P<ast::Item>]) -> Option<Span> {
for item in items {
if let ItemKind::Use(..) = item.kind {
if is_span_suitable_for_use_injection(item.span) {
return Some(item.span.shrink_to_lo());
let mut lo = item.span.lo();
for attr in &item.attrs {
if attr.span.eq_ctxt(item.span) {
lo = std::cmp::min(lo, attr.span.lo());
}
}
return Some(Span::new(lo, lo, item.span.ctxt(), item.span.parent()));
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/resolve/suggest-import-without-clobbering-attrs.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// run-rustfix
// compile-flags: --cfg=whatever -Aunused

use y::z;
#[cfg(whatever)]
use y::Whatever;

mod y {
pub(crate) fn z() {}
pub(crate) struct Whatever;
}

fn main() {
z();
//~^ ERROR cannot find function `z` in this scope
}
15 changes: 15 additions & 0 deletions tests/ui/resolve/suggest-import-without-clobbering-attrs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// run-rustfix
// compile-flags: --cfg=whatever -Aunused

#[cfg(whatever)]
use y::Whatever;

mod y {
pub(crate) fn z() {}
pub(crate) struct Whatever;
}

fn main() {
z();
//~^ ERROR cannot find function `z` in this scope
}
14 changes: 14 additions & 0 deletions tests/ui/resolve/suggest-import-without-clobbering-attrs.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0425]: cannot find function `z` in this scope
--> $DIR/suggest-import-without-clobbering-attrs.rs:13:5
|
LL | z();
| ^ not found in this scope
|
help: consider importing this function
|
LL + use y::z;
|

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.

0 comments on commit e3fd415

Please sign in to comment.