diff options
Diffstat (limited to 'src/libsyntax_ext/assert.rs')
| -rw-r--r-- | src/libsyntax_ext/assert.rs | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/src/libsyntax_ext/assert.rs b/src/libsyntax_ext/assert.rs index c788d062994..331e9fa61d0 100644 --- a/src/libsyntax_ext/assert.rs +++ b/src/libsyntax_ext/assert.rs @@ -2,10 +2,10 @@ use errors::{Applicability, DiagnosticBuilder}; use rustc_parse::parser::Parser; use syntax::ast::{self, *}; -use syntax::token::{self, TokenKind}; use syntax::print::pprust; use syntax::ptr::P; use syntax::symbol::{sym, Symbol}; +use syntax::token::{self, TokenKind}; use syntax::tokenstream::{DelimSpan, TokenStream, TokenTree}; use syntax_expand::base::*; use syntax_pos::{Span, DUMMY_SP}; @@ -28,10 +28,14 @@ pub fn expand_assert<'cx>( let sp = cx.with_call_site_ctxt(sp); let tokens = custom_message.unwrap_or_else(|| { TokenStream::from(TokenTree::token( - TokenKind::lit(token::Str, Symbol::intern(&format!( - "assertion failed: {}", - pprust::expr_to_string(&cond_expr).escape_debug() - )), None), + TokenKind::lit( + token::Str, + Symbol::intern(&format!( + "assertion failed: {}", + pprust::expr_to_string(&cond_expr).escape_debug() + )), + None, + ), DUMMY_SP, )) }); @@ -44,10 +48,7 @@ pub fn expand_assert<'cx>( let if_expr = cx.expr_if( sp, cx.expr(sp, ExprKind::Unary(UnOp::Not, cond_expr)), - cx.expr( - sp, - ExprKind::Mac(panic_call), - ), + cx.expr(sp, ExprKind::Mac(panic_call)), None, ); MacEager::expr(if_expr) @@ -61,7 +62,7 @@ struct Assert { fn parse_assert<'a>( cx: &mut ExtCtxt<'a>, sp: Span, - stream: TokenStream + stream: TokenStream, ) -> Result<Assert, DiagnosticBuilder<'a>> { let mut parser = cx.new_parser_from_tts(stream); @@ -87,7 +88,7 @@ fn parse_assert<'a>( parser.token.span, "try removing semicolon", String::new(), - Applicability::MaybeIncorrect + Applicability::MaybeIncorrect, ); err.note("this is going to be an error in the future"); err.emit(); @@ -102,25 +103,25 @@ fn parse_assert<'a>( // // Parse this as an actual message, and suggest inserting a comma. Eventually, this should be // turned into an error. - let custom_message = if let token::Literal(token::Lit { kind: token::Str, .. }) - = parser.token.kind { - let mut err = cx.struct_span_warn(parser.token.span, "unexpected string literal"); - let comma_span = cx.source_map().next_point(parser.prev_span); - err.span_suggestion_short( - comma_span, - "try adding a comma", - ", ".to_string(), - Applicability::MaybeIncorrect - ); - err.note("this is going to be an error in the future"); - err.emit(); + let custom_message = + if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind { + let mut err = cx.struct_span_warn(parser.token.span, "unexpected string literal"); + let comma_span = cx.source_map().next_point(parser.prev_span); + err.span_suggestion_short( + comma_span, + "try adding a comma", + ", ".to_string(), + Applicability::MaybeIncorrect, + ); + err.note("this is going to be an error in the future"); + err.emit(); - parse_custom_message(&mut parser) - } else if parser.eat(&token::Comma) { - parse_custom_message(&mut parser) - } else { - None - }; + parse_custom_message(&mut parser) + } else if parser.eat(&token::Comma) { + parse_custom_message(&mut parser) + } else { + None + }; if parser.token != token::Eof { parser.expect_one_of(&[], &[])?; @@ -132,9 +133,5 @@ fn parse_assert<'a>( fn parse_custom_message(parser: &mut Parser<'_>) -> Option<TokenStream> { let ts = parser.parse_tokens(); - if !ts.is_empty() { - Some(ts) - } else { - None - } + if !ts.is_empty() { Some(ts) } else { None } } |
