Skip to content

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

@ChrisJefferson

Description

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

Activity

Kampfkarren

Kampfkarren commented on Oct 16, 2019

@Kampfkarren
Contributor

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

ChrisJefferson

ChrisJefferson commented on Oct 16, 2019

@ChrisJefferson
ContributorAuthor

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

Centril commented on Oct 16, 2019

@Centril
Contributor

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

ChrisJefferson commented on Oct 16, 2019

@ChrisJefferson
ContributorAuthor

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.

added
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Oct 16, 2019
changed the title [-]Add easy way to disable "unused" warnings[/-] [+]Make the documentation about `#![allow(unused)]` more visible[/+] on Oct 16, 2019
estebank

estebank commented on Oct 16, 2019

@estebank
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
added
A-diagnosticsArea: Messages for errors, warnings, and lints
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
on Oct 16, 2019
added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Mar 6, 2020
hkBst

hkBst commented on Mar 10, 2025

@hkBst
Member

@estebank I think that is a very good idea! And I'm guessing this should be pretty simple to do, so

@rustbot label -A-docs E-easy

added
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
and removed
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
on Mar 10, 2025
karolzwolak

karolzwolak commented on Mar 21, 2025

@karolzwolak
Member

@rustbot claim

added a commit that references this issue on Aug 14, 2025
f22892b
added a commit that references this issue on Aug 17, 2025
724b908
added a commit that references this issue on Aug 19, 2025
dc37fdf
added 3 commits that reference this issue on Aug 19, 2025
f3fbf39
b9f4ecc
1e6df58
added a commit that references this issue on Aug 20, 2025
1ff2822
added a commit that references this issue on Aug 21, 2025
95f4805
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.C-enhancementCategory: An issue proposing an enhancement or a PR with one.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

    @ChrisJefferson@Centril@estebank@jonas-schievink@Kampfkarren

    Issue actions

      Make the documentation about `#![allow(unused)]` more visible · Issue #65464 · rust-lang/rust