Skip to content
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

Make the documentation about #![allow(unused)] more visible #65464

Open
ChrisJefferson opened this issue Oct 16, 2019 · 5 comments
Open

Make the documentation about #![allow(unused)] more visible #65464

ChrisJefferson opened this issue Oct 16, 2019 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ChrisJefferson
Copy link
Contributor

I like to build functions as a series of parts, for example I might write the following skeleton, then plan to fill in the loop

fn sorter(x: Vec<Vec<isize>>, modifier: bool) -> Vec<isize> {
    let mut out = vec![];
    for i in x {
   
    }
    out
}

If I run a cargo check on this, just to check for typos, I get:

warning: unused variable: `i`
  --> src/playgame.rs:35:9
   |
35 |     for i in x {}
   |         ^ help: consider prefixing with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `modifier`
  --> src/playgame.rs:33:31
   |
33 | fn sorter(x: Vec<Vec<isize>>, modifier: bool) -> Vec<isize> {
   |                               ^^^^^^^^ help: consider prefixing with an underscore: `_modifier`

warning: variable does not need to be mutable
  --> src/playgame.rs:34:9
   |
34 |     let mut out = vec![];
   |         ----^^^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: function is never used: `sorter`
  --> src/playgame.rs:33:1
   |
33 | fn sorter(x: Vec<Vec<isize>>, modifier: bool) -> Vec<isize> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

I feel it should be possible to encapsulate a set of warnings which represent "unused/dead", and have a way of disabling them while developing. I realise this could be abused by some people, but I find it hard to spot the important issues between these unused/dead issues while developing.

@Kampfkarren
Copy link
Contributor

Kampfkarren commented Oct 16, 2019

#![allow(dead_code)] at the root of your crate 🙂

@ChrisJefferson
Copy link
Contributor Author

I tried this (should have said), but I ended up with:

#![allow(dead_code)]
#![allow(unused_assignments)]
#![allow(unused_attributes)]
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(unused_mut)]
#![allow(unused_variables)]

And then, I also had to remember to go remove them all every so often, as I don't want these enabling forever, just while writing a new function.

Perhaps (I'll be honest, I'm maybe not positive what I want), I want a way to disable lints easily while initially making a function, then linting once I think I've got a valid piece of finished(ish) code.

@Centril
Copy link
Contributor

Centril commented Oct 16, 2019

There's always #![allow(unused)] to disable the whole group.

Perhaps (I'll be honest, I'm maybe not positive what I want), I want a way to disable lints easily while initially making a function, then linting once I think I've got a valid piece of finished(ish) code.

I don't think there's anything actionable here yet.

@ChrisJefferson
Copy link
Contributor Author

That is, I think, what I want. That's not too much work to add and remove.

I hadn't found that there was a way of grouping together lints (I had tried googling, but I obviously did hit it). I'm not sure if there is a good way of making this more visible.

@Centril Centril added A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Oct 16, 2019
@Centril Centril changed the title Add easy way to disable "unused" warnings Make the documentation about #![allow(unused)] more visible Oct 16, 2019
@estebank
Copy link
Contributor

@Centril we could rework the lint output to be

warning: unused variable: `i`
  --> src/playgame.rs:35:9
   |
35 |     for i in x {}
   |         ^ help: consider prefixing with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` (implied by `#[warn(unused)]`) on by default

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. labels Oct 16, 2019
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants