-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add await_holding_invalid_type
lint
#8707
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
10 commits
Select commit
Hold shift + click to select a range
4844325
Add `await_holding_invalid_type` lint
lilymara-onesignal 3cd8b5a
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal 5344192
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal 6d0baf2
Update clippy_lints/src/await_holding_invalid.rs
lilymara-onesignal 228ce78
Update clippy_lints/src/await_holding_invalid.rs
lilymara-onesignal ee3ebb3
Update clippy_lints/src/await_holding_invalid.rs
lilymara-onesignal a511072
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal 7e26edc
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal 8eccbbe
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal 0508685
fixup! Add `await_holding_invalid_type` lint
lilymara-onesignal 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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -515,7 +515,12 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: | |||||
} | ||||||
|
||||||
store.register_late_pass(|| Box::new(utils::author::Author)); | ||||||
store.register_late_pass(|| Box::new(await_holding_invalid::AwaitHolding)); | ||||||
let await_holding_invalid_types = conf.await_holding_invalid_types.clone(); | ||||||
store.register_late_pass(move || { | ||||||
Box::new(await_holding_invalid::AwaitHolding::new( | ||||||
await_holding_invalid_types.clone(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No need for double clone, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried this initially but borrowck doesn't like it
|
||||||
)) | ||||||
}); | ||||||
store.register_late_pass(|| Box::new(serde_api::SerdeApi)); | ||||||
let vec_box_size_threshold = conf.vec_box_size_threshold; | ||||||
let type_complexity_threshold = conf.type_complexity_threshold; | ||||||
|
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
41 changes: 41 additions & 0 deletions
41
tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#![warn(clippy::await_holding_invalid_type)] | ||
use std::net::Ipv4Addr; | ||
|
||
async fn bad() -> u32 { | ||
let _x = String::from("hello"); | ||
baz().await | ||
} | ||
|
||
async fn bad_reason() -> u32 { | ||
let _x = Ipv4Addr::new(127, 0, 0, 1); | ||
baz().await | ||
} | ||
|
||
async fn good() -> u32 { | ||
{ | ||
let _x = String::from("hi!"); | ||
let _y = Ipv4Addr::new(127, 0, 0, 1); | ||
} | ||
baz().await; | ||
let _x = String::from("hi!"); | ||
47 | ||
} | ||
|
||
async fn baz() -> u32 { | ||
42 | ||
} | ||
|
||
#[allow(clippy::manual_async_fn)] | ||
fn block_bad() -> impl std::future::Future<Output = u32> { | ||
async move { | ||
let _x = String::from("hi!"); | ||
baz().await | ||
} | ||
} | ||
|
||
fn main() { | ||
good(); | ||
bad(); | ||
bad_reason(); | ||
block_bad(); | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr
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,25 @@ | ||
error: `std::string::String` may not be held across an `await` point per `clippy.toml` | ||
--> $DIR/await_holding_invalid_type.rs:5:9 | ||
| | ||
LL | let _x = String::from("hello"); | ||
| ^^ | ||
| | ||
= note: `-D clippy::await-holding-invalid-type` implied by `-D warnings` | ||
= note: strings are bad | ||
|
||
error: `std::net::Ipv4Addr` may not be held across an `await` point per `clippy.toml` | ||
--> $DIR/await_holding_invalid_type.rs:10:9 | ||
| | ||
LL | let _x = Ipv4Addr::new(127, 0, 0, 1); | ||
| ^^ | ||
|
||
error: `std::string::String` may not be held across an `await` point per `clippy.toml` | ||
--> $DIR/await_holding_invalid_type.rs:31:13 | ||
| | ||
LL | let _x = String::from("hi!"); | ||
| ^^ | ||
| | ||
= note: strings are bad | ||
|
||
error: aborting due to 3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
await-holding-invalid-types = [ | ||
{ path = "std::string::String", reason = "strings are bad" }, | ||
"std::net::Ipv4Addr", | ||
] |
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,4 +1,4 @@ | ||
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `avoid-breaking-exported-api`, `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `disallowed-types`, `unreadable-literal-lint-fractions`, `upper-case-acronyms-aggressive`, `cargo-ignore-publish`, `standard-macro-braces`, `enforced-import-renames`, `allowed-scripts`, `enable-raw-pointer-heuristic-for-send`, `max-suggested-slice-pattern-length`, `third-party` at line 5 column 1 | ||
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `avoid-breaking-exported-api`, `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `disallowed-types`, `unreadable-literal-lint-fractions`, `upper-case-acronyms-aggressive`, `cargo-ignore-publish`, `standard-macro-braces`, `enforced-import-renames`, `allowed-scripts`, `enable-raw-pointer-heuristic-for-send`, `max-suggested-slice-pattern-length`, `await-holding-invalid-types`, `third-party` at line 5 column 1 | ||
|
||
error: aborting due to previous error | ||
|
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.