From b130ce032dad84674b646867f6c5bfbf9cb3c145 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Tue, 16 Mar 2021 12:06:41 -0400 Subject: [PATCH] Remove SmallVec --- clippy_lints/src/write.rs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 94025e53e1aa..a9eb00d430aa 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -13,7 +13,6 @@ use rustc_parse::parser; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::{kw, Symbol}; use rustc_span::{sym, BytePos, Span, DUMMY_SP}; -use smallvec::SmallVec; declare_clippy_lint! { /// **What it does:** This lint warns when you use `println!("")` to @@ -358,8 +357,8 @@ fn newline_span(fmtstr: &StrLit) -> Span { /// empty format string. #[derive(Default)] struct SimpleFormatArgs { - unnamed: Vec>, - named: Vec<(Symbol, SmallVec<[Span; 1]>)>, + unnamed: Vec>, + named: Vec<(Symbol, Vec)>, } impl SimpleFormatArgs { fn get_unnamed(&self) -> impl Iterator { @@ -395,11 +394,11 @@ impl SimpleFormatArgs { ArgumentIs(n) | ArgumentImplicitlyIs(n) => { if self.unnamed.len() <= n { // Use a dummy span to mark all unseen arguments. - self.unnamed.resize_with(n, || SmallVec::from([DUMMY_SP])); + self.unnamed.resize_with(n, || vec![DUMMY_SP]); if arg.format == SIMPLE { - self.unnamed.push(SmallVec::from([span])); + self.unnamed.push(vec![span]); } else { - self.unnamed.push(SmallVec::new()); + self.unnamed.push(Vec::new()); } } else { let args = &mut self.unnamed[n]; @@ -409,7 +408,7 @@ impl SimpleFormatArgs { // Replace the dummy span, if it exists. ([dummy @ DUMMY_SP], true) => *dummy = span, ([_, ..], true) => args.push(span), - ([_, ..], false) => *args = SmallVec::new(), + ([_, ..], false) => *args = Vec::new(), } } }, @@ -419,12 +418,12 @@ impl SimpleFormatArgs { // A non-empty format string has been seen already. [] => (), [_, ..] if arg.format == SIMPLE => x.1.push(span), - [_, ..] => x.1 = SmallVec::new(), + [_, ..] => x.1 = Vec::new(), } } else if arg.format == SIMPLE { - self.named.push((n, SmallVec::from([span]))); + self.named.push((n, vec![span])); } else { - self.named.push((n, SmallVec::new())); + self.named.push((n, Vec::new())); } }, }; @@ -435,16 +434,16 @@ impl Write { /// Parses a format string into a collection of spans for each argument. This only keeps track /// of empty format arguments. Will also lint usages of debug format strings outside of debug /// impls. - fn parse_fmt_string(&self, cx: &EarlyContext<'_>, str: &StrLit) -> Option { + fn parse_fmt_string(&self, cx: &EarlyContext<'_>, str_lit: &StrLit) -> Option { use rustc_parse_format::{ParseMode, Parser, Piece}; - let str_sym = str.symbol_unescaped.as_str(); - let style = match str.style { + let str_sym = str_lit.symbol_unescaped.as_str(); + let style = match str_lit.style { StrStyle::Cooked => None, StrStyle::Raw(n) => Some(n as usize), }; - let mut parser = Parser::new(&str_sym, style, snippet_opt(cx, str.span), false, ParseMode::Format); + let mut parser = Parser::new(&str_sym, style, snippet_opt(cx, str_lit.span), false, ParseMode::Format); let mut args = SimpleFormatArgs::default(); while let Some(arg) = parser.next() { @@ -452,7 +451,10 @@ impl Write { Piece::String(_) => continue, Piece::NextArgument(arg) => arg, }; - let span = parser.arg_places.last().map_or(DUMMY_SP, |&x| str.span.from_inner(x)); + let span = parser + .arg_places + .last() + .map_or(DUMMY_SP, |&x| str_lit.span.from_inner(x)); if !self.in_debug_impl && arg.format.ty == "?" { // FIXME: modify rustc's fmt string parser to give us the current span