-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add #[must_use] to cargo new --lib example code
#16806
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -907,6 +907,7 @@ fn main() { | |
| " | ||
| } else { | ||
| b"\ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
1 change: 1 addition & 0 deletions
1
tests/testsuite/cargo_init/git_ignore_exists_no_conflicting_entries/out/src/lib.rs
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
1 change: 1 addition & 0 deletions
1
tests/testsuite/cargo_init/ignores_failure_to_format_source/out/src/lib.rs
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
1 change: 1 addition & 0 deletions
1
tests/testsuite/cargo_init/simple_git_ignore_exists/out/src/lib.rs
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
1 change: 1 addition & 0 deletions
1
tests/testsuite/cargo_init/simple_hg_ignore_exists/out/src/lib.rs
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
1 change: 1 addition & 0 deletions
1
tests/testsuite/cargo_new/add_members_to_non_workspace/out/bar/src/lib.rs
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
1 change: 1 addition & 0 deletions
1
tests/testsuite/cargo_new/add_members_to_workspace_without_members/out/bar/src/lib.rs
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
1 change: 1 addition & 0 deletions
1
tests/testsuite/cargo_new/ignore_current_dir_workspace/out/out-of-workspace/src/lib.rs
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,3 +1,4 @@ | ||
| #[must_use] | ||
| pub fn add(left: u64, right: u64) -> u64 { | ||
| left + right | ||
| } | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the only warning you got when running clippy with
-Wclippy::pedantic. We have deliberately scoped clippy lints to a subset. We normally don't accept unless there is some compelling reason, for example:clippy::perflint warnings #15631Would you mind share the reason motivating you to open this PR (and only with this lint fixed)? Otherwise I tend to close this. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the only lint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is might be the only lint in the generated code, I think the approach we take to lints in Cargo is relevant.
It is also not clear why this matters. These are pedantic (non-default) lints for code that will be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I understand what @weihanglo meant now. I was only talking about the generated code.
I think the generated example code should be as idiomatic as possible, even if it will be deleted.
But I also understand why this isn't important enough to change. Feel free to close the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is something considered idiomatic, I'd want to better understand why it is relegated to a pedantic lint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well its on
Add::addin the standard library and this function implements the same functionality:#[must_use = "this returns the result of the operation, without modifying the original"]It is a pedantic lint because it has a lot of false positives, but in this specific case the function should have a
#[must_use]attribute. See "Known problems" here: https://rust-lang.github.io/rust-clippy/master/#must_use_candidate