Skip to content

Unused function warnings should return a span of only the function name #58729

@jackmott

Description

@jackmott

Currently a warning for an unused function returns a span of the entire function. As a consequence, RLS based IDE environments may then put green squiggles on the entire function. This makes it very annoying to work on a function, if you have not yet written the function that uses it.

There may be other unused warnings for structs/traits that could be similarly adjusted.

This issue has been assigned to @Quantumplation via this comment.

Activity

added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
on Feb 26, 2019
sanxiyn

sanxiyn commented on Mar 12, 2019

@sanxiyn
Member

Does it? For me warnings for unused functions only return span of function signatures, not bodies. Is that still annoying? Same for structs.

I think this is somewhat intentional as it is the item that is unused. Spanning the name usually means name resolution failure.

jackmott

jackmott commented on Mar 12, 2019

@jackmott
Author

VSCode ends up highlighting the whole function, so if you are correct this bug should be closed and moved to that repo. How can we verify?

sanxiyn

sanxiyn commented on Mar 13, 2019

@sanxiyn
Member

It would help if you could provide a test case that reproduces the bug, preferably in the following format:

$ cat test.rs
fn f() { /* not in span */ }
fn main() {}
$ rustc test.rs
warning: function is never used: `f`
 --> test.rs:1:1
  |
1 | fn f() { /* not in span */ }
  | ^^^^^^
  |
  = note: #[warn(dead_code)] on by default
added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Aug 6, 2019
estebank

estebank commented on Aug 6, 2019

@estebank
Contributor

Some further details in duplicate #63064

estebank

estebank commented on Oct 18, 2019

@estebank
Contributor

Still reproduces.

added
D-papercutDiagnostics: An error or lint that needs small tweaks.
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
on Oct 18, 2019
Quantumplation

Quantumplation commented on Oct 24, 2019

@Quantumplation
Contributor

@rustbot claim

I'd like to pick this up as my first contribution. @jakubadamw had said (on the duplicate) that he intended to work on this, but it's been a few months, so I'm not sure if he's lost interest or not.

I started to work on this, and I figured first step would be to write a ui test for it. I notice that by now there's a few dead-code related tests. Is there a policy around moving tests to sub folders? If no one objects, I'd like to move all the dead-code related tests to a dead-code subfolder as part of this work as well.

self-assigned this
on Oct 24, 2019
jackmott

jackmott commented on Oct 24, 2019

@jackmott
Author

@Quantumplation I can't speak for the rust maintainers but generally it is greatly preferred to just have one thing per PR. I would do the test organization as a separate pr.

estebank

estebank commented on Oct 24, 2019

@estebank
Contributor

@Quantumplation go for it, in separate commits in the same PR.

jakubadamw

jakubadamw commented on Oct 24, 2019

@jakubadamw
Contributor

@Quantumplation, I didn't really lose interest. While investigating a fix I got blocked by #63091. I think you'll hit it too, though maybe you'll come up with a good idea around it.

Quantumplation

Quantumplation commented on Oct 24, 2019

@Quantumplation
Contributor

@jakubadamw following @estebank's suggestion in the other issue about using ident seems to have circumvented the broken span thing. I'll get a PR up soon in case I'm missing something :) Just gotta wait for these 9207 tests to run... 😛

Quantumplation

Quantumplation commented on Oct 24, 2019

@Quantumplation
Contributor

@estebank Do you think I should use the ident span for other constructs as well (struct, enum, etc?) Or keep it to just functions?

estebank

estebank commented on Oct 24, 2019

@estebank
Contributor

@Quantumplation we should prefer the ident span whenever possible, but be mindful of the output, as there are some cases where pointing at just the ident might be misleading (like when talking about lifetimes or wanting to point at the whole enclosing span). I think almost all cases where we use def_span(span) can be replaced with pointing at the ident's span.

Quantumplation

Quantumplation commented on Oct 24, 2019

@Quantumplation
Contributor

@estebank I'm only going to focus on the dead-code case, and if you think it's worth it, i'll follow up with a more extensive PR where I evaluate other def_span cases for replacement. Want to keep my first contribution small :)

added 2 commits that reference this issue on Oct 26, 2019
0cd12d3
838ed89
added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
and removed
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
on Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.D-papercutDiagnostics: An error or lint that needs small tweaks.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @sanxiyn@Quantumplation@estebank@jonas-schievink@jackmott

    Issue actions

      Unused function warnings should return a span of only the function name · Issue #58729 · rust-lang/rust