Skip to content

FP: print_with_newline triggers when there is no println macro #7195

Closed
@DjLogozzo

Description

@DjLogozzo

The clippy lint print_with_newline triggers during scenarios without access to a println macro, such as no_std environments

Lint name:
print_with_newline

I tried this code:

#![no_std]

fn main() {
    print!("Hello World!\n");
    // Replacing print with println, as suggested by the lint, fails to build as there is no println macro
    //println!("Hello World!")
}

#[macro_export]
macro_rules! print {
    ($($arg:tt)*) => {
        unimplemented!()
    }
}

I expected to see this happen:
No lint activation

Instead, this happened:

warning: using `print!()` with a format string that ends in a single newline
 --> src/main.rs:4:5
  |
4 |     print!("Hello World!\n");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(clippy::print_with_newline)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#print_with_newline
help: use `println!` instead
  |
4 |     println!("Hello World!");
  |     ^^^^^^^              --

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.00s

Meta

  • cargo clippy -V: clippy 0.1.52 (9b471a3 2021-02-19)
  • rustc -Vv:
    rustc 1.52.0-nightly (9b471a3f5 2021-02-19)
    binary: rustc
    commit-hash: 9b471a3f5fe57e5c6e08acf665f2094422415a3d
    commit-date: 2021-02-19
    host: x86_64-unknown-linux-gnu
    release: 1.52.0-nightly
    LLVM version: 11.0.1
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions