Skip to content

implicit_return suggestion is invalid syntax #6940

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

Closed
rye opened this issue Mar 20, 2021 · 2 comments · Fixed by #6951
Closed

implicit_return suggestion is invalid syntax #6940

rye opened this issue Mar 20, 2021 · 2 comments · Fixed by #6951
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@rye
Copy link

rye commented Mar 20, 2021

I tried this code (from this file, Archive):

pub async fn execute(&mut self) -> Result<()> {
    use std::net::{IpAddr, SocketAddr};

    let socket = {
        use core::convert::TryInto;

        let config: &config::Config = &self.0;

        let host: IpAddr = config
            .get_str("server.host")?
            .parse()
            .map_err(|_| distringo::Error::InvalidServerHost)?;
        let port: u16 = config
            .get_int("server.port")?
            .try_into()
            .map_err(|_| distringo::Error::InvalidServerPort)?;

        SocketAddr::new(host, port)
    };

    warp::serve(routes::routes(&self.0)?).run(socket).await;

    Ok(())
}

I would expect the implicit_return lint to suggest the last line be changed to:

    return Ok(());

Instead, the implicit_return lint produced the suggestion:

warning: missing `return` statement
  --> server/src/server.rs:40:48
   |
40 |       pub async fn execute(&mut self) -> Result<()> {
   |  ___________________________________________________^
41 | |         use std::net::{IpAddr, SocketAddr};
42 | |
43 | |         let socket = {
...  |
62 | |         Ok(())
63 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return
help: add `return` as shown
   |
40 |     pub async fn execute(&mut self) -> Result<()> return {
41 |         use std::net::{IpAddr, SocketAddr};
42 |
43 |         let socket = {
44 |             use core::convert::TryInto;
45 |
 ...

A return before the body isn't accepted by the compiler and seems broken to me.

Meta

For reference, clippy was invoked with:

cargo clippy --all -- -W clippy::restriction -W clippy::pedantic -D clippy::all -D clippy::correctness
  • cargo clippy -V: clippy 0.1.51 (73f48e5 2021-03-18)
    • This also happens with cargo +stable clippy -V: clippy 0.0.212 (cb75ad5 2021-02-10)
  • rustc -Vv:
    rustc 1.51.0-beta.8 (73f48e5f6 2021-03-18)
    binary: rustc
    commit-hash: 73f48e5f6f6217c4bf93026bc0072637966d6eab
    commit-date: 2021-03-18
    host: x86_64-unknown-linux-gnu
    release: 1.51.0-beta.8
    LLVM version: 11.0.1
    
@rye rye added the C-bug Category: Clippy is not doing the correct thing label Mar 20, 2021
@ThibsG

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2021

Error: Label l-suggestion-causes-error can only be set by Rust team members

Please let @rust-lang/release know if you're having trouble with this bot.

@matthiaskrgr matthiaskrgr added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Mar 20, 2021
@bors bors closed this as completed in 5e49c4b Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants