From 30fc601dde6065172e22ba1b351870390d32ec82 Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Wed, 10 Mar 2021 21:36:37 -0800 Subject: [PATCH 01/19] Tests for field is never read diagnostic --- .../dead-code/drop-only-field-issue-81658.rs | 42 ++++++++++++++++ .../drop-only-field-issue-81658.stderr | 14 ++++++ .../field-used-in-ffi-issue-81658.rs | 50 +++++++++++++++++++ .../field-used-in-ffi-issue-81658.stderr | 14 ++++++ 4 files changed, 120 insertions(+) create mode 100644 src/test/ui/lint/dead-code/drop-only-field-issue-81658.rs create mode 100644 src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr create mode 100644 src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.rs create mode 100644 src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr diff --git a/src/test/ui/lint/dead-code/drop-only-field-issue-81658.rs b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.rs new file mode 100644 index 0000000000000..d28b6430bc587 --- /dev/null +++ b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.rs @@ -0,0 +1,42 @@ +//! The field `guard` is never used directly, but it is still useful for its side effect when +//! dropped. Since rustc doesn't consider a `Drop` impl as a use, we want to make sure we at least +//! produce a helpful diagnostic that points the user to what they can do if they indeed intended to +//! have a field that is only used for its `Drop` side effect. +//! +//! Issue: https://github.com/rust-lang/rust/issues/81658 + +#![deny(dead_code)] + +use std::sync::{Mutex, MutexGuard}; + +/// Holds a locked value until it is dropped +pub struct Locked<'a, T> { + // Field is kept for its affect when dropped, but otherwise unused + guard: MutexGuard<'a, T>, //~ ERROR field is never read +} + +impl<'a, T> Locked<'a, T> { + pub fn new(value: &'a Mutex) -> Self { + Self { + guard: value.lock().unwrap(), + } + } +} + +fn main() { + let items = Mutex::new(vec![1, 2, 3]); + + // Hold a lock on items while doing something else + let result = { + // The lock will be released at the end of this scope + let _lock = Locked::new(&items); + + do_something_else() + }; + + println!("{}", result); +} + +fn do_something_else() -> i32 { + 1 + 1 +} diff --git a/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr new file mode 100644 index 0000000000000..c2a3e9d3c48b4 --- /dev/null +++ b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr @@ -0,0 +1,14 @@ +error: field is never read: `guard` + --> $DIR/drop-only-field-issue-81658.rs:15:5 + | +LL | guard: MutexGuard<'a, T>, + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/drop-only-field-issue-81658.rs:8:9 + | +LL | #![deny(dead_code)] + | ^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.rs b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.rs new file mode 100644 index 0000000000000..12eafe6ae4958 --- /dev/null +++ b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.rs @@ -0,0 +1,50 @@ +//! The field `items` is being "used" by FFI (implicitly through pointers). However, since rustc +//! doesn't know how to detect that, we produce a message that says the field is unused. This can +//! cause some confusion and we want to make sure our diagnostics help as much as they can. +//! +//! Issue: https://github.com/rust-lang/rust/issues/81658 + +#![deny(dead_code)] + +/// A struct for holding on to data while it is being used in our FFI code +pub struct FFIData { + /// These values cannot be dropped while the pointers to each item + /// are still in use + items: Option>, //~ ERROR field is never read +} + +impl FFIData { + pub fn new() -> Self { + Self {items: None} + } + + /// Load items into this type and return pointers to each item that can + /// be passed to FFI + pub fn load(&mut self, items: Vec) -> Vec<*const T> { + let ptrs = items.iter().map(|item| item as *const _).collect(); + + self.items = Some(items); + + ptrs + } +} + +extern { + /// The FFI code that uses items + fn process_item(item: *const i32); +} + +fn main() { + // Data cannot be dropped until the end of this scope or else the items + // will be dropped before they are processed + let mut data = FFIData::new(); + + let ptrs = data.load(vec![1, 2, 3, 4, 5]); + + for ptr in ptrs { + // Safety: This pointer is valid as long as the arena is in scope + unsafe { process_item(ptr); } + } + + // Items will be safely freed at the end of this scope +} diff --git a/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr new file mode 100644 index 0000000000000..874afa110c433 --- /dev/null +++ b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr @@ -0,0 +1,14 @@ +error: field is never read: `items` + --> $DIR/field-used-in-ffi-issue-81658.rs:13:5 + | +LL | items: Option>, + | ^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/field-used-in-ffi-issue-81658.rs:7:9 + | +LL | #![deny(dead_code)] + | ^^^^^^^^^ + +error: aborting due to previous error + From 321aace531687cb6c6a7545341344c9a810492da Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Thu, 11 Mar 2021 20:16:34 -0800 Subject: [PATCH 02/19] Added suggestion and note for when a field is never used --- compiler/rustc_passes/src/dead.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index c63edf365a1aa..0457d287e01e8 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -3,6 +3,7 @@ // from live codes are live, and everything else is dead. use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; @@ -577,7 +578,26 @@ impl DeadVisitor<'tcx> { self.tcx.struct_span_lint_hir(lint::builtin::DEAD_CODE, id, span, |lint| { let def_id = self.tcx.hir().local_def_id(id); let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id()); - lint.build(&format!("{} is never {}: `{}`", descr, participle, name)).emit() + + let prefixed = vec![(span, format!("_{}", name))]; + + let mut diag = + lint.build(&format!("{} is never {}: `{}`", descr, participle, name)); + diag.multipart_suggestion( + "if this is intentional, prefix it with an underscore", + prefixed, + Applicability::MachineApplicable, + ) + .note(&format!( + "the leading underscore helps signal to the reader that the {} may still serve\n\ + a purpose even if it isn't used in a way that we can detect (e.g. the {}\nis \ + only used through FFI or used only for its effect when dropped)", + descr, descr, + )); + // Force the note we added to the front, before any other subdiagnostics + diag.children.rotate_right(1); + + diag.emit() }); } } From 7faaf396b2828f487bd862cfba53b66612998fa2 Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Thu, 11 Mar 2021 21:43:26 -0800 Subject: [PATCH 03/19] Updating test stderr files --- .../associated-const-dead-code.stderr | 5 +- .../ui/derive-uninhabited-enum-38885.stderr | 5 +- src/test/ui/issues/issue-37515.stderr | 5 +- src/test/ui/lint/dead-code/basic.stderr | 5 +- .../ui/lint/dead-code/const-and-self.stderr | 11 +++- .../drop-only-field-issue-81658.stderr | 5 +- .../lint/dead-code/empty-unused-enum.stderr | 5 +- .../field-used-in-ffi-issue-81658.stderr | 5 +- src/test/ui/lint/dead-code/impl-trait.stderr | 5 +- .../ui/lint/dead-code/lint-dead-code-1.stderr | 59 +++++++++++++++---- .../ui/lint/dead-code/lint-dead-code-2.stderr | 17 +++++- .../ui/lint/dead-code/lint-dead-code-3.stderr | 29 +++++++-- .../ui/lint/dead-code/lint-dead-code-4.stderr | 59 +++++++++++++++---- .../ui/lint/dead-code/lint-dead-code-5.stderr | 23 ++++++-- .../ui/lint/dead-code/lint-dead-code-6.stderr | 23 ++++++-- .../ui/lint/dead-code/newline-span.stderr | 17 +++++- src/test/ui/lint/dead-code/type-alias.stderr | 5 +- src/test/ui/lint/dead-code/unused-enum.stderr | 17 +++++- .../dead-code/unused-struct-variant.stderr | 5 +- .../ui/lint/dead-code/unused-variant.stderr | 5 +- .../ui/lint/dead-code/with-core-crate.stderr | 5 +- .../ui/lint/dead-code/write-only-field.stderr | 35 +++++++++-- .../ui/lint/issue-17718-const-naming.stderr | 5 +- .../ui/span/macro-span-replacement.stderr | 5 +- .../unused-warning-point-at-identifier.stderr | 23 ++++++-- .../ui/test-attrs/test-warns-dead-code.stderr | 5 +- src/test/ui/union/union-fields-1.stderr | 23 ++++++-- src/test/ui/union/union-lint-dead-code.stderr | 5 +- 28 files changed, 342 insertions(+), 74 deletions(-) diff --git a/src/test/ui/associated-consts/associated-const-dead-code.stderr b/src/test/ui/associated-consts/associated-const-dead-code.stderr index 9b6bbb68a71f7..60c227ef557f5 100644 --- a/src/test/ui/associated-consts/associated-const-dead-code.stderr +++ b/src/test/ui/associated-consts/associated-const-dead-code.stderr @@ -2,8 +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` | + = note: the leading underscore helps signal to the reader that the associated constant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the associated constant + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/associated-const-dead-code.rs:1:9 | diff --git a/src/test/ui/derive-uninhabited-enum-38885.stderr b/src/test/ui/derive-uninhabited-enum-38885.stderr index 72607629d3c10..7aa5fc4d15b48 100644 --- a/src/test/ui/derive-uninhabited-enum-38885.stderr +++ b/src/test/ui/derive-uninhabited-enum-38885.stderr @@ -2,8 +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` | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) = note: `-W dead-code` implied by `-W unused` warning: 1 warning emitted diff --git a/src/test/ui/issues/issue-37515.stderr b/src/test/ui/issues/issue-37515.stderr index 204a39bc8e8e9..683602ce8af97 100644 --- a/src/test/ui/issues/issue-37515.stderr +++ b/src/test/ui/issues/issue-37515.stderr @@ -2,8 +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` | + = note: the leading underscore helps signal to the reader that the type alias may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the type alias + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/issue-37515.rs:3:9 | diff --git a/src/test/ui/lint/dead-code/basic.stderr b/src/test/ui/lint/dead-code/basic.stderr index f7b9b9c613ae0..f42008b4f0d1b 100644 --- a/src/test/ui/lint/dead-code/basic.stderr +++ b/src/test/ui/lint/dead-code/basic.stderr @@ -2,8 +2,11 @@ error: function is never used: `foo` --> $DIR/basic.rs:4:4 | LL | fn foo() { - | ^^^ + | ^^^ help: if this is intentional, prefix it with an underscore: `_foo` | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/basic.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/const-and-self.stderr b/src/test/ui/lint/dead-code/const-and-self.stderr index c0e406189e8ab..0e2e66cfef7b1 100644 --- a/src/test/ui/lint/dead-code/const-and-self.stderr +++ b/src/test/ui/lint/dead-code/const-and-self.stderr @@ -2,8 +2,11 @@ warning: variant is never constructed: `B` --> $DIR/const-and-self.rs:33:5 | LL | B, - | ^ + | ^ help: if this is intentional, prefix it with an underscore: `_B` | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/const-and-self.rs:3:9 | @@ -14,7 +17,11 @@ warning: variant is never constructed: `C` --> $DIR/const-and-self.rs:34:5 | LL | C, - | ^ + | ^ help: if this is intentional, prefix it with an underscore: `_C` + | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) warning: 2 warnings emitted diff --git a/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr index c2a3e9d3c48b4..8c5a5f0a7e5bf 100644 --- a/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr +++ b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr @@ -2,8 +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` | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/drop-only-field-issue-81658.rs:8:9 | diff --git a/src/test/ui/lint/dead-code/empty-unused-enum.stderr b/src/test/ui/lint/dead-code/empty-unused-enum.stderr index ed9a7ccd14b21..8e16d24c001d5 100644 --- a/src/test/ui/lint/dead-code/empty-unused-enum.stderr +++ b/src/test/ui/lint/dead-code/empty-unused-enum.stderr @@ -2,8 +2,11 @@ error: enum is never used: `E` --> $DIR/empty-unused-enum.rs:3:6 | LL | enum E {} - | ^ + | ^ help: if this is intentional, prefix it with an underscore: `_E` | + = note: the leading underscore helps signal to the reader that the enum may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the enum + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/empty-unused-enum.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr index 874afa110c433..d5b5ee777dc07 100644 --- a/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr +++ b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr @@ -2,8 +2,11 @@ error: field is never read: `items` --> $DIR/field-used-in-ffi-issue-81658.rs:13:5 | LL | items: Option>, - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_items` | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/field-used-in-ffi-issue-81658.rs:7:9 | diff --git a/src/test/ui/lint/dead-code/impl-trait.stderr b/src/test/ui/lint/dead-code/impl-trait.stderr index 09b6d08eb8fb8..fe3d4a8a214b6 100644 --- a/src/test/ui/lint/dead-code/impl-trait.stderr +++ b/src/test/ui/lint/dead-code/impl-trait.stderr @@ -2,8 +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` | + = note: the leading underscore helps signal to the reader that the type alias may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the type alias + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/impl-trait.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/lint-dead-code-1.stderr b/src/test/ui/lint/dead-code/lint-dead-code-1.stderr index af97ea98b2b6d..7d1038db4b289 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-1.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-1.stderr @@ -2,8 +2,11 @@ error: struct is never constructed: `Bar` --> $DIR/lint-dead-code-1.rs:12:16 | LL | pub struct Bar; - | ^^^ + | ^^^ help: if this is intentional, prefix it with an underscore: `_Bar` | + = note: the leading underscore helps signal to the reader that the struct may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the struct + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/lint-dead-code-1.rs:5:9 | @@ -14,55 +17,91 @@ 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` + | + = note: the leading underscore helps signal to the reader that the static may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the static + is only used through FFI or used only for its effect when dropped) 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` + | + = note: the leading underscore helps signal to the reader that the constant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the constant + is only used through FFI or used only for its effect when dropped) 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 helps signal to the reader that the struct may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the struct + is only used through FFI or used only for its effect when dropped) 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 helps signal to the reader that the enum may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the enum + is only used through FFI or used only for its effect when dropped) 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 helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) 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 helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) 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 helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) 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 helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) 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 helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) error: aborting due to 10 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-2.stderr b/src/test/ui/lint/dead-code/lint-dead-code-2.stderr index b01ba57f98580..f840daee7a0c7 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-2.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-2.stderr @@ -2,8 +2,11 @@ error: function is never used: `dead_fn` --> $DIR/lint-dead-code-2.rs:22:4 | LL | fn dead_fn() {} - | ^^^^^^^ + | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_dead_fn` | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/lint-dead-code-2.rs:2:9 | @@ -14,13 +17,21 @@ error: function is never used: `dead_fn2` --> $DIR/lint-dead-code-2.rs:25:4 | LL | fn dead_fn2() {} - | ^^^^^^^^ + | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_dead_fn2` + | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) 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 helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) error: aborting due to 3 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-3.stderr b/src/test/ui/lint/dead-code/lint-dead-code-3.stderr index cf8f01ea19f0c..ad7fec0181519 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-3.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-3.stderr @@ -2,8 +2,11 @@ error: struct is never constructed: `Foo` --> $DIR/lint-dead-code-3.rs:14:8 | LL | struct Foo; - | ^^^ + | ^^^ help: if this is intentional, prefix it with an underscore: `_Foo` | + = note: the leading underscore helps signal to the reader that the struct may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the struct + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/lint-dead-code-3.rs:4:9 | @@ -14,25 +17,41 @@ error: associated function is never used: `foo` --> $DIR/lint-dead-code-3.rs:16:8 | LL | fn foo(&self) { - | ^^^ + | ^^^ help: if this is intentional, prefix it with an underscore: `_foo` + | + = note: the leading underscore helps signal to the reader that the associated function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the associated function + is only used through FFI or used only for its effect when dropped) error: function is never used: `bar` --> $DIR/lint-dead-code-3.rs:21:4 | LL | fn bar() { - | ^^^ + | ^^^ help: if this is intentional, prefix it with an underscore: `_bar` + | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) error: enum is never used: `c_void` --> $DIR/lint-dead-code-3.rs:60:6 | LL | enum c_void {} - | ^^^^^^ + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_c_void` + | + = note: the leading underscore helps signal to the reader that the enum may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the enum + is only used through FFI or used only for its effect when dropped) error: function is never used: `free` --> $DIR/lint-dead-code-3.rs:62:5 | LL | fn free(p: *const c_void); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_free` + | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) error: aborting due to 5 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-4.stderr b/src/test/ui/lint/dead-code/lint-dead-code-4.stderr index 3905d1a06bdfe..7fd275159c2eb 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-4.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-4.stderr @@ -2,8 +2,11 @@ error: field is never read: `b` --> $DIR/lint-dead-code-4.rs:7:5 | LL | b: bool, - | ^^^^^^^ + | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/lint-dead-code-4.rs:3:9 | @@ -14,7 +17,11 @@ error: variant is never constructed: `X` --> $DIR/lint-dead-code-4.rs:15:5 | LL | X, - | ^ + | ^ help: if this is intentional, prefix it with an underscore: `_X` + | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) error: variant is never constructed: `Y` --> $DIR/lint-dead-code-4.rs:16:5 @@ -24,49 +31,81 @@ LL | | a: String, LL | | b: i32, LL | | c: i32, LL | | }, - | |_____^ + | |_____^ help: if this is intentional, prefix it with an underscore: `_Y` + | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) error: enum is never used: `ABC` --> $DIR/lint-dead-code-4.rs:24:6 | LL | enum ABC { - | ^^^ + | ^^^ help: if this is intentional, prefix it with an underscore: `_ABC` + | + = note: the leading underscore helps signal to the reader that the enum may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the enum + is only used through FFI or used only for its effect when dropped) error: variant is never constructed: `I` --> $DIR/lint-dead-code-4.rs:36:5 | LL | I, - | ^ + | ^ help: if this is intentional, prefix it with an underscore: `_I` + | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) error: field is never read: `b` --> $DIR/lint-dead-code-4.rs:39:9 | LL | b: i32, - | ^^^^^^ + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: field is never read: `c` --> $DIR/lint-dead-code-4.rs:40:9 | LL | c: i32, - | ^^^^^^ + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_c` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: variant is never constructed: `K` --> $DIR/lint-dead-code-4.rs:42:5 | LL | K - | ^ + | ^ help: if this is intentional, prefix it with an underscore: `_K` + | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) error: field is never read: `x` --> $DIR/lint-dead-code-4.rs:61:5 | LL | x: usize, - | ^^^^^^^^ + | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_x` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: field is never read: `c` --> $DIR/lint-dead-code-4.rs:63:5 | LL | c: bool, - | ^^^^^^^ + | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_c` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: aborting due to 10 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-5.stderr b/src/test/ui/lint/dead-code/lint-dead-code-5.stderr index 519add826273f..d0868af5f4473 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-5.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-5.stderr @@ -2,8 +2,11 @@ error: variant is never constructed: `Variant2` --> $DIR/lint-dead-code-5.rs:6:5 | LL | Variant2 - | ^^^^^^^^ + | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant2` | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/lint-dead-code-5.rs:2:9 | @@ -14,19 +17,31 @@ error: variant is never constructed: `Variant5` --> $DIR/lint-dead-code-5.rs:13:5 | LL | Variant5 { _x: isize }, - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant5` + | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) error: variant is never constructed: `Variant6` --> $DIR/lint-dead-code-5.rs:14:5 | LL | Variant6(isize), - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant6` + | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) error: enum is never used: `Enum3` --> $DIR/lint-dead-code-5.rs:35:6 | LL | enum Enum3 { - | ^^^^^ + | ^^^^^ help: if this is intentional, prefix it with an underscore: `_Enum3` + | + = note: the leading underscore helps signal to the reader that the enum may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the enum + is only used through FFI or used only for its effect when dropped) error: aborting due to 4 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-6.stderr b/src/test/ui/lint/dead-code/lint-dead-code-6.stderr index 7dc60730d6aad..687a49eb7619a 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-6.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-6.stderr @@ -2,8 +2,11 @@ error: struct is never constructed: `UnusedStruct` --> $DIR/lint-dead-code-6.rs:3:8 | LL | struct UnusedStruct; - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_UnusedStruct` | + = note: the leading underscore helps signal to the reader that the struct may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the struct + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/lint-dead-code-6.rs:1:9 | @@ -14,19 +17,31 @@ error: associated function is never used: `unused_impl_fn_1` --> $DIR/lint-dead-code-6.rs:5:8 | LL | fn unused_impl_fn_1() { - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_1` + | + = note: the leading underscore helps signal to the reader that the associated function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the associated function + is only used through FFI or used only for its effect when dropped) error: associated function is never used: `unused_impl_fn_2` --> $DIR/lint-dead-code-6.rs:9:8 | LL | fn unused_impl_fn_2(var: i32) { - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_2` + | + = note: the leading underscore helps signal to the reader that the associated function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the associated function + is only used through FFI or used only for its effect when dropped) error: associated function is never used: `unused_impl_fn_3` --> $DIR/lint-dead-code-6.rs:13:8 | LL | fn unused_impl_fn_3( - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_3` + | + = note: the leading underscore helps signal to the reader that the associated function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the associated function + is only used through FFI or used only for its effect when dropped) error: aborting due to 4 previous errors diff --git a/src/test/ui/lint/dead-code/newline-span.stderr b/src/test/ui/lint/dead-code/newline-span.stderr index fd74405f2b648..b636079631c35 100644 --- a/src/test/ui/lint/dead-code/newline-span.stderr +++ b/src/test/ui/lint/dead-code/newline-span.stderr @@ -2,8 +2,11 @@ error: function is never used: `unused` --> $DIR/newline-span.rs:3:4 | LL | fn unused() { - | ^^^^^^ + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused` | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/newline-span.rs:1:9 | @@ -14,13 +17,21 @@ error: function is never used: `unused2` --> $DIR/newline-span.rs:7:4 | LL | fn unused2(var: i32) { - | ^^^^^^^ + | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused2` + | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) error: function is never used: `unused3` --> $DIR/newline-span.rs:11:4 | LL | fn unused3( - | ^^^^^^^ + | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused3` + | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) error: aborting due to 3 previous errors diff --git a/src/test/ui/lint/dead-code/type-alias.stderr b/src/test/ui/lint/dead-code/type-alias.stderr index b2acd5d4213b3..5c11626bb1e44 100644 --- a/src/test/ui/lint/dead-code/type-alias.stderr +++ b/src/test/ui/lint/dead-code/type-alias.stderr @@ -2,8 +2,11 @@ error: type alias is never used: `Unused` --> $DIR/type-alias.rs:4:1 | LL | type Unused = u8; - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Unused` | + = note: the leading underscore helps signal to the reader that the type alias may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the type alias + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/type-alias.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/unused-enum.stderr b/src/test/ui/lint/dead-code/unused-enum.stderr index 9f368fdd2f816..c71d305987c77 100644 --- a/src/test/ui/lint/dead-code/unused-enum.stderr +++ b/src/test/ui/lint/dead-code/unused-enum.stderr @@ -2,8 +2,11 @@ error: struct is never constructed: `F` --> $DIR/unused-enum.rs:3:8 | LL | struct F; - | ^ + | ^ help: if this is intentional, prefix it with an underscore: `_F` | + = note: the leading underscore helps signal to the reader that the struct may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the struct + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/unused-enum.rs:1:9 | @@ -15,13 +18,21 @@ error: struct is never constructed: `B` --> $DIR/unused-enum.rs:4:8 | LL | struct B; - | ^ + | ^ help: if this is intentional, prefix it with an underscore: `_B` + | + = note: the leading underscore helps signal to the reader that the struct may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the struct + is only used through FFI or used only for its effect when dropped) error: enum is never used: `E` --> $DIR/unused-enum.rs:6:6 | LL | enum E { - | ^ + | ^ help: if this is intentional, prefix it with an underscore: `_E` + | + = note: the leading underscore helps signal to the reader that the enum may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the enum + is only used through FFI or used only for its effect when dropped) error: aborting due to 3 previous errors diff --git a/src/test/ui/lint/dead-code/unused-struct-variant.stderr b/src/test/ui/lint/dead-code/unused-struct-variant.stderr index b93d6d4ac1866..198986bde049d 100644 --- a/src/test/ui/lint/dead-code/unused-struct-variant.stderr +++ b/src/test/ui/lint/dead-code/unused-struct-variant.stderr @@ -2,8 +2,11 @@ error: variant is never constructed: `Bar` --> $DIR/unused-struct-variant.rs:8:5 | LL | Bar(B), - | ^^^^^^ + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_Bar` | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/unused-struct-variant.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/unused-variant.stderr b/src/test/ui/lint/dead-code/unused-variant.stderr index a547f5af4b082..5fff7b1fdb3e0 100644 --- a/src/test/ui/lint/dead-code/unused-variant.stderr +++ b/src/test/ui/lint/dead-code/unused-variant.stderr @@ -2,8 +2,11 @@ error: variant is never constructed: `Variant1` --> $DIR/unused-variant.rs:5:5 | LL | Variant1, - | ^^^^^^^^ + | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant1` | + = note: the leading underscore helps signal to the reader that the variant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the variant + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/unused-variant.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/with-core-crate.stderr b/src/test/ui/lint/dead-code/with-core-crate.stderr index 2c63e60d67609..ab4c1793b0667 100644 --- a/src/test/ui/lint/dead-code/with-core-crate.stderr +++ b/src/test/ui/lint/dead-code/with-core-crate.stderr @@ -2,8 +2,11 @@ error: function is never used: `foo` --> $DIR/with-core-crate.rs:7:4 | LL | fn foo() { - | ^^^ + | ^^^ help: if this is intentional, prefix it with an underscore: `_foo` | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/with-core-crate.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/write-only-field.stderr b/src/test/ui/lint/dead-code/write-only-field.stderr index a191d22c8b94c..a7dcb69e2e366 100644 --- a/src/test/ui/lint/dead-code/write-only-field.stderr +++ b/src/test/ui/lint/dead-code/write-only-field.stderr @@ -2,8 +2,11 @@ error: field is never read: `f` --> $DIR/write-only-field.rs:4:5 | LL | f: i32, - | ^^^^^^ + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_f` | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/write-only-field.rs:1:9 | @@ -14,31 +17,51 @@ error: field is never read: `sub` --> $DIR/write-only-field.rs:5:5 | LL | sub: Sub, - | ^^^^^^^^ + | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_sub` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: field is never read: `f` --> $DIR/write-only-field.rs:9:5 | LL | f: i32, - | ^^^^^^ + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_f` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: field is never read: `y` --> $DIR/write-only-field.rs:28:9 | LL | y: bool, - | ^^^^^^^ + | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_y` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: field is never read: `u` --> $DIR/write-only-field.rs:58:9 | LL | u: u32, - | ^^^^^^ + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_u` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: field is never read: `v` --> $DIR/write-only-field.rs:59:9 | LL | v: u32, - | ^^^^^^ + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_v` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: aborting due to 6 previous errors diff --git a/src/test/ui/lint/issue-17718-const-naming.stderr b/src/test/ui/lint/issue-17718-const-naming.stderr index ce4ebcb5e3ef6..f0d95f5b83d2f 100644 --- a/src/test/ui/lint/issue-17718-const-naming.stderr +++ b/src/test/ui/lint/issue-17718-const-naming.stderr @@ -2,8 +2,11 @@ error: constant is never used: `foo` --> $DIR/issue-17718-const-naming.rs:4:1 | LL | const foo: isize = 3; - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_foo` | + = note: the leading underscore helps signal to the reader that the constant may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the constant + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/issue-17718-const-naming.rs:2:9 | diff --git a/src/test/ui/span/macro-span-replacement.stderr b/src/test/ui/span/macro-span-replacement.stderr index 45cf5f8688cd1..91f9f271e5ceb 100644 --- a/src/test/ui/span/macro-span-replacement.stderr +++ b/src/test/ui/span/macro-span-replacement.stderr @@ -2,11 +2,14 @@ warning: struct is never constructed: `S` --> $DIR/macro-span-replacement.rs:7:14 | LL | $b $a; - | ^ + | ^ help: if this is intentional, prefix it with an underscore: `_S` ... LL | m!(S struct); | ------------- in this macro invocation | + = note: the leading underscore helps signal to the reader that the struct may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the struct + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/macro-span-replacement.rs:3:9 | diff --git a/src/test/ui/span/unused-warning-point-at-identifier.stderr b/src/test/ui/span/unused-warning-point-at-identifier.stderr index 6ef877da122f5..21579fbd92b7c 100644 --- a/src/test/ui/span/unused-warning-point-at-identifier.stderr +++ b/src/test/ui/span/unused-warning-point-at-identifier.stderr @@ -2,8 +2,11 @@ warning: enum is never used: `Enum` --> $DIR/unused-warning-point-at-identifier.rs:5:6 | LL | enum Enum { - | ^^^^ + | ^^^^ help: if this is intentional, prefix it with an underscore: `_Enum` | + = note: the leading underscore helps signal to the reader that the enum may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the enum + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/unused-warning-point-at-identifier.rs:3:9 | @@ -15,19 +18,31 @@ warning: struct is never constructed: `Struct` --> $DIR/unused-warning-point-at-identifier.rs:12:8 | LL | struct Struct { - | ^^^^^^ + | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_Struct` + | + = note: the leading underscore helps signal to the reader that the struct may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the struct + is only used through FFI or used only for its effect when dropped) warning: function is never used: `func` --> $DIR/unused-warning-point-at-identifier.rs:19:4 | LL | fn func() -> usize { - | ^^^^ + | ^^^^ help: if this is intentional, prefix it with an underscore: `_func` + | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) warning: function is never used: `func_complete_span` --> $DIR/unused-warning-point-at-identifier.rs:24:1 | LL | func_complete_span() - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_func_complete_span` + | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) warning: 4 warnings emitted diff --git a/src/test/ui/test-attrs/test-warns-dead-code.stderr b/src/test/ui/test-attrs/test-warns-dead-code.stderr index d3bcea2951364..d41a4e54985a2 100644 --- a/src/test/ui/test-attrs/test-warns-dead-code.stderr +++ b/src/test/ui/test-attrs/test-warns-dead-code.stderr @@ -2,8 +2,11 @@ error: function is never used: `dead` --> $DIR/test-warns-dead-code.rs:5:4 | LL | fn dead() {} - | ^^^^ + | ^^^^ help: if this is intentional, prefix it with an underscore: `_dead` | + = note: the leading underscore helps signal to the reader that the function may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the function + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/test-warns-dead-code.rs:3:9 | diff --git a/src/test/ui/union/union-fields-1.stderr b/src/test/ui/union/union-fields-1.stderr index 87621cc01b1b9..9c90e94ff91bf 100644 --- a/src/test/ui/union/union-fields-1.stderr +++ b/src/test/ui/union/union-fields-1.stderr @@ -2,8 +2,11 @@ error: field is never read: `c` --> $DIR/union-fields-1.rs:6:5 | LL | c: u8, - | ^^^^^ + | ^^^^^ help: if this is intentional, prefix it with an underscore: `_c` | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/union-fields-1.rs:1:9 | @@ -14,19 +17,31 @@ error: field is never read: `a` --> $DIR/union-fields-1.rs:9:5 | LL | a: u8, - | ^^^^^ + | ^^^^^ help: if this is intentional, prefix it with an underscore: `_a` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: field is never read: `a` --> $DIR/union-fields-1.rs:13:20 | LL | union NoDropLike { a: u8 } - | ^^^^^ + | ^^^^^ help: if this is intentional, prefix it with an underscore: `_a` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: field is never read: `c` --> $DIR/union-fields-1.rs:18:5 | LL | c: u8, - | ^^^^^ + | ^^^^^ help: if this is intentional, prefix it with an underscore: `_c` + | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) error: aborting due to 4 previous errors diff --git a/src/test/ui/union/union-lint-dead-code.stderr b/src/test/ui/union/union-lint-dead-code.stderr index 7de70ec33801f..6dfeae0248455 100644 --- a/src/test/ui/union/union-lint-dead-code.stderr +++ b/src/test/ui/union/union-lint-dead-code.stderr @@ -2,8 +2,11 @@ error: field is never read: `b` --> $DIR/union-lint-dead-code.rs:5:5 | LL | b: bool, - | ^^^^^^^ + | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` | + = note: the leading underscore helps signal to the reader that the field may still serve + a purpose even if it isn't used in a way that we can detect (e.g. the field + is only used through FFI or used only for its effect when dropped) note: the lint level is defined here --> $DIR/union-lint-dead-code.rs:1:9 | From 789186d8befacb9ea933dd80c02e7ca49e190df0 Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Thu, 11 Mar 2021 23:00:22 -0800 Subject: [PATCH 04/19] Trying out a new message that works a little better for values *and* items --- compiler/rustc_passes/src/dead.rs | 9 +-- .../associated-const-dead-code.stderr | 7 +- .../ui/derive-uninhabited-enum-38885.stderr | 7 +- src/test/ui/issues/issue-37515.stderr | 7 +- src/test/ui/lint/dead-code/basic.stderr | 7 +- .../ui/lint/dead-code/const-and-self.stderr | 14 ++-- .../drop-only-field-issue-81658.stderr | 7 +- .../lint/dead-code/empty-unused-enum.stderr | 7 +- .../field-used-in-ffi-issue-81658.stderr | 7 +- src/test/ui/lint/dead-code/impl-trait.stderr | 7 +- .../ui/lint/dead-code/lint-dead-code-1.stderr | 70 +++++++++++-------- .../ui/lint/dead-code/lint-dead-code-2.stderr | 21 +++--- .../ui/lint/dead-code/lint-dead-code-3.stderr | 35 ++++++---- .../ui/lint/dead-code/lint-dead-code-4.stderr | 70 +++++++++++-------- .../ui/lint/dead-code/lint-dead-code-5.stderr | 28 ++++---- .../ui/lint/dead-code/lint-dead-code-6.stderr | 28 ++++---- .../ui/lint/dead-code/newline-span.stderr | 21 +++--- src/test/ui/lint/dead-code/type-alias.stderr | 7 +- src/test/ui/lint/dead-code/unused-enum.stderr | 21 +++--- .../dead-code/unused-struct-variant.stderr | 7 +- .../ui/lint/dead-code/unused-variant.stderr | 7 +- .../ui/lint/dead-code/with-core-crate.stderr | 7 +- .../ui/lint/dead-code/write-only-field.stderr | 42 ++++++----- .../ui/lint/issue-17718-const-naming.stderr | 7 +- .../ui/span/macro-span-replacement.stderr | 7 +- .../unused-warning-point-at-identifier.stderr | 28 ++++---- .../ui/test-attrs/test-warns-dead-code.stderr | 7 +- src/test/ui/union/union-fields-1.stderr | 28 ++++---- src/test/ui/union/union-lint-dead-code.stderr | 7 +- 29 files changed, 301 insertions(+), 226 deletions(-) diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 0457d287e01e8..8df91645626a3 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -589,10 +589,11 @@ impl DeadVisitor<'tcx> { Applicability::MachineApplicable, ) .note(&format!( - "the leading underscore helps signal to the reader that the {} may still serve\n\ - a purpose even if it isn't used in a way that we can detect (e.g. the {}\nis \ - only used through FFI or used only for its effect when dropped)", - descr, descr, + "The leading underscore signals to the reader that while the {} may not be {}\n\ + by any Rust code, it still serves some other purpose that isn't detected by rustc.\n\ + (e.g. some values are used for their effect when dropped or used in FFI code\n\ + exclusively through raw pointers)", + descr, participle, )); // Force the note we added to the front, before any other subdiagnostics diag.children.rotate_right(1); diff --git a/src/test/ui/associated-consts/associated-const-dead-code.stderr b/src/test/ui/associated-consts/associated-const-dead-code.stderr index 60c227ef557f5..9cf817905cc0a 100644 --- a/src/test/ui/associated-consts/associated-const-dead-code.stderr +++ b/src/test/ui/associated-consts/associated-const-dead-code.stderr @@ -4,9 +4,10 @@ error: associated constant is never used: `BAR` LL | const BAR: u32 = 1; | ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_BAR` | - = note: the leading underscore helps signal to the reader that the associated constant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the associated constant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the associated constant may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/associated-const-dead-code.rs:1:9 | diff --git a/src/test/ui/derive-uninhabited-enum-38885.stderr b/src/test/ui/derive-uninhabited-enum-38885.stderr index 7aa5fc4d15b48..de151b915d0a7 100644 --- a/src/test/ui/derive-uninhabited-enum-38885.stderr +++ b/src/test/ui/derive-uninhabited-enum-38885.stderr @@ -4,9 +4,10 @@ warning: variant is never constructed: `Void` LL | Void(Void), | ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Void` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) = note: `-W dead-code` implied by `-W unused` warning: 1 warning emitted diff --git a/src/test/ui/issues/issue-37515.stderr b/src/test/ui/issues/issue-37515.stderr index 683602ce8af97..02da48748ec13 100644 --- a/src/test/ui/issues/issue-37515.stderr +++ b/src/test/ui/issues/issue-37515.stderr @@ -4,9 +4,10 @@ warning: type alias is never used: `Z` LL | type Z = dyn for<'x> Send; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Z` | - = note: the leading underscore helps signal to the reader that the type alias may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the type alias - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the type alias may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/issue-37515.rs:3:9 | diff --git a/src/test/ui/lint/dead-code/basic.stderr b/src/test/ui/lint/dead-code/basic.stderr index f42008b4f0d1b..4b165c30003a6 100644 --- a/src/test/ui/lint/dead-code/basic.stderr +++ b/src/test/ui/lint/dead-code/basic.stderr @@ -4,9 +4,10 @@ error: function is never used: `foo` LL | fn foo() { | ^^^ help: if this is intentional, prefix it with an underscore: `_foo` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/basic.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/const-and-self.stderr b/src/test/ui/lint/dead-code/const-and-self.stderr index 0e2e66cfef7b1..80da402f79817 100644 --- a/src/test/ui/lint/dead-code/const-and-self.stderr +++ b/src/test/ui/lint/dead-code/const-and-self.stderr @@ -4,9 +4,10 @@ warning: variant is never constructed: `B` LL | B, | ^ help: if this is intentional, prefix it with an underscore: `_B` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/const-and-self.rs:3:9 | @@ -19,9 +20,10 @@ warning: variant is never constructed: `C` LL | C, | ^ help: if this is intentional, prefix it with an underscore: `_C` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) warning: 2 warnings emitted diff --git a/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr index 8c5a5f0a7e5bf..dc9dcb770df0b 100644 --- a/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr +++ b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr @@ -4,9 +4,10 @@ error: field is never read: `guard` LL | guard: MutexGuard<'a, T>, | ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_guard` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/drop-only-field-issue-81658.rs:8:9 | diff --git a/src/test/ui/lint/dead-code/empty-unused-enum.stderr b/src/test/ui/lint/dead-code/empty-unused-enum.stderr index 8e16d24c001d5..8fa3ae27af3ea 100644 --- a/src/test/ui/lint/dead-code/empty-unused-enum.stderr +++ b/src/test/ui/lint/dead-code/empty-unused-enum.stderr @@ -4,9 +4,10 @@ error: enum is never used: `E` LL | enum E {} | ^ help: if this is intentional, prefix it with an underscore: `_E` | - = note: the leading underscore helps signal to the reader that the enum may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the enum - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the enum may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/empty-unused-enum.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr index d5b5ee777dc07..e2f6849304d39 100644 --- a/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr +++ b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr @@ -4,9 +4,10 @@ error: field is never read: `items` LL | items: Option>, | ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_items` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/field-used-in-ffi-issue-81658.rs:7:9 | diff --git a/src/test/ui/lint/dead-code/impl-trait.stderr b/src/test/ui/lint/dead-code/impl-trait.stderr index fe3d4a8a214b6..bca3c4002de70 100644 --- a/src/test/ui/lint/dead-code/impl-trait.stderr +++ b/src/test/ui/lint/dead-code/impl-trait.stderr @@ -4,9 +4,10 @@ error: type alias is never used: `Unused` LL | type Unused = (); | ^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Unused` | - = note: the leading underscore helps signal to the reader that the type alias may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the type alias - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the type alias may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/impl-trait.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/lint-dead-code-1.stderr b/src/test/ui/lint/dead-code/lint-dead-code-1.stderr index 7d1038db4b289..bd1de549134a0 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-1.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-1.stderr @@ -4,9 +4,10 @@ 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 helps signal to the reader that the struct may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the struct - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the struct may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/lint-dead-code-1.rs:5:9 | @@ -19,9 +20,10 @@ error: static is never used: `priv_static` LL | static priv_static: isize = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_static` | - = note: the leading underscore helps signal to the reader that the static may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the static - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the static may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: constant is never used: `priv_const` --> $DIR/lint-dead-code-1.rs:27:1 @@ -29,9 +31,10 @@ error: constant is never used: `priv_const` LL | const priv_const: isize = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_const` | - = note: the leading underscore helps signal to the reader that the constant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the constant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the constant may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: struct is never constructed: `PrivStruct` --> $DIR/lint-dead-code-1.rs:35:8 @@ -39,9 +42,10 @@ error: struct is never constructed: `PrivStruct` LL | struct PrivStruct; | ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_PrivStruct` | - = note: the leading underscore helps signal to the reader that the struct may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the struct - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the struct may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: enum is never used: `priv_enum` --> $DIR/lint-dead-code-1.rs:64:6 @@ -49,9 +53,10 @@ error: enum is never used: `priv_enum` LL | enum priv_enum { foo2, bar2 } | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_enum` | - = note: the leading underscore helps signal to the reader that the enum may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the enum - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the enum may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: variant is never constructed: `bar3` --> $DIR/lint-dead-code-1.rs:67:5 @@ -59,9 +64,10 @@ error: variant is never constructed: `bar3` LL | bar3 | ^^^^ help: if this is intentional, prefix it with an underscore: `_bar3` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: function is never used: `priv_fn` --> $DIR/lint-dead-code-1.rs:88:4 @@ -69,9 +75,10 @@ error: function is never used: `priv_fn` LL | fn priv_fn() { | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_fn` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: function is never used: `foo` --> $DIR/lint-dead-code-1.rs:93:4 @@ -79,9 +86,10 @@ error: function is never used: `foo` LL | fn foo() { | ^^^ help: if this is intentional, prefix it with an underscore: `_foo` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: function is never used: `bar` --> $DIR/lint-dead-code-1.rs:98:4 @@ -89,9 +97,10 @@ error: function is never used: `bar` LL | fn bar() { | ^^^ help: if this is intentional, prefix it with an underscore: `_bar` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: function is never used: `baz` --> $DIR/lint-dead-code-1.rs:102:4 @@ -99,9 +108,10 @@ error: function is never used: `baz` LL | fn baz() -> impl Copy { | ^^^ help: if this is intentional, prefix it with an underscore: `_baz` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: aborting due to 10 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-2.stderr b/src/test/ui/lint/dead-code/lint-dead-code-2.stderr index f840daee7a0c7..ecc0169eadd56 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-2.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-2.stderr @@ -4,9 +4,10 @@ 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 helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/lint-dead-code-2.rs:2:9 | @@ -19,9 +20,10 @@ 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 helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: function is never used: `main` --> $DIR/lint-dead-code-2.rs:38:4 @@ -29,9 +31,10 @@ error: function is never used: `main` LL | fn main() { | ^^^^ help: if this is intentional, prefix it with an underscore: `_main` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: aborting due to 3 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-3.stderr b/src/test/ui/lint/dead-code/lint-dead-code-3.stderr index ad7fec0181519..53ccae0f0cec6 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-3.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-3.stderr @@ -4,9 +4,10 @@ error: struct is never constructed: `Foo` LL | struct Foo; | ^^^ help: if this is intentional, prefix it with an underscore: `_Foo` | - = note: the leading underscore helps signal to the reader that the struct may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the struct - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the struct may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/lint-dead-code-3.rs:4:9 | @@ -19,9 +20,10 @@ error: associated function is never used: `foo` LL | fn foo(&self) { | ^^^ help: if this is intentional, prefix it with an underscore: `_foo` | - = note: the leading underscore helps signal to the reader that the associated function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the associated function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the associated function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: function is never used: `bar` --> $DIR/lint-dead-code-3.rs:21:4 @@ -29,9 +31,10 @@ error: function is never used: `bar` LL | fn bar() { | ^^^ help: if this is intentional, prefix it with an underscore: `_bar` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: enum is never used: `c_void` --> $DIR/lint-dead-code-3.rs:60:6 @@ -39,9 +42,10 @@ error: enum is never used: `c_void` LL | enum c_void {} | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_c_void` | - = note: the leading underscore helps signal to the reader that the enum may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the enum - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the enum may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: function is never used: `free` --> $DIR/lint-dead-code-3.rs:62:5 @@ -49,9 +53,10 @@ error: function is never used: `free` LL | fn free(p: *const c_void); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_free` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: aborting due to 5 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-4.stderr b/src/test/ui/lint/dead-code/lint-dead-code-4.stderr index 7fd275159c2eb..23e4a5ca69187 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-4.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-4.stderr @@ -4,9 +4,10 @@ error: field is never read: `b` LL | b: bool, | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/lint-dead-code-4.rs:3:9 | @@ -19,9 +20,10 @@ error: variant is never constructed: `X` LL | X, | ^ help: if this is intentional, prefix it with an underscore: `_X` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: variant is never constructed: `Y` --> $DIR/lint-dead-code-4.rs:16:5 @@ -33,9 +35,10 @@ LL | | c: i32, LL | | }, | |_____^ help: if this is intentional, prefix it with an underscore: `_Y` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: enum is never used: `ABC` --> $DIR/lint-dead-code-4.rs:24:6 @@ -43,9 +46,10 @@ error: enum is never used: `ABC` LL | enum ABC { | ^^^ help: if this is intentional, prefix it with an underscore: `_ABC` | - = note: the leading underscore helps signal to the reader that the enum may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the enum - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the enum may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: variant is never constructed: `I` --> $DIR/lint-dead-code-4.rs:36:5 @@ -53,9 +57,10 @@ error: variant is never constructed: `I` LL | I, | ^ help: if this is intentional, prefix it with an underscore: `_I` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: field is never read: `b` --> $DIR/lint-dead-code-4.rs:39:9 @@ -63,9 +68,10 @@ error: field is never read: `b` LL | b: i32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: field is never read: `c` --> $DIR/lint-dead-code-4.rs:40:9 @@ -73,9 +79,10 @@ error: field is never read: `c` LL | c: i32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_c` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: variant is never constructed: `K` --> $DIR/lint-dead-code-4.rs:42:5 @@ -83,9 +90,10 @@ error: variant is never constructed: `K` LL | K | ^ help: if this is intentional, prefix it with an underscore: `_K` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: field is never read: `x` --> $DIR/lint-dead-code-4.rs:61:5 @@ -93,9 +101,10 @@ error: field is never read: `x` LL | x: usize, | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_x` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: field is never read: `c` --> $DIR/lint-dead-code-4.rs:63:5 @@ -103,9 +112,10 @@ error: field is never read: `c` LL | c: bool, | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_c` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: aborting due to 10 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-5.stderr b/src/test/ui/lint/dead-code/lint-dead-code-5.stderr index d0868af5f4473..b0fcb9a199ca4 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-5.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-5.stderr @@ -4,9 +4,10 @@ error: variant is never constructed: `Variant2` LL | Variant2 | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant2` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/lint-dead-code-5.rs:2:9 | @@ -19,9 +20,10 @@ error: variant is never constructed: `Variant5` LL | Variant5 { _x: isize }, | ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant5` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: variant is never constructed: `Variant6` --> $DIR/lint-dead-code-5.rs:14:5 @@ -29,9 +31,10 @@ error: variant is never constructed: `Variant6` LL | Variant6(isize), | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant6` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: enum is never used: `Enum3` --> $DIR/lint-dead-code-5.rs:35:6 @@ -39,9 +42,10 @@ error: enum is never used: `Enum3` LL | enum Enum3 { | ^^^^^ help: if this is intentional, prefix it with an underscore: `_Enum3` | - = note: the leading underscore helps signal to the reader that the enum may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the enum - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the enum may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: aborting due to 4 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-6.stderr b/src/test/ui/lint/dead-code/lint-dead-code-6.stderr index 687a49eb7619a..58714084ed3b5 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-6.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-6.stderr @@ -4,9 +4,10 @@ error: struct is never constructed: `UnusedStruct` LL | struct UnusedStruct; | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_UnusedStruct` | - = note: the leading underscore helps signal to the reader that the struct may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the struct - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the struct may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/lint-dead-code-6.rs:1:9 | @@ -19,9 +20,10 @@ error: associated function is never used: `unused_impl_fn_1` LL | fn unused_impl_fn_1() { | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_1` | - = note: the leading underscore helps signal to the reader that the associated function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the associated function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the associated function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: associated function is never used: `unused_impl_fn_2` --> $DIR/lint-dead-code-6.rs:9:8 @@ -29,9 +31,10 @@ error: associated function is never used: `unused_impl_fn_2` LL | fn unused_impl_fn_2(var: i32) { | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_2` | - = note: the leading underscore helps signal to the reader that the associated function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the associated function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the associated function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: associated function is never used: `unused_impl_fn_3` --> $DIR/lint-dead-code-6.rs:13:8 @@ -39,9 +42,10 @@ error: associated function is never used: `unused_impl_fn_3` LL | fn unused_impl_fn_3( | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_3` | - = note: the leading underscore helps signal to the reader that the associated function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the associated function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the associated function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: aborting due to 4 previous errors diff --git a/src/test/ui/lint/dead-code/newline-span.stderr b/src/test/ui/lint/dead-code/newline-span.stderr index b636079631c35..cfe83cff7c5ea 100644 --- a/src/test/ui/lint/dead-code/newline-span.stderr +++ b/src/test/ui/lint/dead-code/newline-span.stderr @@ -4,9 +4,10 @@ error: function is never used: `unused` LL | fn unused() { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/newline-span.rs:1:9 | @@ -19,9 +20,10 @@ error: function is never used: `unused2` LL | fn unused2(var: i32) { | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused2` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: function is never used: `unused3` --> $DIR/newline-span.rs:11:4 @@ -29,9 +31,10 @@ error: function is never used: `unused3` LL | fn unused3( | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused3` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: aborting due to 3 previous errors diff --git a/src/test/ui/lint/dead-code/type-alias.stderr b/src/test/ui/lint/dead-code/type-alias.stderr index 5c11626bb1e44..3533209eb1ddf 100644 --- a/src/test/ui/lint/dead-code/type-alias.stderr +++ b/src/test/ui/lint/dead-code/type-alias.stderr @@ -4,9 +4,10 @@ error: type alias is never used: `Unused` LL | type Unused = u8; | ^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Unused` | - = note: the leading underscore helps signal to the reader that the type alias may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the type alias - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the type alias may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/type-alias.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/unused-enum.stderr b/src/test/ui/lint/dead-code/unused-enum.stderr index c71d305987c77..646ec2b701fee 100644 --- a/src/test/ui/lint/dead-code/unused-enum.stderr +++ b/src/test/ui/lint/dead-code/unused-enum.stderr @@ -4,9 +4,10 @@ error: struct is never constructed: `F` LL | struct F; | ^ help: if this is intentional, prefix it with an underscore: `_F` | - = note: the leading underscore helps signal to the reader that the struct may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the struct - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the struct may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/unused-enum.rs:1:9 | @@ -20,9 +21,10 @@ error: struct is never constructed: `B` LL | struct B; | ^ help: if this is intentional, prefix it with an underscore: `_B` | - = note: the leading underscore helps signal to the reader that the struct may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the struct - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the struct may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: enum is never used: `E` --> $DIR/unused-enum.rs:6:6 @@ -30,9 +32,10 @@ error: enum is never used: `E` LL | enum E { | ^ help: if this is intentional, prefix it with an underscore: `_E` | - = note: the leading underscore helps signal to the reader that the enum may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the enum - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the enum may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: aborting due to 3 previous errors diff --git a/src/test/ui/lint/dead-code/unused-struct-variant.stderr b/src/test/ui/lint/dead-code/unused-struct-variant.stderr index 198986bde049d..9fe2259d89db7 100644 --- a/src/test/ui/lint/dead-code/unused-struct-variant.stderr +++ b/src/test/ui/lint/dead-code/unused-struct-variant.stderr @@ -4,9 +4,10 @@ error: variant is never constructed: `Bar` LL | Bar(B), | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_Bar` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/unused-struct-variant.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/unused-variant.stderr b/src/test/ui/lint/dead-code/unused-variant.stderr index 5fff7b1fdb3e0..a8eacf580c257 100644 --- a/src/test/ui/lint/dead-code/unused-variant.stderr +++ b/src/test/ui/lint/dead-code/unused-variant.stderr @@ -4,9 +4,10 @@ error: variant is never constructed: `Variant1` LL | Variant1, | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant1` | - = note: the leading underscore helps signal to the reader that the variant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the variant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the variant may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/unused-variant.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/with-core-crate.stderr b/src/test/ui/lint/dead-code/with-core-crate.stderr index ab4c1793b0667..386a17e953fac 100644 --- a/src/test/ui/lint/dead-code/with-core-crate.stderr +++ b/src/test/ui/lint/dead-code/with-core-crate.stderr @@ -4,9 +4,10 @@ error: function is never used: `foo` LL | fn foo() { | ^^^ help: if this is intentional, prefix it with an underscore: `_foo` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/with-core-crate.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/write-only-field.stderr b/src/test/ui/lint/dead-code/write-only-field.stderr index a7dcb69e2e366..ac307de729ca5 100644 --- a/src/test/ui/lint/dead-code/write-only-field.stderr +++ b/src/test/ui/lint/dead-code/write-only-field.stderr @@ -4,9 +4,10 @@ error: field is never read: `f` LL | f: i32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_f` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/write-only-field.rs:1:9 | @@ -19,9 +20,10 @@ error: field is never read: `sub` LL | sub: Sub, | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_sub` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: field is never read: `f` --> $DIR/write-only-field.rs:9:5 @@ -29,9 +31,10 @@ error: field is never read: `f` LL | f: i32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_f` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: field is never read: `y` --> $DIR/write-only-field.rs:28:9 @@ -39,9 +42,10 @@ error: field is never read: `y` LL | y: bool, | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_y` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: field is never read: `u` --> $DIR/write-only-field.rs:58:9 @@ -49,9 +53,10 @@ error: field is never read: `u` LL | u: u32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_u` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: field is never read: `v` --> $DIR/write-only-field.rs:59:9 @@ -59,9 +64,10 @@ error: field is never read: `v` LL | v: u32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_v` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: aborting due to 6 previous errors diff --git a/src/test/ui/lint/issue-17718-const-naming.stderr b/src/test/ui/lint/issue-17718-const-naming.stderr index f0d95f5b83d2f..a7805c3b8788f 100644 --- a/src/test/ui/lint/issue-17718-const-naming.stderr +++ b/src/test/ui/lint/issue-17718-const-naming.stderr @@ -4,9 +4,10 @@ error: constant is never used: `foo` LL | const foo: isize = 3; | ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_foo` | - = note: the leading underscore helps signal to the reader that the constant may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the constant - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the constant may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/issue-17718-const-naming.rs:2:9 | diff --git a/src/test/ui/span/macro-span-replacement.stderr b/src/test/ui/span/macro-span-replacement.stderr index 91f9f271e5ceb..b432bcb947eac 100644 --- a/src/test/ui/span/macro-span-replacement.stderr +++ b/src/test/ui/span/macro-span-replacement.stderr @@ -7,9 +7,10 @@ LL | $b $a; LL | m!(S struct); | ------------- in this macro invocation | - = note: the leading underscore helps signal to the reader that the struct may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the struct - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the struct may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/macro-span-replacement.rs:3:9 | diff --git a/src/test/ui/span/unused-warning-point-at-identifier.stderr b/src/test/ui/span/unused-warning-point-at-identifier.stderr index 21579fbd92b7c..f6d8dad9b9090 100644 --- a/src/test/ui/span/unused-warning-point-at-identifier.stderr +++ b/src/test/ui/span/unused-warning-point-at-identifier.stderr @@ -4,9 +4,10 @@ warning: enum is never used: `Enum` LL | enum Enum { | ^^^^ help: if this is intentional, prefix it with an underscore: `_Enum` | - = note: the leading underscore helps signal to the reader that the enum may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the enum - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the enum may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/unused-warning-point-at-identifier.rs:3:9 | @@ -20,9 +21,10 @@ warning: struct is never constructed: `Struct` LL | struct Struct { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_Struct` | - = note: the leading underscore helps signal to the reader that the struct may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the struct - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the struct may not be constructed + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) warning: function is never used: `func` --> $DIR/unused-warning-point-at-identifier.rs:19:4 @@ -30,9 +32,10 @@ warning: function is never used: `func` LL | fn func() -> usize { | ^^^^ help: if this is intentional, prefix it with an underscore: `_func` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) warning: function is never used: `func_complete_span` --> $DIR/unused-warning-point-at-identifier.rs:24:1 @@ -40,9 +43,10 @@ warning: function is never used: `func_complete_span` LL | func_complete_span() | ^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_func_complete_span` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) warning: 4 warnings emitted diff --git a/src/test/ui/test-attrs/test-warns-dead-code.stderr b/src/test/ui/test-attrs/test-warns-dead-code.stderr index d41a4e54985a2..0ab483e485c0f 100644 --- a/src/test/ui/test-attrs/test-warns-dead-code.stderr +++ b/src/test/ui/test-attrs/test-warns-dead-code.stderr @@ -4,9 +4,10 @@ error: function is never used: `dead` LL | fn dead() {} | ^^^^ help: if this is intentional, prefix it with an underscore: `_dead` | - = note: the leading underscore helps signal to the reader that the function may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the function - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the function may not be used + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/test-warns-dead-code.rs:3:9 | diff --git a/src/test/ui/union/union-fields-1.stderr b/src/test/ui/union/union-fields-1.stderr index 9c90e94ff91bf..1e0d6f48eb73a 100644 --- a/src/test/ui/union/union-fields-1.stderr +++ b/src/test/ui/union/union-fields-1.stderr @@ -4,9 +4,10 @@ error: field is never read: `c` LL | c: u8, | ^^^^^ help: if this is intentional, prefix it with an underscore: `_c` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/union-fields-1.rs:1:9 | @@ -19,9 +20,10 @@ error: field is never read: `a` LL | a: u8, | ^^^^^ help: if this is intentional, prefix it with an underscore: `_a` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: field is never read: `a` --> $DIR/union-fields-1.rs:13:20 @@ -29,9 +31,10 @@ error: field is never read: `a` LL | union NoDropLike { a: u8 } | ^^^^^ help: if this is intentional, prefix it with an underscore: `_a` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: field is never read: `c` --> $DIR/union-fields-1.rs:18:5 @@ -39,9 +42,10 @@ error: field is never read: `c` LL | c: u8, | ^^^^^ help: if this is intentional, prefix it with an underscore: `_c` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) error: aborting due to 4 previous errors diff --git a/src/test/ui/union/union-lint-dead-code.stderr b/src/test/ui/union/union-lint-dead-code.stderr index 6dfeae0248455..0e8546ec19803 100644 --- a/src/test/ui/union/union-lint-dead-code.stderr +++ b/src/test/ui/union/union-lint-dead-code.stderr @@ -4,9 +4,10 @@ error: field is never read: `b` LL | b: bool, | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` | - = note: the leading underscore helps signal to the reader that the field may still serve - a purpose even if it isn't used in a way that we can detect (e.g. the field - is only used through FFI or used only for its effect when dropped) + = note: The leading underscore signals to the reader that while the field may not be read + by any Rust code, it still serves some other purpose that isn't detected by rustc. + (e.g. some values are used for their effect when dropped or used in FFI code + exclusively through raw pointers) note: the lint level is defined here --> $DIR/union-lint-dead-code.rs:1:9 | From 2acd8eb21f9ab5a28f7c64efcf0245691e619da0 Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Fri, 12 Mar 2021 21:11:16 -0800 Subject: [PATCH 05/19] New shorter diagnostic note that is different for items versus fields --- compiler/rustc_passes/src/dead.rs | 54 +++++++++++---- .../associated-const-dead-code.stderr | 6 +- .../ui/derive-uninhabited-enum-38885.stderr | 6 +- src/test/ui/issues/issue-37515.stderr | 6 +- src/test/ui/lint/dead-code/basic.stderr | 6 +- .../ui/lint/dead-code/const-and-self.stderr | 12 ++-- .../drop-only-field-issue-81658.stderr | 7 +- .../lint/dead-code/empty-unused-enum.stderr | 6 +- .../field-used-in-ffi-issue-81658.stderr | 7 +- src/test/ui/lint/dead-code/impl-trait.stderr | 6 +- .../ui/lint/dead-code/lint-dead-code-1.stderr | 60 ++++++----------- .../ui/lint/dead-code/lint-dead-code-2.stderr | 18 ++--- .../ui/lint/dead-code/lint-dead-code-3.stderr | 30 +++------ .../ui/lint/dead-code/lint-dead-code-4.stderr | 65 +++++++------------ .../ui/lint/dead-code/lint-dead-code-5.stderr | 24 +++---- .../ui/lint/dead-code/lint-dead-code-6.stderr | 24 +++---- .../ui/lint/dead-code/newline-span.stderr | 18 ++--- src/test/ui/lint/dead-code/type-alias.stderr | 6 +- src/test/ui/lint/dead-code/unused-enum.stderr | 18 ++--- .../dead-code/unused-struct-variant.stderr | 6 +- .../ui/lint/dead-code/unused-variant.stderr | 6 +- .../ui/lint/dead-code/with-core-crate.stderr | 6 +- .../ui/lint/dead-code/write-only-field.stderr | 42 +++++------- .../ui/lint/issue-17718-const-naming.stderr | 6 +- .../ui/span/macro-span-replacement.stderr | 6 +- .../unused-warning-point-at-identifier.stderr | 24 +++---- .../ui/test-attrs/test-warns-dead-code.stderr | 6 +- src/test/ui/union/union-fields-1.stderr | 28 ++++---- src/test/ui/union/union-lint-dead-code.stderr | 7 +- 29 files changed, 207 insertions(+), 309 deletions(-) diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 8df91645626a3..3f6bb2c8d0f0a 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -506,6 +506,13 @@ fn find_live<'tcx>( symbol_visitor.live_symbols } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +enum ExtraNote { + /// Use this to provide some examples in the diagnostic of potential other purposes for a value + /// or field that is dead code + OtherPurposeExamples, +} + struct DeadVisitor<'tcx> { tcx: TyCtxt<'tcx>, live_symbols: FxHashSet, @@ -573,6 +580,7 @@ impl DeadVisitor<'tcx> { span: rustc_span::Span, name: Symbol, participle: &str, + extra_note: Option, ) { if !name.as_str().starts_with('_') { self.tcx.struct_span_lint_hir(lint::builtin::DEAD_CODE, id, span, |lint| { @@ -583,19 +591,26 @@ impl DeadVisitor<'tcx> { let mut diag = lint.build(&format!("{} is never {}: `{}`", descr, participle, name)); + diag.multipart_suggestion( "if this is intentional, prefix it with an underscore", prefixed, Applicability::MachineApplicable, - ) - .note(&format!( - "The leading underscore signals to the reader that while the {} may not be {}\n\ - by any Rust code, it still serves some other purpose that isn't detected by rustc.\n\ - (e.g. some values are used for their effect when dropped or used in FFI code\n\ - exclusively through raw pointers)", - descr, participle, - )); + ); + + 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.", + descr, + ); + if matches!(extra_note, Some(ExtraNote::OtherPurposeExamples)) { + note += " (e.g. for its effect\nwhen dropped or in foreign code)"; + } + + diag.note(¬e); + // Force the note we added to the front, before any other subdiagnostics + // added in lint.build(...) diag.children.rotate_right(1); diag.emit() @@ -644,7 +659,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); + self.warn_dead_code(item.hir_id(), span, item.ident.name, participle, None); } else { // Only continue if we didn't warn intravisit::walk_item(self, item); @@ -658,7 +673,7 @@ 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"); + self.warn_dead_code(variant.id, variant.span, variant.ident.name, "constructed", None); } else { intravisit::walk_variant(self, variant, g, id); } @@ -666,14 +681,20 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { 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"); + self.warn_dead_code(fi.hir_id(), fi.span, fi.ident.name, "used", None); } intravisit::walk_foreign_item(self, fi); } fn visit_field_def(&mut self, field: &'tcx hir::FieldDef<'tcx>) { if self.should_warn_about_field(&field) { - self.warn_dead_code(field.hir_id, field.span, field.ident.name, "read"); + self.warn_dead_code( + field.hir_id, + field.span, + field.ident.name, + "read", + Some(ExtraNote::OtherPurposeExamples), + ); } intravisit::walk_field_def(self, field); } @@ -687,6 +708,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { impl_item.span, impl_item.ident.name, "used", + None, ); } self.visit_nested_body(body_id) @@ -704,7 +726,13 @@ 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"); + self.warn_dead_code( + impl_item.hir_id(), + span, + impl_item.ident.name, + "used", + None, + ); } self.visit_nested_body(body_id) } diff --git a/src/test/ui/associated-consts/associated-const-dead-code.stderr b/src/test/ui/associated-consts/associated-const-dead-code.stderr index 9cf817905cc0a..ebd21c66a98b1 100644 --- a/src/test/ui/associated-consts/associated-const-dead-code.stderr +++ b/src/test/ui/associated-consts/associated-const-dead-code.stderr @@ -4,10 +4,8 @@ error: associated constant is never used: `BAR` LL | const BAR: u32 = 1; | ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_BAR` | - = note: The leading underscore signals to the reader that while the associated constant may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 | diff --git a/src/test/ui/derive-uninhabited-enum-38885.stderr b/src/test/ui/derive-uninhabited-enum-38885.stderr index de151b915d0a7..1583420697898 100644 --- a/src/test/ui/derive-uninhabited-enum-38885.stderr +++ b/src/test/ui/derive-uninhabited-enum-38885.stderr @@ -4,10 +4,8 @@ warning: variant is never constructed: `Void` LL | Void(Void), | ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Void` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 diff --git a/src/test/ui/issues/issue-37515.stderr b/src/test/ui/issues/issue-37515.stderr index 02da48748ec13..70bb990445236 100644 --- a/src/test/ui/issues/issue-37515.stderr +++ b/src/test/ui/issues/issue-37515.stderr @@ -4,10 +4,8 @@ warning: type alias is never used: `Z` LL | type Z = dyn for<'x> Send; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Z` | - = note: The leading underscore signals to the reader that while the type alias may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 | diff --git a/src/test/ui/lint/dead-code/basic.stderr b/src/test/ui/lint/dead-code/basic.stderr index 4b165c30003a6..40a1b69dc2fc7 100644 --- a/src/test/ui/lint/dead-code/basic.stderr +++ b/src/test/ui/lint/dead-code/basic.stderr @@ -4,10 +4,8 @@ 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 to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 | diff --git a/src/test/ui/lint/dead-code/const-and-self.stderr b/src/test/ui/lint/dead-code/const-and-self.stderr index 80da402f79817..b22fed0e537c1 100644 --- a/src/test/ui/lint/dead-code/const-and-self.stderr +++ b/src/test/ui/lint/dead-code/const-and-self.stderr @@ -4,10 +4,8 @@ warning: variant is never constructed: `B` LL | B, | ^ help: if this is intentional, prefix it with an underscore: `_B` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 | @@ -20,10 +18,8 @@ warning: variant is never constructed: `C` LL | C, | ^ help: if this is intentional, prefix it with an underscore: `_C` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 diff --git a/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr index dc9dcb770df0b..4418d8d5d3033 100644 --- a/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr +++ b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr @@ -4,10 +4,9 @@ error: field is never read: `guard` LL | guard: MutexGuard<'a, T>, | ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_guard` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 | diff --git a/src/test/ui/lint/dead-code/empty-unused-enum.stderr b/src/test/ui/lint/dead-code/empty-unused-enum.stderr index 8fa3ae27af3ea..bd62e9a984b1a 100644 --- a/src/test/ui/lint/dead-code/empty-unused-enum.stderr +++ b/src/test/ui/lint/dead-code/empty-unused-enum.stderr @@ -4,10 +4,8 @@ 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 to the reader that while the enum may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 | diff --git a/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr index e2f6849304d39..fab196a267517 100644 --- a/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr +++ b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr @@ -4,10 +4,9 @@ error: field is never read: `items` LL | items: Option>, | ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_items` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 | diff --git a/src/test/ui/lint/dead-code/impl-trait.stderr b/src/test/ui/lint/dead-code/impl-trait.stderr index bca3c4002de70..cca84602ba857 100644 --- a/src/test/ui/lint/dead-code/impl-trait.stderr +++ b/src/test/ui/lint/dead-code/impl-trait.stderr @@ -4,10 +4,8 @@ error: type alias is never used: `Unused` LL | type Unused = (); | ^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Unused` | - = note: The leading underscore signals to the reader that while the type alias may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 | diff --git a/src/test/ui/lint/dead-code/lint-dead-code-1.stderr b/src/test/ui/lint/dead-code/lint-dead-code-1.stderr index bd1de549134a0..7ddc89c995760 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-1.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-1.stderr @@ -4,10 +4,8 @@ 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 to the reader that while the struct may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 | @@ -20,10 +18,8 @@ error: static is never used: `priv_static` LL | static priv_static: isize = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_static` | - = note: The leading underscore signals to the reader that while the static may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 @@ -31,10 +27,8 @@ error: constant is never used: `priv_const` LL | const priv_const: isize = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_const` | - = note: The leading underscore signals to the reader that while the constant may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 @@ -42,10 +36,8 @@ error: struct is never constructed: `PrivStruct` LL | struct PrivStruct; | ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_PrivStruct` | - = note: The leading underscore signals to the reader that while the struct may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 @@ -53,10 +45,8 @@ error: enum is never used: `priv_enum` LL | enum priv_enum { foo2, bar2 } | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_enum` | - = note: The leading underscore signals to the reader that while the enum may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 @@ -64,10 +54,8 @@ error: variant is never constructed: `bar3` LL | bar3 | ^^^^ help: if this is intentional, prefix it with an underscore: `_bar3` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 @@ -75,10 +63,8 @@ error: function is never used: `priv_fn` LL | fn priv_fn() { | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_fn` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 @@ -86,10 +72,8 @@ 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 to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 @@ -97,10 +81,8 @@ error: function is never used: `bar` LL | fn bar() { | ^^^ help: if this is intentional, prefix it with an underscore: `_bar` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 @@ -108,10 +90,8 @@ error: function is never used: `baz` LL | fn baz() -> impl Copy { | ^^^ help: if this is intentional, prefix it with an underscore: `_baz` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 diff --git a/src/test/ui/lint/dead-code/lint-dead-code-2.stderr b/src/test/ui/lint/dead-code/lint-dead-code-2.stderr index ecc0169eadd56..dce763c5ed61f 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-2.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-2.stderr @@ -4,10 +4,8 @@ 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 to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 | @@ -20,10 +18,8 @@ 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 to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 @@ -31,10 +27,8 @@ error: function is never used: `main` LL | fn main() { | ^^^^ help: if this is intentional, prefix it with an underscore: `_main` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 diff --git a/src/test/ui/lint/dead-code/lint-dead-code-3.stderr b/src/test/ui/lint/dead-code/lint-dead-code-3.stderr index 53ccae0f0cec6..a5ecc91edb060 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-3.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-3.stderr @@ -4,10 +4,8 @@ error: struct is never constructed: `Foo` LL | struct Foo; | ^^^ help: if this is intentional, prefix it with an underscore: `_Foo` | - = note: The leading underscore signals to the reader that while the struct may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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-3.rs:4:9 | @@ -20,10 +18,8 @@ error: associated function is never used: `foo` LL | fn foo(&self) { | ^^^ help: if this is intentional, prefix it with an underscore: `_foo` | - = note: The leading underscore signals to the reader that while the associated function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = note: the leading underscore signals that this associated 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-3.rs:21:4 @@ -31,10 +27,8 @@ error: function is never used: `bar` LL | fn bar() { | ^^^ help: if this is intentional, prefix it with an underscore: `_bar` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: enum is never used: `c_void` --> $DIR/lint-dead-code-3.rs:60:6 @@ -42,10 +36,8 @@ error: enum is never used: `c_void` LL | enum c_void {} | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_c_void` | - = note: The leading underscore signals to the reader that while the enum may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: function is never used: `free` --> $DIR/lint-dead-code-3.rs:62:5 @@ -53,10 +45,8 @@ error: function is never used: `free` LL | fn free(p: *const c_void); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_free` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 5 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-4.stderr b/src/test/ui/lint/dead-code/lint-dead-code-4.stderr index 23e4a5ca69187..2297c172fc987 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-4.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-4.stderr @@ -4,10 +4,9 @@ error: field is never read: `b` LL | b: bool, | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/lint-dead-code-4.rs:3:9 | @@ -20,10 +19,8 @@ error: variant is never constructed: `X` LL | X, | ^ help: if this is intentional, prefix it with an underscore: `_X` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: variant is never constructed: `Y` --> $DIR/lint-dead-code-4.rs:16:5 @@ -35,10 +32,8 @@ LL | | c: i32, LL | | }, | |_____^ help: if this is intentional, prefix it with an underscore: `_Y` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: enum is never used: `ABC` --> $DIR/lint-dead-code-4.rs:24:6 @@ -46,10 +41,8 @@ error: enum is never used: `ABC` LL | enum ABC { | ^^^ help: if this is intentional, prefix it with an underscore: `_ABC` | - = note: The leading underscore signals to the reader that while the enum may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: `I` --> $DIR/lint-dead-code-4.rs:36:5 @@ -57,10 +50,8 @@ error: variant is never constructed: `I` LL | I, | ^ help: if this is intentional, prefix it with an underscore: `_I` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: field is never read: `b` --> $DIR/lint-dead-code-4.rs:39:9 @@ -68,10 +59,9 @@ error: field is never read: `b` LL | b: i32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: field is never read: `c` --> $DIR/lint-dead-code-4.rs:40:9 @@ -79,10 +69,9 @@ error: field is never read: `c` LL | c: i32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_c` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: variant is never constructed: `K` --> $DIR/lint-dead-code-4.rs:42:5 @@ -90,10 +79,8 @@ error: variant is never constructed: `K` LL | K | ^ help: if this is intentional, prefix it with an underscore: `_K` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: field is never read: `x` --> $DIR/lint-dead-code-4.rs:61:5 @@ -101,10 +88,9 @@ error: field is never read: `x` LL | x: usize, | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_x` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: field is never read: `c` --> $DIR/lint-dead-code-4.rs:63:5 @@ -112,10 +98,9 @@ error: field is never read: `c` LL | c: bool, | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_c` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: aborting due to 10 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-5.stderr b/src/test/ui/lint/dead-code/lint-dead-code-5.stderr index b0fcb9a199ca4..afe159c2d8bba 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-5.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-5.stderr @@ -4,10 +4,8 @@ error: variant is never constructed: `Variant2` LL | Variant2 | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant2` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/lint-dead-code-5.rs:2:9 | @@ -20,10 +18,8 @@ error: variant is never constructed: `Variant5` LL | Variant5 { _x: isize }, | ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant5` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: variant is never constructed: `Variant6` --> $DIR/lint-dead-code-5.rs:14:5 @@ -31,10 +27,8 @@ error: variant is never constructed: `Variant6` LL | Variant6(isize), | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant6` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: enum is never used: `Enum3` --> $DIR/lint-dead-code-5.rs:35:6 @@ -42,10 +36,8 @@ error: enum is never used: `Enum3` LL | enum Enum3 { | ^^^^^ help: if this is intentional, prefix it with an underscore: `_Enum3` | - = note: The leading underscore signals to the reader that while the enum may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: aborting due to 4 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-6.stderr b/src/test/ui/lint/dead-code/lint-dead-code-6.stderr index 58714084ed3b5..d212a4bc443d9 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-6.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-6.stderr @@ -4,10 +4,8 @@ error: struct is never constructed: `UnusedStruct` LL | struct UnusedStruct; | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_UnusedStruct` | - = note: The leading underscore signals to the reader that while the struct may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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-6.rs:1:9 | @@ -20,10 +18,8 @@ error: associated function is never used: `unused_impl_fn_1` LL | fn unused_impl_fn_1() { | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_1` | - = note: The leading underscore signals to the reader that while the associated function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = note: the leading underscore signals that this associated function serves some other purpose + even if it isn't used in a way that we can detect. error: associated function is never used: `unused_impl_fn_2` --> $DIR/lint-dead-code-6.rs:9:8 @@ -31,10 +27,8 @@ error: associated function is never used: `unused_impl_fn_2` LL | fn unused_impl_fn_2(var: i32) { | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_2` | - = note: The leading underscore signals to the reader that while the associated function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = note: the leading underscore signals that this associated function serves some other purpose + even if it isn't used in a way that we can detect. error: associated function is never used: `unused_impl_fn_3` --> $DIR/lint-dead-code-6.rs:13:8 @@ -42,10 +36,8 @@ error: associated function is never used: `unused_impl_fn_3` LL | fn unused_impl_fn_3( | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_3` | - = note: The leading underscore signals to the reader that while the associated function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = note: the leading underscore signals that this associated function serves some other purpose + even if it isn't used in a way that we can detect. error: aborting due to 4 previous errors diff --git a/src/test/ui/lint/dead-code/newline-span.stderr b/src/test/ui/lint/dead-code/newline-span.stderr index cfe83cff7c5ea..b57df1dfcedb4 100644 --- a/src/test/ui/lint/dead-code/newline-span.stderr +++ b/src/test/ui/lint/dead-code/newline-span.stderr @@ -4,10 +4,8 @@ error: function is never used: `unused` LL | fn unused() { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/newline-span.rs:1:9 | @@ -20,10 +18,8 @@ error: function is never used: `unused2` LL | fn unused2(var: i32) { | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused2` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: `unused3` --> $DIR/newline-span.rs:11:4 @@ -31,10 +27,8 @@ error: function is never used: `unused3` LL | fn unused3( | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused3` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 diff --git a/src/test/ui/lint/dead-code/type-alias.stderr b/src/test/ui/lint/dead-code/type-alias.stderr index 3533209eb1ddf..3e7298a6f2d3e 100644 --- a/src/test/ui/lint/dead-code/type-alias.stderr +++ b/src/test/ui/lint/dead-code/type-alias.stderr @@ -4,10 +4,8 @@ error: type alias is never used: `Unused` LL | type Unused = u8; | ^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Unused` | - = note: The leading underscore signals to the reader that while the type alias may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/type-alias.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/unused-enum.stderr b/src/test/ui/lint/dead-code/unused-enum.stderr index 646ec2b701fee..6e65e6565076f 100644 --- a/src/test/ui/lint/dead-code/unused-enum.stderr +++ b/src/test/ui/lint/dead-code/unused-enum.stderr @@ -4,10 +4,8 @@ error: struct is never constructed: `F` LL | struct F; | ^ help: if this is intentional, prefix it with an underscore: `_F` | - = note: The leading underscore signals to the reader that while the struct may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/unused-enum.rs:1:9 | @@ -21,10 +19,8 @@ error: struct is never constructed: `B` LL | struct B; | ^ help: if this is intentional, prefix it with an underscore: `_B` | - = note: The leading underscore signals to the reader that while the struct may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: `E` --> $DIR/unused-enum.rs:6:6 @@ -32,10 +28,8 @@ 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 to the reader that while the enum may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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: aborting due to 3 previous errors diff --git a/src/test/ui/lint/dead-code/unused-struct-variant.stderr b/src/test/ui/lint/dead-code/unused-struct-variant.stderr index 9fe2259d89db7..a5c7eea0579e6 100644 --- a/src/test/ui/lint/dead-code/unused-struct-variant.stderr +++ b/src/test/ui/lint/dead-code/unused-struct-variant.stderr @@ -4,10 +4,8 @@ error: variant is never constructed: `Bar` LL | Bar(B), | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_Bar` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/unused-struct-variant.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/unused-variant.stderr b/src/test/ui/lint/dead-code/unused-variant.stderr index a8eacf580c257..9536c492fc04f 100644 --- a/src/test/ui/lint/dead-code/unused-variant.stderr +++ b/src/test/ui/lint/dead-code/unused-variant.stderr @@ -4,10 +4,8 @@ error: variant is never constructed: `Variant1` LL | Variant1, | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant1` | - = note: The leading underscore signals to the reader that while the variant may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/unused-variant.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/with-core-crate.stderr b/src/test/ui/lint/dead-code/with-core-crate.stderr index 386a17e953fac..563b0b65020ee 100644 --- a/src/test/ui/lint/dead-code/with-core-crate.stderr +++ b/src/test/ui/lint/dead-code/with-core-crate.stderr @@ -4,10 +4,8 @@ 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 to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/with-core-crate.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/write-only-field.stderr b/src/test/ui/lint/dead-code/write-only-field.stderr index ac307de729ca5..f750beade18ec 100644 --- a/src/test/ui/lint/dead-code/write-only-field.stderr +++ b/src/test/ui/lint/dead-code/write-only-field.stderr @@ -4,10 +4,9 @@ error: field is never read: `f` LL | f: i32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_f` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/write-only-field.rs:1:9 | @@ -20,10 +19,9 @@ error: field is never read: `sub` LL | sub: Sub, | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_sub` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: field is never read: `f` --> $DIR/write-only-field.rs:9:5 @@ -31,10 +29,9 @@ error: field is never read: `f` LL | f: i32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_f` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: field is never read: `y` --> $DIR/write-only-field.rs:28:9 @@ -42,10 +39,9 @@ error: field is never read: `y` LL | y: bool, | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_y` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: field is never read: `u` --> $DIR/write-only-field.rs:58:9 @@ -53,10 +49,9 @@ error: field is never read: `u` LL | u: u32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_u` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: field is never read: `v` --> $DIR/write-only-field.rs:59:9 @@ -64,10 +59,9 @@ error: field is never read: `v` LL | v: u32, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_v` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: aborting due to 6 previous errors diff --git a/src/test/ui/lint/issue-17718-const-naming.stderr b/src/test/ui/lint/issue-17718-const-naming.stderr index a7805c3b8788f..0bafca2e4d785 100644 --- a/src/test/ui/lint/issue-17718-const-naming.stderr +++ b/src/test/ui/lint/issue-17718-const-naming.stderr @@ -4,10 +4,8 @@ error: constant is never used: `foo` LL | const foo: isize = 3; | ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_foo` | - = note: The leading underscore signals to the reader that while the constant may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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 lint level is defined here --> $DIR/issue-17718-const-naming.rs:2:9 | diff --git a/src/test/ui/span/macro-span-replacement.stderr b/src/test/ui/span/macro-span-replacement.stderr index b432bcb947eac..d5fad7c3b88ec 100644 --- a/src/test/ui/span/macro-span-replacement.stderr +++ b/src/test/ui/span/macro-span-replacement.stderr @@ -7,10 +7,8 @@ LL | $b $a; LL | m!(S struct); | ------------- in this macro invocation | - = note: The leading underscore signals to the reader that while the struct may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/macro-span-replacement.rs:3:9 | diff --git a/src/test/ui/span/unused-warning-point-at-identifier.stderr b/src/test/ui/span/unused-warning-point-at-identifier.stderr index f6d8dad9b9090..0bf85d252d60c 100644 --- a/src/test/ui/span/unused-warning-point-at-identifier.stderr +++ b/src/test/ui/span/unused-warning-point-at-identifier.stderr @@ -4,10 +4,8 @@ warning: enum is never used: `Enum` LL | enum Enum { | ^^^^ help: if this is intentional, prefix it with an underscore: `_Enum` | - = note: The leading underscore signals to the reader that while the enum may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/unused-warning-point-at-identifier.rs:3:9 | @@ -21,10 +19,8 @@ warning: struct is never constructed: `Struct` LL | struct Struct { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_Struct` | - = note: The leading underscore signals to the reader that while the struct may not be constructed - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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. warning: function is never used: `func` --> $DIR/unused-warning-point-at-identifier.rs:19:4 @@ -32,10 +28,8 @@ warning: function is never used: `func` LL | fn func() -> usize { | ^^^^ help: if this is intentional, prefix it with an underscore: `_func` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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. warning: function is never used: `func_complete_span` --> $DIR/unused-warning-point-at-identifier.rs:24:1 @@ -43,10 +37,8 @@ warning: function is never used: `func_complete_span` LL | func_complete_span() | ^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_func_complete_span` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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. warning: 4 warnings emitted diff --git a/src/test/ui/test-attrs/test-warns-dead-code.stderr b/src/test/ui/test-attrs/test-warns-dead-code.stderr index 0ab483e485c0f..795a9fb8820ce 100644 --- a/src/test/ui/test-attrs/test-warns-dead-code.stderr +++ b/src/test/ui/test-attrs/test-warns-dead-code.stderr @@ -4,10 +4,8 @@ error: function is never used: `dead` LL | fn dead() {} | ^^^^ help: if this is intentional, prefix it with an underscore: `_dead` | - = note: The leading underscore signals to the reader that while the function may not be used - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/test-warns-dead-code.rs:3:9 | diff --git a/src/test/ui/union/union-fields-1.stderr b/src/test/ui/union/union-fields-1.stderr index 1e0d6f48eb73a..e1695ca12cf72 100644 --- a/src/test/ui/union/union-fields-1.stderr +++ b/src/test/ui/union/union-fields-1.stderr @@ -4,10 +4,9 @@ error: field is never read: `c` LL | c: u8, | ^^^^^ help: if this is intentional, prefix it with an underscore: `_c` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/union-fields-1.rs:1:9 | @@ -20,10 +19,9 @@ error: field is never read: `a` LL | a: u8, | ^^^^^ help: if this is intentional, prefix it with an underscore: `_a` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: field is never read: `a` --> $DIR/union-fields-1.rs:13:20 @@ -31,10 +29,9 @@ error: field is never read: `a` LL | union NoDropLike { a: u8 } | ^^^^^ help: if this is intentional, prefix it with an underscore: `_a` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: field is never read: `c` --> $DIR/union-fields-1.rs:18:5 @@ -42,10 +39,9 @@ error: field is never read: `c` LL | c: u8, | ^^^^^ help: if this is intentional, prefix it with an underscore: `_c` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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) error: aborting due to 4 previous errors diff --git a/src/test/ui/union/union-lint-dead-code.stderr b/src/test/ui/union/union-lint-dead-code.stderr index 0e8546ec19803..565e13fb2ae1f 100644 --- a/src/test/ui/union/union-lint-dead-code.stderr +++ b/src/test/ui/union/union-lint-dead-code.stderr @@ -4,10 +4,9 @@ error: field is never read: `b` LL | b: bool, | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` | - = note: The leading underscore signals to the reader that while the field may not be read - by any Rust code, it still serves some other purpose that isn't detected by rustc. - (e.g. some values are used for their effect when dropped or used in FFI code - exclusively through raw pointers) + = 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/union-lint-dead-code.rs:1:9 | From 3e34eb8d7162efcd7d902e975d6501f422c148df Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Wed, 24 Mar 2021 20:23:49 -0700 Subject: [PATCH 06/19] Putting help message only under the identifier that needs to be prefixed --- compiler/rustc_passes/src/dead.rs | 28 ++++----- .../associated-const-dead-code.stderr | 7 ++- .../ui/derive-uninhabited-enum-38885.stderr | 7 ++- src/test/ui/issues/issue-37515.stderr | 7 ++- src/test/ui/lint/dead-code/basic.stderr | 3 +- .../ui/lint/dead-code/const-and-self.stderr | 6 +- .../drop-only-field-issue-81658.stderr | 8 +-- .../lint/dead-code/empty-unused-enum.stderr | 3 +- .../field-used-in-ffi-issue-81658.stderr | 8 +-- src/test/ui/lint/dead-code/impl-trait.stderr | 7 ++- .../ui/lint/dead-code/lint-dead-code-1.stderr | 38 +++++------- .../ui/lint/dead-code/lint-dead-code-2.stderr | 9 +-- .../ui/lint/dead-code/lint-dead-code-3.stderr | 19 +++--- .../ui/lint/dead-code/lint-dead-code-4.stderr | 62 +++++++++---------- .../ui/lint/dead-code/lint-dead-code-5.stderr | 20 +++--- .../ui/lint/dead-code/lint-dead-code-6.stderr | 12 ++-- .../ui/lint/dead-code/newline-span.stderr | 9 +-- src/test/ui/lint/dead-code/type-alias.stderr | 7 ++- src/test/ui/lint/dead-code/unused-enum.stderr | 9 +-- .../dead-code/unused-struct-variant.stderr | 7 ++- .../ui/lint/dead-code/unused-variant.stderr | 3 +- .../ui/lint/dead-code/with-core-crate.stderr | 3 +- .../ui/lint/dead-code/write-only-field.stderr | 48 +++++++------- .../ui/lint/issue-17718-const-naming.stderr | 7 ++- .../ui/span/macro-span-replacement.stderr | 7 ++- .../unused-warning-point-at-identifier.stderr | 12 ++-- .../ui/test-attrs/test-warns-dead-code.stderr | 3 +- src/test/ui/union/union-fields-1.stderr | 32 +++++----- src/test/ui/union/union-lint-dead-code.stderr | 8 +-- 29 files changed, 183 insertions(+), 216 deletions(-) diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 3f6bb2c8d0f0a..70b019e8468e7 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -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 @@ -578,7 +578,7 @@ impl DeadVisitor<'tcx> { &mut self, id: hir::HirId, span: rustc_span::Span, - name: Symbol, + name: Ident, participle: &str, extra_note: Option, ) { @@ -587,7 +587,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)); @@ -600,11 +600,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(¬e); @@ -659,7 +659,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); @@ -673,7 +673,7 @@ 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); } @@ -681,7 +681,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { 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); } @@ -691,7 +691,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), ); @@ -706,7 +706,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, ); @@ -726,13 +726,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) } diff --git a/src/test/ui/associated-consts/associated-const-dead-code.stderr b/src/test/ui/associated-consts/associated-const-dead-code.stderr index ebd21c66a98b1..e9915ba9e96a5 100644 --- a/src/test/ui/associated-consts/associated-const-dead-code.stderr +++ b/src/test/ui/associated-consts/associated-const-dead-code.stderr @@ -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 | diff --git a/src/test/ui/derive-uninhabited-enum-38885.stderr b/src/test/ui/derive-uninhabited-enum-38885.stderr index 1583420697898..ff8fb9953fb53 100644 --- a/src/test/ui/derive-uninhabited-enum-38885.stderr +++ b/src/test/ui/derive-uninhabited-enum-38885.stderr @@ -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 diff --git a/src/test/ui/issues/issue-37515.stderr b/src/test/ui/issues/issue-37515.stderr index 70bb990445236..3223554a5b778 100644 --- a/src/test/ui/issues/issue-37515.stderr +++ b/src/test/ui/issues/issue-37515.stderr @@ -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 | diff --git a/src/test/ui/lint/dead-code/basic.stderr b/src/test/ui/lint/dead-code/basic.stderr index 40a1b69dc2fc7..8264d0736e03e 100644 --- a/src/test/ui/lint/dead-code/basic.stderr +++ b/src/test/ui/lint/dead-code/basic.stderr @@ -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 | diff --git a/src/test/ui/lint/dead-code/const-and-self.stderr b/src/test/ui/lint/dead-code/const-and-self.stderr index b22fed0e537c1..e7233f386cc68 100644 --- a/src/test/ui/lint/dead-code/const-and-self.stderr +++ b/src/test/ui/lint/dead-code/const-and-self.stderr @@ -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 | @@ -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 diff --git a/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr index 4418d8d5d3033..f379a0941166f 100644 --- a/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr +++ b/src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr @@ -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 | diff --git a/src/test/ui/lint/dead-code/empty-unused-enum.stderr b/src/test/ui/lint/dead-code/empty-unused-enum.stderr index bd62e9a984b1a..5c06cd5a6a0b2 100644 --- a/src/test/ui/lint/dead-code/empty-unused-enum.stderr +++ b/src/test/ui/lint/dead-code/empty-unused-enum.stderr @@ -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 | diff --git a/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr index fab196a267517..d6a247d98e292 100644 --- a/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr +++ b/src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr @@ -2,11 +2,11 @@ error: field is never read: `items` --> $DIR/field-used-in-ffi-issue-81658.rs:13:5 | LL | items: Option>, - | ^^^^^^^^^^^^^^^^^^^^^ 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 | diff --git a/src/test/ui/lint/dead-code/impl-trait.stderr b/src/test/ui/lint/dead-code/impl-trait.stderr index cca84602ba857..fb18eb2819f76 100644 --- a/src/test/ui/lint/dead-code/impl-trait.stderr +++ b/src/test/ui/lint/dead-code/impl-trait.stderr @@ -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 | diff --git a/src/test/ui/lint/dead-code/lint-dead-code-1.stderr b/src/test/ui/lint/dead-code/lint-dead-code-1.stderr index 7ddc89c995760..15448448e1169 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-1.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-1.stderr @@ -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 | @@ -16,19 +15,21 @@ 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 @@ -36,8 +37,7 @@ error: struct is never constructed: `PrivStruct` 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 @@ -45,8 +45,7 @@ error: enum is never used: `priv_enum` 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 @@ -54,8 +53,7 @@ error: variant is never constructed: `bar3` 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 @@ -63,8 +61,7 @@ error: function is never used: `priv_fn` 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 @@ -72,8 +69,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. error: function is never used: `bar` --> $DIR/lint-dead-code-1.rs:98:4 @@ -81,8 +77,7 @@ error: function is never used: `bar` 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 @@ -90,8 +85,7 @@ error: function is never used: `baz` 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 diff --git a/src/test/ui/lint/dead-code/lint-dead-code-2.stderr b/src/test/ui/lint/dead-code/lint-dead-code-2.stderr index dce763c5ed61f..5e19c7d02ffd3 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-2.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-2.stderr @@ -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 | @@ -18,8 +17,7 @@ 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 @@ -27,8 +25,7 @@ error: function is never used: `main` 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 diff --git a/src/test/ui/lint/dead-code/lint-dead-code-3.stderr b/src/test/ui/lint/dead-code/lint-dead-code-3.stderr index a5ecc91edb060..d32fde5872d99 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-3.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-3.stderr @@ -4,8 +4,7 @@ error: struct is never constructed: `Foo` LL | struct Foo; | ^^^ help: if this is intentional, prefix it with an underscore: `_Foo` | - = 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-3.rs:4:9 | @@ -18,8 +17,7 @@ error: associated function is never used: `foo` LL | fn foo(&self) { | ^^^ help: if this is intentional, prefix it with an underscore: `_foo` | - = note: the leading underscore signals that this associated 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 associated 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-3.rs:21:4 @@ -27,8 +25,7 @@ error: function is never used: `bar` 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: enum is never used: `c_void` --> $DIR/lint-dead-code-3.rs:60:6 @@ -36,17 +33,17 @@ error: enum is never used: `c_void` LL | enum c_void {} | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_c_void` | - = 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: function is never used: `free` --> $DIR/lint-dead-code-3.rs:62:5 | LL | fn free(p: *const c_void); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_free` + | ^^^----^^^^^^^^^^^^^^^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_free` | - = 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 5 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-4.stderr b/src/test/ui/lint/dead-code/lint-dead-code-4.stderr index 2297c172fc987..2785faa29f5d9 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-4.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-4.stderr @@ -2,11 +2,11 @@ error: field is never read: `b` --> $DIR/lint-dead-code-4.rs:7:5 | LL | b: bool, - | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` + | -^^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_b` | - = 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/lint-dead-code-4.rs:3:9 | @@ -19,21 +19,22 @@ error: variant is never constructed: `X` LL | X, | ^ help: if this is intentional, prefix it with an underscore: `_X` | - = 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: variant is never constructed: `Y` --> $DIR/lint-dead-code-4.rs:16:5 | -LL | / Y { +LL | Y { + | ^ help: if this is intentional, prefix it with an underscore: `_Y` + | _____| + | | LL | | a: String, LL | | b: i32, LL | | c: i32, LL | | }, - | |_____^ help: if this is intentional, prefix it with an underscore: `_Y` + | |_____^ | - = 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: enum is never used: `ABC` --> $DIR/lint-dead-code-4.rs:24:6 @@ -41,8 +42,7 @@ error: enum is never used: `ABC` LL | enum ABC { | ^^^ help: if this is intentional, prefix it with an underscore: `_ABC` | - = 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: `I` --> $DIR/lint-dead-code-4.rs:36:5 @@ -50,28 +50,27 @@ error: variant is never constructed: `I` LL | I, | ^ help: if this is intentional, prefix it with an underscore: `_I` | - = 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: field is never read: `b` --> $DIR/lint-dead-code-4.rs:39:9 | LL | b: i32, - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` + | -^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_b` | - = 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) error: field is never read: `c` --> $DIR/lint-dead-code-4.rs:40:9 | LL | c: i32, - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_c` + | -^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_c` | - = 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) error: variant is never constructed: `K` --> $DIR/lint-dead-code-4.rs:42:5 @@ -79,28 +78,27 @@ error: variant is never constructed: `K` LL | K | ^ help: if this is intentional, prefix it with an underscore: `_K` | - = 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: field is never read: `x` --> $DIR/lint-dead-code-4.rs:61:5 | LL | x: usize, - | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_x` + | -^^^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_x` | - = 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) error: field is never read: `c` --> $DIR/lint-dead-code-4.rs:63:5 | LL | c: bool, - | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_c` + | -^^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_c` | - = 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) error: aborting due to 10 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-5.stderr b/src/test/ui/lint/dead-code/lint-dead-code-5.stderr index afe159c2d8bba..6375d98d35cb2 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-5.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-5.stderr @@ -4,8 +4,7 @@ error: variant is never constructed: `Variant2` LL | Variant2 | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant2` | - = 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/lint-dead-code-5.rs:2:9 | @@ -16,19 +15,21 @@ error: variant is never constructed: `Variant5` --> $DIR/lint-dead-code-5.rs:13:5 | LL | Variant5 { _x: isize }, - | ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant5` + | --------^^^^^^^^^^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_Variant5` | - = 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: variant is never constructed: `Variant6` --> $DIR/lint-dead-code-5.rs:14:5 | LL | Variant6(isize), - | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant6` + | --------^^^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_Variant6` | - = 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: enum is never used: `Enum3` --> $DIR/lint-dead-code-5.rs:35:6 @@ -36,8 +37,7 @@ error: enum is never used: `Enum3` LL | enum Enum3 { | ^^^^^ help: if this is intentional, prefix it with an underscore: `_Enum3` | - = 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: aborting due to 4 previous errors diff --git a/src/test/ui/lint/dead-code/lint-dead-code-6.stderr b/src/test/ui/lint/dead-code/lint-dead-code-6.stderr index d212a4bc443d9..ef26fe54ab589 100644 --- a/src/test/ui/lint/dead-code/lint-dead-code-6.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-6.stderr @@ -4,8 +4,7 @@ error: struct is never constructed: `UnusedStruct` LL | struct UnusedStruct; | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_UnusedStruct` | - = 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-6.rs:1:9 | @@ -18,8 +17,7 @@ error: associated function is never used: `unused_impl_fn_1` LL | fn unused_impl_fn_1() { | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_1` | - = note: the leading underscore signals that this associated 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 associated function serves some other purpose even if it isn't used in a way that we can detect. error: associated function is never used: `unused_impl_fn_2` --> $DIR/lint-dead-code-6.rs:9:8 @@ -27,8 +25,7 @@ error: associated function is never used: `unused_impl_fn_2` LL | fn unused_impl_fn_2(var: i32) { | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_2` | - = note: the leading underscore signals that this associated 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 associated function serves some other purpose even if it isn't used in a way that we can detect. error: associated function is never used: `unused_impl_fn_3` --> $DIR/lint-dead-code-6.rs:13:8 @@ -36,8 +33,7 @@ error: associated function is never used: `unused_impl_fn_3` LL | fn unused_impl_fn_3( | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_impl_fn_3` | - = note: the leading underscore signals that this associated 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 associated function serves some other purpose even if it isn't used in a way that we can detect. error: aborting due to 4 previous errors diff --git a/src/test/ui/lint/dead-code/newline-span.stderr b/src/test/ui/lint/dead-code/newline-span.stderr index b57df1dfcedb4..5bd566be35e01 100644 --- a/src/test/ui/lint/dead-code/newline-span.stderr +++ b/src/test/ui/lint/dead-code/newline-span.stderr @@ -4,8 +4,7 @@ error: function is never used: `unused` LL | fn unused() { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused` | - = 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/newline-span.rs:1:9 | @@ -18,8 +17,7 @@ error: function is never used: `unused2` LL | fn unused2(var: i32) { | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused2` | - = 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: `unused3` --> $DIR/newline-span.rs:11:4 @@ -27,8 +25,7 @@ error: function is never used: `unused3` LL | fn unused3( | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused3` | - = 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 diff --git a/src/test/ui/lint/dead-code/type-alias.stderr b/src/test/ui/lint/dead-code/type-alias.stderr index 3e7298a6f2d3e..1e7a030de3aa7 100644 --- a/src/test/ui/lint/dead-code/type-alias.stderr +++ b/src/test/ui/lint/dead-code/type-alias.stderr @@ -2,10 +2,11 @@ error: type alias is never used: `Unused` --> $DIR/type-alias.rs:4:1 | LL | type Unused = u8; - | ^^^^^^^^^^^^^^^^^ 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/type-alias.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/unused-enum.stderr b/src/test/ui/lint/dead-code/unused-enum.stderr index 6e65e6565076f..d536479c800ae 100644 --- a/src/test/ui/lint/dead-code/unused-enum.stderr +++ b/src/test/ui/lint/dead-code/unused-enum.stderr @@ -4,8 +4,7 @@ error: struct is never constructed: `F` LL | struct F; | ^ help: if this is intentional, prefix it with an underscore: `_F` | - = 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/unused-enum.rs:1:9 | @@ -19,8 +18,7 @@ error: struct is never constructed: `B` LL | struct B; | ^ help: if this is intentional, prefix it with an underscore: `_B` | - = 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: `E` --> $DIR/unused-enum.rs:6:6 @@ -28,8 +26,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. error: aborting due to 3 previous errors diff --git a/src/test/ui/lint/dead-code/unused-struct-variant.stderr b/src/test/ui/lint/dead-code/unused-struct-variant.stderr index a5c7eea0579e6..394ced3e81001 100644 --- a/src/test/ui/lint/dead-code/unused-struct-variant.stderr +++ b/src/test/ui/lint/dead-code/unused-struct-variant.stderr @@ -2,10 +2,11 @@ error: variant is never constructed: `Bar` --> $DIR/unused-struct-variant.rs:8:5 | LL | Bar(B), - | ^^^^^^ 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 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/unused-struct-variant.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/unused-variant.stderr b/src/test/ui/lint/dead-code/unused-variant.stderr index 9536c492fc04f..7dcb79d0490c1 100644 --- a/src/test/ui/lint/dead-code/unused-variant.stderr +++ b/src/test/ui/lint/dead-code/unused-variant.stderr @@ -4,8 +4,7 @@ error: variant is never constructed: `Variant1` LL | Variant1, | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Variant1` | - = 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/unused-variant.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/with-core-crate.stderr b/src/test/ui/lint/dead-code/with-core-crate.stderr index 563b0b65020ee..1bde434069ee7 100644 --- a/src/test/ui/lint/dead-code/with-core-crate.stderr +++ b/src/test/ui/lint/dead-code/with-core-crate.stderr @@ -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/with-core-crate.rs:1:9 | diff --git a/src/test/ui/lint/dead-code/write-only-field.stderr b/src/test/ui/lint/dead-code/write-only-field.stderr index f750beade18ec..13a21bb1193de 100644 --- a/src/test/ui/lint/dead-code/write-only-field.stderr +++ b/src/test/ui/lint/dead-code/write-only-field.stderr @@ -2,11 +2,11 @@ error: field is never read: `f` --> $DIR/write-only-field.rs:4:5 | LL | f: i32, - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_f` + | -^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_f` | - = 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/write-only-field.rs:1:9 | @@ -17,51 +17,51 @@ error: field is never read: `sub` --> $DIR/write-only-field.rs:5:5 | LL | sub: Sub, - | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_sub` + | ---^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_sub` | - = 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) error: field is never read: `f` --> $DIR/write-only-field.rs:9:5 | LL | f: i32, - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_f` + | -^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_f` | - = 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) error: field is never read: `y` --> $DIR/write-only-field.rs:28:9 | LL | y: bool, - | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_y` + | -^^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_y` | - = 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) error: field is never read: `u` --> $DIR/write-only-field.rs:58:9 | LL | u: u32, - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_u` + | -^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_u` | - = 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) error: field is never read: `v` --> $DIR/write-only-field.rs:59:9 | LL | v: u32, - | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_v` + | -^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_v` | - = 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) error: aborting due to 6 previous errors diff --git a/src/test/ui/lint/issue-17718-const-naming.stderr b/src/test/ui/lint/issue-17718-const-naming.stderr index 0bafca2e4d785..e880006e114c1 100644 --- a/src/test/ui/lint/issue-17718-const-naming.stderr +++ b/src/test/ui/lint/issue-17718-const-naming.stderr @@ -2,10 +2,11 @@ error: constant is never used: `foo` --> $DIR/issue-17718-const-naming.rs:4:1 | LL | const foo: isize = 3; - | ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_foo` + | ^^^^^^---^^^^^^^^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_foo` | - = 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. note: the lint level is defined here --> $DIR/issue-17718-const-naming.rs:2:9 | diff --git a/src/test/ui/span/macro-span-replacement.stderr b/src/test/ui/span/macro-span-replacement.stderr index d5fad7c3b88ec..f94a9e30a3dfa 100644 --- a/src/test/ui/span/macro-span-replacement.stderr +++ b/src/test/ui/span/macro-span-replacement.stderr @@ -2,13 +2,14 @@ warning: struct is never constructed: `S` --> $DIR/macro-span-replacement.rs:7:14 | LL | $b $a; - | ^ help: if this is intentional, prefix it with an underscore: `_S` + | --^ + | | + | help: if this is intentional, prefix it with an underscore: `_S` ... LL | m!(S struct); | ------------- in this macro invocation | - = 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/macro-span-replacement.rs:3:9 | diff --git a/src/test/ui/span/unused-warning-point-at-identifier.stderr b/src/test/ui/span/unused-warning-point-at-identifier.stderr index 0bf85d252d60c..3bf342f197252 100644 --- a/src/test/ui/span/unused-warning-point-at-identifier.stderr +++ b/src/test/ui/span/unused-warning-point-at-identifier.stderr @@ -4,8 +4,7 @@ warning: enum is never used: `Enum` LL | enum Enum { | ^^^^ help: if this is intentional, prefix it with an underscore: `_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. note: the lint level is defined here --> $DIR/unused-warning-point-at-identifier.rs:3:9 | @@ -19,8 +18,7 @@ warning: struct is never constructed: `Struct` LL | struct Struct { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_Struct` | - = 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. warning: function is never used: `func` --> $DIR/unused-warning-point-at-identifier.rs:19:4 @@ -28,8 +26,7 @@ warning: function is never used: `func` LL | fn func() -> usize { | ^^^^ help: if this is intentional, prefix it with an underscore: `_func` | - = 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. warning: function is never used: `func_complete_span` --> $DIR/unused-warning-point-at-identifier.rs:24:1 @@ -37,8 +34,7 @@ warning: function is never used: `func_complete_span` LL | func_complete_span() | ^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_func_complete_span` | - = 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. warning: 4 warnings emitted diff --git a/src/test/ui/test-attrs/test-warns-dead-code.stderr b/src/test/ui/test-attrs/test-warns-dead-code.stderr index 795a9fb8820ce..e5a8dee6ccb68 100644 --- a/src/test/ui/test-attrs/test-warns-dead-code.stderr +++ b/src/test/ui/test-attrs/test-warns-dead-code.stderr @@ -4,8 +4,7 @@ error: function is never used: `dead` LL | fn dead() {} | ^^^^ help: if this is intentional, prefix it with an underscore: `_dead` | - = 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/test-warns-dead-code.rs:3:9 | diff --git a/src/test/ui/union/union-fields-1.stderr b/src/test/ui/union/union-fields-1.stderr index e1695ca12cf72..3595bf6dce688 100644 --- a/src/test/ui/union/union-fields-1.stderr +++ b/src/test/ui/union/union-fields-1.stderr @@ -2,11 +2,11 @@ error: field is never read: `c` --> $DIR/union-fields-1.rs:6:5 | LL | c: u8, - | ^^^^^ help: if this is intentional, prefix it with an underscore: `_c` + | -^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_c` | - = 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/union-fields-1.rs:1:9 | @@ -17,31 +17,31 @@ error: field is never read: `a` --> $DIR/union-fields-1.rs:9:5 | LL | a: u8, - | ^^^^^ help: if this is intentional, prefix it with an underscore: `_a` + | -^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_a` | - = 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) error: field is never read: `a` --> $DIR/union-fields-1.rs:13:20 | LL | union NoDropLike { a: u8 } - | ^^^^^ help: if this is intentional, prefix it with an underscore: `_a` + | -^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_a` | - = 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) error: field is never read: `c` --> $DIR/union-fields-1.rs:18:5 | LL | c: u8, - | ^^^^^ help: if this is intentional, prefix it with an underscore: `_c` + | -^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_c` | - = 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) error: aborting due to 4 previous errors diff --git a/src/test/ui/union/union-lint-dead-code.stderr b/src/test/ui/union/union-lint-dead-code.stderr index 565e13fb2ae1f..8ead9cde9b333 100644 --- a/src/test/ui/union/union-lint-dead-code.stderr +++ b/src/test/ui/union/union-lint-dead-code.stderr @@ -2,11 +2,11 @@ error: field is never read: `b` --> $DIR/union-lint-dead-code.rs:5:5 | LL | b: bool, - | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_b` + | -^^^^^^ + | | + | help: if this is intentional, prefix it with an underscore: `_b` | - = 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/union-lint-dead-code.rs:1:9 | From 539242a07b15ec95aa196bfa4c18f6a8b01b8ecb Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 1 Apr 2021 08:37:29 +0900 Subject: [PATCH 07/19] Add a suggestion when using a type alias instead of trait alias --- compiler/rustc_resolve/src/late/diagnostics.rs | 9 ++++++++- src/test/ui/codemap_tests/two_files.stderr | 5 ++--- src/test/ui/resolve/issue-3907.stderr | 5 ++--- src/test/ui/resolve/issue-5035.stderr | 14 +++++++------- .../unboxed-closure-sugar-nonexistent-trait.stderr | 5 ++--- .../suggest-trait-alias-instead-of-type.fixed | 13 +++++++++++++ .../alias/suggest-trait-alias-instead-of-type.rs | 13 +++++++++++++ .../suggest-trait-alias-instead-of-type.stderr | 14 ++++++++++++++ 8 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.fixed create mode 100644 src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.rs create mode 100644 src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.stderr diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 1fb07bdae9d00..0314de9ebbe5d 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -928,7 +928,14 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \ `type` alias"; if let Some(span) = self.def_span(def_id) { - err.span_help(span, msg); + if let Ok(snip) = self.r.session.source_map().span_to_snippet(span) { + // The span contains a type alias so we should be able to + // replace `type` with `trait`. + let snip = snip.replacen("type", "trait", 1); + err.span_suggestion(span, msg, snip, Applicability::MaybeIncorrect); + } else { + err.span_help(span, msg); + } } else { err.help(msg); } diff --git a/src/test/ui/codemap_tests/two_files.stderr b/src/test/ui/codemap_tests/two_files.stderr index de2ffc2e5dc1d..aff51ee9e2f54 100644 --- a/src/test/ui/codemap_tests/two_files.stderr +++ b/src/test/ui/codemap_tests/two_files.stderr @@ -5,10 +5,9 @@ LL | impl Bar for Baz { } | ^^^ type aliases cannot be used as traits | help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias - --> $DIR/two_files_data.rs:5:1 | -LL | type Bar = dyn Foo; - | ^^^^^^^^^^^^^^^^^^^ +LL | trait Bar = dyn Foo; + | error: aborting due to previous error diff --git a/src/test/ui/resolve/issue-3907.stderr b/src/test/ui/resolve/issue-3907.stderr index 4d0b0af58a320..6fc61cae84339 100644 --- a/src/test/ui/resolve/issue-3907.stderr +++ b/src/test/ui/resolve/issue-3907.stderr @@ -5,10 +5,9 @@ LL | impl Foo for S { | ^^^ type aliases cannot be used as traits | help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias - --> $DIR/issue-3907.rs:5:1 | -LL | type Foo = dyn issue_3907::Foo; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | trait Foo = dyn issue_3907::Foo; + | help: consider importing this trait instead | LL | use issue_3907::Foo; diff --git a/src/test/ui/resolve/issue-5035.stderr b/src/test/ui/resolve/issue-5035.stderr index 41dff2fe54205..a8aa50b7c3ab2 100644 --- a/src/test/ui/resolve/issue-5035.stderr +++ b/src/test/ui/resolve/issue-5035.stderr @@ -11,16 +11,16 @@ LL | trait I {} | ------- similarly named trait `I` defined here LL | type K = dyn I; LL | impl K for isize {} - | ^ - | | - | type aliases cannot be used as traits - | help: a trait with a similar name exists: `I` + | ^ type aliases cannot be used as traits | help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias - --> $DIR/issue-5035.rs:2:1 | -LL | type K = dyn I; - | ^^^^^^^^^^^^^^^ +LL | trait K = dyn I; + | +help: a trait with a similar name exists + | +LL | impl I for isize {} + | ^ error: aborting due to 2 previous errors diff --git a/src/test/ui/resolve/unboxed-closure-sugar-nonexistent-trait.stderr b/src/test/ui/resolve/unboxed-closure-sugar-nonexistent-trait.stderr index 2974d08eb23b1..8addc0303fb91 100644 --- a/src/test/ui/resolve/unboxed-closure-sugar-nonexistent-trait.stderr +++ b/src/test/ui/resolve/unboxed-closure-sugar-nonexistent-trait.stderr @@ -11,10 +11,9 @@ LL | fn g isize>(x: F) {} | ^^^^^^^^^^^^^^^^^^^^^^^ type aliases cannot be used as traits | help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias - --> $DIR/unboxed-closure-sugar-nonexistent-trait.rs:4:1 | -LL | type Typedef = isize; - | ^^^^^^^^^^^^^^^^^^^^^ +LL | trait Typedef = isize; + | error: aborting due to 2 previous errors diff --git a/src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.fixed b/src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.fixed new file mode 100644 index 0000000000000..8a94abaeb0744 --- /dev/null +++ b/src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.fixed @@ -0,0 +1,13 @@ +// Regression test of #43913. + +// run-rustfix + +#![feature(trait_alias)] +#![allow(bare_trait_objects, dead_code)] + +trait Strings = Iterator; + +struct Struct(S); +//~^ ERROR: expected trait, found type alias `Strings` + +fn main() {} diff --git a/src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.rs b/src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.rs new file mode 100644 index 0000000000000..40c678c281f4c --- /dev/null +++ b/src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.rs @@ -0,0 +1,13 @@ +// Regression test of #43913. + +// run-rustfix + +#![feature(trait_alias)] +#![allow(bare_trait_objects, dead_code)] + +type Strings = Iterator; + +struct Struct(S); +//~^ ERROR: expected trait, found type alias `Strings` + +fn main() {} diff --git a/src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.stderr b/src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.stderr new file mode 100644 index 0000000000000..6e03eeada499c --- /dev/null +++ b/src/test/ui/traits/alias/suggest-trait-alias-instead-of-type.stderr @@ -0,0 +1,14 @@ +error[E0404]: expected trait, found type alias `Strings` + --> $DIR/suggest-trait-alias-instead-of-type.rs:10:18 + | +LL | struct Struct(S); + | ^^^^^^^ type aliases cannot be used as traits + | +help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias + | +LL | trait Strings = Iterator; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0404`. From eea27b81366a6a91a5b05153cd9ab6207d7f11bc Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 1 Apr 2021 08:39:48 +0900 Subject: [PATCH 08/19] Mention trait alias on the E0404 note --- .../src/error_codes/E0404.md | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0404.md b/compiler/rustc_error_codes/src/error_codes/E0404.md index 1360cc99afcc4..d6fa51e618c4c 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0404.md +++ b/compiler/rustc_error_codes/src/error_codes/E0404.md @@ -8,14 +8,15 @@ struct Foo; struct Bar; impl Foo for Bar {} // error: `Foo` is not a trait +fn baz(t: T) {} // error: `Foo` is not a trait ``` Another erroneous code example: ```compile_fail,E0404 -struct Foo; +type Foo = Iterator; -fn bar(t: T) {} // error: `Foo` is not a trait +fn bar(t: T) {} // error: `Foo` is a type alias ``` Please verify that the trait's name was not misspelled or that the right @@ -30,14 +31,27 @@ struct Bar; impl Foo for Bar { // ok! // functions implementation } + +fn baz(t: T) {} // ok! ``` -or: +Alternatively, you could introduce a new trait with your desired restrictions +as a super trait: ``` -trait Foo { - // some functions -} +# trait Foo {} +# struct Bar; +# impl Foo for Bar {} +trait Qux: Foo {} // Anything that implements Qux also needs to implement Foo +fn baz(t: T) {} // also ok! +``` + +Finally, if you are on nightly and want to use a trait alias +instead of a type alias, you should use `#![feature(trait_alias)]`: + +``` +#![feature(trait_alias)] +trait Foo = Iterator; fn bar(t: T) {} // ok! ``` From 9aa6c1e0c9ec1b24862ac061118a539706fbd7dc Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 16 Apr 2021 20:35:14 +0200 Subject: [PATCH 09/19] fix 'const-stable since' for NonZeroU*::new_unchecked --- library/core/src/num/nonzero.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 81262a2f91839..6b9b435d47fe9 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -23,7 +23,7 @@ macro_rules! impl_nonzero_fmt { } macro_rules! nonzero_integers { - ( $( #[$stability: meta] $Ty: ident($Int: ty); )+ ) => { + ( $( #[$stability: meta] #[$const_new_unchecked_stability: meta] $Ty: ident($Int: ty); )+ ) => { $( /// An integer that is known not to equal zero. /// @@ -48,7 +48,7 @@ macro_rules! nonzero_integers { /// /// The value must not be zero. #[$stability] - #[rustc_const_stable(feature = "nonzero", since = "1.34.0")] + #[$const_new_unchecked_stability] #[inline] pub const unsafe fn new_unchecked(n: $Int) -> Self { // SAFETY: this is guaranteed to be safe by the caller. @@ -146,18 +146,18 @@ macro_rules! nonzero_integers { } nonzero_integers! { - #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8); - #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16); - #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32); - #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU64(u64); - #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU128(u128); - #[stable(feature = "nonzero", since = "1.28.0")] NonZeroUsize(usize); - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI8(i8); - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI16(i16); - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI32(i32); - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI64(i64); - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI128(i128); - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIsize(isize); + #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8); + #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16); + #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32); + #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU64(u64); + #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU128(u128); + #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroUsize(usize); + #[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI8(i8); + #[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI16(i16); + #[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI32(i32); + #[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI64(i64); + #[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI128(i128); + #[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIsize(isize); } macro_rules! from_str_radix_nzint_impl { From df01b3a67b33ef0ff7ab1f27f41056093f5b2574 Mon Sep 17 00:00:00 2001 From: r00ster Date: Sun, 18 Apr 2021 15:51:16 +0200 Subject: [PATCH 10/19] Document that `index` and `index_mut` can panic --- library/core/src/ops/index.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/core/src/ops/index.rs b/library/core/src/ops/index.rs index a8dea4e9b4ea8..515ccd6aa2389 100644 --- a/library/core/src/ops/index.rs +++ b/library/core/src/ops/index.rs @@ -61,6 +61,10 @@ pub trait Index { type Output: ?Sized; /// Performs the indexing (`container[index]`) operation. + /// + /// # Panics + /// + /// Panics if the index is out of bounds. #[stable(feature = "rust1", since = "1.0.0")] #[track_caller] fn index(&self, index: Idx) -> &Self::Output; @@ -161,6 +165,10 @@ see chapter in The Book : Index { /// Performs the mutable indexing (`container[index]`) operation. + /// + /// # Panics + /// + /// Panics if the index is out of bounds. #[stable(feature = "rust1", since = "1.0.0")] #[track_caller] fn index_mut(&mut self, index: Idx) -> &mut Self::Output; From c86ffe9e8910cb1bac1737878a524e146b54375e Mon Sep 17 00:00:00 2001 From: r00ster Date: Sun, 18 Apr 2021 18:16:10 +0200 Subject: [PATCH 11/19] Say that it "may panic" --- library/core/src/ops/index.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/ops/index.rs b/library/core/src/ops/index.rs index 515ccd6aa2389..964378cc9c3c6 100644 --- a/library/core/src/ops/index.rs +++ b/library/core/src/ops/index.rs @@ -64,7 +64,7 @@ pub trait Index { /// /// # Panics /// - /// Panics if the index is out of bounds. + /// May panic if the index is out of bounds. #[stable(feature = "rust1", since = "1.0.0")] #[track_caller] fn index(&self, index: Idx) -> &Self::Output; @@ -168,7 +168,7 @@ pub trait IndexMut: Index { /// /// # Panics /// - /// Panics if the index is out of bounds. + /// May panic if the index is out of bounds. #[stable(feature = "rust1", since = "1.0.0")] #[track_caller] fn index_mut(&mut self, index: Idx) -> &mut Self::Output; From 569096cbaffe39fbede339430c5ed8e80d991a80 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sat, 17 Apr 2021 23:43:20 -0700 Subject: [PATCH 12/19] rustdoc: use details tag for trait implementors This switches from JS-generated toggles to using the HTML
tag for expanding and collapsing entries in the "Implementors" section. --- src/librustdoc/html/render/mod.rs | 15 ++++++++--- src/librustdoc/html/static/main.js | 27 +++++-------------- src/librustdoc/html/static/rustdoc.css | 8 +++++- src/test/rustdoc/const-generics/add-impl.rs | 2 +- .../rustdoc/duplicate_impls/issue-33054.rs | 4 +-- src/test/rustdoc/issue-21474.rs | 2 +- src/test/rustdoc/issue-29503.rs | 2 +- src/test/rustdoc/issue-45584.rs | 4 +-- src/test/rustdoc/issue-50159.rs | 4 +-- src/test/rustdoc/issue-51236.rs | 2 +- src/test/rustdoc/issue-53812.rs | 10 +++---- src/test/rustdoc/issue-54705.rs | 4 +-- src/test/rustdoc/issue-55321.rs | 8 +++--- src/test/rustdoc/issue-56822.rs | 2 +- src/test/rustdoc/issue-60726.rs | 4 +-- src/test/rustdoc/synthetic_auto/basic.rs | 4 +-- src/test/rustdoc/synthetic_auto/complex.rs | 2 +- src/test/rustdoc/synthetic_auto/lifetimes.rs | 4 +-- src/test/rustdoc/synthetic_auto/manual.rs | 8 +++--- src/test/rustdoc/synthetic_auto/negative.rs | 4 +-- src/test/rustdoc/synthetic_auto/nested.rs | 4 +-- .../rustdoc/synthetic_auto/no-redundancy.rs | 2 +- src/test/rustdoc/synthetic_auto/project.rs | 4 +-- .../synthetic_auto/self-referential.rs | 2 +- .../rustdoc/synthetic_auto/static-region.rs | 2 +- 25 files changed, 68 insertions(+), 66 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index d10b612a73799..a879a08ee472c 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1313,6 +1313,7 @@ fn render_impl( let cache = cx.cache(); let traits = &cache.traits; let trait_ = i.trait_did_full(cache).map(|did| &traits[&did]); + let mut close_tags = String::new(); if render_mode == RenderMode::Normal { let id = cx.derive_id(match i.inner_impl().trait_ { @@ -1331,7 +1332,12 @@ fn render_impl( format!(" aliases=\"{}\"", aliases.join(",")) }; if let Some(use_absolute) = use_absolute { - write!(w, "

", id, aliases); + write!( + w, + "

", + id, aliases + ); + close_tags.insert_str(0, "

"); write!(w, "{}", i.inner_impl().print(use_absolute, cx)); if show_def_docs { for it in &i.inner_impl().items { @@ -1354,11 +1360,12 @@ fn render_impl( } else { write!( w, - "

{}", + "

{}", id, aliases, i.inner_impl().print(false, cx) ); + close_tags.insert_str(0, "

"); } write!(w, "", id); render_stability_since_raw( @@ -1370,6 +1377,7 @@ fn render_impl( ); write_srclink(cx, &i.impl_item, w); w.write_str("

"); + w.write_str(""); if trait_.is_some() { if let Some(portability) = portability(&i.impl_item, Some(parent)) { @@ -1580,6 +1588,7 @@ fn render_impl( } w.write_str("
"); + close_tags.insert_str(0, "
"); for trait_item in &i.inner_impl().items { doc_impl_item( w, @@ -1650,7 +1659,7 @@ fn render_impl( ); } } - w.write_str(""); + w.write_str(&close_tags); } fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index f017fd846b1db..705ce89746a6a 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1196,31 +1196,18 @@ function hideThemeButtonState() { if (!next) { return; } - if (hasClass(e, "impl") && - (next.getElementsByClassName("method").length > 0 || - next.getElementsByClassName("associatedconstant").length > 0)) { - var newToggle = toggle.cloneNode(true); - insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]); - // In case the option "auto-collapse implementors" is not set to false, we collapse - // all implementors. - if (hideImplementors === true && e.parentNode.id === "implementors-list") { - collapseDocs(newToggle, "hide"); - } - } }; onEachLazy(document.getElementsByClassName("method"), func); onEachLazy(document.getElementsByClassName("associatedconstant"), func); - onEachLazy(document.getElementsByClassName("impl"), funcImpl); var impl_call = function() {}; - // Large items are hidden by default in the HTML. If the setting overrides that, show 'em. - if (!hideLargeItemContents) { - onEachLazy(document.getElementsByTagName("details"), function (e) { - if (hasClass(e, "type-contents-toggle")) { - e.open = true; - } - }); - } + onEachLazy(document.getElementsByTagName("details"), function (e) { + var showLargeItem = !hideLargeItemContents && hasClass(e, "type-contents-toggle"); + var showImplementor = !hideImplementors && hasClass(e, "implementors-toggle"); + if (showLargeItem || showImplementor) { + e.open = true; + } + }); if (hideMethodDocs === true) { impl_call = function(e, newToggle) { if (e.id.match(/^impl(?:-\d+)?$/) === null) { diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 427564cd7794a..d63679fa1570c 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1561,6 +1561,10 @@ h4 > .notable-traits { left: -10px; } + .item-list > details.rustdoc-toggle > summary:not(.hideme)::before { + left: -10px; + } + #all-types { margin: 10px; } @@ -1775,6 +1779,7 @@ details.rustdoc-toggle > summary::before { font-weight: 300; font-size: 0.8em; letter-spacing: 1px; + cursor: pointer; } details.rustdoc-toggle > summary.hideme::before { @@ -1782,7 +1787,8 @@ details.rustdoc-toggle > summary.hideme::before { } details.rustdoc-toggle > summary:not(.hideme)::before { - float: left; + position: absolute; + left: -23px; } /* When a "hideme" summary is open and the "Expand description" or "Show diff --git a/src/test/rustdoc/const-generics/add-impl.rs b/src/test/rustdoc/const-generics/add-impl.rs index db4be82e6bfd9..77432ba153955 100644 --- a/src/test/rustdoc/const-generics/add-impl.rs +++ b/src/test/rustdoc/const-generics/add-impl.rs @@ -8,7 +8,7 @@ pub struct Simd { inner: T, } -// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]/h3/code' 'impl Add> for Simd' +// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3/code' 'impl Add> for Simd' impl Add for Simd { type Output = Self; diff --git a/src/test/rustdoc/duplicate_impls/issue-33054.rs b/src/test/rustdoc/duplicate_impls/issue-33054.rs index 112d632971a5f..1e644bb973987 100644 --- a/src/test/rustdoc/duplicate_impls/issue-33054.rs +++ b/src/test/rustdoc/duplicate_impls/issue-33054.rs @@ -1,8 +1,8 @@ // @has issue_33054/impls/struct.Foo.html // @has - '//code' 'impl Foo' // @has - '//code' 'impl Bar for Foo' -// @count - '//*[@id="trait-implementations-list"]/*[@class="impl"]' 1 -// @count - '//*[@id="main"]/*[@class="impl"]' 1 +// @count - '//*[@id="trait-implementations-list"]//*[@class="impl"]' 1 +// @count - '//*[@id="main"]/details/summary/*[@class="impl"]' 1 // @has issue_33054/impls/bar/trait.Bar.html // @has - '//code' 'impl Bar for Foo' // @count - '//*[@class="struct"]' 1 diff --git a/src/test/rustdoc/issue-21474.rs b/src/test/rustdoc/issue-21474.rs index 896fc1a78f13f..5de26abace6fa 100644 --- a/src/test/rustdoc/issue-21474.rs +++ b/src/test/rustdoc/issue-21474.rs @@ -7,5 +7,5 @@ mod inner { pub trait Blah { } // @count issue_21474/struct.What.html \ -// '//*[@id="trait-implementations-list"]/*[@class="impl"]' 1 +// '//*[@id="trait-implementations-list"]//*[@class="impl"]' 1 pub struct What; diff --git a/src/test/rustdoc/issue-29503.rs b/src/test/rustdoc/issue-29503.rs index 19bab394dcf20..2b25da77d7e7b 100644 --- a/src/test/rustdoc/issue-29503.rs +++ b/src/test/rustdoc/issue-29503.rs @@ -5,7 +5,7 @@ pub trait MyTrait { fn my_string(&self) -> String; } -// @has - "//div[@id='implementors-list']/h3[@id='impl-MyTrait']//code" "impl MyTrait for T where T: Debug" +// @has - "//div[@id='implementors-list']//h3[@id='impl-MyTrait']//code" "impl MyTrait for T where T: Debug" impl MyTrait for T where T: fmt::Debug { fn my_string(&self) -> String { format!("{:?}", self) diff --git a/src/test/rustdoc/issue-45584.rs b/src/test/rustdoc/issue-45584.rs index 0225c0c5c2fa7..8a5f0413826a9 100644 --- a/src/test/rustdoc/issue-45584.rs +++ b/src/test/rustdoc/issue-45584.rs @@ -4,12 +4,12 @@ pub trait Bar {} // @has 'foo/struct.Foo1.html' pub struct Foo1; -// @count - '//*[@id="trait-implementations-list"]/*[@class="impl"]' 1 +// @count - '//*[@id="trait-implementations-list"]//*[@class="impl"]' 1 // @has - '//*[@class="impl"]' "impl Bar for Foo1" impl Bar for Foo1 {} // @has 'foo/struct.Foo2.html' pub struct Foo2; -// @count - '//*[@id="trait-implementations-list"]/*[@class="impl"]' 1 +// @count - '//*[@id="trait-implementations-list"]//*[@class="impl"]' 1 // @has - '//*[@class="impl"]' "impl Bar<&'static Foo2, Foo2> for u8" impl Bar<&'static Foo2, Foo2> for u8 {} diff --git a/src/test/rustdoc/issue-50159.rs b/src/test/rustdoc/issue-50159.rs index 74502be622a4f..0820512e52140 100644 --- a/src/test/rustdoc/issue-50159.rs +++ b/src/test/rustdoc/issue-50159.rs @@ -13,8 +13,8 @@ impl Signal2 for B where B: Signal { // @has issue_50159/struct.Switch.html // @has - '//code' 'impl Send for Switch where ::Item: Send' // @has - '//code' 'impl Sync for Switch where ::Item: Sync' -// @count - '//*[@id="implementations-list"]/*[@class="impl"]' 0 -// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 5 +// @count - '//*[@id="implementations-list"]//*[@class="impl"]' 0 +// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 5 pub struct Switch { pub inner: ::Item2, } diff --git a/src/test/rustdoc/issue-51236.rs b/src/test/rustdoc/issue-51236.rs index d9accf9c5998b..d018c948162d9 100644 --- a/src/test/rustdoc/issue-51236.rs +++ b/src/test/rustdoc/issue-51236.rs @@ -7,7 +7,7 @@ pub mod traits { } // @has issue_51236/struct.Owned.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl Send for \ // Owned where >::Reader: Send" pub struct Owned where T: for<'a> ::traits::Owned<'a> { marker: PhantomData<>::Reader>, diff --git a/src/test/rustdoc/issue-53812.rs b/src/test/rustdoc/issue-53812.rs index 3ebf154077f49..daebe059f8ef6 100644 --- a/src/test/rustdoc/issue-53812.rs +++ b/src/test/rustdoc/issue-53812.rs @@ -12,9 +12,9 @@ macro_rules! array_impls { } } -// @has issue_53812/trait.MyIterator.html '//*[@id="implementors-list"]//h3[1]' 'MyStruct<[T; 0]>' -// @has - '//*[@id="implementors-list"]//h3[2]' 'MyStruct<[T; 1]>' -// @has - '//*[@id="implementors-list"]//h3[3]' 'MyStruct<[T; 2]>' -// @has - '//*[@id="implementors-list"]//h3[4]' 'MyStruct<[T; 3]>' -// @has - '//*[@id="implementors-list"]//h3[5]' 'MyStruct<[T; 10]>' +// @has issue_53812/trait.MyIterator.html '//*[@id="implementors-list"]/details[1]/summary/h3' 'MyStruct<[T; 0]>' +// @has - '//*[@id="implementors-list"]/details[2]/summary/h3' 'MyStruct<[T; 1]>' +// @has - '//*[@id="implementors-list"]/details[3]/summary/h3' 'MyStruct<[T; 2]>' +// @has - '//*[@id="implementors-list"]/details[4]/summary/h3' 'MyStruct<[T; 3]>' +// @has - '//*[@id="implementors-list"]/details[5]/summary/h3' 'MyStruct<[T; 10]>' array_impls! { 10 3 2 1 0 } diff --git a/src/test/rustdoc/issue-54705.rs b/src/test/rustdoc/issue-54705.rs index 263b1eb0bd65a..47da94a4ccf4c 100644 --- a/src/test/rustdoc/issue-54705.rs +++ b/src/test/rustdoc/issue-54705.rs @@ -3,10 +3,10 @@ pub trait ScopeHandle<'scope> {} // @has issue_54705/struct.ScopeFutureContents.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'scope, S> \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'scope, S> \ // Send for ScopeFutureContents<'scope, S> where S: Sync" // -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'scope, S> \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'scope, S> \ // Sync for ScopeFutureContents<'scope, S> where S: Sync" pub struct ScopeFutureContents<'scope, S> where S: ScopeHandle<'scope>, diff --git a/src/test/rustdoc/issue-55321.rs b/src/test/rustdoc/issue-55321.rs index d312a5114595a..d1877f39ba761 100644 --- a/src/test/rustdoc/issue-55321.rs +++ b/src/test/rustdoc/issue-55321.rs @@ -1,16 +1,16 @@ #![feature(negative_impls)] // @has issue_55321/struct.A.html -// @has - '//*[@id="trait-implementations-list"]/*[@class="impl"]//code' "impl !Send for A" -// @has - '//*[@id="trait-implementations-list"]/*[@class="impl"]//code' "impl !Sync for A" +// @has - '//*[@id="trait-implementations-list"]//*[@class="impl"]//code' "impl !Send for A" +// @has - '//*[@id="trait-implementations-list"]//*[@class="impl"]//code' "impl !Sync for A" pub struct A(); impl !Send for A {} impl !Sync for A {} // @has issue_55321/struct.B.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl !Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl !Send for \ // B" -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl !Sync for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl !Sync for \ // B" pub struct B(A, Box); diff --git a/src/test/rustdoc/issue-56822.rs b/src/test/rustdoc/issue-56822.rs index 5b67817fa4caa..b932a3d34749c 100644 --- a/src/test/rustdoc/issue-56822.rs +++ b/src/test/rustdoc/issue-56822.rs @@ -17,7 +17,7 @@ impl<'a, T> MyTrait for Inner<'a, T> { } // @has issue_56822/struct.Parser.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'a> Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'a> Send for \ // Parser<'a>" pub struct Parser<'a> { field: > as MyTrait>::Output diff --git a/src/test/rustdoc/issue-60726.rs b/src/test/rustdoc/issue-60726.rs index 6acc86277385d..79b8b70c54525 100644 --- a/src/test/rustdoc/issue-60726.rs +++ b/src/test/rustdoc/issue-60726.rs @@ -26,9 +26,9 @@ where {} // @has issue_60726/struct.IntoIter.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl !Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl !Send for \ // IntoIter" -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl !Sync for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl !Sync for \ // IntoIter" pub struct IntoIter{ hello:DynTrait>, diff --git a/src/test/rustdoc/synthetic_auto/basic.rs b/src/test/rustdoc/synthetic_auto/basic.rs index 38de5316b6cf5..0dd3a3f7a86c5 100644 --- a/src/test/rustdoc/synthetic_auto/basic.rs +++ b/src/test/rustdoc/synthetic_auto/basic.rs @@ -1,8 +1,8 @@ // @has basic/struct.Foo.html // @has - '//code' 'impl Send for Foo where T: Send' // @has - '//code' 'impl Sync for Foo where T: Sync' -// @count - '//*[@id="implementations-list"]/*[@class="impl"]' 0 -// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 5 +// @count - '//*[@id="implementations-list"]//*[@class="impl"]' 0 +// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 5 pub struct Foo { field: T, } diff --git a/src/test/rustdoc/synthetic_auto/complex.rs b/src/test/rustdoc/synthetic_auto/complex.rs index 80a717718c22b..d951a20e2dec0 100644 --- a/src/test/rustdoc/synthetic_auto/complex.rs +++ b/src/test/rustdoc/synthetic_auto/complex.rs @@ -20,7 +20,7 @@ mod foo { } // @has complex/struct.NotOuter.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'a, T, K: \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'a, T, K: \ // ?Sized> Send for Outer<'a, T, K> where K: for<'b> Fn((&'b bool, &'a u8)) \ // -> &'b i8, T: MyTrait<'a>, >::MyItem: Copy, 'a: 'static" diff --git a/src/test/rustdoc/synthetic_auto/lifetimes.rs b/src/test/rustdoc/synthetic_auto/lifetimes.rs index 6d0a68f9b0734..05c88f10822ca 100644 --- a/src/test/rustdoc/synthetic_auto/lifetimes.rs +++ b/src/test/rustdoc/synthetic_auto/lifetimes.rs @@ -9,10 +9,10 @@ where {} // @has lifetimes/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'c, K> Send \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'c, K> Send \ // for Foo<'c, K> where K: for<'b> Fn(&'b bool) -> &'c u8, 'c: 'static" // -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'c, K> Sync \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'c, K> Sync \ // for Foo<'c, K> where K: Sync" pub struct Foo<'c, K: 'c> { inner_field: Inner<'c, K>, diff --git a/src/test/rustdoc/synthetic_auto/manual.rs b/src/test/rustdoc/synthetic_auto/manual.rs index d20b4744af15b..88ddd57349a29 100644 --- a/src/test/rustdoc/synthetic_auto/manual.rs +++ b/src/test/rustdoc/synthetic_auto/manual.rs @@ -1,12 +1,12 @@ // @has manual/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' 'impl Sync for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' 'impl Sync for \ // Foo where T: Sync' // -// @has - '//*[@id="trait-implementations-list"]/*[@class="impl"]//code' \ +// @has - '//*[@id="trait-implementations-list"]//*[@class="impl"]//code' \ // 'impl Send for Foo' // -// @count - '//*[@id="trait-implementations-list"]/*[@class="impl"]' 1 -// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 4 +// @count - '//*[@id="trait-implementations-list"]//*[@class="impl"]' 1 +// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 4 pub struct Foo { field: T, } diff --git a/src/test/rustdoc/synthetic_auto/negative.rs b/src/test/rustdoc/synthetic_auto/negative.rs index 30713849da221..53801542c9520 100644 --- a/src/test/rustdoc/synthetic_auto/negative.rs +++ b/src/test/rustdoc/synthetic_auto/negative.rs @@ -3,10 +3,10 @@ pub struct Inner { } // @has negative/struct.Outer.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl !Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl !Send for \ // Outer" // -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl \ // !Sync for Outer" pub struct Outer { inner_field: Inner, diff --git a/src/test/rustdoc/synthetic_auto/nested.rs b/src/test/rustdoc/synthetic_auto/nested.rs index e710ce1c2ed95..d4d93a87ffc9b 100644 --- a/src/test/rustdoc/synthetic_auto/nested.rs +++ b/src/test/rustdoc/synthetic_auto/nested.rs @@ -9,10 +9,10 @@ where } // @has nested/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' 'impl Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' 'impl Send for \ // Foo where T: Copy' // -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' \ // 'impl Sync for Foo where T: Sync' pub struct Foo { inner_field: Inner, diff --git a/src/test/rustdoc/synthetic_auto/no-redundancy.rs b/src/test/rustdoc/synthetic_auto/no-redundancy.rs index cf173111ec1e2..3a23dc2cf9576 100644 --- a/src/test/rustdoc/synthetic_auto/no-redundancy.rs +++ b/src/test/rustdoc/synthetic_auto/no-redundancy.rs @@ -9,7 +9,7 @@ where } // @has no_redundancy/struct.Outer.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl Send for \ // Outer where T: Copy + Send" pub struct Outer { inner_field: Inner, diff --git a/src/test/rustdoc/synthetic_auto/project.rs b/src/test/rustdoc/synthetic_auto/project.rs index 5346521f8d2e3..060491e3cf10f 100644 --- a/src/test/rustdoc/synthetic_auto/project.rs +++ b/src/test/rustdoc/synthetic_auto/project.rs @@ -23,10 +23,10 @@ where } // @has project/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'c, K> Send \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'c, K> Send \ // for Foo<'c, K> where K: MyTrait, 'c: 'static" // -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'c, K> Sync \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'c, K> Sync \ // for Foo<'c, K> where K: MyTrait, ::MyItem: OtherTrait, 'c: 'static," pub struct Foo<'c, K: 'c> { inner_field: Inner<'c, K>, diff --git a/src/test/rustdoc/synthetic_auto/self-referential.rs b/src/test/rustdoc/synthetic_auto/self-referential.rs index 905aa20918bef..ecdbdf41b2025 100644 --- a/src/test/rustdoc/synthetic_auto/self-referential.rs +++ b/src/test/rustdoc/synthetic_auto/self-referential.rs @@ -23,7 +23,7 @@ impl Pattern for Wrapper { // @has self_referential/struct.WriteAndThen.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl Send for \ // WriteAndThen where ::Value: Send" pub struct WriteAndThen(pub P1::Value,pub > as Pattern>::Value) where P1: Pattern; diff --git a/src/test/rustdoc/synthetic_auto/static-region.rs b/src/test/rustdoc/synthetic_auto/static-region.rs index 59493744b623d..a10e694c1b281 100644 --- a/src/test/rustdoc/synthetic_auto/static-region.rs +++ b/src/test/rustdoc/synthetic_auto/static-region.rs @@ -3,7 +3,7 @@ pub trait OwnedTrait<'a> { } // @has static_region/struct.Owned.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl Send for \ // Owned where >::Reader: Send" pub struct Owned where T: OwnedTrait<'static> { marker: >::Reader, From e85f19bbc82ad763bc0feba0e6af16a195d6a3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 20 Apr 2021 09:25:34 +0300 Subject: [PATCH 13/19] :arrow_up: rust-analyzer --- src/tools/rust-analyzer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer index 7be06139b632e..7570212a544b8 160000 --- a/src/tools/rust-analyzer +++ b/src/tools/rust-analyzer @@ -1 +1 @@ -Subproject commit 7be06139b632ee615fc18af04dd67947e2c794b2 +Subproject commit 7570212a544b8e973a7d57be3657aae6465028a7 From 8cc918a3dca757c6ea649f7d5d2aed963668bb38 Mon Sep 17 00:00:00 2001 From: Edd Barrett Date: Tue, 20 Apr 2021 10:19:25 +0100 Subject: [PATCH 14/19] Improve the docstrings of the `Lto` struct. --- compiler/rustc_session/src/config.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index b6b349e4a803d..b683626bbd64d 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -75,19 +75,21 @@ impl_stable_hash_via_hash!(OptLevel); /// This is what the `LtoCli` values get mapped to after resolving defaults and /// and taking other command line options into account. +/// +/// Note that linker plugin-based LTO is a different mechanism entirely. #[derive(Clone, PartialEq)] pub enum Lto { - /// Don't do any LTO whatsoever + /// Don't do any LTO whatsoever. No, - /// Do a full crate graph LTO with ThinLTO + /// Do a full-crate-graph (inter-crate) LTO with ThinLTO. Thin, - /// Do a local graph LTO with ThinLTO (only relevant for multiple codegen - /// units). + /// Do a local ThinLTO (intra-crate, over the CodeGen Units of the local crate only). This is + /// only relevant if multiple CGUs are used. ThinLocal, - /// Do a full crate graph LTO with "fat" LTO + /// Do a full-crate-graph (inter-crate) LTO with "fat" LTO. Fat, } From e9696c8b62c45903bed1bb39782abe43e392cd21 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 26 Mar 2021 13:39:04 +0000 Subject: [PATCH 15/19] Implement a lint that highlights all moves larger than 1000 bytes --- compiler/rustc_lint_defs/src/builtin.rs | 34 +++++++++++++++++ compiler/rustc_middle/src/mir/mod.rs | 22 ++++++++++- .../rustc_mir/src/monomorphize/collector.rs | 37 ++++++++++++++++++ .../rustc_mir/src/transform/const_prop.rs | 15 +------- src/test/ui/async-await/large_moves.rs | 21 ++++++++++ src/test/ui/async-await/large_moves.stderr | 38 +++++++++++++++++++ 6 files changed, 153 insertions(+), 14 deletions(-) create mode 100644 src/test/ui/async-await/large_moves.rs create mode 100644 src/test/ui/async-await/large_moves.stderr diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index f15a7cc5ec2ca..e29005c0c897d 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -2877,6 +2877,39 @@ declare_lint! { }; } +declare_lint! { + /// The `large_assigments` lint detects when objects of large + /// types are being moved around. + /// + /// ### Example + /// + /// ```rust,ignore (can crash on some platforms) + /// let x = [0; 50000]; + /// let y = x; + /// ``` + /// + /// produces: + /// + /// ```text + /// warning: moving a large value + /// --> $DIR/move-large.rs:1:3 + /// let y = x; + /// - Copied large value here + /// ``` + /// + /// ### Explanation + /// + /// When using a large type in a plain assignment or in a function + /// argument, idiomatic code can be inefficient. + /// Ideally appropriate optimizations would resolve this, but such + /// optimizations are only done in a best-effort manner. + /// This lint will trigger on all sites of large moves and thus allow the + /// user to resolve them in code. + pub LARGE_ASSIGNMENTS, + Allow, + "detects large moves or copies", +} + declare_lint_pass! { /// Does nothing as a lint pass, but registers some `Lint`s /// that are used by other parts of the compiler. @@ -2962,6 +2995,7 @@ declare_lint_pass! { LEGACY_DERIVE_HELPERS, PROC_MACRO_BACK_COMPAT, OR_PATTERNS_BACK_COMPAT, + LARGE_ASSIGNMENTS, ] } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 998868211401f..1ebb3dbe7c634 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -12,10 +12,10 @@ use crate::ty::print::{FmtPrinter, Printer}; use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::{self, List, Ty, TyCtxt}; use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex}; -use rustc_hir as hir; use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX}; use rustc_hir::{self, GeneratorKind}; +use rustc_hir::{self as hir, HirId}; use rustc_target::abi::{Size, VariantIdx}; use polonius_engine::Atom; @@ -1948,6 +1948,26 @@ rustc_index::newtype_index! { } } +impl SourceScope { + /// Finds the original HirId this MIR item came from. + /// This is necessary after MIR optimizations, as otherwise we get a HirId + /// from the function that was inlined instead of the function call site. + pub fn lint_root(self, source_scopes: &IndexVec>) -> Option { + let mut data = &source_scopes[self]; + // FIXME(oli-obk): we should be able to just walk the `inlined_parent_scope`, but it + // does not work as I thought it would. Needs more investigation and documentation. + while data.inlined.is_some() { + trace!(?data); + data = &source_scopes[data.parent_scope.unwrap()]; + } + trace!(?data); + match &data.local_data { + ClearCrossCrate::Set(data) => Some(data.lint_root), + ClearCrossCrate::Clear => None, + } + } +} + #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable)] pub struct SourceScopeData<'tcx> { pub span: Span, diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_mir/src/monomorphize/collector.rs index 1fda71d74bbf5..8ff3edac65fbe 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_mir/src/monomorphize/collector.rs @@ -198,7 +198,9 @@ use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts}; use rustc_middle::ty::{self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable}; use rustc_middle::{middle::codegen_fn_attrs::CodegenFnAttrFlags, mir::visit::TyContext}; use rustc_session::config::EntryFnType; +use rustc_session::lint::builtin::LARGE_ASSIGNMENTS; use rustc_span::source_map::{dummy_spanned, respan, Span, Spanned, DUMMY_SP}; +use rustc_target::abi::Size; use smallvec::SmallVec; use std::iter; use std::ops::Range; @@ -753,6 +755,41 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { self.super_terminator(terminator, location); } + fn visit_operand(&mut self, operand: &mir::Operand<'tcx>, location: Location) { + self.super_operand(operand, location); + let ty = operand.ty(self.body, self.tcx); + let ty = self.monomorphize(ty); + let layout = self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)); + if let Ok(layout) = layout { + if layout.size > Size::from_bytes(1000) { + debug!(?layout); + let source_info = self.body.source_info(location); + debug!(?source_info); + let lint_root = source_info.scope.lint_root(&self.body.source_scopes); + debug!(?lint_root); + let lint_root = match lint_root { + Some(lint_root) => lint_root, + // This happens when the issue is in a function from a foreign crate that + // we monomorphized in the current crate. We can't get a `HirId` for things + // in other crates. + // FIXME: Find out where to report the lint on. Maybe simply crate-level lint root + // but correct span? This would make the lint at least accept crate-level lint attributes. + None => return, + }; + self.tcx.struct_span_lint_hir( + LARGE_ASSIGNMENTS, + lint_root, + source_info.span, + |lint| { + let mut err = lint.build(&format!("moving {} bytes", layout.size.bytes())); + err.span_label(source_info.span, "value moved from here"); + err.emit() + }, + ); + } + } + } + fn visit_local( &mut self, _place_local: &Local, diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 7706316c96516..0d48ff6530e5b 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -13,7 +13,7 @@ use rustc_middle::mir::visit::{ MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor, }; use rustc_middle::mir::{ - AssertKind, BasicBlock, BinOp, Body, ClearCrossCrate, Constant, ConstantKind, Local, LocalDecl, + AssertKind, BasicBlock, BinOp, Body, Constant, ConstantKind, Local, LocalDecl, LocalKind, Location, Operand, Place, Rvalue, SourceInfo, SourceScope, SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE, }; @@ -440,18 +440,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } fn lint_root(&self, source_info: SourceInfo) -> Option { - let mut data = &self.source_scopes[source_info.scope]; - // FIXME(oli-obk): we should be able to just walk the `inlined_parent_scope`, but it - // does not work as I thought it would. Needs more investigation and documentation. - while data.inlined.is_some() { - trace!(?data); - data = &self.source_scopes[data.parent_scope.unwrap()]; - } - trace!(?data); - match &data.local_data { - ClearCrossCrate::Set(data) => Some(data.lint_root), - ClearCrossCrate::Clear => None, - } + source_info.scope.lint_root(&self.source_scopes) } fn use_ecx(&mut self, f: F) -> Option diff --git a/src/test/ui/async-await/large_moves.rs b/src/test/ui/async-await/large_moves.rs new file mode 100644 index 0000000000000..7e6819d6d1390 --- /dev/null +++ b/src/test/ui/async-await/large_moves.rs @@ -0,0 +1,21 @@ +#![deny(large_assignments)] +// build-fail + +// edition:2018 + +fn main() { + let x = async { //~ ERROR large_assignments + let y = [0; 9999]; + dbg!(y); + thing(&y).await; + dbg!(y); + }; + let z = (x, 42); //~ ERROR large_assignments + //~^ ERROR large_assignments + let a = z.0; //~ ERROR large_assignments + let b = z.1; +} + +async fn thing(y: &[u8]) { + dbg!(y); +} \ No newline at end of file diff --git a/src/test/ui/async-await/large_moves.stderr b/src/test/ui/async-await/large_moves.stderr new file mode 100644 index 0000000000000..d395d2ae8696d --- /dev/null +++ b/src/test/ui/async-await/large_moves.stderr @@ -0,0 +1,38 @@ +error: moving 10024 bytes + --> $DIR/large_moves.rs:7:13 + | +LL | let x = async { + | _____________^ +LL | | let y = [0; 9999]; +LL | | dbg!(y); +LL | | thing(&y).await; +LL | | dbg!(y); +LL | | }; + | |_____^ value moved from here + | +note: the lint level is defined here + --> $DIR/large_moves.rs:1:9 + | +LL | #![deny(large_assignments)] + | ^^^^^^^^^^^^^^^^^ + +error: moving 10024 bytes + --> $DIR/large_moves.rs:13:14 + | +LL | let z = (x, 42); + | ^ value moved from here + +error: moving 10024 bytes + --> $DIR/large_moves.rs:13:13 + | +LL | let z = (x, 42); + | ^^^^^^^ value moved from here + +error: moving 10024 bytes + --> $DIR/large_moves.rs:15:13 + | +LL | let a = z.0; + | ^^^ value moved from here + +error: aborting due to 4 previous errors + From a2f217902675d8ad29ecb79a8c153b485d85cb7b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 26 Mar 2021 16:28:52 +0000 Subject: [PATCH 16/19] Add an attribute to be able to configure the limit --- compiler/rustc_feature/src/active.rs | 3 +++ compiler/rustc_feature/src/builtin_attrs.rs | 4 ++++ compiler/rustc_lint_defs/src/builtin.rs | 2 +- compiler/rustc_middle/src/middle/limits.rs | 15 ++++++++++----- compiler/rustc_mir/src/monomorphize/collector.rs | 7 ++++++- compiler/rustc_session/src/session.rs | 16 ++++++++++++++++ compiler/rustc_span/src/symbol.rs | 2 ++ src/test/ui/async-await/large_moves.rs | 2 ++ src/test/ui/async-await/large_moves.stderr | 8 ++++---- .../feature-gate-large-assignments.rs | 5 +++++ .../feature-gate-large-assignments.stderr | 12 ++++++++++++ 11 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 src/test/ui/feature-gates/feature-gate-large-assignments.rs create mode 100644 src/test/ui/feature-gates/feature-gate-large-assignments.stderr diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index a410826d3fda6..eb143e5bac22d 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -633,6 +633,9 @@ declare_features! ( /// Allows associated types in inherent impls. (active, inherent_associated_types, "1.52.0", Some(8995), None), + // Allows setting the threshold for the `large_assignments` lint. + (active, large_assignments, "1.52.0", Some(83518), None), + /// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries. (active, c_unwind, "1.52.0", Some(74990), None), diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 43054f5bf5e70..8dfc4572a848c 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -241,6 +241,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ const_eval_limit, CrateLevel, template!(NameValueStr: "N"), const_eval_limit, experimental!(const_eval_limit) ), + gated!( + move_size_limit, CrateLevel, template!(NameValueStr: "N"), large_assignments, + experimental!(move_size_limit) + ), // Entry point: ungated!(main, Normal, template!(Word)), diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index e29005c0c897d..2edb8b717fd57 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -2906,7 +2906,7 @@ declare_lint! { /// This lint will trigger on all sites of large moves and thus allow the /// user to resolve them in code. pub LARGE_ASSIGNMENTS, - Allow, + Warn, "detects large moves or copies", } diff --git a/compiler/rustc_middle/src/middle/limits.rs b/compiler/rustc_middle/src/middle/limits.rs index 61f850c2fc166..601198fd0de04 100644 --- a/compiler/rustc_middle/src/middle/limits.rs +++ b/compiler/rustc_middle/src/middle/limits.rs @@ -1,4 +1,8 @@ -//! Registering limits, recursion_limit, type_length_limit and const_eval_limit +//! Registering limits: +//! * recursion_limit, +//! * move_size_limit, +//! * type_length_limit, and +//! * const_eval_limit //! //! There are various parts of the compiler that must impose arbitrary limits //! on how deeply they recurse to prevent stack overflow. Users can override @@ -8,13 +12,14 @@ use crate::bug; use rustc_ast as ast; use rustc_data_structures::sync::OnceCell; -use rustc_session::{Limit, Session}; +use rustc_session::Session; use rustc_span::symbol::{sym, Symbol}; use std::num::IntErrorKind; pub fn update_limits(sess: &Session, krate: &ast::Crate) { update_limit(sess, krate, &sess.recursion_limit, sym::recursion_limit, 128); + update_limit(sess, krate, &sess.move_size_limit, sym::move_size_limit, 0); update_limit(sess, krate, &sess.type_length_limit, sym::type_length_limit, 1048576); update_limit(sess, krate, &sess.const_eval_limit, sym::const_eval_limit, 1_000_000); } @@ -22,7 +27,7 @@ pub fn update_limits(sess: &Session, krate: &ast::Crate) { fn update_limit( sess: &Session, krate: &ast::Crate, - limit: &OnceCell, + limit: &OnceCell + std::fmt::Debug>, name: Symbol, default: usize, ) { @@ -34,7 +39,7 @@ fn update_limit( if let Some(s) = attr.value_str() { match s.as_str().parse() { Ok(n) => { - limit.set(Limit::new(n)).unwrap(); + limit.set(From::from(n)).unwrap(); return; } Err(e) => { @@ -63,5 +68,5 @@ fn update_limit( } } } - limit.set(Limit::new(default)).unwrap(); + limit.set(From::from(default)).unwrap(); } diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_mir/src/monomorphize/collector.rs index 8ff3edac65fbe..e621bc9167d80 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_mir/src/monomorphize/collector.rs @@ -757,11 +757,16 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { fn visit_operand(&mut self, operand: &mir::Operand<'tcx>, location: Location) { self.super_operand(operand, location); + let limit = self.tcx.sess.move_size_limit(); + if limit == 0 { + return; + } + let limit = Size::from_bytes(limit); let ty = operand.ty(self.body, self.tcx); let ty = self.monomorphize(ty); let layout = self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)); if let Ok(layout) = layout { - if layout.size > Size::from_bytes(1000) { + if layout.size > limit { debug!(?layout); let source_info = self.body.source_info(location); debug!(?source_info); diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index cc2583be94474..7bff634fb2dd0 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -83,6 +83,12 @@ impl Limit { } } +impl From for Limit { + fn from(value: usize) -> Self { + Self::new(value) + } +} + impl fmt::Display for Limit { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0) @@ -143,6 +149,10 @@ pub struct Session { /// operations such as auto-dereference and monomorphization. pub recursion_limit: OnceCell, + /// The size at which the `large_assignments` lint starts + /// being emitted. + pub move_size_limit: OnceCell, + /// The maximum length of types during monomorphization. pub type_length_limit: OnceCell, @@ -352,6 +362,11 @@ impl Session { self.recursion_limit.get().copied().unwrap() } + #[inline] + pub fn move_size_limit(&self) -> usize { + self.move_size_limit.get().copied().unwrap() + } + #[inline] pub fn type_length_limit(&self) -> Limit { self.type_length_limit.get().copied().unwrap() @@ -1414,6 +1429,7 @@ pub fn build_session( features: OnceCell::new(), lint_store: OnceCell::new(), recursion_limit: OnceCell::new(), + move_size_limit: OnceCell::new(), type_length_limit: OnceCell::new(), const_eval_limit: OnceCell::new(), incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 52270f0e6277b..5c46e7d9af90d 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -669,6 +669,7 @@ symbols! { label_break_value, lang, lang_items, + large_assignments, lateout, lazy_normalization_consts, le, @@ -749,6 +750,7 @@ symbols! { more_struct_aliases, movbe_target_feature, move_ref_pattern, + move_size_limit, mul, mul_assign, mul_with_overflow, diff --git a/src/test/ui/async-await/large_moves.rs b/src/test/ui/async-await/large_moves.rs index 7e6819d6d1390..fff23db3351e8 100644 --- a/src/test/ui/async-await/large_moves.rs +++ b/src/test/ui/async-await/large_moves.rs @@ -1,4 +1,6 @@ #![deny(large_assignments)] +#![feature(large_assignments)] +#![move_size_limit = "1000"] // build-fail // edition:2018 diff --git a/src/test/ui/async-await/large_moves.stderr b/src/test/ui/async-await/large_moves.stderr index d395d2ae8696d..476f5875beb3b 100644 --- a/src/test/ui/async-await/large_moves.stderr +++ b/src/test/ui/async-await/large_moves.stderr @@ -1,5 +1,5 @@ error: moving 10024 bytes - --> $DIR/large_moves.rs:7:13 + --> $DIR/large_moves.rs:9:13 | LL | let x = async { | _____________^ @@ -17,19 +17,19 @@ LL | #![deny(large_assignments)] | ^^^^^^^^^^^^^^^^^ error: moving 10024 bytes - --> $DIR/large_moves.rs:13:14 + --> $DIR/large_moves.rs:15:14 | LL | let z = (x, 42); | ^ value moved from here error: moving 10024 bytes - --> $DIR/large_moves.rs:13:13 + --> $DIR/large_moves.rs:15:13 | LL | let z = (x, 42); | ^^^^^^^ value moved from here error: moving 10024 bytes - --> $DIR/large_moves.rs:15:13 + --> $DIR/large_moves.rs:17:13 | LL | let a = z.0; | ^^^ value moved from here diff --git a/src/test/ui/feature-gates/feature-gate-large-assignments.rs b/src/test/ui/feature-gates/feature-gate-large-assignments.rs new file mode 100644 index 0000000000000..7e9e574bfa08f --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-large-assignments.rs @@ -0,0 +1,5 @@ +// check that `move_size_limit is feature-gated + +#![move_size_limit = "42"] //~ ERROR the `#[move_size_limit]` attribute is an experimental feature + +fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-large-assignments.stderr b/src/test/ui/feature-gates/feature-gate-large-assignments.stderr new file mode 100644 index 0000000000000..8ddc3043e966c --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-large-assignments.stderr @@ -0,0 +1,12 @@ +error[E0658]: the `#[move_size_limit]` attribute is an experimental feature + --> $DIR/feature-gate-large-assignments.rs:3:1 + | +LL | #![move_size_limit = "42"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #83518 for more information + = help: add `#![feature(large_assignments)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. From a46bc5664a88f7a4ffdd74e5a45c5e2c2e31826e Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 26 Mar 2021 16:33:14 +0000 Subject: [PATCH 17/19] Tidy --- compiler/rustc_middle/src/mir/mod.rs | 5 ++++- compiler/rustc_mir/src/transform/const_prop.rs | 6 +++--- src/test/ui/async-await/large_moves.rs | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 1ebb3dbe7c634..e22c0b40d5a53 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1952,7 +1952,10 @@ impl SourceScope { /// Finds the original HirId this MIR item came from. /// This is necessary after MIR optimizations, as otherwise we get a HirId /// from the function that was inlined instead of the function call site. - pub fn lint_root(self, source_scopes: &IndexVec>) -> Option { + pub fn lint_root( + self, + source_scopes: &IndexVec>, + ) -> Option { let mut data = &source_scopes[self]; // FIXME(oli-obk): we should be able to just walk the `inlined_parent_scope`, but it // does not work as I thought it would. Needs more investigation and documentation. diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 0d48ff6530e5b..5968bbbfca7f3 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -13,9 +13,9 @@ use rustc_middle::mir::visit::{ MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor, }; use rustc_middle::mir::{ - AssertKind, BasicBlock, BinOp, Body, Constant, ConstantKind, Local, LocalDecl, - LocalKind, Location, Operand, Place, Rvalue, SourceInfo, SourceScope, SourceScopeData, - Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE, + AssertKind, BasicBlock, BinOp, Body, Constant, ConstantKind, Local, LocalDecl, LocalKind, + Location, Operand, Place, Rvalue, SourceInfo, SourceScope, SourceScopeData, Statement, + StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE, }; use rustc_middle::ty::layout::{HasTyCtxt, LayoutError, TyAndLayout}; use rustc_middle::ty::subst::{InternalSubsts, Subst}; diff --git a/src/test/ui/async-await/large_moves.rs b/src/test/ui/async-await/large_moves.rs index fff23db3351e8..612433f26789e 100644 --- a/src/test/ui/async-await/large_moves.rs +++ b/src/test/ui/async-await/large_moves.rs @@ -20,4 +20,4 @@ fn main() { async fn thing(y: &[u8]) { dbg!(y); -} \ No newline at end of file +} From 6e988c061330a53ea6826aee2fa2c057202aa1c4 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 26 Mar 2021 18:22:35 +0000 Subject: [PATCH 18/19] Typo --- compiler/rustc_lint_defs/src/builtin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 2edb8b717fd57..04e45e2351b56 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -2878,7 +2878,7 @@ declare_lint! { } declare_lint! { - /// The `large_assigments` lint detects when objects of large + /// The `large_assignments` lint detects when objects of large /// types are being moved around. /// /// ### Example From 85b1c67910dbeede8aabb16bc0c1c09a2fefe8ab Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 29 Mar 2021 14:22:01 +0000 Subject: [PATCH 19/19] Limit test to 64 bit systems to keep the sizes in the diagnostics stable --- src/test/ui/async-await/large_moves.rs | 1 + src/test/ui/async-await/large_moves.stderr | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/ui/async-await/large_moves.rs b/src/test/ui/async-await/large_moves.rs index 612433f26789e..4fac046beef62 100644 --- a/src/test/ui/async-await/large_moves.rs +++ b/src/test/ui/async-await/large_moves.rs @@ -2,6 +2,7 @@ #![feature(large_assignments)] #![move_size_limit = "1000"] // build-fail +// only-x86_64 // edition:2018 diff --git a/src/test/ui/async-await/large_moves.stderr b/src/test/ui/async-await/large_moves.stderr index 476f5875beb3b..8c47ec0ed9d38 100644 --- a/src/test/ui/async-await/large_moves.stderr +++ b/src/test/ui/async-await/large_moves.stderr @@ -1,5 +1,5 @@ error: moving 10024 bytes - --> $DIR/large_moves.rs:9:13 + --> $DIR/large_moves.rs:10:13 | LL | let x = async { | _____________^ @@ -17,19 +17,19 @@ LL | #![deny(large_assignments)] | ^^^^^^^^^^^^^^^^^ error: moving 10024 bytes - --> $DIR/large_moves.rs:15:14 + --> $DIR/large_moves.rs:16:14 | LL | let z = (x, 42); | ^ value moved from here error: moving 10024 bytes - --> $DIR/large_moves.rs:15:13 + --> $DIR/large_moves.rs:16:13 | LL | let z = (x, 42); | ^^^^^^^ value moved from here error: moving 10024 bytes - --> $DIR/large_moves.rs:17:13 + --> $DIR/large_moves.rs:18:13 | LL | let a = z.0; | ^^^ value moved from here