pre-expansion gate type_ascription
This commit is contained in:
parent
e4ed886578
commit
15a6c09b6e
5 changed files with 14 additions and 17 deletions
|
@ -498,21 +498,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, e: &'a ast::Expr) {
|
||||
match e.kind {
|
||||
ast::ExprKind::Type(..) => {
|
||||
// To avoid noise about type ascription in common syntax errors, only emit if it
|
||||
// is the *only* error.
|
||||
if self.parse_sess.span_diagnostic.err_count() == 0 {
|
||||
gate_feature_post!(&self, type_ascription, e.span,
|
||||
"type ascription is experimental");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
visit::walk_expr(self, e)
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, pattern: &'a ast::Pat) {
|
||||
match &pattern.kind {
|
||||
PatKind::Slice(pats) => {
|
||||
|
@ -805,6 +790,12 @@ pub fn check_crate(krate: &ast::Crate,
|
|||
gate_all!(label_break_value, "labels on blocks are unstable");
|
||||
gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead");
|
||||
|
||||
// To avoid noise about type ascription in common syntax errors,
|
||||
// only emit if it is the *only* error. (Also check it last.)
|
||||
if parse_sess.span_diagnostic.err_count() == 0 {
|
||||
gate_all!(type_ascription, "type ascription is experimental");
|
||||
}
|
||||
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
}
|
||||
|
||||
|
|
|
@ -252,6 +252,7 @@ impl<'a> Parser<'a> {
|
|||
self.last_type_ascription = Some((self.prev_span, maybe_path));
|
||||
|
||||
lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Type)?;
|
||||
self.sess.gated_spans.type_ascription.borrow_mut().push(lhs.span);
|
||||
continue
|
||||
} else if op == AssocOp::DotDot || op == AssocOp::DotDotEq {
|
||||
// If we didn’t have to handle `x..`/`x..=`, it would be pretty easy to
|
||||
|
|
|
@ -50,6 +50,8 @@ crate struct GatedSpans {
|
|||
pub label_break_value: Lock<Vec<Span>>,
|
||||
/// Spans collected for gating `box_syntax`, e.g. `box $expr`.
|
||||
pub box_syntax: Lock<Vec<Span>>,
|
||||
/// Spans collected for gating `type_ascription`, e.g. `42: usize`.
|
||||
pub type_ascription: Lock<Vec<Span>>,
|
||||
}
|
||||
|
||||
/// Info about a parsing session.
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
// Type ascription is unstable
|
||||
|
||||
fn main() {
|
||||
#[cfg(FALSE)]
|
||||
fn foo() {
|
||||
let a = 10: u8; //~ ERROR type ascription is experimental
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0658]: type ascription is experimental
|
||||
--> $DIR/feature-gate-type_ascription.rs:4:13
|
||||
--> $DIR/feature-gate-type_ascription.rs:5:13
|
||||
|
|
||||
LL | let a = 10: u8;
|
||||
| ^^^^^^
|
||||
|
|
Loading…
Reference in a new issue