Skip to content

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

Closed
@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.

14 remaining items

Loading
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