Skip to content

Commit c17a1fd

Browse files
committed
pre-expansion gate associated_type_bounds
1 parent 2d182b8 commit c17a1fd

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

src/libsyntax/feature_gate/check.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use super::accepted::ACCEPTED_FEATURES;
33
use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
44
use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
55

6-
use crate::ast::{
7-
self, AssocTyConstraint, AssocTyConstraintKind, NodeId, GenericParam, GenericParamKind,
8-
PatKind, RangeEnd, VariantData,
9-
};
6+
use crate::ast::{self, NodeId, GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData};
107
use crate::attr::{self, check_builtin_attribute};
118
use crate::source_map::Spanned;
129
use crate::edition::{ALL_EDITIONS, Edition};
@@ -584,16 +581,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
584581
visit::walk_generic_param(self, param)
585582
}
586583

587-
fn visit_assoc_ty_constraint(&mut self, constraint: &'a AssocTyConstraint) {
588-
match constraint.kind {
589-
AssocTyConstraintKind::Bound { .. } =>
590-
gate_feature_post!(&self, associated_type_bounds, constraint.span,
591-
"associated type bounds are unstable"),
592-
_ => {}
593-
}
594-
visit::walk_assoc_ty_constraint(self, constraint)
595-
}
596-
597584
fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) {
598585
match ti.kind {
599586
ast::TraitItemKind::Method(ref sig, ref block) => {
@@ -859,6 +846,7 @@ pub fn check_crate(krate: &ast::Crate,
859846
gate_all!(or_patterns, "or-patterns syntax is experimental");
860847
gate_all!(const_extern_fn, "`const extern fn` definitions are unstable");
861848
gate_all!(trait_alias, "trait aliases are experimental");
849+
gate_all!(associated_type_bounds, "associated type bounds are unstable");
862850

863851
visit::walk_crate(&mut visitor, krate);
864852
}

src/libsyntax/parse/parser/path.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,9 @@ impl<'a> Parser<'a> {
404404
// Parse lifetime argument.
405405
args.push(GenericArg::Lifetime(self.expect_lifetime()));
406406
misplaced_assoc_ty_constraints.append(&mut assoc_ty_constraints);
407-
} else if self.check_ident() && self.look_ahead(1,
408-
|t| t == &token::Eq || t == &token::Colon) {
407+
} else if self.check_ident()
408+
&& self.look_ahead(1, |t| t == &token::Eq || t == &token::Colon)
409+
{
409410
// Parse associated type constraint.
410411
let lo = self.token.span;
411412
let ident = self.parse_ident()?;
@@ -420,7 +421,14 @@ impl<'a> Parser<'a> {
420421
} else {
421422
unreachable!();
422423
};
424+
423425
let span = lo.to(self.prev_span);
426+
427+
// Gate associated type bounds, e.g., `Iterator<Item: Ord>`.
428+
if let AssocTyConstraintKind::Bound { .. } = kind {
429+
self.sess.gated_spans.associated_type_bounds.borrow_mut().push(span);
430+
}
431+
424432
constraints.push(AssocTyConstraint {
425433
id: ast::DUMMY_NODE_ID,
426434
ident,

src/libsyntax/sess.rs

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ crate struct GatedSpans {
3232
crate const_extern_fn: Lock<Vec<Span>>,
3333
/// Spans collected for gating `trait_alias`, e.g. `trait Foo = Ord + Eq;`.
3434
pub trait_alias: Lock<Vec<Span>>,
35+
/// Spans collected for gating `associated_type_bounds`, e.g. `Iterator<Item: Ord>`.
36+
pub associated_type_bounds: Lock<Vec<Span>>,
3537
}
3638

3739
/// Info about a parsing session.

src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs

+4
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@ fn main() {
7070
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
7171
// let _: &dyn Tr1<As1: Copy> = &S1;
7272
}
73+
74+
macro_rules! accept_path { ($p:path) => {} }
75+
accept_path!(Iterator<Item: Ord>);
76+
//~^ ERROR associated type bounds are unstable

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ LL | let _: impl Tr1<As1: Copy> = S1;
115115
= note: for more information, see https://github.com/rust-lang/rust/issues/52662
116116
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
117117

118+
error[E0658]: associated type bounds are unstable
119+
--> $DIR/feature-gate-associated_type_bounds.rs:75:23
120+
|
121+
LL | accept_path!(Iterator<Item: Ord>);
122+
| ^^^^^^^^^
123+
|
124+
= note: for more information, see https://github.com/rust-lang/rust/issues/52662
125+
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
126+
118127
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
119128
--> $DIR/feature-gate-associated_type_bounds.rs:54:14
120129
|
@@ -139,7 +148,7 @@ LL | let _: impl Tr1<As1: Copy> = S1;
139148
|
140149
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
141150

142-
error: aborting due to 16 previous errors
151+
error: aborting due to 17 previous errors
143152

144153
Some errors have detailed explanations: E0562, E0658.
145154
For more information about an error, try `rustc --explain E0562`.

0 commit comments

Comments
 (0)