-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Extend the #[must_use]
lint to arrays
#62235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b613ef1
Extend the #[must_use] lint to boxed types
varkor d066f19
Improve error messages for boxed trait objects in tuples
varkor 75f31e7
Fix run-pass tests
varkor 400fd60
Update miri
varkor 76f5b50
Extend #[must_use] lint to arrays
varkor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// run-pass | ||
|
||
#![allow(stable_features)] | ||
#![allow(unused_must_use)] | ||
|
||
// ignore-emscripten no threads support | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#![deny(unused_must_use)] | ||
|
||
#[must_use] | ||
struct S; | ||
|
||
struct A; | ||
|
||
#[must_use] | ||
trait T {} | ||
|
||
impl T for A {} | ||
|
||
fn empty() -> [S; 0] { | ||
[] | ||
} | ||
|
||
fn singleton() -> [S; 1] { | ||
[S] | ||
} | ||
|
||
fn many() -> [S; 4] { | ||
[S, S, S, S] | ||
} | ||
|
||
fn array_of_impl_trait() -> [impl T; 2] { | ||
[A, A] | ||
} | ||
|
||
fn impl_array() -> [(u8, Box<dyn T>); 2] { | ||
[(0, Box::new(A)), (0, Box::new(A))] | ||
} | ||
|
||
fn array_of_arrays_of_arrays() -> [[[S; 1]; 2]; 1] { | ||
[[[S], [S]]] | ||
} | ||
|
||
fn main() { | ||
empty(); // ok | ||
singleton(); //~ ERROR unused array of `S` that must be used | ||
many(); //~ ERROR unused array of `S` that must be used | ||
([S], 0, ()); //~ ERROR unused array of `S` in tuple element 0 that must be used | ||
array_of_impl_trait(); //~ ERROR unused array of implementers of `T` that must be used | ||
impl_array(); | ||
//~^ ERROR unused array of boxed `T` trait objects in tuple element 1 that must be used | ||
array_of_arrays_of_arrays(); | ||
//~^ ERROR unused array of arrays of arrays of `S` that must be used | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
error: unused array of `S` that must be used | ||
--> $DIR/must_use-array.rs:39:5 | ||
| | ||
LL | singleton(); | ||
| ^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/must_use-array.rs:1:9 | ||
| | ||
LL | #![deny(unused_must_use)] | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: unused array of `S` that must be used | ||
--> $DIR/must_use-array.rs:40:5 | ||
| | ||
LL | many(); | ||
| ^^^^^^^ | ||
|
||
error: unused array of `S` in tuple element 0 that must be used | ||
--> $DIR/must_use-array.rs:41:6 | ||
| | ||
LL | ([S], 0, ()); | ||
| ^^^ | ||
|
||
error: unused array of implementers of `T` that must be used | ||
--> $DIR/must_use-array.rs:42:5 | ||
| | ||
LL | array_of_impl_trait(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: unused array of boxed `T` trait objects in tuple element 1 that must be used | ||
--> $DIR/must_use-array.rs:43:5 | ||
| | ||
LL | impl_array(); | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: unused array of arrays of arrays of `S` that must be used | ||
--> $DIR/must_use-array.rs:45:5 | ||
| | ||
LL | array_of_arrays_of_arrays(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 6 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule miri
updated
24 files
+1 −1 | miri | |
+248 −0 | src/eval.rs | |
+1 −1 | src/helpers.rs | |
+49 −21 | src/intptrcast.rs | |
+14 −574 | src/lib.rs | |
+388 −0 | src/machine.rs | |
+0 −51 | src/memory.rs | |
+1 −1 | src/operator.rs | |
+13 −7 | src/shims/foreign_items.rs | |
+0 −0 | src/shims/intrinsics.rs | |
+2 −0 | src/shims/mod.rs | |
+13 −4 | test-cargo-miri/Cargo.lock | |
+2 −1 | test-cargo-miri/Cargo.toml | |
+3 −3 | test-cargo-miri/run-test.py | |
+3 −0 | test-cargo-miri/src/main.rs | |
+5 −3 | test-cargo-miri/test.stdout.ref | |
+2 −2 | test-cargo-miri/test.stdout.ref2 | |
+19 −7 | test-cargo-miri/tests/test.rs | |
+18 −0 | tests/compile-fail/intptrcast_alignment_check.rs | |
+5 −0 | tests/run-pass/intptrcast.rs | |
+6 −0 | tests/run-pass/intptrcast_format.rs | |
+2 −0 | tests/run-pass/intptrcast_format.stdout | |
+3 −1 | tests/run-pass/issue-30530.rs | |
+1 −2 | tests/run-pass/sync.rs |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.