-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #44818 - petrochenkov:astymac2, r=jseyfried
Improve resolution of associated types in declarative macros 2.0 Make various identifier comparisons for associated types (and sometimes other associated items) hygienic. Now declarative macros 2.0 can use `Self::AssocTy`, `TyParam::AssocTy`, `Trait<AssocTy = u8>` where `AssocTy` is an associated type of a trait `Trait` visible from the macro. Also, `Trait` can now be implemented inside the macro and specialization should work properly (fixes #40847 (comment)). r? @jseyfried or @eddyb
- Loading branch information
Showing
11 changed files
with
182 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.