///
/// **Example:**
/// ```rust
+ /// // Bad
/// println!("");
+ ///
+ /// // Good
+ /// println!();
/// ```
pub PRINTLN_EMPTY_STRING,
style,
declare_clippy_lint! {
/// **What it does:** This lint warns when you use `print!()` with a format
- /// string that
- /// ends in a newline.
+ /// string that ends in a newline.
///
/// **Why is this bad?** You should use `println!()` instead, which appends the
/// newline.
/// ```rust
/// # use std::fmt::Write;
/// # let mut buf = String::new();
+ ///
+ /// // Bad
/// writeln!(buf, "");
+ ///
+ /// // Good
+ /// writeln!(buf);
/// ```
pub WRITELN_EMPTY_STRING,
style,
/// # use std::fmt::Write;
/// # let mut buf = String::new();
/// # let name = "World";
+ ///
+ /// // Bad
/// write!(buf, "Hello {}!\n", name);
+ ///
+ /// // Good
+ /// writeln!(buf, "Hello {}!", name);
/// ```
pub WRITE_WITH_NEWLINE,
style,
/// ```rust
/// # use std::fmt::Write;
/// # let mut buf = String::new();
+ ///
+ /// // Bad
/// writeln!(buf, "{}", "foo");
+ ///
+ /// // Good
+ /// writeln!(buf, "foo");
/// ```
pub WRITE_LITERAL,
style,
if fmt_str.symbol == Symbol::intern("") {
let mut applicability = Applicability::MachineApplicable;
let suggestion = expr.map_or_else(
- move || {
+ || {
applicability = Applicability::HasPlaceholders;
Cow::Borrowed("v")
},
- move |expr| snippet_with_applicability(cx, expr.span, "v", &mut applicability),
+ |e| snippet_with_applicability(cx, e.span, "v", &mut Applicability::MachineApplicable),
);
span_lint_and_sugg(
tts: &TokenStream,
is_write: bool,
) -> (Option<StrLit>, Option<Expr>) {
- use fmt_macros::{
- AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, Parser, Piece,
+ use rustc_parse_format::{
+ AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, ParseMode, Parser,
+ Piece,
};
let tts = tts.clone();
};
let tmp = fmtstr.symbol.as_str();
let mut args = vec![];
- let mut fmt_parser = Parser::new(&tmp, None, Vec::new(), false);
+ let mut fmt_parser = Parser::new(&tmp, None, None, false, ParseMode::Format);
while let Some(piece) = fmt_parser.next() {
if !fmt_parser.errors.is_empty() {
return (None, expr);
};
match fmtstr.style {
- StrStyle::Cooked => unescape::unescape_str(contents, &mut cb),
- StrStyle::Raw(_) => unescape::unescape_raw_str(contents, &mut cb),
+ StrStyle::Cooked => unescape::unescape_literal(contents, unescape::Mode::Str, &mut cb),
+ StrStyle::Raw(_) => unescape::unescape_literal(contents, unescape::Mode::RawStr, &mut cb),
}
should_lint