Skip to content

Commit d0c59e2

Browse files
committed
add tests for $crate in QSelf paths
1 parent b202beb commit d0c59e2

File tree

3 files changed

+101
-4
lines changed

3 files changed

+101
-4
lines changed

src/test/run-pass-fulldeps/proc-macro/auxiliary/double.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ extern crate proc_macro;
1616

1717
use proc_macro::TokenStream;
1818

19+
// Outputs another copy of the struct. Useful for testing the tokens
20+
// seen by the proc_macro.
1921
#[proc_macro_derive(Double)]
2022
pub fn derive(input: TokenStream) -> TokenStream {
2123
format!("mod foo {{ {} }}", input.to_string()).parse().unwrap()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub struct ExternFoo;
12+
13+
pub trait ExternTrait {
14+
const CONST: u32;
15+
type Assoc;
16+
}
17+
18+
impl ExternTrait for ExternFoo {
19+
const CONST: u32 = 0;
20+
type Assoc = ExternFoo;
21+
}
22+
23+
#[macro_export]
24+
macro_rules! external { () => {
25+
mod bar {
26+
#[derive(Double)]
27+
struct Bar($crate::ExternFoo);
28+
}
29+
30+
mod qself {
31+
#[derive(Double)]
32+
struct QSelf(<$crate::ExternFoo as $crate::ExternTrait>::Assoc);
33+
}
34+
35+
mod qself_recurse {
36+
#[derive(Double)]
37+
struct QSelfRecurse(<
38+
<$crate::ExternFoo as $crate::ExternTrait>::Assoc
39+
as $crate::ExternTrait>::Assoc
40+
);
41+
}
42+
43+
mod qself_in_const {
44+
#[derive(Double)]
45+
#[repr(u32)]
46+
enum QSelfInConst {
47+
Variant = <$crate::ExternFoo as $crate::ExternTrait>::CONST,
48+
}
49+
}
50+
} }
51+

src/test/run-pass-fulldeps/proc-macro/crate-var.rs

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,63 @@
99
// except according to those terms.
1010

1111
// aux-build:double.rs
12+
// aux-build:external-crate-var.rs
1213
// ignore-stage1
1314

1415
#![allow(unused)]
1516

1617
#[macro_use]
1718
extern crate double;
19+
#[macro_use]
20+
extern crate external_crate_var;
1821

1922
struct Foo;
2023

21-
macro_rules! m { () => {
22-
#[derive(Double)]
23-
struct Bar($crate::Foo);
24+
trait Trait {
25+
const CONST: u32;
26+
type Assoc;
27+
}
28+
29+
impl Trait for Foo {
30+
const CONST: u32 = 0;
31+
type Assoc = Foo;
32+
}
33+
34+
macro_rules! local { () => {
35+
// derive_Double outputs secondary copies of each definition
36+
// to test what the proc_macro sees.
37+
mod bar {
38+
#[derive(Double)]
39+
struct Bar($crate::Foo);
40+
}
41+
42+
mod qself {
43+
#[derive(Double)]
44+
struct QSelf(<::Foo as $crate::Trait>::Assoc);
45+
}
46+
47+
mod qself_recurse {
48+
#[derive(Double)]
49+
struct QSelfRecurse(<<$crate::Foo as $crate::Trait>::Assoc as $crate::Trait>::Assoc);
50+
}
51+
52+
mod qself_in_const {
53+
#[derive(Double)]
54+
#[repr(u32)]
55+
enum QSelfInConst {
56+
Variant = <::Foo as $crate::Trait>::CONST,
57+
}
58+
}
2459
} }
25-
m!();
60+
61+
mod local {
62+
local!();
63+
}
64+
65+
// and now repeat the above tests, using a macro defined in another crate
66+
67+
mod external {
68+
external!{}
69+
}
2670

2771
fn main() {}

0 commit comments

Comments
 (0)