///
/// ### Example
/// ```rust
- /// // Bad
/// println!("");
+ /// ```
///
- /// // Good
+ /// Use instead:
+ /// ```rust
/// println!();
/// ```
#[clippy::version = "pre 1.29.0"]
/// ```rust
/// # use std::fmt::Write;
/// # let mut buf = String::new();
- /// // Bad
/// writeln!(buf, "");
+ /// ```
///
- /// // Good
+ /// Use instead:
+ /// ```rust
+ /// # use std::fmt::Write;
+ /// # let mut buf = String::new();
/// writeln!(buf);
/// ```
#[clippy::version = "pre 1.29.0"]
/// # use std::fmt::Write;
/// # let mut buf = String::new();
/// # let name = "World";
- /// // Bad
/// write!(buf, "Hello {}!\n", name);
+ /// ```
///
- /// // Good
+ /// Use instead:
+ /// ```rust
+ /// # use std::fmt::Write;
+ /// # let mut buf = String::new();
+ /// # let name = "World";
/// writeln!(buf, "Hello {}!", name);
/// ```
#[clippy::version = "pre 1.29.0"]
/// ```rust
/// # use std::fmt::Write;
/// # let mut buf = String::new();
- /// // Bad
/// writeln!(buf, "{}", "foo");
+ /// ```
///
- /// // Good
+ /// Use instead:
+ /// ```rust
+ /// # use std::fmt::Write;
+ /// # let mut buf = String::new();
/// writeln!(buf, "foo");
/// ```
#[clippy::version = "pre 1.29.0"]
if let (Some(fmt_str), expr) = self.check_tts(cx, mac.args.inner_tokens(), true) {
if fmt_str.symbol == kw::Empty {
let mut applicability = Applicability::MachineApplicable;
- // FIXME: remove this `#[allow(...)]` once the issue #5822 gets fixed
- #[allow(clippy::option_if_let_else)]
let suggestion = if let Some(e) = expr {
snippet_with_applicability(cx, e.span, "v", &mut applicability)
} else {
args.push(arg, span);
}
- parser.errors.is_empty().then(move || args)
+ parser.errors.is_empty().then_some(args)
}
/// Checks the arguments of `print[ln]!` and `write[ln]!` calls. It will return a tuple of two
/// ```rust,ignore
/// (Some("string to write: {}"), Some(buf))
/// ```
- #[allow(clippy::too_many_lines)]
fn check_tts<'a>(&self, cx: &EarlyContext<'a>, tts: TokenStream, is_write: bool) -> (Option<StrLit>, Option<Expr>) {
let mut parser = parser::Parser::new(&cx.sess().parse_sess, tts, false, None);
let expr = if is_write {