Skip to content

Commit 2259877

Browse files
committed
Re-add support for impl Trait for .. to the parser
1 parent 8b4d852 commit 2259877

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

src/librustc_passes/ast_validation.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
215215

216216
fn visit_item(&mut self, item: &'a Item) {
217217
match item.node {
218-
ItemKind::Impl(.., Some(..), _, ref impl_items) => {
218+
ItemKind::Impl(.., Some(..), ref ty, ref impl_items) => {
219219
self.invalid_visibility(&item.vis, item.span, None);
220+
if ty.node == TyKind::Err {
221+
self.err_handler()
222+
.struct_span_err(item.span, "`impl Trait for .. {}` is an obsolete syntax")
223+
.help("use `auto trait Trait {}` instead").emit();
224+
}
220225
for impl_item in impl_items {
221226
self.invalid_visibility(&impl_item.vis, impl_item.span, None);
222227
if let ImplItemKind::Method(ref sig, _) = impl_item.node {

src/libsyntax/parse/parser.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -5422,7 +5422,11 @@ impl<'a> Parser<'a> {
54225422
};
54235423

54245424
if opt_trait.is_some() {
5425-
ty = self.parse_ty()?;
5425+
ty = if self.eat(&token::DotDot) {
5426+
P(Ty { node: TyKind::Err, span: self.prev_span, id: ast::DUMMY_NODE_ID })
5427+
} else {
5428+
self.parse_ty()?
5429+
}
54265430
}
54275431
generics.where_clause = self.parse_where_clause()?;
54285432

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Trait1 {}
12+
trait Trait2 {}
13+
14+
#[cfg(not_enabled)]
15+
impl Trait1 for .. {}
16+
17+
impl Trait2 for .. {} //~ ERROR `impl Trait for .. {}` is an obsolete syntax
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: `impl Trait for .. {}` is an obsolete syntax
2+
--> $DIR/obsolete-syntax-impl-for-dotdot.rs:17:1
3+
|
4+
17 | impl Trait2 for .. {} //~ ERROR `impl Trait for .. {}` is an obsolete syntax
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: use `auto trait Trait {}` instead
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)