about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2022-09-15 22:39:16 +0800
committeryukang <moorekang@gmail.com>2022-09-15 22:39:16 +0800
commitf43562b95bb80d91cd3f880e1d63b129a65a9b44 (patch)
tree57b907b3a83ededa97a3601ec4d144b985ba2152 /compiler/rustc_parse/src
parent2194fc957a2a7daaf35703603553649dfc23e34d (diff)
downloadrust-f43562b95bb80d91cd3f880e1d63b129a65a9b44.tar.gz
rust-f43562b95bb80d91cd3f880e1d63b129a65a9b44.zip
more tweak on diagnostic messages
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs1
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs9
2 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index be524db785b..d2a8daa150c 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -430,6 +430,7 @@ pub(crate) struct NotAsNegationOperator {
     #[primary_span]
     pub negated: Span,
     pub negated_desc: String,
+    pub negated_msg: String,
     #[suggestion_short(applicability = "machine-applicable", code = "!")]
     pub not: Span,
 }
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index ed37ede65d5..1fdd312572a 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -660,9 +660,18 @@ impl<'a> Parser<'a> {
     fn recover_not_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> {
         // Emit the error...
         let negated_token = self.look_ahead(1, |t| t.clone());
+        let negtated_msg = if negated_token.is_numeric_lit() {
+            "bitwise not"
+        } else if negated_token.is_bool_lit() {
+            "logical negation"
+        } else {
+            "logical negation or bitwise not"
+        };
+
         self.sess.emit_err(NotAsNegationOperator {
             negated: negated_token.span,
             negated_desc: super::token_descr(&negated_token),
+            negated_msg: negtated_msg.to_string(),
             // Span the `not` plus trailing whitespace to avoid
             // trailing whitespace after the `!` in our suggestion
             not: self.sess.source_map().span_until_non_whitespace(lo.to(negated_token.span)),