Skip to content

Commit 15a6c09

Browse files
committed
pre-expansion gate type_ascription
1 parent e4ed886 commit 15a6c09

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

src/libsyntax/feature_gate/check.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -498,21 +498,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
498498
}
499499
}
500500

501-
fn visit_expr(&mut self, e: &'a ast::Expr) {
502-
match e.kind {
503-
ast::ExprKind::Type(..) => {
504-
// To avoid noise about type ascription in common syntax errors, only emit if it
505-
// is the *only* error.
506-
if self.parse_sess.span_diagnostic.err_count() == 0 {
507-
gate_feature_post!(&self, type_ascription, e.span,
508-
"type ascription is experimental");
509-
}
510-
}
511-
_ => {}
512-
}
513-
visit::walk_expr(self, e)
514-
}
515-
516501
fn visit_pat(&mut self, pattern: &'a ast::Pat) {
517502
match &pattern.kind {
518503
PatKind::Slice(pats) => {
@@ -805,6 +790,12 @@ pub fn check_crate(krate: &ast::Crate,
805790
gate_all!(label_break_value, "labels on blocks are unstable");
806791
gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead");
807792

793+
// To avoid noise about type ascription in common syntax errors,
794+
// only emit if it is the *only* error. (Also check it last.)
795+
if parse_sess.span_diagnostic.err_count() == 0 {
796+
gate_all!(type_ascription, "type ascription is experimental");
797+
}
798+
808799
visit::walk_crate(&mut visitor, krate);
809800
}
810801

src/libsyntax/parse/parser/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ impl<'a> Parser<'a> {
252252
self.last_type_ascription = Some((self.prev_span, maybe_path));
253253

254254
lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Type)?;
255+
self.sess.gated_spans.type_ascription.borrow_mut().push(lhs.span);
255256
continue
256257
} else if op == AssocOp::DotDot || op == AssocOp::DotDotEq {
257258
// If we didn’t have to handle `x..`/`x..=`, it would be pretty easy to

src/libsyntax/sess.rs

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ crate struct GatedSpans {
5050
pub label_break_value: Lock<Vec<Span>>,
5151
/// Spans collected for gating `box_syntax`, e.g. `box $expr`.
5252
pub box_syntax: Lock<Vec<Span>>,
53+
/// Spans collected for gating `type_ascription`, e.g. `42: usize`.
54+
pub type_ascription: Lock<Vec<Span>>,
5355
}
5456

5557
/// Info about a parsing session.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Type ascription is unstable
22

3-
fn main() {
3+
#[cfg(FALSE)]
4+
fn foo() {
45
let a = 10: u8; //~ ERROR type ascription is experimental
56
}
7+
8+
fn main() {}

src/test/ui/feature-gates/feature-gate-type_ascription.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: type ascription is experimental
2-
--> $DIR/feature-gate-type_ascription.rs:4:13
2+
--> $DIR/feature-gate-type_ascription.rs:5:13
33
|
44
LL | let a = 10: u8;
55
| ^^^^^^

0 commit comments

Comments
 (0)