-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add rc_buffer
lint for checking Rc<String> and friends
#6044
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @yaahc (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
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.
This is a bit different from the original PR attempting to implement this type of lint. Rather than linting against converting into the unwanted types, this PR lints against declaring the unwanted type in a struct or function definition.
👍
I'm reasonably happy with what I have here, although I used the fully qualified type names for the Path and OsString suggestions, and I'm not sure if I should have just used the short versions instead, even if they might not have been declared via use.
I think using fully qualified paths is fine. It can always be changed later if it's causing issues.
the changes look great btw, once we fix the dogfood issue I'll be happy to approve this. |
We can avoid the data copy again by fixing rustc_ast::ast::LitKind later.
@bors r+ |
📌 Commit 6c056d3 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
This new lint popped up overnight, see rust-lang/rust-clippy#6044 The problem is that we do indeed want this structure. - The outer Arc allows us to clone in .send() without cloning the array. - The Vec allows us to add middleware at runtime. - The inner Arc-s allow us to implement Clone without sharing the vector with the parent. - We don't use a Mutex around the Vec here because adding a middleware during execution should be an error.
We've hit this lint in Surf and are moving to disable it: http-rs/surf#242. We use a similar structure for middleware in Tide as well. This may be an interesting case study for legitimate uses that are disallowed by this lint. |
This didn't display some types properly in the docs due the lack of code formatting. Also, refs for the caveat: rust-lang#6044 (comment) http-rs/surf#242
So to elaborate more on Tide & Surf's usage: The structure we have is The outer In both cases, the following information from the lint is not true:
This is because the behavior described is useful to both Surf and Tide. Middleware needs to be mutable up-front, but once a Client or Server is executing on a request, messing with the middleware would lead to unexpected (and probably zalgo-esque timing bug) behavior, so having it panic is fine, because that is considered a programmer error. We could use an extra |
lints: clarify rc_buffer and add caveats This didn't display some types properly in the docs due the lack of code formatting. Also, refs for the caveat: #6044 (comment) http-rs/surf#242 Fwiw I can't get `cargo test` to run, even on nightly. I get: ``` error[E0463]: can't find crate for `rustc_ast` ``` *Please keep the line below* changelog: none, nightly
Fix LitKind's byte buffer to use refcounted slice While working on adding a new lint for clippy (see rust-lang/rust-clippy#6044) for avoiding shared ownership of "mutable buffer" types (such as using `Rc<Vec<T>>` instead of `Rc<[T]>`), I noticed a type exported from rustc_ast and used by clippy gets caught by the lint. This PR fixes the exported type. This PR includes the actual change to clippy too, but I will open a PR directly against clippy for that part (although it will currently fail to build there).
Fix LitKind's byte buffer to use refcounted slice While working on adding a new lint for clippy (see rust-lang#6044) for avoiding shared ownership of "mutable buffer" types (such as using `Rc<Vec<T>>` instead of `Rc<[T]>`), I noticed a type exported from rustc_ast and used by clippy gets caught by the lint. This PR fixes the exported type. This PR includes the actual change to clippy too, but I will open a PR directly against clippy for that part (although it will currently fail to build there).
Downgrade rc_buffer to restriction I think Arc\<Vec\<T\>\> and Arc\<String\> and similar are a totally reasonable data structure, as observed by others in the comments on [#6044](#6044 (comment)) as well. Doing `Arc::make_mut(&mut self.vec).push(...)` or `Arc::make_mut(&mut self.string).push_str("...")` is a terrific and well performing copy-on-write pattern. Linting this with an enabled-by-default <kbd>performance</kbd> lint strikes me as an unacceptable false positive balance. As of #6090 the documentation of this lint now contains: > **Known problems:** This pattern can be desirable ... which should indicate that we shouldn't be linting against correct, reasonable, well-performing patterns with an enabled-by-default lint. Mentioning #6044, #6090. r? `@yaahc,` who reviewed the lint. --- changelog: Remove rc_buffer from default set of enabled lints
Fixes #2623
This is a bit different from the original PR attempting to implement this type of lint. Rather than linting against converting into the unwanted types, this PR lints against declaring the unwanted type in a struct or function definition.
I'm reasonably happy with what I have here, although I used the fully qualified type names for the Path and OsString suggestions, and I'm not sure if I should have just used the short versions instead, even if they might not have been declared via use.
Also, I don't know if "buffer type" is the best way to put it or not. Alternatively I could call it a "growable type" or "growable buffer type", but I was thinking of PathBuf when I started making the lint.
changelog: Add
rc_buffer
lint