diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-09-21 18:05:26 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-10-24 00:32:03 +0200 |
| commit | c17a1fd7d0ef0f1f546445d0c8bdb11be55e4be7 (patch) | |
| tree | cfb224137c513499e9dfc7dd49e3005b4ad6e47d /src/libsyntax | |
| parent | 2d182b82ce5ecfe8090ba3d4e78f1cd72c072ef1 (diff) | |
| download | rust-c17a1fd7d0ef0f1f546445d0c8bdb11be55e4be7.tar.gz rust-c17a1fd7d0ef0f1f546445d0c8bdb11be55e4be7.zip | |
pre-expansion gate associated_type_bounds
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/feature_gate/check.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser/path.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/sess.rs | 2 |
3 files changed, 14 insertions, 16 deletions
diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 97172691a11..43a3f45bb06 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -3,10 +3,7 @@ use super::accepted::ACCEPTED_FEATURES; use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; -use crate::ast::{ - self, AssocTyConstraint, AssocTyConstraintKind, NodeId, GenericParam, GenericParamKind, - PatKind, RangeEnd, VariantData, -}; +use crate::ast::{self, NodeId, GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData}; use crate::attr::{self, check_builtin_attribute}; use crate::source_map::Spanned; use crate::edition::{ALL_EDITIONS, Edition}; @@ -584,16 +581,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { visit::walk_generic_param(self, param) } - fn visit_assoc_ty_constraint(&mut self, constraint: &'a AssocTyConstraint) { - match constraint.kind { - AssocTyConstraintKind::Bound { .. } => - gate_feature_post!(&self, associated_type_bounds, constraint.span, - "associated type bounds are unstable"), - _ => {} - } - visit::walk_assoc_ty_constraint(self, constraint) - } - fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) { match ti.kind { ast::TraitItemKind::Method(ref sig, ref block) => { @@ -859,6 +846,7 @@ pub fn check_crate(krate: &ast::Crate, gate_all!(or_patterns, "or-patterns syntax is experimental"); gate_all!(const_extern_fn, "`const extern fn` definitions are unstable"); gate_all!(trait_alias, "trait aliases are experimental"); + gate_all!(associated_type_bounds, "associated type bounds are unstable"); visit::walk_crate(&mut visitor, krate); } diff --git a/src/libsyntax/parse/parser/path.rs b/src/libsyntax/parse/parser/path.rs index 639d61a2b5c..77709a22953 100644 --- a/src/libsyntax/parse/parser/path.rs +++ b/src/libsyntax/parse/parser/path.rs @@ -404,8 +404,9 @@ impl<'a> Parser<'a> { // Parse lifetime argument. args.push(GenericArg::Lifetime(self.expect_lifetime())); misplaced_assoc_ty_constraints.append(&mut assoc_ty_constraints); - } else if self.check_ident() && self.look_ahead(1, - |t| t == &token::Eq || t == &token::Colon) { + } else if self.check_ident() + && self.look_ahead(1, |t| t == &token::Eq || t == &token::Colon) + { // Parse associated type constraint. let lo = self.token.span; let ident = self.parse_ident()?; @@ -420,7 +421,14 @@ impl<'a> Parser<'a> { } else { unreachable!(); }; + let span = lo.to(self.prev_span); + + // Gate associated type bounds, e.g., `Iterator<Item: Ord>`. + if let AssocTyConstraintKind::Bound { .. } = kind { + self.sess.gated_spans.associated_type_bounds.borrow_mut().push(span); + } + constraints.push(AssocTyConstraint { id: ast::DUMMY_NODE_ID, ident, diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs index b48b2b494c8..13f89c3720b 100644 --- a/src/libsyntax/sess.rs +++ b/src/libsyntax/sess.rs @@ -32,6 +32,8 @@ crate struct GatedSpans { crate const_extern_fn: Lock<Vec<Span>>, /// Spans collected for gating `trait_alias`, e.g. `trait Foo = Ord + Eq;`. pub trait_alias: Lock<Vec<Span>>, + /// Spans collected for gating `associated_type_bounds`, e.g. `Iterator<Item: Ord>`. + pub associated_type_bounds: Lock<Vec<Span>>, } /// Info about a parsing session. |
