Skip to content

Commit b143aa2

Browse files
authored
Rollup merge of rust-lang#65357 - Centril:simplify-maybe-annotate-with-ascription, r=davidtwco
syntax: simplify maybe_annotate_with_ascription Split out from rust-lang#65324. r? @estebank
2 parents 293d02d + 9f09387 commit b143aa2

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/libsyntax/parse/diagnostics.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::ast::{
22
self, Param, BinOpKind, BindingMode, BlockCheckMode, Expr, ExprKind, Ident, Item, ItemKind,
33
Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind, VariantData,
44
};
5-
use crate::feature_gate::{feature_err, UnstableFeatures};
5+
use crate::feature_gate::feature_err;
66
use crate::parse::{SeqSep, PResult, Parser, ParseSess};
77
use crate::parse::parser::{BlockMode, PathStyle, SemiColonMode, TokenType, TokenExpectType};
88
use crate::parse::token::{self, TokenKind};
@@ -387,14 +387,17 @@ impl<'a> Parser<'a> {
387387
let next_pos = sm.lookup_char_pos(self.token.span.lo());
388388
let op_pos = sm.lookup_char_pos(sp.hi());
389389

390+
let allow_unstable = self.sess.unstable_features.is_nightly_build();
391+
390392
if likely_path {
391393
err.span_suggestion(
392394
sp,
393395
"maybe write a path separator here",
394396
"::".to_string(),
395-
match self.sess.unstable_features {
396-
UnstableFeatures::Disallow => Applicability::MachineApplicable,
397-
_ => Applicability::MaybeIncorrect,
397+
if allow_unstable {
398+
Applicability::MaybeIncorrect
399+
} else {
400+
Applicability::MachineApplicable
398401
},
399402
);
400403
} else if op_pos.line != next_pos.line && maybe_expected_semicolon {
@@ -404,14 +407,13 @@ impl<'a> Parser<'a> {
404407
";".to_string(),
405408
Applicability::MaybeIncorrect,
406409
);
407-
} else if let UnstableFeatures::Disallow = self.sess.unstable_features {
408-
err.span_label(sp, "tried to parse a type due to this");
409-
} else {
410+
} else if allow_unstable {
410411
err.span_label(sp, "tried to parse a type due to this type ascription");
412+
} else {
413+
err.span_label(sp, "tried to parse a type due to this");
411414
}
412-
if let UnstableFeatures::Disallow = self.sess.unstable_features {
415+
if allow_unstable {
413416
// Give extra information about type ascription only if it's a nightly compiler.
414-
} else {
415417
err.note("`#![feature(type_ascription)]` lets you annotate an expression with a \
416418
type: `<expr>: <type>`");
417419
err.note("for more information, see \

0 commit comments

Comments
 (0)