hygiene: Implement transparent marks

This commit is contained in:
Vadim Petrochenkov 2018-06-24 19:54:23 +03:00
parent 09856c85b7
commit 99ecdb3f5f
14 changed files with 253 additions and 27 deletions

View file

@ -19,3 +19,9 @@ pub mod foo {
}
}
}
pub struct SomeType;
pub macro uses_dollar_crate() {
type Alias = $crate::SomeType;
}

View file

@ -0,0 +1,16 @@
// Copyright 2018 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(decl_macro, rustc_attrs)]
#[rustc_transparent_macro]
pub macro dollar_crate() {
let s = $crate::S;
}

View file

@ -0,0 +1,22 @@
// Copyright 2018 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.
// Make sure `$crate` works in `macro` macros.
// compile-pass
// aux-build:intercrate.rs
#![feature(use_extern_macros)]
extern crate intercrate;
intercrate::uses_dollar_crate!();
fn main() {}

View file

@ -0,0 +1,24 @@
// Copyright 2018 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.
// This is an equivalent of issue #50504, but for declarative macros.
#![feature(decl_macro, rustc_attrs)]
#[rustc_transparent_macro]
macro genmod() {
mod m {
type A = S; //~ ERROR cannot find type `S` in this scope
}
}
struct S;
genmod!();

View file

@ -0,0 +1,17 @@
error[E0412]: cannot find type `S` in this scope
--> $DIR/generate-mod.rs:18:18
|
LL | type A = S; //~ ERROR cannot find type `S` in this scope
| ^ did you mean `A`?
...
LL | genmod!();
| ---------- in this macro invocation
error[E0601]: `main` function not found in crate `generate_mod`
|
= note: consider adding a `main` function to `$DIR/generate-mod.rs`
error: aborting due to 2 previous errors
Some errors occurred: E0412, E0601.
For more information about an error, try `rustc --explain E0412`.

View file

@ -0,0 +1,53 @@
// Copyright 2018 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-pass
// aux-build:transparent-basic.rs
#![feature(decl_macro, rustc_attrs)]
extern crate transparent_basic;
#[rustc_transparent_macro]
macro binding() {
let x = 10;
}
#[rustc_transparent_macro]
macro label() {
break 'label
}
macro_rules! legacy {
() => {
binding!();
let y = x;
}
}
fn legacy_interaction1() {
legacy!();
}
struct S;
fn check_dollar_crate() {
// `$crate::S` inside the macro resolves to `S` from this crate.
transparent_basic::dollar_crate!();
}
fn main() {
binding!();
let y = x;
'label: loop {
label!();
}
}