Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proc_macro: Validate inputs to
Punct::new
and Ident::new
- Loading branch information
1 parent
f116ab6
commit 780616e
Showing
12 changed files
with
203 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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. | ||
|
||
// force-host | ||
// no-prefer-dynamic | ||
|
||
#![feature(proc_macro)] | ||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
use proc_macro::*; | ||
|
||
#[proc_macro] | ||
pub fn invalid_punct(_: TokenStream) -> TokenStream { | ||
TokenTree::from(Punct::new('`', Spacing::Alone)).into() | ||
} | ||
|
||
#[proc_macro] | ||
pub fn invalid_ident(_: TokenStream) -> TokenStream { | ||
TokenTree::from(Ident::new("*", Span::call_site())).into() | ||
} | ||
|
||
#[proc_macro] | ||
pub fn invalid_raw_ident(_: TokenStream) -> TokenStream { | ||
TokenTree::from(Ident::new_raw("self", Span::call_site())).into() | ||
} | ||
|
||
#[proc_macro] | ||
pub fn lexer_failure(_: TokenStream) -> TokenStream { | ||
"a b ) c".parse().expect("parsing failed without panic") | ||
} |
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,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. | ||
|
||
// aux-build:invalid-punct-ident.rs | ||
#![feature(proc_macro)] | ||
#[macro_use] | ||
extern crate invalid_punct_ident; | ||
|
||
invalid_punct!(); //~ ERROR proc macro panicked |
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,10 @@ | ||
error: proc macro panicked | ||
--> $DIR/invalid-punct-ident-1.rs:16:1 | ||
| | ||
LL | invalid_punct!(); //~ ERROR proc macro panicked | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: message: unsupported character `'`'` | ||
|
||
error: aborting due to previous error | ||
|
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,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. | ||
|
||
// aux-build:invalid-punct-ident.rs | ||
#![feature(proc_macro)] | ||
#[macro_use] | ||
extern crate invalid_punct_ident; | ||
|
||
invalid_ident!(); //~ ERROR proc macro panicked |
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,10 @@ | ||
error: proc macro panicked | ||
--> $DIR/invalid-punct-ident-2.rs:16:1 | ||
| | ||
LL | invalid_ident!(); //~ ERROR proc macro panicked | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: message: `"*"` is not a valid identifier | ||
|
||
error: aborting due to previous error | ||
|
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,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. | ||
|
||
// aux-build:invalid-punct-ident.rs | ||
#![feature(proc_macro)] | ||
#[macro_use] | ||
extern crate invalid_punct_ident; | ||
|
||
invalid_raw_ident!(); //~ ERROR proc macro panicked |
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,10 @@ | ||
error: proc macro panicked | ||
--> $DIR/invalid-punct-ident-3.rs:16:1 | ||
| | ||
LL | invalid_raw_ident!(); //~ ERROR proc macro panicked | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: message: `"self"` is not a valid raw identifier | ||
|
||
error: aborting due to previous error | ||
|
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,17 @@ | ||
// 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. | ||
|
||
// aux-build:invalid-punct-ident.rs | ||
#![feature(proc_macro)] | ||
#[macro_use] | ||
extern crate invalid_punct_ident; | ||
|
||
lexer_failure!(); //~ ERROR proc macro panicked | ||
//~| ERROR unexpected close delimiter: `)` |
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,14 @@ | ||
error: unexpected close delimiter: `)` | ||
--> $DIR/invalid-punct-ident-4.rs:16:1 | ||
| | ||
LL | lexer_failure!(); //~ ERROR proc macro panicked | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: proc macro panicked | ||
--> $DIR/invalid-punct-ident-4.rs:16:1 | ||
| | ||
LL | lexer_failure!(); //~ ERROR proc macro panicked | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|