Skip to content

Commit 7c4e855

Browse files
oli-obkmichaelwoerister
authored andcommitted
WIP: don't suggest placing use statements into expanded code
1 parent c39a3ad commit 7c4e855

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

src/librustc_resolve/lib.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
605605
ItemKind::Use(..) => {
606606
// don't suggest placing a use before the prelude
607607
// import or other generated ones
608-
if item.span == DUMMY_SP {
608+
if item.span.ctxt.outer().expn_info().is_none() {
609609
let mut span = item.span;
610610
span.hi = span.lo;
611611
self.span = Some(span);
@@ -617,9 +617,23 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
617617
ItemKind::ExternCrate(_) => {}
618618
// but place them before the first other item
619619
_ => if self.span.map_or(true, |span| item.span < span ) {
620-
let mut span = item.span;
621-
span.hi = span.lo;
622-
self.span = Some(span);
620+
if item.span.ctxt.outer().expn_info().is_none() {
621+
// don't insert between attributes and an item
622+
if item.attrs.is_empty() {
623+
let mut span = item.span;
624+
span.hi = span.lo;
625+
self.span = Some(span);
626+
} else {
627+
// find the first attribute on the item
628+
for attr in &item.attrs {
629+
if self.span.map_or(true, |span| attr.span < span) {
630+
let mut span = attr.span;
631+
span.hi = span.lo;
632+
self.span = Some(span);
633+
}
634+
}
635+
}
636+
}
623637
},
624638
}
625639
}

src/test/ui/resolve/privacy-struct-ctor.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0423]: expected value, found struct `Z`
1010
|
1111
help: possible better candidate is found in another module, you can import it into scope
1212
|
13-
16 | use m::n::Z;
13+
22 | use m::n::Z;
1414
|
1515

1616
error[E0423]: expected value, found struct `S`
@@ -24,7 +24,7 @@ error[E0423]: expected value, found struct `S`
2424
|
2525
help: possible better candidate is found in another module, you can import it into scope
2626
|
27-
15 | use m::S;
27+
32 | use m::S;
2828
|
2929

3030
error[E0423]: expected value, found struct `xcrate::S`
@@ -38,7 +38,7 @@ error[E0423]: expected value, found struct `xcrate::S`
3838
|
3939
help: possible better candidate is found in another module, you can import it into scope
4040
|
41-
15 | use m::S;
41+
32 | use m::S;
4242
|
4343

4444
error[E0603]: tuple struct `Z` is private

src/test/ui/resolve/use_suggestion_placement.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ error[E0412]: cannot find type `Path` in this scope
66
|
77
help: possible candidate is found in another module, you can import it into scope
88
|
9-
20 | #[derive(use std::path::Path;
9+
21 | use std::path::Path;
1010
|
1111

1212
error[E0425]: cannot find value `A` in this scope

src/test/ui/span/issue-35987.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ error[E0404]: expected trait, found type parameter `Add`
66
|
77
help: possible better candidate is found in another module, you can import it into scope
88
|
9-
11 | use std::ops::Add;
9+
13 | use std::ops::Add;
1010
|
1111

1212
error[E0601]: main function not found

0 commit comments

Comments
 (0)