Skip to content

dead code lint to say "never constructed" for variants - #46103

Merged
bors merged 1 commit into
rust-lang:masterfrom
zackmdavis:dead_code_lint_should_say_never_constructed_for_variants
Nov 21, 2017
Merged

dead code lint to say "never constructed" for variants#46103
bors merged 1 commit into
rust-lang:masterfrom
zackmdavis:dead_code_lint_should_say_never_constructed_for_variants

Conversation

@zackmdavis

Copy link
Copy Markdown
Contributor

As reported in #19140, #44083, and #44565, some users were confused when
the dead-code lint reported an enum variant to be "unused" when it was
matched on (but not constructed). This wording change makes it clearer
that the lint is in fact checking for construction.

We continue to say "used" for all other items (it's tempting to say
"called" for functions and methods, but this turns out not to be
correct: functions can be passed as arguments and the dead-code lint
isn't special-casing that or anything).

Resolves#19140.

r? @pnkfelix

As reported in rust-lang#19140, rust-lang#44083, and rust-lang#44565, some users were confused when
the dead-code lint reported an enum variant to be "unused" when it was
matched on (but not constructed). This wording change makes it clearer
that the lint is in fact checking for construction.
We continue to say "used" for all other items (it's tempting to say
"called" for functions and methods, but this turns out not to be
correct: functions can be passed as arguments and the dead-code lint
isn't special-casing that or anything).
Resolvesrust-lang#19140.
@nagisa

Copy link
Copy Markdown
Member

We continue to say "used" for all other items (it's tempting to say
"called" for functions and methods, but this turns out not to be
correct: functions can be passed as arguments and the dead-code lint
isn't special-casing that or anything).

Same also is true for enum variants though. Much like with functions:

enum Foo {
A(usize),
}
fn main() {
drop::<fn(usize)->Foo>(Foo::A);
}

will not warn, despite the enum variant never having been constructed. It might be worthwhile to find some other wording.

e.g. rather than saying that enum variant is never used, say that the enum variant constructor is never used or something?

@kennytmkennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 20, 2017
@arielb1

Copy link
Copy Markdown
Contributor

@nagisa

This is a static analysis, so it can never be 100% precise (see if false { Foo::A(0) }).

I think "variant is never constructed" is a fluent way of saying "variant constructor is never used".

@bors r+

@bors

bors commented Nov 20, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 1a9dc2e has been approved by arielb1

@kennytmkennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 21, 2017
@kennytmkennytm mentioned this pull request Nov 21, 2017
kennytm added a commit to kennytm/rust that referenced this pull request Nov 21, 2017
…y_never_constructed_for_variants, r=arielb1
dead code lint to say "never constructed" for variants
As reported in rust-lang#19140, rust-lang#44083, and rust-lang#44565, some users were confused when
the dead-code lint reported an enum variant to be "unused" when it was
matched on (but not constructed). This wording change makes it clearer
that the lint is in fact checking for construction.
We continue to say "used" for all other items (it's tempting to say
"called" for functions and methods, but this turns out not to be
correct: functions can be passed as arguments and the dead-code lint
isn't special-casing that or anything).
Resolvesrust-lang#19140.
r? @pnkfelix
@kennytmkennytm mentioned this pull request Nov 21, 2017
bors added a commit that referenced this pull request Nov 21, 2017
Rollup of 11 pull requests
- Successful merges: #45987, #46031, #46050, #46052, #46103, #46120, #46134, #46141, #46148, #46155, #46157
- Failed merges:
@bors
bors merged commit 1a9dc2e into rust-lang:masterNov 21, 2017
@zackmdavis
zackmdavis deleted the dead_code_lint_should_say_never_constructed_for_variants branch January 13, 2018 07:41
zackmdavis added a commit to zackmdavis/rust that referenced this pull request Jul 13, 2018
Respectively.
This is a sequel to November 2017's rust-lang#46103 / 1a9dc2e. It had been
reported (more than once—at least rust-lang#19140, rust-lang#44083, and rust-lang#44565) that the
"never used" language was confusing for enum variants that were "used"
as match patterns, so the wording was changed to say never "constructed"
specifically for enum variants. More recently, the same issue was raised
for structs (rust-lang#52325). It seems consistent to say "constructed" here,
too, for the same reasons.
While we're here, we can also use more specific word "called" for unused
functions and methods. (We declined to do this in rust-lang#46103, but the
rationale given in the commit message doesn't actually make sense.)
This resolvesrust-lang#52325.
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jul 13, 2018
…y_2_electric_boogaloo, r=pnkfelix
dead-code lint: say "constructed", "called" for structs, functions
Respectively.
This is a sequel to November 2017's rust-lang#46103 / 1a9dc2e. It had been
reported (more than once—at least rust-lang#19140, rust-lang#44083, and rust-lang#44565) that the
"never used" language was confusing for enum variants that were "used"
as match patterns, so the wording was changed to say never "constructed"
specifically for enum variants. More recently, the same issue was raised
for structs (rust-lang#52325). It seems consistent to say "constructed" here,
too, for the same reasons.
While we're here, we can also use more specific word "called" for unused
functions and methods. (We declined to do this in rust-lang#46103, but the
rationale given in the commit message doesn't actually make sense.)
This resolvesrust-lang#52325.
zackmdavis added a commit to zackmdavis/rust that referenced this pull request Jul 22, 2018
This is a sequel to November 2017's rust-lang#46103 / 1a9dc2e. It had been
reported (more than once—at least rust-lang#19140, rust-lang#44083, and rust-lang#44565) that the
"never used" language was confusing for enum variants that were "used"
as match patterns, so the wording was changed to say never
"constructed" specifically for enum variants. More recently, the same
issue was raised for structs (rust-lang#52325). It seems consistent to say
"constructed" here, too, for the same reasons.
We considered using more specific word "called" for unused functions
and methods (while we declined to do this in rust-lang#46103, the rationale
given in the commit message doesn't actually make sense), but it turns
out that Cargo's test suite expects the "never used" message, and
maybe we don't care enough even to make a Cargo PR over such a petty
and subjective wording change.
This resolvesrust-lang#52325.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 31, 2018
…y_2_electric_boogaloo, r=pnkfelix
dead-code lint: say "constructed" for structs
Respectively.
This is a sequel to November 2017's rust-lang#46103 / 1a9dc2e. It had been
reported (more than once—at least rust-lang#19140, rust-lang#44083, and rust-lang#44565) that the
"never used" language was confusing for enum variants that were "used"
as match patterns, so the wording was changed to say never "constructed"
specifically for enum variants. More recently, the same issue was raised
for structs (rust-lang#52325). It seems consistent to say "constructed" here,
too, for the same reasons.
~~While we're here, we can also use more specific word "called" for unused
functions and methods. (We declined to do this in rust-lang#46103, but the
rationale given in the commit message doesn't actually make sense.)~~
This resolvesrust-lang#52325.
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Aug 1, 2018
…y_2_electric_boogaloo, r=pnkfelix
dead-code lint: say "constructed" for structs
Respectively.
This is a sequel to November 2017's rust-lang#46103 / 1a9dc2e. It had been
reported (more than once—at least rust-lang#19140, rust-lang#44083, and rust-lang#44565) that the
"never used" language was confusing for enum variants that were "used"
as match patterns, so the wording was changed to say never "constructed"
specifically for enum variants. More recently, the same issue was raised
for structs (rust-lang#52325). It seems consistent to say "constructed" here,
too, for the same reasons.
~~While we're here, we can also use more specific word "called" for unused
functions and methods. (We declined to do this in rust-lang#46103, but the
rationale given in the commit message doesn't actually make sense.)~~
This resolvesrust-lang#52325.
bors added a commit that referenced this pull request Aug 6, 2018
…c_boogaloo, r=pnkfelix
dead-code lint: say "constructed" for structs
Respectively.
This is a sequel to November 2017's #46103 / 1a9dc2e. It had been
reported (more than once—at least #19140, #44083, and #44565) that the
"never used" language was confusing for enum variants that were "used"
as match patterns, so the wording was changed to say never "constructed"
specifically for enum variants. More recently, the same issue was raised
for structs (#52325). It seems consistent to say "constructed" here,
too, for the same reasons.
~~While we're here, we can also use more specific word "called" for unused
functions and methods. (We declined to do this in #46103, but the
rationale given in the commit message doesn't actually make sense.)~~
This resolves#52325.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@zackmdavis@nagisa@arielb1@bors@kennytm@pnkfelix