提交 64cd30e0 编写于 作者: N Niko Matsakis

Declare `&foo[]` to be obsolete syntax. Modify the obsolete mechanism to

support warnings.
上级 dfc5c0f1
......@@ -28,6 +28,7 @@ pub enum ObsoleteSyntax {
ProcExpr,
ClosureType,
ClosureKind,
EmptyIndex,
}
pub trait ParserObsoleteMethods {
......@@ -48,35 +49,46 @@ fn report(&mut self,
impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
/// Reports an obsolete syntax non-fatal error.
fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) {
let (kind_str, desc) = match kind {
let (kind_str, desc, error) = match kind {
ObsoleteSyntax::ForSized => (
"for Sized?",
"no longer required. Traits (and their `Self` type) do not have the `Sized` bound \
by default",
true,
),
ObsoleteSyntax::ProcType => (
"the `proc` type",
"use unboxed closures instead",
true,
),
ObsoleteSyntax::ProcExpr => (
"`proc` expression",
"use a `move ||` expression instead",
true,
),
ObsoleteSyntax::ClosureType => (
"`|usize| -> bool` closure type",
"use unboxed closures instead, no type annotation needed"
true,
),
ObsoleteSyntax::ClosureKind => (
"`:`, `&mut:`, or `&:`",
"rely on inference instead"
true,
),
ObsoleteSyntax::Sized => (
"`Sized? T` for removing the `Sized` bound",
"write `T: ?Sized` instead"
true,
),
ObsoleteSyntax::EmptyIndex => (
"[]",
"write `[..]` instead",
false, // warning for now
),
};
self.report(sp, kind, kind_str, desc);
self.report(sp, kind, kind_str, desc, error);
}
/// Reports an obsolete syntax non-fatal error, and returns
......@@ -90,9 +102,13 @@ fn report(&mut self,
sp: Span,
kind: ObsoleteSyntax,
kind_str: &str,
desc: &str) {
self.span_err(sp,
&format!("obsolete syntax: {}", kind_str)[]);
desc: &str,
error: bool) {
if error {
self.span_err(sp, &format!("obsolete syntax: {}", kind_str)[]);
} else {
self.span_warn(sp, &format!("obsolete syntax: {}", kind_str)[]);
}
if !self.obsolete_set.contains(&kind) {
self.sess
......
......@@ -2552,8 +2552,9 @@ pub fn parse_dot_or_call_expr_with(&mut self, e0: P<Expr>) -> P<Expr> {
parameters: ast::PathParameters::none(),
}
}).collect();
let span = mk_sp(lo, hi);
let path = ast::Path {
span: mk_sp(lo, hi),
span: span,
global: true,
segments: segments,
};
......@@ -2562,10 +2563,8 @@ pub fn parse_dot_or_call_expr_with(&mut self, e0: P<Expr>) -> P<Expr> {
let ix = self.mk_expr(bracket_pos, hi, range);
let index = self.mk_index(e, ix);
e = self.mk_expr(lo, hi, index);
// Enable after snapshot.
// self.span_warn(e.span, "deprecated slicing syntax: `[]`");
// self.span_note(e.span,
// "use `&expr[..]` to construct a slice of the whole of expr");
self.obsolete(span, ObsoleteSyntax::EmptyIndex);
} else {
let ix = self.parse_expr();
hi = self.span.hi;
......
......@@ -9,14 +9,12 @@
// except according to those terms.
// Test slicing &expr[] is deprecated and gives a helpful error message.
//
// ignore-test
struct Foo;
fn main() {
let x = Foo;
&x[]; //~ WARNING deprecated slicing syntax: `[]`
//~^ NOTE use `&expr[..]` to construct a slice of the whole of expr
//~^^ ERROR cannot index a value of type `Foo`
&x[];
//~^ WARN obsolete syntax
//~| ERROR cannot index
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册