diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 8342af6011d..c41591bbc37 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -215,8 +215,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { fn visit_item(&mut self, item: &'a Item) { match item.node { - ItemKind::Impl(.., Some(..), _, ref impl_items) => { + ItemKind::Impl(.., Some(..), ref ty, ref impl_items) => { self.invalid_visibility(&item.vis, item.span, None); + if ty.node == TyKind::Err { + self.err_handler() + .struct_span_err(item.span, "`impl Trait for .. {}` is an obsolete syntax") + .help("use `auto trait Trait {}` instead").emit(); + } for impl_item in impl_items { self.invalid_visibility(&impl_item.vis, impl_item.span, None); if let ImplItemKind::Method(ref sig, _) = impl_item.node { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ce42b05b8bb..ad9c802ac85 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5422,7 +5422,11 @@ impl<'a> Parser<'a> { }; if opt_trait.is_some() { - ty = self.parse_ty()?; + ty = if self.eat(&token::DotDot) { + P(Ty { node: TyKind::Err, span: self.prev_span, id: ast::DUMMY_NODE_ID }) + } else { + self.parse_ty()? + } } generics.where_clause = self.parse_where_clause()?; diff --git a/src/test/ui/obsolete-syntax-impl-for-dotdot.rs b/src/test/ui/obsolete-syntax-impl-for-dotdot.rs new file mode 100644 index 00000000000..914621a117d --- /dev/null +++ b/src/test/ui/obsolete-syntax-impl-for-dotdot.rs @@ -0,0 +1,19 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Trait1 {} +trait Trait2 {} + +#[cfg(not_enabled)] +impl Trait1 for .. {} + +impl Trait2 for .. {} //~ ERROR `impl Trait for .. {}` is an obsolete syntax + +fn main() {} diff --git a/src/test/ui/obsolete-syntax-impl-for-dotdot.stderr b/src/test/ui/obsolete-syntax-impl-for-dotdot.stderr new file mode 100644 index 00000000000..aa0af840d1a --- /dev/null +++ b/src/test/ui/obsolete-syntax-impl-for-dotdot.stderr @@ -0,0 +1,10 @@ +error: `impl Trait for .. {}` is an obsolete syntax + --> $DIR/obsolete-syntax-impl-for-dotdot.rs:17:1 + | +17 | impl Trait2 for .. {} //~ ERROR `impl Trait for .. {}` is an obsolete syntax + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: use `auto trait Trait {}` instead + +error: aborting due to previous error +