Skip to content

Called Option::unwrap() on a None value, warning in simple hello world Rocket app #10570

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
Tracked by #11387 ...
joemooney opened this issue Oct 18, 2021 · 18 comments · Fixed by #11797
Closed
Tracked by #11387 ...

Called Option::unwrap() on a None value, warning in simple hello world Rocket app #10570

joemooney opened this issue Oct 18, 2021 · 18 comments · Fixed by #11797
Assignees
Labels
A-macro macro expansion Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@joemooney
Copy link

This compiles and runs fine but there is a rust-analyzer warning present in 2.776 and 2.768 but not in 2.760 and earlier versions of rust-analyzer.

 ::::::::::::::
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();
}
@bjorn3
Copy link
Member

bjorn3 commented Oct 18, 2021

Which rustc version do you use?

@lnicola
Copy link
Member

lnicola commented Oct 18, 2021

Can reproduce in rustc 1.57.0-nightly (a8f2463c6 2021-10-09).

@lnicola
Copy link
Member

lnicola commented Oct 18, 2021

This doesn't look like our panic. We might be missing some part of the Span API, causing a crash inside the proc macro.

@lnicola lnicola added A-macro macro expansion C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now labels Oct 18, 2021
@ripxorip
Copy link

This is happening to me as well using rust-analyzer 2021-11-08 on arch

@lnicola
Copy link
Member

lnicola commented Nov 12, 2021

Possibly a dupe of #10710.

@MiroFurtado
Copy link

This is still occurring on latest nightly release.

@Tamschi
Copy link

Tamschi commented Dec 25, 2021

Here's a smaller reproduction that builds on stable Rust 1.57.0:

[package]
name = "macro-test"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
# Needed because `unquote`'s syn dependency isn't set up correctly. It's hopefully not relevant.
proc_macro = true

[dependencies]
quote = "1.0.10"
syn = "1.0.83"
unquote = "0.0.6"
use quote::quote;
use syn::parse::ParseStream;
use unquote::unquote;

#[allow(dead_code)]
fn parse(input: ParseStream) -> syn::Result<()> {
    unquote!(input, a); // <--
    Ok(())
}

Settings (not minimal):

{
    "rust-analyzer.cargo-watch.command": "clippy",
    "rust-analyzer.rainbowHighlightingOn": true,
    "rust-analyzer.procMacro.enabled": true,
    "rust-analyzer.procMacro.enable": true,
    "rust-analyzer.cargo.loadOutDirsFromCheck": true,
    "rust-analyzer.checkOnSave.command": "clippy",
    "rust-analyzer.experimental.procAttrMacros": true,
    "rust-analyzer.cargo.allFeatures": true,
    "rust-analyzer.checkOnSave.extraArgs": [
        "--locked"
    ],
    "rust-analyzer.updates.channel": "nightly"
}

cargo expand:

Probably not relevant, but it's a fairly simple macro:
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
use quote::quote;
use syn::parse::ParseStream;
use unquote::unquote;
#[allow(dead_code)]
fn parse(input: ParseStream) -> syn::Result<()> {
    let input = input;
    let mut prev_span = input.cursor().span();
    if input.call(<syn::Ident as syn::ext::IdentExt>::parse_any)?
        != syn::parse::Parser::parse2(<syn::Ident as syn::ext::IdentExt>::parse_any, {
            let mut _s = ::quote::__private::TokenStream::new();
            ::quote::__private::push_ident(&mut _s, "a");
            _s
        })
        .unwrap()
    {
        return Err(syn::Error::new(input.cursor().span(), "Expected `a`"));
    };
    Ok(())
}
const _: () = {
    extern crate proc_macro;
    #[rustc_proc_macro_decls]
    #[allow(deprecated)]
    static _DECLS: &[proc_macro::bridge::client::ProcMacro] = &[];
};

Error:

[{
	"resource": "[project directory]/src/lib.rs",
	"owner": "rustc",
	"code": {
		"value": "macro-error",
		"target": {
			"$mid": 1,
			"external": "https://rust-analyzer.github.io/manual.html#macro-error",
			"path": "/manual.html",
			"scheme": "https",
			"authority": "rust-analyzer.github.io",
			"fragment": "macro-error"
		}
	},
	"severity": 8,
	"message": "called `Option::unwrap()` on a `None` value",
	"source": "rust-analyzer",
	"startLineNumber": 7,
	"startColumn": 5,
	"endLineNumber": 7,
	"endColumn": 23
}]

Rust Analyzer Client output (abbreviated):

INFO [25.12.2021, 18:38:34]: Extension version: 0.3.875
INFO [25.12.2021, 18:38:34]: Using configuration {
  […]
}
INFO [25.12.2021, 18:38:34]: PersistentState: { serverVersion: '0.3.875' }
INFO [25.12.2021, 18:38:34]: Using server binary at [~]\.vscode\extensions\matklad.rust-analyzer-0.3.875\server\rust-analyzer.exe

Rust Analyzer Language Server Trace appears to be empty.

@oren0e
Copy link

oren0e commented Dec 28, 2021

Hi, I am having this same issue with rocket. I use rustc 1.56.0-nightly (0035d9dce 2021-08-16) with coc-rust-analyzer 0.57.0. Any updates on a fix?

@lnicola
Copy link
Member

lnicola commented Dec 28, 2021

@MiroFurtado, @Tamschi, @oren0e see #10710 (comment).

Updating to a newer version of Rocket might fix it.

@Tamschi
Copy link

Tamschi commented Dec 28, 2021

@MiroFurtado, @Tamschi, @oren0e see #10710 (comment).

Updating to a newer version of Rocket might fix it.

I'm not using Rocket and I'm on stable, so that's not the issue/fix for me, unfortunately.

@Tamschi
Copy link

Tamschi commented Dec 28, 2021

(A separate comment since @lnicola already saw the previous reply.)

Should I open a separate issue?
It looks like my problem is likely unrelated then, if this error message can be caused by not implemented endpoints generally.

@oren0e
Copy link

oren0e commented Dec 29, 2021

@MiroFurtado, @Tamschi, @oren0e see #10710 (comment).

Updating to a newer version of Rocket might fix it.

Unfortunately I can't use the rc version of rocket for various stability and dependency reasons, so that fix is not for me either (I use rocket 0.4.10). Any chance to work it out in rust-analyzer itself?

@zojize
Copy link

zojize commented Jan 11, 2022

this also occurred to me with realworld-rust-rocket. Any updates?

@jonas-schievink jonas-schievink added the Broken Window Bugs / technical debt to be addressed immediately label Jan 27, 2022
@lnicola lnicola mentioned this issue Jan 31, 2022
15 tasks
@nbittich
Copy link

Same Here.
nightly-x86_64-unknown-linux-gnu (default)
rustc 1.60.0-nightly (09cb29c64 2022-02-15)

@bors bors bot closed this as completed in cdd1477 Mar 23, 2022
@jonas-schievink
Copy link
Contributor

I hope #11797 has properly fixed this. If not, please leave a comment.

@oren0e
Copy link

oren0e commented Mar 23, 2022

Not for me. I still have

macro-error: called Option::unwrap() on a None value

error in my vim (I use coc.nvim with rust-analyzer) on each one of my endpoints with rocket

@jonas-schievink
Copy link
Contributor

Presumably because of the same issue as #10772 (comment)

@jonas-schievink
Copy link
Contributor

@oren0e If you're still using the same nightly version as in #10570 (comment), it is quite outdated. We can't reasonably support outdated nightly versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.