Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5d9eeff
Ensure TLS destructors run before thread joins in SGX
mzohreva Apr 21, 2021
8a0a4b1
Use atomics in join_orders_after_tls_destructors test
mzohreva Apr 29, 2021
fe68b1a
Fix linker_args with --target=sparcv9-sun-solaris
iladin Apr 30, 2021
50c3890
bump deps
klensy May 1, 2021
0b0d293
Report coverage `0` of dead blocks
richkadel May 1, 2021
3fca198
Move coverage tests from run-make-fulldeps to run-make
richkadel May 1, 2021
dd43d13
Reduce duplication in `impl_dep_tracking_hash` macros
jyn514 Apr 22, 2021
1e89b58
Account for unsatisfied bounds in E0599
estebank May 2, 2021
2e559c8
use `else if` in std library
wcampbell0x2a May 3, 2021
b4bfb0e
Update RELEASES.md for 1.52.0
XAMPPRocky Apr 14, 2021
f9eda61
rustbuild: Pass a `threads` flag that works to windows-gnu lld
petrochenkov May 3, 2021
03c763e
manually crafted revert of PR #80653, to address issue #82465.
pnkfelix May 3, 2021
86e3f76
regression test for issue 82465.
pnkfelix May 3, 2021
d53469c
Clarify documentation for `[T]::contains`. Fixes #84877.
jimblandy May 3, 2021
d459b5d
platform-support: Center the contents of the `std` and `host` columns
joshtriplett May 3, 2021
389333a
Update `ptr` docs with regards to `ptr::addr_of!`
jfrimmel Mar 27, 2021
450d121
Tests for field is never read diagnostic
sunjay Mar 11, 2021
67f228e
Added suggestion and note for when a field is never used
sunjay Mar 12, 2021
715a2d4
Updating test stderr files
sunjay Mar 12, 2021
d4c1ade
Trying out a new message that works a little better for values *and* …
sunjay Mar 12, 2021
bacfc34
New shorter diagnostic note that is different for items versus fields
sunjay Mar 13, 2021
0ba2c6a
Putting help message only under the identifier that needs to be prefixed
sunjay Mar 25, 2021
11379f0
Do not ICE on invalid const param
estebank May 4, 2021
a99ff06
Rollup merge of #83004 - sunjay:field-never-read-issue-81658, r=pnkfelix
Dylan-DPC May 4, 2021
ed33dd1
Rollup merge of #83553 - jfrimmel:addr-of, r=m-ou-se
Dylan-DPC May 4, 2021
8955013
Rollup merge of #84183 - rust-lang:relnotes-1.52.0, r=pietroalbini
Dylan-DPC May 4, 2021
f8296b8
Rollup merge of #84409 - mzohreva:mz/tls-dtors-before-join, r=dtolnay
Dylan-DPC May 4, 2021
89f9b08
Rollup merge of #84468 - iladin:iladin/fix-84467, r=petrochenkov
Dylan-DPC May 4, 2021
6d6121a
Rollup merge of #84787 - klensy:deps-bump, r=Mark-Simulacrum
Dylan-DPC May 4, 2021
f189603
Rollup merge of #84797 - richkadel:cover-unreachable-statements, r=tm…
Dylan-DPC May 4, 2021
57ec93a
Rollup merge of #84803 - jyn514:duplicate-macros, r=petrochenkov
Dylan-DPC May 4, 2021
df55085
Rollup merge of #84808 - estebank:issue-84769, r=petrochenkov
Dylan-DPC May 4, 2021
7153b3d
Rollup merge of #84843 - wcampbell0x2a:use-else-if-let, r=dtolnay
Dylan-DPC May 4, 2021
755a3a4
Rollup merge of #84865 - petrochenkov:llthread, r=Mark-Simulacrum
Dylan-DPC May 4, 2021
f651a5f
Rollup merge of #84867 - pnkfelix:rustdoc-revert-deref-recur, r=jyn514
Dylan-DPC May 4, 2021
47b6b34
Rollup merge of #84878 - jimblandy:contains-doc-fix, r=joshtriplett
Dylan-DPC May 4, 2021
0b861df
Rollup merge of #84882 - joshtriplett:platform-support-formatting, r=…
Dylan-DPC May 4, 2021
5d8f6ff
Rollup merge of #84913 - estebank:issue-84831, r=varkor
Dylan-DPC May 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Putting help message only under the identifier that needs to be prefixed
  • Loading branch information
