Called `Option::unwrap()` on a `None` value

I get this macro expansion warning with matklad.rust-analyzer v 0.2.776 with VSCode but not with cargo builld.

If I take out the a and b parameters the macro warning goes away.
Also, if I strip out much of the rest of the code then the warning goes away. Its unclear at what point when I add back in all the rest of my code it trips rust-analyzer into generating this warning for every route get/put/post with an argument.

Any tips on how I can begin to try to debug the issue?

This is the top of my main.rs

#![feature(decl_macro, proc_macro_hygiene)]

#[macro_use]
extern crate rocket;
#[macro_use]
extern crate rocket_contrib;

use rocket::response::Stream;
use rocket_contrib::json::JsonValue;
#[get("/foobar/<a>/<b>")]
fn foobar(a: usize, b: usize) {  // <-- this function is highlighted in red
    println!("foobar {} {}", a, b);
}

when I cargo expand I get

fn foobar(a: usize, b: usize) {
    {
        ::std::io::_print(::core::fmt::Arguments::new_v1(
            &["foobar ", " ", "\n"],
            &match (&a, &b) {
                (arg0, arg1) => [
                    ::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Display::fmt),
                    ::core::fmt::ArgumentV1::new(arg1, ::core::fmt::Display::fmt),
                ],
            },
        ));
    };
}

I stripped out everything I could and still get the warning

::::::::::::::
Cargo.toml
::::::::::::::
[package]
name = "foobar"
version = "0.0.1"
edition = "2018"

[dependencies]
rocket = "0.4"
::::::::::::::
src/main.rs
::::::::::::::
#![feature(decl_macro, proc_macro_hygiene)]
#[macro_use]
extern crate rocket;

#[get("/hello")]
fn status() -> String {
    format!("rust-analyzer No warnings in this function")
}

// Compiles fine but rust-analyzer highlights function with:
// called `Option::unwrap()` on a `None` value

#[get("/foobar/<_a>")]
fn foobar(_a: bool) -> String {
    format!("rust-analyzer Warnings in this function")
}

fn main() {
    rocket::ignite()
        .mount("/", routes![status, foobar])
        .launch();
}

Ok, I was able to change the rust-analyzer extension version back to 2.760 and the warning went away. 2.776 and 2.768 both have this warning. I will open a ticket.

Opened Issue:

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.