-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multispan support to proc-macro diagnostics.
Also updates the issue number for 'proc_macro_diagnostic'.
- Loading branch information
1 parent
50d8693
commit 10bb5ed
Showing
5 changed files
with
244 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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. | ||
|
||
// no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
#![feature(proc_macro_diagnostic, proc_macro_span)] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::{TokenStream, TokenTree, Span, Diagnostic}; | ||
|
||
fn parse(input: TokenStream) -> Result<(), Diagnostic> { | ||
let mut hi_spans = vec![]; | ||
for tree in input { | ||
if let TokenTree::Ident(ref ident) = tree { | ||
if ident.to_string() == "hi" { | ||
hi_spans.push(ident.span()); | ||
} | ||
} | ||
} | ||
|
||
if !hi_spans.is_empty() { | ||
return Err(Span::def_site() | ||
.error("hello to you, too!") | ||
.span_note(hi_spans, "found these 'hi's")); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[proc_macro] | ||
pub fn hello(input: TokenStream) -> TokenStream { | ||
if let Err(diag) = parse(input) { | ||
diag.emit(); | ||
} | ||
|
||
TokenStream::new() | ||
} |
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 2016 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:multispan.rs | ||
// ignore-stage1 | ||
|
||
#![feature(proc_macro_non_items)] | ||
|
||
extern crate multispan; | ||
|
||
use multispan::hello; | ||
|
||
fn main() { | ||
// This one emits no error. | ||
hello!(); | ||
|
||
// Exactly one 'hi'. | ||
hello!(hi); //~ ERROR hello to you, too! | ||
|
||
// Now two, back to back. | ||
hello!(hi hi); //~ ERROR hello to you, too! | ||
|
||
// Now three, back to back. | ||
hello!(hi hi hi); //~ ERROR hello to you, too! | ||
|
||
// Now several, with spacing. | ||
hello!(hi hey hi yo hi beep beep hi hi); //~ ERROR hello to you, too! | ||
hello!(hi there, hi how are you? hi... hi.); //~ ERROR hello to you, too! | ||
hello!(whoah. hi di hi di ho); //~ ERROR hello to you, too! | ||
hello!(hi good hi and good bye); //~ ERROR hello to you, too! | ||
} |
Oops, something went wrong.