1 // Copyright 2017 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.
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.
13 #![crate_type = "proc-macro"]
14 #![feature(proc_macro_diagnostic, proc_macro_span)]
16 extern crate proc_macro
;
18 use proc_macro
::{TokenStream, TokenTree, Span, Diagnostic}
;
20 fn parse(input
: TokenStream
) -> Result
<(), Diagnostic
> {
22 let mut last_span
= Span
::def_site();
24 let span
= tree
.span();
26 return Err(span
.error(format
!("expected EOF, found `{}`.", tree
))
27 .span_note(last_span
, "last good input was here")
28 .help("input must be: `===`"))
31 if let TokenTree
::Punct(ref tt
) = tree
{
32 if tt
.as_char() == '
='
{
38 return Err(span
.error(format
!("expected `=`, found `{}`.", tree
)));
42 return Err(Span
::def_site()
43 .error(format
!("found {} equal signs, need exactly 3", count
))
44 .help("input must be: `===`"))
51 pub fn three_equals(input
: TokenStream
) -> TokenStream
{
52 if let Err(diag
) = parse(input
) {
54 return TokenStream
::new();