sunjay committed May 4, 2021
commit 0ba2c6afa9b4d5f0db36ea2a9f71db0c125040b1
28 changes: 11 additions & 17 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_middle::middle::privacy;
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
use rustc_session::lint;

use rustc_span::symbol::{sym, Symbol};
use rustc_span::symbol::{sym, Ident, Symbol};

// Any local node that may call something in its body block should be
// explored. For example, if it's a live Node::Item that is a
Expand Down Expand Up @@ -580,7 +580,7 @@ impl DeadVisitor<'tcx> {
&mut self,
id: hir::HirId,
span: rustc_span::Span,
name: Symbol,
name: Ident,
participle: &str,
extra_note: Option<ExtraNote>,
) {
Expand All @@ -589,7 +589,7 @@ impl DeadVisitor<'tcx> {
let def_id = self.tcx.hir().local_def_id(id);
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());

let prefixed = vec![(span, format!("_{}", name))];
let prefixed = vec![(name.span, format!("_{}", name))];

let mut diag =
lint.build(&format!("{} is never {}: `{}`", descr, participle, name));
Expand All @@ -602,11 +602,11 @@ impl DeadVisitor<'tcx> {

let mut note = format!(
"the leading underscore signals that this {} serves some other \
purpose\neven if it isn't used in a way that we can detect.",
purpose even if it isn't used in a way that we can detect.",
descr,
);
if matches!(extra_note, Some(ExtraNote::OtherPurposeExamples)) {
note += " (e.g. for its effect\nwhen dropped or in foreign code)";
note += " (e.g. for its effect when dropped or in foreign code)";
}

diag.note(&note);
Expand Down Expand Up @@ -661,7 +661,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
hir::ItemKind::Struct(..) => "constructed", // Issue #52325
_ => "used",
};
self.warn_dead_code(item.hir_id(), span, item.ident.name, participle, None);
self.warn_dead_code(item.hir_id(), span, item.ident, participle, None);
} else {
// Only continue if we didn't warn
intravisit::walk_item(self, item);
Expand All @@ -675,15 +675,15 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
id: hir::HirId,
) {
if self.should_warn_about_variant(&variant) {
self.warn_dead_code(variant.id, variant.span, variant.ident.name, "constructed", None);
self.warn_dead_code(variant.id, variant.span, variant.ident, "constructed", None);
} else {
intravisit::walk_variant(self, variant, g, id);
}
}

fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem<'tcx>) {
if self.should_warn_about_foreign_item(fi) {
self.warn_dead_code(fi.hir_id(), fi.span, fi.ident.name, "used", None);
self.warn_dead_code(fi.hir_id(), fi.span, fi.ident, "used", None);
}
intravisit::walk_foreign_item(self, fi);
}
Expand All @@ -693,7 +693,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
self.warn_dead_code(
field.hir_id,
field.span,
field.ident.name,
field.ident,
"read",
Some(ExtraNote::OtherPurposeExamples),
);
Expand All @@ -708,7 +708,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
self.warn_dead_code(
impl_item.hir_id(),
impl_item.span,
impl_item.ident.name,
impl_item.ident,
"used",
None,
);
Expand All @@ -728,13 +728,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
} else {
impl_item.ident.span
};
self.warn_dead_code(
impl_item.hir_id(),
span,
impl_item.ident.name,
"used",
None,
);
self.warn_dead_code(impl_item.hir_id(), span, impl_item.ident, "used", None);
}
self.visit_nested_body(body_id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ error: associated constant is never used: `BAR`
--> $DIR/associated-const-dead-code.rs:6:5
|
LL | const BAR: u32 = 1;
| ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_BAR`
| ^^^^^^---^^^^^^^^^^
| |
| help: if this is intentional, prefix it with an underscore: `_BAR`
|
= note: the leading underscore signals that this associated constant serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this associated constant serves some other purpose even if it isn't used in a way that we can detect.
note: the lint level is defined here
--> $DIR/associated-const-dead-code.rs:1:9
|
Expand Down
7 changes: 4 additions & 3 deletions src/test/ui/derive-uninhabited-enum-38885.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ warning: variant is never constructed: `Void`
--> $DIR/derive-uninhabited-enum-38885.rs:13:5
|
LL | Void(Void),
| ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Void`
| ----^^^^^^
| |
| help: if this is intentional, prefix it with an underscore: `_Void`
|
= note: the leading underscore signals that this variant serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this variant serves some other purpose even if it isn't used in a way that we can detect.
= note: `-W dead-code` implied by `-W unused`

warning: 1 warning emitted
Expand Down
7 changes: 4 additions & 3 deletions src/test/ui/issues/issue-37515.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ warning: type alias is never used: `Z`
--> $DIR/issue-37515.rs:5:1
|
LL | type Z = dyn for<'x> Send;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Z`
| ^^^^^-^^^^^^^^^^^^^^^^^^^^
| |
| help: if this is intentional, prefix it with an underscore: `_Z`
|
= note: the leading underscore signals that this type alias serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this type alias serves some other purpose even if it isn't used in a way that we can detect.
note: the lint level is defined here
--> $DIR/issue-37515.rs:3:9
|
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/lint/dead-code/basic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ error: function is never used: `foo`
LL | fn foo() {
| ^^^ help: if this is intentional, prefix it with an underscore: `_foo`
|
= note: the leading underscore signals that this function serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this function serves some other purpose even if it isn't used in a way that we can detect.
note: the lint level is defined here
--> $DIR/basic.rs:1:9
|
Expand Down
6 changes: 2 additions & 4 deletions src/test/ui/lint/dead-code/const-and-self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ warning: variant is never constructed: `B`
LL | B,
| ^ help: if this is intentional, prefix it with an underscore: `_B`
|
= note: the leading underscore signals that this variant serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this variant serves some other purpose even if it isn't used in a way that we can detect.
note: the lint level is defined here
--> $DIR/const-and-self.rs:3:9
|
Expand All @@ -18,8 +17,7 @@ warning: variant is never constructed: `C`
LL | C,
| ^ help: if this is intentional, prefix it with an underscore: `_C`
|
= note: the leading underscore signals that this variant serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this variant serves some other purpose even if it isn't used in a way that we can detect.

warning: 2 warnings emitted

8 changes: 4 additions & 4 deletions src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ error: field is never read: `guard`
--> $DIR/drop-only-field-issue-81658.rs:15:5
|
LL | guard: MutexGuard<'a, T>,
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_guard`
| -----^^^^^^^^^^^^^^^^^^^
| |
| help: if this is intentional, prefix it with an underscore: `_guard`
|
= note: the leading underscore signals that this field serves some other purpose
even if it isn't used in a way that we can detect. (e.g. for its effect
when dropped or in foreign code)
= note: the leading underscore signals that this field serves some other purpose even if it isn't used in a way that we can detect. (e.g. for its effect when dropped or in foreign code)
note: the lint level is defined here
--> $DIR/drop-only-field-issue-81658.rs:8:9
|
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/lint/dead-code/empty-unused-enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ error: enum is never used: `E`
LL | enum E {}
| ^ help: if this is intentional, prefix it with an underscore: `_E`
|
= note: the leading underscore signals that this enum serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this enum serves some other purpose even if it isn't used in a way that we can detect.
note: the lint level is defined here
--> $DIR/empty-unused-enum.rs:1:9
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ error: field is never read: `items`
--> $DIR/field-used-in-ffi-issue-81658.rs:13:5
|
LL | items: Option<Vec<T>>,
| ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_items`
| -----^^^^^^^^^^^^^^^^
| |
| help: if this is intentional, prefix it with an underscore: `_items`
|
= note: the leading underscore signals that this field serves some other purpose
even if it isn't used in a way that we can detect. (e.g. for its effect
when dropped or in foreign code)
= note: the leading underscore signals that this field serves some other purpose even if it isn't used in a way that we can detect. (e.g. for its effect when dropped or in foreign code)
note: the lint level is defined here
--> $DIR/field-used-in-ffi-issue-81658.rs:7:9
|
Expand Down
7 changes: 4 additions & 3 deletions src/test/ui/lint/dead-code/impl-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ error: type alias is never used: `Unused`
--> $DIR/impl-trait.rs:12:1
|
LL | type Unused = ();
| ^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Unused`
| ^^^^^------^^^^^^
| |
| help: if this is intentional, prefix it with an underscore: `_Unused`
|
= note: the leading underscore signals that this type alias serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this type alias serves some other purpose even if it isn't used in a way that we can detect.
note: the lint level is defined here
--> $DIR/impl-trait.rs:1:9
|
Expand Down
38 changes: 16 additions & 22 deletions src/test/ui/lint/dead-code/lint-dead-code-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ error: struct is never constructed: `Bar`
LL | pub struct Bar;
| ^^^ help: if this is intentional, prefix it with an underscore: `_Bar`
|
= note: the leading underscore signals that this struct serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this struct serves some other purpose even if it isn't used in a way that we can detect.
note: the lint level is defined here
--> $DIR/lint-dead-code-1.rs:5:9
|
Expand All @@ -16,82 +15,77 @@ error: static is never used: `priv_static`
--> $DIR/lint-dead-code-1.rs:20:1
|
LL | static priv_static: isize = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_static`
| ^^^^^^^-----------^^^^^^^^^^^^
| |
| help: if this is intentional, prefix it with an underscore: `_priv_static`
|
= note: the leading underscore signals that this static serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this static serves some other purpose even if it isn't used in a way that we can detect.

error: constant is never used: `priv_const`
--> $DIR/lint-dead-code-1.rs:27:1
|
LL | const priv_const: isize = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_const`
| ^^^^^^----------^^^^^^^^^^^^
| |
| help: if this is intentional, prefix it with an underscore: `_priv_const`
|
= note: the leading underscore signals that this constant serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this constant serves some other purpose even if it isn't used in a way that we can detect.

error: struct is never constructed: `PrivStruct`
--> $DIR/lint-dead-code-1.rs:35:8
|
LL | struct PrivStruct;
| ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_PrivStruct`
|
= note: the leading underscore signals that this struct serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this struct serves some other purpose even if it isn't used in a way that we can detect.

error: enum is never used: `priv_enum`
--> $DIR/lint-dead-code-1.rs:64:6
|
LL | enum priv_enum { foo2, bar2 }
| ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_enum`
|
= note: the leading underscore signals that this enum serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this enum serves some other purpose even if it isn't used in a way that we can detect.

error: variant is never constructed: `bar3`
--> $DIR/lint-dead-code-1.rs:67:5
|
LL | bar3
| ^^^^ help: if this is intentional, prefix it with an underscore: `_bar3`
|
= note: the leading underscore signals that this variant serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this variant serves some other purpose even if it isn't used in a way that we can detect.

error: function is never used: `priv_fn`
--> $DIR/lint-dead-code-1.rs:88:4
|
LL | fn priv_fn() {
| ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_fn`
|
= note: the leading underscore signals that this function serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this function serves some other purpose even if it isn't used in a way that we can detect.

error: function is never used: `foo`
--> $DIR/lint-dead-code-1.rs:93:4
|
LL | fn foo() {
| ^^^ help: if this is intentional, prefix it with an underscore: `_foo`
|
= note: the leading underscore signals that this function serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this function serves some other purpose even if it isn't used in a way that we can detect.

error: function is never used: `bar`
--> $DIR/lint-dead-code-1.rs:98:4
|
LL | fn bar() {
| ^^^ help: if this is intentional, prefix it with an underscore: `_bar`
|
= note: the leading underscore signals that this function serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this function serves some other purpose even if it isn't used in a way that we can detect.

error: function is never used: `baz`
--> $DIR/lint-dead-code-1.rs:102:4
|
LL | fn baz() -> impl Copy {
| ^^^ help: if this is intentional, prefix it with an underscore: `_baz`
|
= note: the leading underscore signals that this function serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this function serves some other purpose even if it isn't used in a way that we can detect.

error: aborting due to 10 previous errors

9 changes: 3 additions & 6 deletions src/test/ui/lint/dead-code/lint-dead-code-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ error: function is never used: `dead_fn`
LL | fn dead_fn() {}
| ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_dead_fn`
|
= note: the leading underscore signals that this function serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this function serves some other purpose even if it isn't used in a way that we can detect.
note: the lint level is defined here
--> $DIR/lint-dead-code-2.rs:2:9
|
Expand All @@ -18,17 +17,15 @@ error: function is never used: `dead_fn2`
LL | fn dead_fn2() {}
| ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_dead_fn2`
|
= note: the leading underscore signals that this function serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this function serves some other purpose even if it isn't used in a way that we can detect.

error: function is never used: `main`
--> $DIR/lint-dead-code-2.rs:38:4
|
LL | fn main() {
| ^^^^ help: if this is intentional, prefix it with an underscore: `_main`
|
= note: the leading underscore signals that this function serves some other purpose
even if it isn't used in a way that we can detect.
= note: the leading underscore signals that this function serves some other purpose even if it isn't used in a way that we can detect.

error: aborting due to 3 previous errors

Loading