Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ fn main() {
"
} else {
b"\
#[must_use]
Copy link
Copy Markdown
Member

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:

Would 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.

Copy link
Copy Markdown
Author

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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Author

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.

Ah, I understand what @weihanglo meant now. I was only talking about the generated code.

It is also not clear why this matters. These are pedantic (non-default) lints for code that will be deleted.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the generated example code should be as idiomatic as possible, even if it will be deleted.

If this is something considered idiomatic, I'd want to better understand why it is relegated to a pedantic lint.

Copy link
Copy Markdown
Author

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.

Well its on Add::add in 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

pub fn add(left: u64, right: u64) -> u64 {
left + right
}
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_init/auto_git/out/src/lib.rs
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
}
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_init/formats_source/out/src/lib.rs
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
}
Expand Down
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
}
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_init/git_autodetect/out/src/lib.rs
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
}
Expand Down
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
}
Expand Down
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
}
Expand Down
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
}
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_init/pijul_autodetect/out/src/lib.rs
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
}
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_init/simple_git/out/src/lib.rs
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
}
Expand Down
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
}
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_init/simple_hg/out/src/lib.rs
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
}
Expand Down
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
}
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_init/simple_lib/out/src/lib.rs
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
}
Expand Down
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
}
Expand Down
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
}
Expand Down
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
}
Expand Down
3 changes: 2 additions & 1 deletion tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ fn simple_lib() {
let contents = fs::read_to_string(&lib).unwrap();
assert_eq!(
contents,
r#"pub fn add(left: u64, right: u64) -> u64 {
r#"#[must_use]
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

Expand Down