Fix suggestion to slice if scrutinee is a `Result` or `Option` by FabianWolff ·...
source link: https://github.com/rust-lang/rust/pull/91343
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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) =>
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.
I guess we could in general be smarter above too for Result<T>
to only suggest if T: Deref<Target=X>
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?).
Yes, let's leave this as a followup. Can you add a FIXME comment though?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK