about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2022-12-27 09:25:00 -0800
committerEsteban Küber <esteban@kuber.com.ar>2022-12-27 09:25:00 -0800
commit0c0685bb68a53636e1347ea93dccfa7ac1e24deb (patch)
tree6f46e9393e558745f5c220f1f3d350a2b4457f2b /compiler/rustc_resolve/src
parentc9381fc334cb8db62fdb5a8f75807ebdff3d6e15 (diff)
downloadrust-0c0685bb68a53636e1347ea93dccfa7ac1e24deb.tar.gz
rust-0c0685bb68a53636e1347ea93dccfa7ac1e24deb.zip
review comments: make suggestion more accurate
Diffstat (limited to 'compiler/rustc_resolve/src')
-rw-r--r--compiler/rustc_resolve/src/late.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs
index 13b001af7ea..7720d87c04b 100644
--- a/compiler/rustc_resolve/src/late.rs
+++ b/compiler/rustc_resolve/src/late.rs
@@ -3344,10 +3344,18 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
                 let suggestion = if let Some((start, end)) = this.diagnostic_metadata.in_range
                     && path[0].ident.span.lo() == end.span.lo()
                 {
+                    let mut sugg = ".";
+                    let mut span = start.span.between(end.span);
+                    if span.lo() + BytePos(2) == span.hi() {
+                        // There's no space between the start, the range op and the end, suggest
+                        // removal which will look better.
+                        span = span.with_lo(span.lo() + BytePos(1));
+                        sugg = "";
+                    }
                     Some((
-                        start.span.between(end.span),
+                        span,
                         "you might have meant to write a method call instead of a range",
-                        ".".to_string(),
+                        sugg.to_string(),
                         Applicability::MaybeIncorrect,
                     ))
                 } else if res.is_none() {