-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix suggestion to slice if scrutinee is a Result
or Option
#91343
Conversation
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
None | ||
} | ||
ty::Adt(adt_def, _) | ||
if self.tcx.is_diagnostic_item(sym::Vec, adt_def.did) => |
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.
So...I think I'm learning something today about how Rust's SliceIndex
works (at least, unless I've missed something). So...I guess when we do a_vec[..]
, what's actually happening is there is an implicit deref: (a_vec.deref())[..])
- because SliceIndex
is only implemented for slice
, then the implicit deref is basically "forced". (At least, I think this is the case...please someone correct me if I'm wrong.)
I bring this up because rather than checking for Vec
exactly, we could check if the type impls Deref<Target=X>
?
Of course, this could be done as followup. This looks good otherwise.
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 guess we could in general be smarter above too for Result<T>
to only suggest if T: Deref<Target=X>
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.
Yes, that would be nicer, but I don't know how to check for such a trait bound here. Let's leave it to a follow-up (or do you know an easy way to implement this?).
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.
Yes, let's leave this as a followup. Can you add a FIXME comment though?
dceac6f
to
b1c5f7b
Compare
@rustbot ready |
@bors delegate+ rollup r=me with FIXME |
✌️ @FabianWolff can now approve this pull request |
b1c5f7b
to
95344c0
Compare
Done, thanks for reviewing this! @bors r=jackh726 |
📌 Commit 95344c0 has been approved by |
…=jackh726 Fix suggestion to slice if scrutinee is a `Result` or `Option` Fixes rust-lang#91328.
Rollup of 9 pull requests Successful merges: - rust-lang#91343 (Fix suggestion to slice if scrutinee is a `Result` or `Option`) - rust-lang#93019 (If an integer is entered with an upper-case base prefix (0Xbeef, 0O755, 0B1010), suggest to make it lowercase) - rust-lang#93090 (`impl Display for io::ErrorKind`) - rust-lang#93456 (Remove an unnecessary transmute from opaque::Encoder) - rust-lang#93492 (Hide failed command unless in verbose mode) - rust-lang#93504 (kmc-solid: Increase the default stack size) - rust-lang#93513 (Allow any pretty printed line to have at least 60 chars) - rust-lang#93532 (Update books) - rust-lang#93533 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This still does not work with references: pub fn foo(v: &Option<Vec<i32>>) {
match v {
Some([]) => {}
_ => {}
}
}
|
…-option-result, r=davidtwco Fix suggestion to slice if scurtinee is a reference to `Result` or `Option` Fixes rust-lang#91343 (comment) and rust-lang#91343 (comment).
…-option-result, r=davidtwco Fix suggestion to slice if scurtinee is a reference to `Result` or `Option` Fixes rust-lang#91343 (comment) and rust-lang#91343 (comment).
…-option-result, r=davidtwco Fix suggestion to slice if scurtinee is a reference to `Result` or `Option` Fixes rust-lang#91343 (comment) and rust-lang#91343 (comment).
Fixes #91328.