about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-10-13 13:34:40 +0200
committerGitHub <noreply@github.com>2019-10-13 13:34:40 +0200
commitb143aa2b387920e4076e17d9c42c7bd4e2aebc36 (patch)
tree1e32356a2e1de103b9563d14789729d4f2513d50 /src/libsyntax
parent293d02de7070f1c0fa3422fa42ae40a5d8922dbb (diff)
parent9f09387f53792740edcb5dd0eea49ab02d3fe891 (diff)
downloadrust-b143aa2b387920e4076e17d9c42c7bd4e2aebc36.tar.gz
rust-b143aa2b387920e4076e17d9c42c7bd4e2aebc36.zip
Rollup merge of #65357 - Centril:simplify-maybe-annotate-with-ascription, r=davidtwco
syntax: simplify maybe_annotate_with_ascription

Split out from https://github.com/rust-lang/rust/pull/65324.

r? @estebank
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/parse/diagnostics.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs
index f376c19a66c..42cbe28fc17 100644
--- a/src/libsyntax/parse/diagnostics.rs
+++ b/src/libsyntax/parse/diagnostics.rs
@@ -2,7 +2,7 @@ use crate::ast::{
     self, Param, BinOpKind, BindingMode, BlockCheckMode, Expr, ExprKind, Ident, Item, ItemKind,
     Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind, VariantData,
 };
-use crate::feature_gate::{feature_err, UnstableFeatures};
+use crate::feature_gate::feature_err;
 use crate::parse::{SeqSep, PResult, Parser, ParseSess};
 use crate::parse::parser::{BlockMode, PathStyle, SemiColonMode, TokenType, TokenExpectType};
 use crate::parse::token::{self, TokenKind};
@@ -387,14 +387,17 @@ impl<'a> Parser<'a> {
             let next_pos = sm.lookup_char_pos(self.token.span.lo());
             let op_pos = sm.lookup_char_pos(sp.hi());
 
+            let allow_unstable = self.sess.unstable_features.is_nightly_build();
+
             if likely_path {
                 err.span_suggestion(
                     sp,
                     "maybe write a path separator here",
                     "::".to_string(),
-                    match self.sess.unstable_features {
-                        UnstableFeatures::Disallow => Applicability::MachineApplicable,
-                        _ => Applicability::MaybeIncorrect,
+                    if allow_unstable {
+                        Applicability::MaybeIncorrect
+                    } else {
+                        Applicability::MachineApplicable
                     },
                 );
             } else if op_pos.line != next_pos.line && maybe_expected_semicolon {
@@ -404,14 +407,13 @@ impl<'a> Parser<'a> {
                     ";".to_string(),
                     Applicability::MaybeIncorrect,
                 );
-            } else if let UnstableFeatures::Disallow = self.sess.unstable_features {
-                err.span_label(sp, "tried to parse a type due to this");
-            } else {
+            } else if allow_unstable {
                 err.span_label(sp, "tried to parse a type due to this type ascription");
+            } else {
+                err.span_label(sp, "tried to parse a type due to this");
             }
-            if let UnstableFeatures::Disallow = self.sess.unstable_features {
+            if allow_unstable {
                 // Give extra information about type ascription only if it's a nightly compiler.
-            } else {
                 err.note("`#![feature(type_ascription)]` lets you annotate an expression with a \
                           type: `<expr>: <type>`");
                 err.note("for more information, see \