rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.17k stars 1.58k forks source link

Classify the `main` function as used #8603

Closed GopherJ closed 3 years ago

GopherJ commented 3 years ago

hi, I still have this while calling codelens run:

Screen Shot 2021-04-20 at 11 51 05 PM

is it possible to remove it?

lnicola commented 3 years ago

Do you have rust-analyzer.lens.methodReferences disabled?

GopherJ commented 3 years ago

@lnicola how should I disable this one in coc-rust-analyzer? I'd like to try

lnicola commented 3 years ago

https://github.com/fannheyward/coc-rust-analyzer#configurations.

GopherJ commented 3 years ago

Ok I understood what do you mean, actually I still want tto keep method reference in other places but remove it from the list of code lens run

lnicola commented 3 years ago

In Code all three lenses items (Run, Debug, references) are clickable and have an associated action. I guess we could do one or both of:

GopherJ commented 3 years ago

I prefer the first one

Veykril commented 3 years ago

I also think the first one is a better idea, when a function has no references seeing the 0 references still gives the user the information that that function isn't referenced.

So we have to filter out the main function here https://github.com/rust-analyzer/rust-analyzer/blob/70fe7a4515ebdc6222a6565cd4cd1c5fd0c77350/crates/ide/src/annotations.rs#L143-L151, that is if the function is called "main" and defined inside the root module.

flodiebold commented 3 years ago

What if we are calling the main function though?

GopherJ commented 3 years ago

@flodiebold which case will we call main function?

lnicola commented 3 years ago

When it's recursive, for example. That's disallowed in C, but not in Rust AFAIK.

Or in no_std / no_main code.

flodiebold commented 3 years ago

It just doesn't seem worth special-casing to me. I wouldn't expect the fact that main is the entry point to have an effect on the "X references", just like for some function exported from a library.

lnicola commented 3 years ago

Yeah, I don't see this warranting a special case.