From 958c67d9c8ca74370e2052fd8a3d209b8184d1f4 Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Sat, 13 May 2017 21:40:06 +0200 Subject: [PATCH] adressed comments by @kennytm and @petrochenkov --- src/libsyntax/diagnostics/plugin.rs | 4 +-- src/libsyntax/ext/base.rs | 4 +-- src/libsyntax/ext/tt/macro_parser.rs | 50 +++++++++++++++------------- src/libsyntax/ext/tt/macro_rules.rs | 3 +- src/libsyntax/feature_gate.rs | 7 ++-- src/libsyntax/parse/classify.rs | 2 +- src/libsyntax/parse/mod.rs | 1 - src/libsyntax/parse/parser.rs | 6 ++-- src/libsyntax/print/pprust.rs | 2 +- 9 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index ca89a80fdee..73aeb40df84 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -111,7 +111,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt, // overflow the maximum line width. description.map(|raw_msg| { let msg = raw_msg.as_str(); - if !msg.starts_with('\n') || !msg.ends_with('\n') { + if !msg.starts_with("\n") || !msg.ends_with("\n") { ecx.span_err(span, &format!( "description for error code {} doesn't start and end with a newline", code @@ -120,7 +120,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt, // URLs can be unavoidably longer than the line limit, so we allow them. // Allowed format is: `[name]: https://www.rust-lang.org/` - let is_url = |l: &str| l.starts_with('[') && l.contains("]:") && l.contains("http"); + let is_url = |l: &str| l.starts_with("[") && l.contains("]:") && l.contains("http"); if msg.lines().any(|line| line.len() > MAX_DESCRIPTION_WIDTH && !is_url(line)) { ecx.span_err(span, &format!( diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index f78089aaa75..31a7e0d58d0 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -635,8 +635,8 @@ pub struct ExpansionData { } /// One of these is made during expansion and incrementally updated as we go; -/// when a macro expansion occurs, the resulting nodes have the backtrace() -/// -> `expn_info` of their expansion context stored into their span. +/// when a macro expansion occurs, the resulting nodes have the `backtrace() +/// -> expn_info` of their expansion context stored into their span. pub struct ExtCtxt<'a> { pub parse_sess: &'a parse::ParseSess, pub ecfg: expand::ExpansionConfig<'a>, diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 8e28135b11d..a0103a1e3fe 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -36,43 +36,47 @@ //! repetitions indicated by Kleene stars. It only advances or calls out to the //! real Rust parser when no `cur_eis` items remain //! -//! Example: Start parsing `a a a a b` against [· a $( a )* a b]. +//! Example: //! -//! Remaining input: `a a a a b` -//! `next_eis`: `[· a $( a )* a b]` +//! ```text, ignore +//! Start parsing a a a a b against [· a $( a )* a b]. //! -//! - - - Advance over an `a`. - - - +//! Remaining input: a a a a b +//! next_eis: [· a $( a )* a b] //! -//! Remaining input: `a a a b` -//! cur: `[a · $( a )* a b]` +//! - - - Advance over an a. - - - +//! +//! Remaining input: a a a b +//! cur: [a · $( a )* a b] //! Descend/Skip (first item). -//! next: `[a $( · a )* a b] [a $( a )* · a b]`. +//! next: [a $( · a )* a b] [a $( a )* · a b]. //! -//! - - - Advance over an `a`. - - - +//! - - - Advance over an a. - - - //! -//! Remaining input: `a a b` -//! cur: `[a $( a · )* a b]` next: `[a $( a )* a · b]` +//! Remaining input: a a b +//! cur: [a $( a · )* a b] next: [a $( a )* a · b] //! Finish/Repeat (first item) -//! next: `[a $( a )* · a b] [a $( · a )* a b] [a $( a )* a · b]` +//! next: [a $( a )* · a b] [a $( · a )* a b] [a $( a )* a · b] //! -//! - - - Advance over an `a`. - - - (this looks exactly like the last step) +//! - - - Advance over an a. - - - (this looks exactly like the last step) //! -//! Remaining input: `a b` -//! cur: `[a $( a · )* a b]` next: `[a $( a )* a · b]` +//! Remaining input: a b +//! cur: [a $( a · )* a b] next: [a $( a )* a · b] //! Finish/Repeat (first item) -//! next: `[a $( a )* · a b] [a $( · a )* a b] [a $( a )* a · b]` +//! next: [a $( a )* · a b] [a $( · a )* a b] [a $( a )* a · b] //! -//! - - - Advance over an `a`. - - - (this looks exactly like the last step) +//! - - - Advance over an a. - - - (this looks exactly like the last step) //! -//! Remaining input: `b` -//! cur: `[a $( a · )* a b]` next: `[a $( a )* a · b]` +//! Remaining input: b +//! cur: [a $( a · )* a b] next: [a $( a )* a · b] //! Finish/Repeat (first item) -//! next: `[a $( a )* · a b] [a $( · a )* a b]` +//! next: [a $( a )* · a b] [a $( · a )* a b] //! -//! - - - Advance over a `b`. - - - +//! - - - Advance over a b. - - - //! -//! Remaining input: `` -//! eof: `[a $( a )* a b ·]` +//! Remaining input: '' +//! eof: [a $( a )* a b ·] +//! ``` pub use self::NamedMatch::*; pub use self::ParseResult::*; @@ -485,7 +489,7 @@ pub fn parse(sess: &ParseSess, tts: TokenStream, ms: &[TokenTree], directory: Op } fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal { - if let "tt" = name { + if name == "tt" { return token::NtTT(p.parse_token_tree()); } // check at the beginning and the parser checks after each bump diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 9e3fe30e7bf..4a307ab18a5 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -858,6 +858,7 @@ fn quoted_tt_to_string(tt: "ed::TokenTree) -> String { match *tt { quoted::TokenTree::Token(_, ref tok) => ::print::pprust::token_to_string(tok), quoted::TokenTree::MetaVarDecl(_, name, kind) => format!("${}:{}", name, kind), - _ => panic!("unexpected quoted::TokenTree::{{Sequence or Delimited}} in follow set checker"), + _ => panic!("unexpected quoted::TokenTree::{{Sequence or Delimited}} \ + in follow set checker"), } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index f95693f6820..09090ab8731 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1216,7 +1216,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } ast::ItemKind::Impl(_, polarity, defaultness, _, _, _, _) => { - if let ast::ImplPolarity::Negative = polarity { + if polarity == ast::ImplPolarity::Negative { gate_feature_post!(&self, optin_builtin_traits, i.span, "negative trait bounds are not yet fully implemented; \ @@ -1269,10 +1269,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FunctionRetTy) { if let ast::FunctionRetTy::Ty(ref output_ty) = *ret_ty { - if let ast::TyKind::Never = output_ty.node { - return + if output_ty.node != ast::TyKind::Never { + self.visit_ty(output_ty) } - self.visit_ty(output_ty) } } diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index c2755cf0591..0c6f09ba766 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -48,8 +48,8 @@ pub fn expr_is_simple_block(e: &ast::Expr) -> bool { pub fn stmt_ends_with_semi(stmt: &ast::StmtKind) -> bool { match *stmt { ast::StmtKind::Local(_) => true, - ast::StmtKind::Item(_) => false, ast::StmtKind::Expr(ref e) => expr_requires_semi_to_be_stmt(e), + ast::StmtKind::Item(_) | ast::StmtKind::Semi(..) | ast::StmtKind::Mac(..) => false, } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 4fcf7614622..1eff819d755 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -341,7 +341,6 @@ pub fn raw_str_lit(lit: &str) -> String { debug!("raw_str_lit: given {}", escape_default(lit)); let mut res = String::with_capacity(lit.len()); - // FIXME #8372: This could be a for-loop if it didn't borrow the iterator let mut chars = lit.chars().peekable(); while let Some(c) = chars.next() { if c == '\r' { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 28c57e0855f..4741f896d3c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1546,7 +1546,7 @@ impl<'a> Parser<'a> { pub fn is_named_argument(&mut self) -> bool { let offset = match self.token { token::BinOp(token::And) | - token::AndAnd | + token::AndAnd => 1, _ if self.token.is_keyword(keywords::Mut) => 1, _ => 0 }; @@ -2569,7 +2569,7 @@ impl<'a> Parser<'a> { s.print_usize(float.trunc() as usize)?; s.pclose()?; word(&mut s.s, ".")?; - word(&mut s.s, fstr.splitn(2, '.').last().unwrap()) + word(&mut s.s, fstr.splitn(2, ".").last().unwrap()) }); err.span_suggestion( lo.to(self.prev_span), @@ -4917,7 +4917,7 @@ impl<'a> Parser<'a> { } } } else { - if let ast::ImplPolarity::Negative = polarity { + if polarity == ast::ImplPolarity::Negative { // This is a negated type implementation // `impl !MyType {}`, which is not allowed. self.span_err(neg_span, "inherent implementation can't be negated"); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 6114db25fe8..bdb4ce34b91 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1327,7 +1327,7 @@ impl<'a> State<'a> { space(&mut self.s)?; } - if let ast::ImplPolarity::Negative = polarity { + if polarity == ast::ImplPolarity::Negative { word(&mut self.s, "!")?; }