Auto merge of #5897 - matthiaskrgr:no_clone_tts, r=flip1995
write.rs: don't clone TokenStream changelog: none
This commit is contained in:
commit
dc1e09bdc1
@ -237,7 +237,7 @@ impl EarlyLintPass for Write {
|
|||||||
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &MacCall) {
|
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &MacCall) {
|
||||||
if mac.path == sym!(println) {
|
if mac.path == sym!(println) {
|
||||||
span_lint(cx, PRINT_STDOUT, mac.span(), "use of `println!`");
|
span_lint(cx, PRINT_STDOUT, mac.span(), "use of `println!`");
|
||||||
if let (Some(fmt_str), _) = self.check_tts(cx, &mac.args.inner_tokens(), false) {
|
if let (Some(fmt_str), _) = self.check_tts(cx, mac.args.inner_tokens(), false) {
|
||||||
if fmt_str.symbol == Symbol::intern("") {
|
if fmt_str.symbol == Symbol::intern("") {
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
@ -252,7 +252,7 @@ impl EarlyLintPass for Write {
|
|||||||
}
|
}
|
||||||
} else if mac.path == sym!(print) {
|
} else if mac.path == sym!(print) {
|
||||||
span_lint(cx, PRINT_STDOUT, mac.span(), "use of `print!`");
|
span_lint(cx, PRINT_STDOUT, mac.span(), "use of `print!`");
|
||||||
if let (Some(fmt_str), _) = self.check_tts(cx, &mac.args.inner_tokens(), false) {
|
if let (Some(fmt_str), _) = self.check_tts(cx, mac.args.inner_tokens(), false) {
|
||||||
if check_newlines(&fmt_str) {
|
if check_newlines(&fmt_str) {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
@ -273,7 +273,7 @@ impl EarlyLintPass for Write {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if mac.path == sym!(write) {
|
} else if mac.path == sym!(write) {
|
||||||
if let (Some(fmt_str), _) = self.check_tts(cx, &mac.args.inner_tokens(), true) {
|
if let (Some(fmt_str), _) = self.check_tts(cx, mac.args.inner_tokens(), true) {
|
||||||
if check_newlines(&fmt_str) {
|
if check_newlines(&fmt_str) {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
@ -294,7 +294,7 @@ impl EarlyLintPass for Write {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if mac.path == sym!(writeln) {
|
} else if mac.path == sym!(writeln) {
|
||||||
if let (Some(fmt_str), expr) = self.check_tts(cx, &mac.args.inner_tokens(), true) {
|
if let (Some(fmt_str), expr) = self.check_tts(cx, mac.args.inner_tokens(), true) {
|
||||||
if fmt_str.symbol == Symbol::intern("") {
|
if fmt_str.symbol == Symbol::intern("") {
|
||||||
let mut applicability = Applicability::MachineApplicable;
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
let suggestion = expr.map_or_else(
|
let suggestion = expr.map_or_else(
|
||||||
@ -364,17 +364,11 @@ impl Write {
|
|||||||
/// (Some("string to write: {}"), Some(buf))
|
/// (Some("string to write: {}"), Some(buf))
|
||||||
/// ```
|
/// ```
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
fn check_tts<'a>(
|
fn check_tts<'a>(&self, cx: &EarlyContext<'a>, tts: TokenStream, is_write: bool) -> (Option<StrLit>, Option<Expr>) {
|
||||||
&self,
|
|
||||||
cx: &EarlyContext<'a>,
|
|
||||||
tts: &TokenStream,
|
|
||||||
is_write: bool,
|
|
||||||
) -> (Option<StrLit>, Option<Expr>) {
|
|
||||||
use rustc_parse_format::{
|
use rustc_parse_format::{
|
||||||
AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, ParseMode, Parser,
|
AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, ParseMode, Parser,
|
||||||
Piece,
|
Piece,
|
||||||
};
|
};
|
||||||
let tts = tts.clone();
|
|
||||||
|
|
||||||
let mut parser = parser::Parser::new(&cx.sess.parse_sess, tts, false, None);
|
let mut parser = parser::Parser::new(&cx.sess.parse_sess, tts, false, None);
|
||||||
let mut expr: Option<Expr> = None;
|
let mut expr: Option<Expr> = None;
|
||||||
|
Loading…
Reference in New Issue
Block a user