Declare &foo[]
to be obsolete syntax. Modify the obsolete mechanism to
support warnings.
This commit is contained in:
parent
dfc5c0f1e8
commit
64cd30e0ca
@ -28,6 +28,7 @@ pub enum ObsoleteSyntax {
|
||||
ProcExpr,
|
||||
ClosureType,
|
||||
ClosureKind,
|
||||
EmptyIndex,
|
||||
}
|
||||
|
||||
pub trait ParserObsoleteMethods {
|
||||
@ -48,35 +49,46 @@ pub trait ParserObsoleteMethods {
|
||||
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 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
|
||||
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 @@ impl<'a> Parser<'a> {
|
||||
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 @@ impl<'a> Parser<'a> {
|
||||
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user