From 1400cb0295210bc500aa27f6cca3ccb546b38814 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 17 May 2021 20:39:28 -0700 Subject: Fix use placement for suggestions near main. --- compiler/rustc_resolve/src/lib.rs | 16 ++++++++-------- compiler/rustc_typeck/src/check/method/suggest.rs | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 300d2c01cb5..c36aa91a5e8 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -330,15 +330,15 @@ impl UsePlacementFinder { if self.span.map_or(true, |span| item.span < span) && !item.span.from_expansion() { + self.span = Some(item.span.shrink_to_lo()); // don't insert between attributes and an item - if item.attrs.is_empty() { - self.span = Some(item.span.shrink_to_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.shrink_to_lo()); - } + // find the first attribute on the item + // FIXME: This is broken for active attributes. + for attr in &item.attrs { + if !attr.span.is_dummy() + && self.span.map_or(true, |span| attr.span < span) + { + self.span = Some(attr.span.shrink_to_lo()); } } } diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 2320a29e6d8..2aab29d3f7c 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -1557,16 +1557,16 @@ impl intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> { _ => { if self.span.map_or(true, |span| item.span < span) { if !item.span.from_expansion() { + self.span = Some(item.span.shrink_to_lo()); // Don't insert between attributes and an item. let attrs = self.tcx.hir().attrs(item.hir_id()); - if attrs.is_empty() { - self.span = Some(item.span.shrink_to_lo()); - } else { - // Find the first attribute on the item. - for attr in attrs { - if self.span.map_or(true, |span| attr.span < span) { - self.span = Some(attr.span.shrink_to_lo()); - } + // Find the first attribute on the item. + // FIXME: This is broken for active attributes. + for attr in attrs { + if !attr.span.is_dummy() + && self.span.map_or(true, |span| attr.span < span) + { + self.span = Some(attr.span.shrink_to_lo()); } } } -- cgit 1.4.1-3-g733a5