diff options
| author | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-08-31 15:45:16 +0200 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-08-31 15:45:16 +0200 |
| commit | 74748b11bb313d2df6ffec0192fee344b3f7562d (patch) | |
| tree | 3515e23a352db3f7796ab9ec57182128ad9eb7e0 | |
| parent | f9a07bc11be83663f3e4120c21cbfb92518c004f (diff) | |
| download | rust-74748b11bb313d2df6ffec0192fee344b3f7562d.tar.gz rust-74748b11bb313d2df6ffec0192fee344b3f7562d.zip | |
WIP: don't suggest placing `use` statements into expanded code
| -rw-r--r-- | src/librustc_resolve/lib.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/resolve/privacy-struct-ctor.stderr | 6 | ||||
| -rw-r--r-- | src/test/ui/resolve/use_suggestion_placement.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/span/issue-35987.stderr | 2 |
4 files changed, 19 insertions, 7 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 2183c9124e7..88e092a1684 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -605,7 +605,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder { ItemKind::Use(..) => { // don't suggest placing a use before the prelude // import or other generated ones - if item.span == DUMMY_SP { + if item.span.ctxt().outer().expn_info().is_none() { self.span = Some(item.span.with_hi(item.span.lo())); self.found_use = true; return; @@ -615,7 +615,19 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder { ItemKind::ExternCrate(_) => {} // but place them before the first other item _ => if self.span.map_or(true, |span| item.span < span ) { - self.span = Some(item.span.with_hi(item.span.lo())); + if item.span.ctxt().outer().expn_info().is_none() { + // don't insert between attributes and an item + if item.attrs.is_empty() { + self.span = Some(item.span.with_hi(item.span.lo())); + } else { + // find the first attribute on the item + for attr in &item.attrs { + if self.span.map_or(true, |span| attr.span < span) { + self.span = Some(attr.span.with_hi(attr.span.lo())); + } + } + } + } }, } } diff --git a/src/test/ui/resolve/privacy-struct-ctor.stderr b/src/test/ui/resolve/privacy-struct-ctor.stderr index ee1481ec6f2..f7e5c602644 100644 --- a/src/test/ui/resolve/privacy-struct-ctor.stderr +++ b/src/test/ui/resolve/privacy-struct-ctor.stderr @@ -10,7 +10,7 @@ error[E0423]: expected value, found struct `Z` | help: possible better candidate is found in another module, you can import it into scope | -16 | use m::n::Z; +22 | use m::n::Z; | error[E0423]: expected value, found struct `S` @@ -24,7 +24,7 @@ error[E0423]: expected value, found struct `S` | help: possible better candidate is found in another module, you can import it into scope | -15 | use m::S; +32 | use m::S; | error[E0423]: expected value, found struct `xcrate::S` @@ -38,7 +38,7 @@ error[E0423]: expected value, found struct `xcrate::S` | help: possible better candidate is found in another module, you can import it into scope | -15 | use m::S; +32 | use m::S; | error[E0603]: tuple struct `Z` is private diff --git a/src/test/ui/resolve/use_suggestion_placement.stderr b/src/test/ui/resolve/use_suggestion_placement.stderr index d9c0528addb..8a4dfdc8027 100644 --- a/src/test/ui/resolve/use_suggestion_placement.stderr +++ b/src/test/ui/resolve/use_suggestion_placement.stderr @@ -6,7 +6,7 @@ error[E0412]: cannot find type `Path` in this scope | help: possible candidate is found in another module, you can import it into scope | -20 | #[derive(use std::path::Path; +21 | use std::path::Path; | error[E0425]: cannot find value `A` in this scope diff --git a/src/test/ui/span/issue-35987.stderr b/src/test/ui/span/issue-35987.stderr index 0cd7e1046f6..b57b58e3d2a 100644 --- a/src/test/ui/span/issue-35987.stderr +++ b/src/test/ui/span/issue-35987.stderr @@ -6,7 +6,7 @@ error[E0404]: expected trait, found type parameter `Add` | help: possible better candidate is found in another module, you can import it into scope | -11 | use std::ops::Add; +13 | use std::ops::Add; | error[E0601]: main function not found |
