-
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
Want to extend clear_with_drain
to other types of containers
#10572
Comments
Sure, go for it! |
@rustbot claim |
I got most of it working, but I'm running into an issue regarding I can't get it to work in that case because my call to &cx.tcx.diagnostic_items(adt.did().krate).name_to_id = {
"BinaryHeap": DefId(5:781 ~ alloc[3758]::collections::binary_heap::BinaryHeap),
"BTreeEntry": DefId(5:1212 ~ alloc[3758]::collections::btree::map::entry::Entry),
"LinkedList": DefId(5:3477 ~ alloc[3758]::collections::linked_list::LinkedList),
"cstring_type": DefId(5:7080 ~ alloc[3758]::ffi::c_str::CString),
"Vec": DefId(5:6600 ~ alloc[3758]::vec::Vec),
"Cow": DefId(5:688 ~ alloc[3758]::borrow::Cow),
"ToString": DefId(5:5549 ~ alloc[3758]::string::ToString),
"Arc": DefId(5:5705 ~ alloc[3758]::sync::Arc),
"BTreeSet": DefId(5:3057 ~ alloc[3758]::collections::btree::set::BTreeSet),
"box_new": DefId(5:296 ~ alloc[3758]::boxed::{impl#0}::new),
"ToOwned": DefId(5:679 ~ alloc[3758]::borrow::ToOwned),
"BTreeMap": DefId(5:1329 ~ alloc[3758]::collections::btree::map::BTreeMap),
"vec_macro": DefId(5:5 ~ alloc[3758]::macros::vec),
"VecDeque": DefId(5:4219 ~ alloc[3758]::collections::vec_deque::VecDeque),
"Rc": DefId(5:4722 ~ alloc[3758]::rc::Rc),
"format_macro": DefId(5:6 ~ alloc[3758]::macros::format),
} As you can see, the I found another source ( |
Author of Interestingly, |
So I performed the same debug test inside of Note that I'm getting two different lists in the same test, depending on the expression that is being checked by Any help on that would be appreciated 🙂 &cx.tcx.diagnostic_items(adt.did().krate).name_to_id = {
"FromResidual": DefId(2:3168 ~ core[9d00]::ops::try_trait::FromResidual),
"assert_ne_macro": DefId(2:6 ~ core[9d00]::macros::assert_ne),
// ...
// Skipped items
// ...
"mir_set_discriminant": DefId(2:29856 ~ core[9d00]::intrinsics::mir::SetDiscriminant),
--> "Option": DefId(2:48673 ~ core[9d00]::option::Option), <--
"Debug": DefId(2:9011 ~ core[9d00]::fmt::Debug),
// ...
// Skipped items
// ...
"mir_make_place": DefId(2:29865 ~ core[9d00]::intrinsics::mir::__internal_make_place),
"Alignment": DefId(2:49672 ~ core[9d00]::fmt::Alignment),
} |
There is a |
@llogiq I guess we can do that, it's just a little unfortunate that we have to use lang items for |
Ok, I'm currently on mobile, but it shouldn't be a big problem to add a String diagnostic item in a Rust PR. That would still mean we'd need the LangItem until the next sync, but it's a start. |
@schubart would you like to fix Either way is fine by me, just let me know :) |
Please give it go! Thanks very much.
|
Demonstrate false negative for `String` as discussed in rust-lang#10572.
I implemented clear_with_drain for
Vec
, and then I had a look at #9059 and saw thatmanual_retain
applies to a bunch of containers (BTW I admire your work on that lint @kyoto7250 👏).So I'm thinking
clear_with_drain
should probably be extended in a similar fashion to apply to the collections instd
that have both aclear
and adrain
method, i.e.:What do you think?
Also note that the documentations for Vec, VecDeque and String explicitly mention that
drain
with a full range will clear the container, "likeclear()
does". Does this change anything regarding the category proposed originally in #9339? Style was suggested, but that would mean the examples in the standard library would get warnings 😅. Maybe Pedantic is more suitable?@rustbot label +C-enhancement
The text was updated successfully, but these errors were encountered: