summary refs log tree commit diff
path: root/compiler/rustc_session/src/parse.rs
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2021-06-28 11:22:47 -0700
committerEsteban Küber <esteban@kuber.com.ar>2021-07-30 09:26:31 -0700
commit0b8f192cfee2f107867e7b9a0b0f781a5cb48787 (patch)
tree7740090507212c2bf5f630672125bab43d68d093 /compiler/rustc_session/src/parse.rs
parent5fb3394cbdf0622c9d0c292feb55db0f4c828dc3 (diff)
downloadrust-0b8f192cfee2f107867e7b9a0b0f781a5cb48787.tar.gz
rust-0b8f192cfee2f107867e7b9a0b0f781a5cb48787.zip
Use multispan suggestions more often
* Use more accurate span for `async move` suggestion
* Use more accurate span for deref suggestion
* Use `multipart_suggestion` more often
Diffstat (limited to 'compiler/rustc_session/src/parse.rs')
-rw-r--r--compiler/rustc_session/src/parse.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs
index 226fde2343a..a007b530302 100644
--- a/compiler/rustc_session/src/parse.rs
+++ b/compiler/rustc_session/src/parse.rs
@@ -228,20 +228,12 @@ impl ParseSess {
 
     /// Extend an error with a suggestion to wrap an expression with parentheses to allow the
     /// parser to continue parsing the following operation as part of the same expression.
-    pub fn expr_parentheses_needed(
-        &self,
-        err: &mut DiagnosticBuilder<'_>,
-        span: Span,
-        alt_snippet: Option<String>,
-    ) {
-        if let Some(snippet) = self.source_map().span_to_snippet(span).ok().or(alt_snippet) {
-            err.span_suggestion(
-                span,
-                "parentheses are required to parse this as an expression",
-                format!("({})", snippet),
-                Applicability::MachineApplicable,
-            );
-        }
+    pub fn expr_parentheses_needed(&self, err: &mut DiagnosticBuilder<'_>, span: Span) {
+        err.multipart_suggestion(
+            "parentheses are required to parse this as an expression",
+            vec![(span.shrink_to_lo(), "(".to_string()), (span.shrink_to_hi(), ")".to_string())],
+            Applicability::MachineApplicable,
+        );
     }
 
     pub fn save_proc_macro_span(&self, span: Span) -> usize {