Skip to content

Inappropriate warning: unreachable expression in println! #57377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mizdra opened this issue Jan 6, 2019 · 1 comment
Open

Inappropriate warning: unreachable expression in println! #57377

mizdra opened this issue Jan 6, 2019 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mizdra
Copy link

mizdra commented Jan 6, 2019

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

@estebank estebank added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-diagnostics Area: Messages for errors, warnings, and lints labels Jan 6, 2019
@estebank estebank added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Mar 18, 2019
@estebank
Copy link
Contributor

Current output:

warning: unreachable expression
 --> src/main.rs:2:5
  |
2 |     assert_eq!((), return ());
  |     ^^^^^^^^^^^^^^^---------^^
  |     |              |
  |     |              any code following this expression is unreachable
  |     unreachable expression
  |
  = note: `#[warn(unreachable_code)]` on by default
  = note: this warning 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 ());
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |     |
  |     unreachable expression
  |     any code following this expression is unreachable
  |
  = note: this warning 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 ());
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |     |
  |     unreachable expression
  |     any code following this expression is unreachable
  |
  = note: this warning 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 ());
  |                    ^^^^^^^^^
  |                    |
  |                    unreachable expression
  |                    any code following this expression is unreachable

@crlf0710 crlf0710 added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants