about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-07-30 17:30:50 +0000
committerbors <bors@rust-lang.org>2022-07-30 17:30:50 +0000
commit038f9e6bef9c8fcf122d93a8a33ac546f5606eb3 (patch)
tree0d2728e319fe7994124679b81b529533d0cc39fe /compiler/rustc_parse/src/parser
parent1202bbaf48a0a919a2e0cfd8b7dce97e8fc3030d (diff)
parentdf2cf97830dde8f563b898820ffbba200253326b (diff)
downloadrust-038f9e6bef9c8fcf122d93a8a33ac546f5606eb3.tar.gz
rust-038f9e6bef9c8fcf122d93a8a33ac546f5606eb3.zip
Auto merge of #99948 - Dylan-DPC:rollup-ed5136t, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #99311 (change maybe_body_owned_by to take local def id)
 - #99862 (Improve type mismatch w/ function signatures)
 - #99895 (don't call type ascription "cast")
 - #99900 (remove some manual hash stable impls)
 - #99903 (Add diagnostic when using public instead of pub)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs11
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs13
2 files changed, 18 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index 63055c56c5c..09329f18c67 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -601,6 +601,17 @@ impl<'a> Parser<'a> {
         self.last_unexpected_token_span = Some(self.token.span);
         let mut err = self.struct_span_err(self.token.span, &msg_exp);
 
+        if let TokenKind::Ident(symbol, _) = &self.prev_token.kind {
+            if symbol.as_str() == "public" {
+                err.span_suggestion_short(
+                    self.prev_token.span,
+                    "write `pub` instead of `public` to make the item public",
+                    "pub",
+                    appl,
+                );
+            }
+        }
+
         // Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens
         // there are unclosed angle brackets
         if self.unmatched_angle_bracket_count > 0
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 43b48613976..c0f661f7dbb 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -827,11 +827,12 @@ impl<'a> Parser<'a> {
         cast_expr: P<Expr>,
     ) -> PResult<'a, P<Expr>> {
         let span = cast_expr.span;
-        let maybe_ascription_span = if let ExprKind::Type(ascripted_expr, _) = &cast_expr.kind {
-            Some(ascripted_expr.span.shrink_to_hi().with_hi(span.hi()))
-        } else {
-            None
-        };
+        let (cast_kind, maybe_ascription_span) =
+            if let ExprKind::Type(ascripted_expr, _) = &cast_expr.kind {
+                ("type ascription", Some(ascripted_expr.span.shrink_to_hi().with_hi(span.hi())))
+            } else {
+                ("cast", None)
+            };
 
         // Save the memory location of expr before parsing any following postfix operators.
         // This will be compared with the memory location of the output expression.
@@ -844,7 +845,7 @@ impl<'a> Parser<'a> {
         // If the resulting expression is not a cast, or has a different memory location, it is an illegal postfix operator.
         if !matches!(with_postfix.kind, ExprKind::Cast(_, _) | ExprKind::Type(_, _)) || changed {
             let msg = format!(
-                "casts cannot be followed by {}",
+                "{cast_kind} cannot be followed by {}",
                 match with_postfix.kind {
                     ExprKind::Index(_, _) => "indexing",
                     ExprKind::Try(_) => "`?`",