Add tests for auto trait
, fix parsing bug
Now we can do the well formedness checks in the parser, yay!
This commit is contained in:
parent
37dfc0c598
commit
acf50ee236
@ -1394,7 +1394,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
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 @@ impl<'a> Parser<'a> {
|
||||
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 @@ impl<'a> Parser<'a> {
|
||||
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()?;
|
||||
|
29
src/test/compile-fail/auto-is-contextual.rs
Normal file
29
src/test/compile-fail/auto-is-contextual.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// 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
|
||||
|
||||
|
14
src/test/parse-fail/auto-trait-no-generics.rs
Normal file
14
src/test/parse-fail/auto-trait-no-generics.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// 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 `<`
|
14
src/test/parse-fail/auto-trait-no-rename.rs
Normal file
14
src/test/parse-fail/auto-trait-no-rename.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// 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`
|
14
src/test/parse-fail/auto-trait-no-super.rs
Normal file
14
src/test/parse-fail/auto-trait-no-super.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// 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 `:`
|
35
src/test/run-pass/auto-traits.rs
Normal file
35
src/test/run-pass/auto-traits.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// 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));
|
||||
}
|
Loading…
Reference in New Issue
Block a user