mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 13:05:18 +03:00
Parse and report obsolete fixed-length vector syntax
This commit is contained in:
@@ -23,7 +23,8 @@ pub enum ObsoleteSyntax {
|
||||
ObsoleteClassTraits,
|
||||
ObsoletePrivSection,
|
||||
ObsoleteModeInFnType,
|
||||
ObsoleteByMutRefMode
|
||||
ObsoleteByMutRefMode,
|
||||
ObsoleteFixedLengthVec,
|
||||
}
|
||||
|
||||
impl ObsoleteSyntax : cmp::Eq {
|
||||
@@ -99,6 +100,11 @@ fn obsolete(sp: span, kind: ObsoleteSyntax) {
|
||||
"by-mutable-reference mode",
|
||||
"Declare an argument of type &mut T instead"
|
||||
),
|
||||
ObsoleteFixedLengthVec => (
|
||||
"fixed-length vector",
|
||||
"Fixed-length types are now written `[T * N]`, and instances \
|
||||
are type-inferred"
|
||||
)
|
||||
};
|
||||
|
||||
self.report(sp, kind, kind_str, desc);
|
||||
@@ -183,5 +189,66 @@ fn try_parse_obsolete_priv_section() -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn try_parse_obsolete_fixed_vstore() -> Option<Option<uint>> {
|
||||
if self.token == token::BINOP(token::SLASH) {
|
||||
self.bump();
|
||||
match copy self.token {
|
||||
token::UNDERSCORE => {
|
||||
self.obsolete(copy self.last_span,
|
||||
ObsoleteFixedLengthVec);
|
||||
self.bump(); Some(None)
|
||||
}
|
||||
token::LIT_INT_UNSUFFIXED(i) if i >= 0i64 => {
|
||||
self.obsolete(copy self.last_span,
|
||||
ObsoleteFixedLengthVec);
|
||||
self.bump(); Some(Some(i as uint))
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn try_convert_ty_to_obsolete_fixed_length_vstore(sp: span, t: ast::ty_)
|
||||
-> ast::ty_ {
|
||||
match self.try_parse_obsolete_fixed_vstore() {
|
||||
// Consider a fixed length vstore suffix (/N or /_)
|
||||
None => t,
|
||||
Some(v) => {
|
||||
ast::ty_fixed_length(
|
||||
@{id: self.get_id(), node: t, span: sp}, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn try_convert_expr_to_obsolete_fixed_length_vstore(
|
||||
lo: uint, hi: uint, ex: ast::expr_
|
||||
) -> (uint, ast::expr_) {
|
||||
|
||||
let mut hi = hi;
|
||||
let mut ex = ex;
|
||||
|
||||
// Vstore is legal following expr_lit(lit_str(...)) and expr_vec(...)
|
||||
// only.
|
||||
match ex {
|
||||
ast::expr_lit(@{node: ast::lit_str(_), span: _}) |
|
||||
ast::expr_vec(_, _) => {
|
||||
match self.try_parse_obsolete_fixed_vstore() {
|
||||
None => (),
|
||||
Some(v) => {
|
||||
hi = self.span.hi;
|
||||
ex = ast::expr_vstore(self.mk_expr(lo, hi, ex),
|
||||
ast::expr_vstore_fixed(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
||||
return (hi, ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -553,9 +553,13 @@ fn parse_ty(colons_before_params: bool) -> @Ty {
|
||||
} else { self.fatal(~"expected type"); };
|
||||
|
||||
let sp = mk_sp(lo, self.last_span.hi);
|
||||
return @{id: self.get_id(),
|
||||
node: t,
|
||||
return {
|
||||
let node =
|
||||
self.try_convert_ty_to_obsolete_fixed_length_vstore(sp, t);
|
||||
@{id: self.get_id(),
|
||||
node: node,
|
||||
span: sp}
|
||||
};
|
||||
}
|
||||
|
||||
fn parse_arg_mode() -> mode {
|
||||
@@ -1061,6 +1065,9 @@ fn parse_bottom_expr() -> pexpr {
|
||||
ex = expr_lit(@lit);
|
||||
}
|
||||
|
||||
let (hi, ex) =
|
||||
self.try_convert_expr_to_obsolete_fixed_length_vstore(lo, hi, ex);
|
||||
|
||||
return self.mk_pexpr(lo, hi, ex);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,4 +56,15 @@ struct S {
|
||||
//~^ ERROR obsolete syntax: with
|
||||
}
|
||||
|
||||
fn obsolete_fixed_length_vec() {
|
||||
let foo: [int]/1;
|
||||
//~^ ERROR obsolete syntax: fixed-length vector
|
||||
foo = [1]/_;
|
||||
//~^ ERROR obsolete syntax: fixed-length vector
|
||||
let foo: [int]/1;
|
||||
//~^ ERROR obsolete syntax: fixed-length vector
|
||||
foo = [1]/1;
|
||||
//~^ ERROR obsolete syntax: fixed-length vector
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
||||
Reference in New Issue
Block a user