Skip to content

Inappropriate warning: unreachable expression in println! #57377

Open
@mizdra

Description

@mizdra

return expression in call params of println! macro causes inappropriate warning message.

I tried this code (ref: Playground):

fn func1() {
    assert_eq!((), return ());
}

fn func2() {
    println!("{}", return ());
}

fn main() {
    func1();
    func2();
}

I expected to print ^^^ against an entire statement:

warning: unreachable expression
 --> src/main.rs:2:5
  |
2 |     assert_eq!((), return ());
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unreachable_code)] on by default
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: unreachable expression
 --> src/main.rs:2:5
  |
2 |     assert_eq!((), return ());
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: unreachable expression
 --> src/main.rs:6:20
  |
6 |     println!("{}", return ());
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^

But, it was printed against an expression instead of a sentence:

warning: unreachable expression
 --> src/main.rs:2:5
  |
2 |     assert_eq!((), return ());
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unreachable_code)] on by default
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: unreachable expression
 --> src/main.rs:2:5
  |
2 |     assert_eq!((), return ());
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: unreachable expression
 --> src/main.rs:6:20
  |
6 |     println!("{}", return ());
  |                    ^^^^^^^^^

Meta

rustc --version --verbose: 1.31.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions