Skip to content

Commit b2ae84c

Browse files
committed
[TO BE SQUASHED] Fix2
1 parent 1673552 commit b2ae84c

10 files changed

+281
-178
lines changed

library/proc_macro/src/quote.rs

Lines changed: 162 additions & 155 deletions
Large diffs are not rendered by default.

tests/ui/proc-macro/quote/auxiliary/basic.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub fn run_tests(_: TokenStream) -> TokenStream {
1717
test_sep_group2();
1818
test_dollar_dollar1();
1919
test_dollar_dollar2();
20+
test_dollar_dollar3();
21+
test_dollar_dollar4();
2022

2123
test_quote_impl();
2224
test_substitution();
@@ -70,7 +72,7 @@ fn test_sep2() {
7072
let iter2 = [1, 2, 3];
7173
let tokens = quote!($($iter1) ($($iter1) $($iter2),* A) *);
7274

73-
let expected = "\"a\" ($(\"b\") 1i32, 2i32, 3i32 A) \"b\"";
75+
let expected = "\"a\" ($(\"b\") 1i32 , 2i32 , 3i32 A) \"b\"";
7476
assert_eq!(expected, tokens.to_string());
7577
}
7678

@@ -108,6 +110,24 @@ fn test_dollar_dollar2() {
108110
assert_eq!(expected, tokens.to_string());
109111
}
110112

113+
fn test_dollar_dollar3() {
114+
let x = "X";
115+
let iter = ["a", "b", "c"].into_iter();
116+
let tokens = quote!($($x)$$($x),*);
117+
118+
let expected = "$(\"X\") $ (\"X\"),*";
119+
assert_eq!(expected, tokens.to_string());
120+
}
121+
122+
fn test_dollar_dollar4() {
123+
let x = "X";
124+
let iter = ["a", "b", "c"].into_iter();
125+
let tokens = quote!($($x)$$y$($iter)*);
126+
127+
let expected = "$(\"X\") $y \"a\" \"b\" \"c\"";
128+
assert_eq!(expected, tokens.to_string());
129+
}
130+
111131
// Based on https://github.com/dtolnay/quote/blob/0245506323a3616daa2ee41c6ad0b871e4d78ae4/tests/test.rs
112132
//
113133
// FIXME(quote):
@@ -164,7 +184,7 @@ fn test_iter() {
164184

165185
assert_eq!("X, X, X, X,", quote!($($primes,)*).to_string());
166186

167-
assert_eq!("X, X, X, X", quote!($($primes),*).to_string());
187+
assert_eq!("X , X , X , X", quote!($($primes),*).to_string());
168188
}
169189

170190
fn test_array() {
@@ -378,7 +398,7 @@ fn test_fancy_repetition() {
378398
$($foo: $bar),*
379399
};
380400

381-
let expected = r#""a" : true, "b" : false"#;
401+
let expected = r#""a" : true , "b" : false"#;
382402
assert_eq!(expected, tokens.to_string());
383403
}
384404

@@ -391,7 +411,7 @@ fn test_nested_fancy_repetition() {
391411
),*
392412
};
393413

394-
let expected = "'a' 'b' 'c', 'x' 'y' 'z'";
414+
let expected = "'a' 'b' 'c' , 'x' 'y' 'z'";
395415
assert_eq!(expected, tokens.to_string());
396416
}
397417

@@ -403,7 +423,7 @@ fn test_duplicate_name_repetition() {
403423
$($foo: $foo),*
404424
};
405425

406-
let expected = r#""a" : "a", "b" : "b" "a" : "a", "b" : "b""#;
426+
let expected = r#""a" : "a" , "b" : "b" "a" : "a" , "b" : "b""#;
407427
assert_eq!(expected, tokens.to_string());
408428
}
409429

@@ -414,7 +434,7 @@ fn test_duplicate_name_repetition_no_copy() {
414434
$($foo: $foo),*
415435
};
416436

417-
let expected = r#""a" : "a", "b" : "b""#;
437+
let expected = r#""a" : "a" , "b" : "b""#;
418438
assert_eq!(expected, tokens.to_string());
419439
}
420440

@@ -427,7 +447,7 @@ fn test_btreeset_repetition() {
427447
$($set: $set),*
428448
};
429449

430-
let expected = r#""a" : "a", "b" : "b""#;
450+
let expected = r#""a" : "a" , "b" : "b""#;
431451
assert_eq!(expected, tokens.to_string());
432452
}
433453

@@ -436,7 +456,7 @@ fn test_variable_name_conflict() {
436456
// fine, if a little confusing when debugging.
437457
let _i = vec!['a', 'b'];
438458
let tokens = quote! { $($_i),* };
439-
let expected = "'a', 'b'";
459+
let expected = "'a' , 'b'";
440460
assert_eq!(expected, tokens.to_string());
441461
}
442462

@@ -448,7 +468,7 @@ fn test_nonrep_in_repetition() {
448468
$($rep $rep : $nonrep $nonrep),*
449469
};
450470

451-
let expected = r#""a" "a" : "c" "c", "b" "b" : "c" "c""#;
471+
let expected = r#""a" "a" : "c" "c" , "b" "b" : "c" "c""#;
452472
assert_eq!(expected, tokens.to_string());
453473
}
454474

