Skip to content

implicit_return suggestion is invalid syntax #6940

Closed
@rye

Description

@rye

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
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions