diff options
| author | bors <bors@rust-lang.org> | 2022-09-21 12:32:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-21 12:32:54 +0000 |
| commit | b79b7d8b4e0f2b112142a9ce1fea335f321a6558 (patch) | |
| tree | dc6a19284e0fad10ac77c06130c1ec97155c3332 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | cba4a389b3961a2fd72e01bd6cb0b0e065edaf3d (diff) | |
| parent | 484b612909fed94c21846ec54832b676174c9b57 (diff) | |
| download | rust-b79b7d8b4e0f2b112142a9ce1fea335f321a6558.tar.gz rust-b79b7d8b4e0f2b112142a9ce1fea335f321a6558.zip | |
Auto merge of #101846 - chenyukang:fix-101793, r=davidtwco
Fix the wording of help msg for bitwise not Fixes #101793
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index ed37ede65d5..f4f75f71e72 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -6,8 +6,9 @@ use super::diagnostics::{ InvalidComparisonOperatorSub, InvalidLogicalOperator, InvalidLogicalOperatorSub, LeftArrowOperator, LifetimeInBorrowExpression, MacroInvocationWithQualifiedPath, MalformedLoopLabel, MissingInInForLoop, MissingInInForLoopSub, MissingSemicolonBeforeArray, - NotAsNegationOperator, OuterAttributeNotAllowedOnIfElse, RequireColonAfterLabeledExpression, - SnapshotParser, TildeAsUnaryOperator, UnexpectedTokenAfterLabel, + NotAsNegationOperator, NotAsNegationOperatorSub, OuterAttributeNotAllowedOnIfElse, + RequireColonAfterLabeledExpression, SnapshotParser, TildeAsUnaryOperator, + UnexpectedTokenAfterLabel, }; use super::pat::{CommaRecoveryMode, RecoverColon, RecoverComma, PARAM_EXPECTED}; use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign}; @@ -660,12 +661,23 @@ 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 sub_diag = if negated_token.is_numeric_lit() { + NotAsNegationOperatorSub::SuggestNotBitwise + } else if negated_token.is_bool_lit() { + NotAsNegationOperatorSub::SuggestNotLogical + } else { + NotAsNegationOperatorSub::SuggestNotDefault + }; + self.sess.emit_err(NotAsNegationOperator { negated: negated_token.span, negated_desc: super::token_descr(&negated_token), // 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)), + sub: sub_diag( + self.sess.source_map().span_until_non_whitespace(lo.to(negated_token.span)), + ), }); // ...and recover! |
