pre-expansion gate associated_type_bounds
This commit is contained in:
parent
2d182b82ce
commit
c17a1fd7d0
5 changed files with 28 additions and 17 deletions
|
@ -3,10 +3,7 @@ use super::accepted::ACCEPTED_FEATURES;
|
||||||
use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
|
use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
|
||||||
use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
|
use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
|
||||||
|
|
||||||
use crate::ast::{
|
use crate::ast::{self, NodeId, GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData};
|
||||||
self, AssocTyConstraint, AssocTyConstraintKind, NodeId, GenericParam, GenericParamKind,
|
|
||||||
PatKind, RangeEnd, VariantData,
|
|
||||||
};
|
|
||||||
use crate::attr::{self, check_builtin_attribute};
|
use crate::attr::{self, check_builtin_attribute};
|
||||||
use crate::source_map::Spanned;
|
use crate::source_map::Spanned;
|
||||||
use crate::edition::{ALL_EDITIONS, Edition};
|
use crate::edition::{ALL_EDITIONS, Edition};
|
||||||
|
@ -584,16 +581,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||||
visit::walk_generic_param(self, param)
|
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) {
|
fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) {
|
||||||
match ti.kind {
|
match ti.kind {
|
||||||
ast::TraitItemKind::Method(ref sig, ref block) => {
|
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!(or_patterns, "or-patterns syntax is experimental");
|
||||||
gate_all!(const_extern_fn, "`const extern fn` definitions are unstable");
|
gate_all!(const_extern_fn, "`const extern fn` definitions are unstable");
|
||||||
gate_all!(trait_alias, "trait aliases are experimental");
|
gate_all!(trait_alias, "trait aliases are experimental");
|
||||||
|
gate_all!(associated_type_bounds, "associated type bounds are unstable");
|
||||||
|
|
||||||
visit::walk_crate(&mut visitor, krate);
|
visit::walk_crate(&mut visitor, krate);
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,8 +404,9 @@ impl<'a> Parser<'a> {
|
||||||
// Parse lifetime argument.
|
// Parse lifetime argument.
|
||||||
args.push(GenericArg::Lifetime(self.expect_lifetime()));
|
args.push(GenericArg::Lifetime(self.expect_lifetime()));
|
||||||
misplaced_assoc_ty_constraints.append(&mut assoc_ty_constraints);
|
misplaced_assoc_ty_constraints.append(&mut assoc_ty_constraints);
|
||||||
} else if self.check_ident() && self.look_ahead(1,
|
} else if self.check_ident()
|
||||||
|t| t == &token::Eq || t == &token::Colon) {
|
&& self.look_ahead(1, |t| t == &token::Eq || t == &token::Colon)
|
||||||
|
{
|
||||||
// Parse associated type constraint.
|
// Parse associated type constraint.
|
||||||
let lo = self.token.span;
|
let lo = self.token.span;
|
||||||
let ident = self.parse_ident()?;
|
let ident = self.parse_ident()?;
|
||||||
|
@ -420,7 +421,14 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
|
||||||
let span = lo.to(self.prev_span);
|
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 {
|
constraints.push(AssocTyConstraint {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
ident,
|
ident,
|
||||||
|
|
|
@ -32,6 +32,8 @@ crate struct GatedSpans {
|
||||||
crate const_extern_fn: Lock<Vec<Span>>,
|
crate const_extern_fn: Lock<Vec<Span>>,
|
||||||
/// Spans collected for gating `trait_alias`, e.g. `trait Foo = Ord + Eq;`.
|
/// Spans collected for gating `trait_alias`, e.g. `trait Foo = Ord + Eq;`.
|
||||||
pub trait_alias: Lock<Vec<Span>>,
|
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.
|
/// Info about a parsing session.
|
||||||
|
|
|
@ -70,3 +70,7 @@ fn main() {
|
||||||
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
|
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
|
||||||
// let _: &dyn Tr1<As1: Copy> = &S1;
|
// let _: &dyn Tr1<As1: Copy> = &S1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! accept_path { ($p:path) => {} }
|
||||||
|
accept_path!(Iterator<Item: Ord>);
|
||||||
|
//~^ ERROR associated type bounds are unstable
|
||||||
|
|
|
@ -115,6 +115,15 @@ LL | let _: impl Tr1<As1: Copy> = S1;
|
||||||
= note: for more information, see https://github.com/rust-lang/rust/issues/52662
|
= note: for more information, see https://github.com/rust-lang/rust/issues/52662
|
||||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error[E0658]: associated type bounds are unstable
|
||||||
|
--> $DIR/feature-gate-associated_type_bounds.rs:75:23
|
||||||
|
|
|
||||||
|
LL | accept_path!(Iterator<Item: Ord>);
|
||||||
|
| ^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/52662
|
||||||
|
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
|
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
|
||||||
--> $DIR/feature-gate-associated_type_bounds.rs:54:14
|
--> $DIR/feature-gate-associated_type_bounds.rs:54:14
|
||||||
|
|
|
|
||||||
|
@ -139,7 +148,7 @@ LL | let _: impl Tr1<As1: Copy> = S1;
|
||||||
|
|
|
|
||||||
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
|
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
|
||||||
|
|
||||||
error: aborting due to 16 previous errors
|
error: aborting due to 17 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0562, E0658.
|
Some errors have detailed explanations: E0562, E0658.
|
||||||
For more information about an error, try `rustc --explain E0562`.
|
For more information about an error, try `rustc --explain E0562`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue