diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2017-09-26 02:49:34 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2017-10-06 00:35:21 +0300 |
| commit | 2d9161d1887b2bbb2586e3674710e30963b845ff (patch) | |
| tree | 3a13f1ec041eb592f465090f0378181acb6c17f2 /src/test | |
| parent | 4531131bf328e1372663310bfd45cd354db511ce (diff) | |
Improve resolution of associated types in macros 2.0
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/hygiene/assoc_item_ctxt.rs | 52 | ||||
| -rw-r--r-- | src/test/compile-fail/hygiene/assoc_ty_bindings.rs | 49 | ||||
| -rw-r--r-- | src/test/run-pass/hygiene/specialization.rs | 34 |
3 files changed, 135 insertions, 0 deletions
diff --git a/src/test/compile-fail/hygiene/assoc_item_ctxt.rs b/src/test/compile-fail/hygiene/assoc_item_ctxt.rs new file mode 100644 index 00000000000..e336b0df13f --- /dev/null +++ b/src/test/compile-fail/hygiene/assoc_item_ctxt.rs @@ -0,0 +1,52 @@ +// 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. + +// ignore-pretty pretty-printing is unhygienic + +#![feature(decl_macro)] +#![allow(unused)] + +mod ok { + macro mac_trait_item($method: ident) { + fn $method(); + } + + trait Tr { + mac_trait_item!(method); + } + + macro mac_trait_impl() { + impl Tr for u8 { // OK + fn method() {} // OK + } + } + + mac_trait_impl!(); +} + +mod error { + macro mac_trait_item() { + fn method(); + } + + trait Tr { + mac_trait_item!(); + } + + macro mac_trait_impl() { + impl Tr for u8 { //~ ERROR not all trait items implemented, missing: `method` + fn method() {} //~ ERROR method `method` is not a member of trait `Tr` + } + } + + mac_trait_impl!(); +} + +fn main() {} diff --git a/src/test/compile-fail/hygiene/assoc_ty_bindings.rs b/src/test/compile-fail/hygiene/assoc_ty_bindings.rs new file mode 100644 index 00000000000..46a138749ff --- /dev/null +++ b/src/test/compile-fail/hygiene/assoc_ty_bindings.rs @@ -0,0 +1,49 @@ +// 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. + +// ignore-pretty pretty-printing is unhygienic + +#![feature(decl_macro, associated_type_defaults)] +#![feature(rustc_attrs)] + +trait Base { + type AssocTy; + fn f(); +} +trait Derived: Base { + fn g(); +} + +macro mac() { + type A = Base<AssocTy = u8>; + type B = Derived<AssocTy = u8>; + + impl Base for u8 { + type AssocTy = u8; + fn f() { + let _: Self::AssocTy; + } + } + impl Derived for u8 { + fn g() { + let _: Self::AssocTy; + } + } + + fn h<T: Base, U: Derived>() { + let _: T::AssocTy; + let _: U::AssocTy; + } +} + +mac!(); + +#[rustc_error] +fn main() {} //~ ERROR compilation successful diff --git a/src/test/run-pass/hygiene/specialization.rs b/src/test/run-pass/hygiene/specialization.rs new file mode 100644 index 00000000000..3d46d2ec99e --- /dev/null +++ b/src/test/run-pass/hygiene/specialization.rs @@ -0,0 +1,34 @@ +// 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. + +// ignore-pretty pretty-printing is unhygienic + +#![feature(decl_macro)] + +trait Tr { + fn f(&self) -> &'static str { + "This shouldn't happen" + } +} + +pub macro m($t:ty) { + impl Tr for $t { + fn f(&self) -> &'static str { + "Run me" + } + } +} + +struct S; +m!(S); + +fn main() { + assert_eq!(S.f(), "Run me"); +} |