tests/ui/proc-macro/quote/not-quotable-repetition-group-brace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ use proc_macro::quote;
66

77
fn main() {
88
let arr = [1, 2, 3];
9-
let _ = quote! { ${$arr}* }; //~ ERROR the trait bound `[{integer}; 3]: ToTokens` is not satisfied [E0277]
9+
quote! { ${$arr}* }; //~ ERROR the trait bound `[{integer}; 3]: ToTokens` is not satisfied [E0277]
1010
}

tests/ui/proc-macro/quote/not-quotable-repetition-group-brace.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0277]: the trait bound `[{integer}; 3]: ToTokens` is not satisfied
2-
--> $DIR/not-quotable-repetition-group-brace.rs:9:13
2+
--> $DIR/not-quotable-repetition-group-brace.rs:9:5
33
|
4-
LL | let _ = quote! { ${$arr}* };
5-
| ^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| the trait `ToTokens` is not implemented for `[{integer}; 3]`
8-
| required by a bound introduced by this call
4+
LL | quote! { ${$arr}* };
5+
| ^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| the trait `ToTokens` is not implemented for `[{integer}; 3]`
8+
| required by a bound introduced by this call
99
|
1010
= help: the following other types implement trait `ToTokens`:
1111
&T

tests/ui/proc-macro/quote/not-quotable-repetition-group-bracket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ use proc_macro::quote;
66

77
fn main() {
88
let arr = [1, 2, 3];
9-
let _ = quote! { ${$arr}* }; //~ ERROR the trait bound `[{integer}; 3]: ToTokens` is not satisfied [E0277]
9+
quote! { $[$arr]* }; //~ ERROR the trait bound `[{integer}; 3]: ToTokens` is not satisfied [E0277]
1010
}

tests/ui/proc-macro/quote/not-quotable-repetition-group-bracket.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0277]: the trait bound `[{integer}; 3]: ToTokens` is not satisfied
2-
--> $DIR/not-quotable-repetition-group-bracket.rs:9:13
2+
--> $DIR/not-quotable-repetition-group-bracket.rs:9:5
33
|
4-
LL | let _ = quote! { ${$arr}* };
5-
| ^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| the trait `ToTokens` is not implemented for `[{integer}; 3]`
8-
| required by a bound introduced by this call
4+
LL | quote! { $[$arr]* };
5+
| ^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| the trait `ToTokens` is not implemented for `[{integer}; 3]`
8+
| required by a bound introduced by this call
99
|
1010
= help: the following other types implement trait `ToTokens`:
1111
&T
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(proc_macro_quote)]
2+
3+
extern crate proc_macro;
4+
5+
use proc_macro::quote;
6+
7+
macro_rules! do_quote {
8+
($dollar:tt $content:expr) => {
9+
proc_macro::quote!($dollar $content *) //~ ERROR the trait bound `[{integer}; 3]: ToTokens` is not satisfied [E0277]
10+
};
11+
}
12+
13+
fn main() {
14+
let arr = [1, 2, 3];
15+
do_quote!($ f!($arr));
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0277]: the trait bound `[{integer}; 3]: ToTokens` is not satisfied
2+
--> $DIR/not-quotable-repetition-group-none.rs:9:9
3+
|
4+
LL | proc_macro::quote!($dollar $content *)
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `ToTokens` is not implemented for `[{integer}; 3]`
6+
...
7+
LL | do_quote!($ f!($arr));
8+
| ---------------------
9+
| |
10+
| required by a bound introduced by this call
11+
| in this macro invocation
12+
|
13+
= help: the following other types implement trait `ToTokens`:
14+
&T
15+
&mut T
16+
Box<T>
17+
CString
18+
Cow<'_, T>
19+
Option<T>
20+
Rc<T>
21+
bool
22+
and 24 others
23+
= note: this error originates in the macro `proc_macro::quote` which comes from the expansion of the macro `do_quote` (in Nightly builds, run with -Z macro-backtrace for more info)
24+
25+
error: aborting due to 1 previous error
26+
27+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(proc_macro_quote)]
2+
3+
extern crate proc_macro;
4+
5+
use proc_macro::quote;
6+
7+
fn main() {
8+
let arr = [1, 2, 3];
9+
quote! { $($arr) $$ x .. false [] * }; //~ ERROR the trait bound `[{integer}; 3]: ToTokens` is not satisfied [E0277]
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0277]: the trait bound `[{integer}; 3]: ToTokens` is not satisfied
2+
--> $DIR/not-quotable-repetition-invalid-separator.rs:9:5
3+
|
4+
LL | quote! { $($arr) $$ x .. false [] * };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| the trait `ToTokens` is not implemented for `[{integer}; 3]`
8+
| required by a bound introduced by this call
9+
|
10+
= help: the following other types implement trait `ToTokens`:
11+
&T
12+
&mut T
13+
Box<T>
14+
CString
15+
Cow<'_, T>
16+
Option<T>
17+
Rc<T>
18+
bool
19+
and 24 others
20+
21+
error: aborting due to 1 previous error
22+
23+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)