提交 acf50ee2 编写于 作者: L leonardo.yvens

Add tests for `auto trait`, fix parsing bug

Now we can do the well formedness checks in the parser, yay!
上级 37dfc0c5
......@@ -1394,7 +1394,7 @@ fn visit_item(&mut self, i: &'a ast::Item) {
i.span,
"auto traits are experimental and possibly buggy");
}
ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => {
let msg = "`macro` is experimental";
gate_feature_post!(&self, decl_macro, i.span, msg);
......
......@@ -6014,6 +6014,37 @@ fn parse_item_(&mut self, attrs: Vec<Attribute>,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.eat_keyword(keywords::Auto) {
self.expect_keyword(keywords::Trait)?;
// AUTO TRAIT ITEM
let (ident,
item_,
extra_attrs) = self.parse_item_auto_trait(ast::Unsafety::Normal)?;
let prev_span = self.prev_span;
let item = self.mk_item(lo.to(prev_span),
ident,
item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.check_keyword(keywords::Unsafe) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Auto)) {
self.expect_keyword(keywords::Unsafe)?;
self.expect_keyword(keywords::Auto)?;
self.expect_keyword(keywords::Trait)?;
// UNSAFE AUTO TRAIT ITEM
let (ident,
item_,
extra_attrs) = self.parse_item_auto_trait(ast::Unsafety::Unsafe)?;
let prev_span = self.prev_span;
let item = self.mk_item(lo.to(prev_span),
ident,
item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if (self.check_keyword(keywords::Unsafe) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Impl))) ||
(self.check_keyword(keywords::Default) &&
......@@ -6138,37 +6169,6 @@ fn parse_item_(&mut self, attrs: Vec<Attribute>,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.eat_keyword(keywords::Auto) {
self.expect_keyword(keywords::Trait)?;
// AUTO TRAIT ITEM
let (ident,
item_,
extra_attrs) = self.parse_item_auto_trait(ast::Unsafety::Normal)?;
let prev_span = self.prev_span;
let item = self.mk_item(lo.to(prev_span),
ident,
item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.check_keyword(keywords::Unsafe) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Auto)) {
self.expect_keyword(keywords::Unsafe)?;
self.expect_keyword(keywords::Auto)?;
self.expect_keyword(keywords::Trait)?;
// UNSAFE AUTO TRAIT ITEM
let (ident,
item_,
extra_attrs) = self.parse_item_auto_trait(ast::Unsafety::Unsafe)?;
let prev_span = self.prev_span;
let item = self.mk_item(lo.to(prev_span),
ident,
item_,
visibility,
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.eat_keyword(keywords::Struct) {
// STRUCT ITEM
let (ident, item_, extra_attrs) = self.parse_item_struct()?;
......
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type A0 = auto;
//~^ ERROR cannot find type `auto` in this scope
type A1 = auto::auto;
//~^ ERROR Use of undeclared type or module `auto`
type A2 = auto<auto, auto>;
//~^ ERROR cannot find type `auto` in this scope
//~| ERROR cannot find type `auto` in this scope
//~| ERROR cannot find type `auto` in this scope
type A3 = auto<<auto as auto>::auto>;
//~^ ERROR cannot find type `auto` in this scope
//~| ERROR cannot find type `auto` in this scope
//~| ERROR Use of undeclared type or module `auto`
type A4 = auto(auto, auto) -> auto;
//~^ ERROR cannot find type `auto` in this scope
//~| ERROR cannot find type `auto` in this scope
//~| ERROR cannot find type `auto` in this scope
//~| ERROR cannot find type `auto` in this scope
fn main() {}
......@@ -17,6 +17,9 @@ trait DummyTrait {
fn dummy(&self) {}
}
auto trait AutoDummyTrait {}
//~^ ERROR auto traits are experimental and possibly buggy
impl DummyTrait for .. {}
//~^ ERROR auto trait implementations are experimental and possibly buggy
......
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: -Z parse-only
auto trait Auto<T> { }
//~^ ERROR: expected `{`, found `<`
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: -Z parse-only
auto trait Auto { fn item() }
//~^ ERROR: expected `}`, found `fn`
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: -Z parse-only
auto trait Auto : Send { }
//~^ ERROR: expected `{`, found `:`
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(optin_builtin_traits)]
auto trait Auto {}
// Redundant but accepted until we remove it.
impl Auto for .. {}
unsafe auto trait AutoUnsafe {}
impl !Auto for bool {}
impl !AutoUnsafe for bool {}
struct AutoBool(bool);
impl Auto for AutoBool {}
unsafe impl AutoUnsafe for AutoBool {}
fn take_auto<T: Auto>(_: T) {}
fn take_auto_unsafe<T: AutoUnsafe>(_: T) {}
fn main() {
take_auto(0);
take_auto(AutoBool(true));
take_auto_unsafe(0);
take_auto_unsafe(AutoBool(true));
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册