| Age | Commit message (Collapse) | Author | Lines |
|
Co-Authored-By: Ralf Jung <post@ralfj.de>
|
|
Update Box::from_raw example to generalize better
I know very little about rust, so I saw the example here
```
use std::alloc::{alloc, Layout};
unsafe {
let ptr = alloc(Layout::new::<i32>()) as *mut i32;
*ptr = 5;
let x = Box::from_raw(ptr);
}
```
and tried to generalize it by writing,
```
let layout = Layout::new::<T>();
let new_obj = unsafe {
let ptr = alloc(layout) as *mut T;
*ptr = obj;
Box::from_raw(ptr)
};
```
for some more complicated `T`, which ended up crashing with SIGSEGV,
because it tried to `drop_in_place` the previous object in `ptr` which is
of course garbage. I think that changing this example to use `.write` instead
would be a good idea to suggest the correct generalization. It is also more
consistent with other documentation items in this file, which use `.write`.
I also added a comment to explain it, but I'm not too attached to that,
and can see it being too verbose in this place.
|
|
impl From<char> for String
This allows us to write
````rust
fn char_to_string() -> String {
'a'.into()
}
````
which was not possible before.
|
|
|
|
|
|
|
|
This reduces the amount of LLVM IR generated by up to 1 or 2%.
|
|
Add liballoc doc panic detail according to RawVec
|
|
|
|
|
|
|
|
|
|
Remove blank line
|
|
Shortcuts for min/max on double-ended BTreeMap/BTreeSet iterators
Closes #59947: a performance tweak that might benefit some. Optimizes `min` and `max ` on all btree double-ended iterators that do not drop, i.e. the iterators created by:
- `BTreeMap::iter`
- `BTreeMap::iter_mut`
- `BTreeMap::keys` and `BTreeSet::iter`
- `BTreeMap::range` and `BTreeSet::range`
- `BTreeMap::range_mut`
Also in these (currently) single-ended iterators, but obviously for `min` only:
- `BTreeSet::difference`
- `BTreeSet::intersection`
- `BTreeSet::symmetric_difference`
- `BTreeSet::union`
Did not do this in iterators created by `into_iter` to preserve drop order, as outlined in #62316.
Did not do this in iterators created by `drain_filter`, possibly to preserve drop order, possibly to preserve predicate invocation, mostly to not have to think about it too hard (I guess maybe it wouldn't be a change for `min`, which is the only shortcut possible in this single-ended iterator).
|
|
Add liballoc impl SpecFromElem for i8
Speedup vec![1_i8; N] for non-zero element.
Before
test do_bench_from_elem_i8 ... bench: 130 ns/iter (+/- 7) = 61 MB/s
test do_bench_from_elem_u8 ... bench: 121 ns/iter (+/- 4) = 66 MB/s
After
test do_bench_from_elem_i8 ... bench: 123 ns/iter (+/- 7) = 65 MB/s
test do_bench_from_elem_u8 ... bench: 121 ns/iter (+/- 5) = 66 MB/s
No speed difference if element is already zero.
```rust
#[bench]
fn do_bench_from_elem_i8(b: &mut Bencher) {
b.bytes = 8 as u64;
b.iter(|| {
let dst = ve::vec![10_i8; 100];
assert_eq!(dst.len(), 100);
assert!(dst.iter().all(|x| *x == 10));
})
}
```
As suggested by @cuviper
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/SpecForElem.20for.20other.20integers
r? @cuviper
CC @joshtriplett
Edit: Wow, I just realized both reviewers are Josh.
|
|
|
|
|
|
|
|
r=sfackler
disable collectionbenches for android
Fixes #73535
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
|
|
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
|
|
Liballoc minor hash import tweak
|
|
r=lcnr,varkor
`improper_ctypes_definitions` lint
Addresses #19834, #66220, and #66373.
This PR takes another attempt at #65134 (reverted in #66378). Instead of modifying the existing `improper_ctypes` lint to consider `extern "C" fn` definitions in addition to `extern "C" {}` declarations, this PR adds a new lint - `improper_ctypes_definitions` - which only applies to `extern "C" fn` definitions.
In addition, the `improper_ctype_definitions` lint differs from `improper_ctypes` by considering `*T` and `&T` (where `T: Sized`) FFI-safe (addressing #66220).
There wasn't a clear consensus in #66220 (where the issues with #65134 were primarily discussed) on the approach to take, but there has [been some discussion in Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/.2366220.20improper_ctypes.20definitions.20vs.20declarations/near/198903086). I fully expect that we'll want to iterate on this before landing.
cc @varkor + @shepmaster (from #19834) @hanna-kruppe (active in discussing #66220), @SimonSapin (#65134 caused problems for Servo, want to make sure that this PR doesn't)
|
|
Update BTreeMap::new() doc
Updates the documentation according to [this comment](https://github.com/rust-lang/rust/pull/72876/files/0c5c644c91edf6ed949cfa5ffc524f43369df604#r433232581) on #72876
|
|
Remove unused crate imports in 2018 edition crates
Closes #73570
|
|
This commit adds a new lint - `improper_ctypes_definitions` - which
functions identically to `improper_ctypes`, but on `extern "C" fn`
definitions (as opposed to `improper_ctypes`'s `extern "C" {}`
declarations).
Signed-off-by: David Wood <david@davidtw.co>
|
|
I know very little about rust, so I saw this example and tried to generalize it by writing,
```
let layout = Layout::new::<T>();
let new_obj = unsafe {
let ptr = alloc(layout) as *mut T;
*ptr = obj;
Box::from_raw(ptr)
};
```
for some more complicated `T`, which ended up crashing with SIGSEGV,
because it tried to `drop_in_place` the previous object in `ptr` which is
of course garbage. I also added a comment that explains why `.write`
is used, but I think adding that comment is optional and may be too verbose
here. I do however think that changing this example is a good idea to
suggest the correct generalization. `.write` is also used in most of the rest
of the documentation here, even if the example is `i32`, so it would additionally
be more consistent.
|
|
Mention that BTreeMap::new() doesn't allocate
I think it would be nice to mention this, so you don't have to dig through the src to look at the definition of new().
|
|
|
|
A way forward for pointer equality in const eval
r? @varkor on the first commit and @RalfJung on the second commit
cc #53020
|
|
|
|
impl PartialEq<Vec<B>> for &[A], &mut [A]
https://github.com/rust-lang/rfcs/issues/2917
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Speedup vec![1_i8; N] for non-zero element.
Before
test do_bench_from_elem_i8 ... bench: 130 ns/iter (+/- 7) = 61 MB/s
test do_bench_from_elem_u8 ... bench: 121 ns/iter (+/- 4) = 66 MB/s
After
test do_bench_from_elem_i8 ... bench: 123 ns/iter (+/- 7) = 65 MB/s
test do_bench_from_elem_u8 ... bench: 121 ns/iter (+/- 5) = 66 MB/s
No speed difference if element is already zero.
#[bench]
fn do_bench_from_elem_i8(b: &mut Bencher) {
b.bytes = 8 as u64;
b.iter(|| {
let dst = ve::vec![10_i8; 100];
assert_eq!(dst.len(), 100);
assert!(dst.iter().all(|x| *x == 10));
})
}
As suggested by @cuviper
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/SpecForElem.20for.20other.20integers
|
|
Add specialization of `ToString for char`
Closes #73462
|
|
`#[deny(unsafe_op_in_unsafe_fn)]` in liballoc
This PR proposes to make use of the new `unsafe_op_in_unsafe_fn` lint, i.e. no longer consider the body of an unsafe function as an unsafe block and require explicit unsafe block to perform unsafe operations.
This has been first (partly) suggested by @Mark-Simulacrum in https://github.com/rust-lang/rust/pull/69245#issuecomment-587817065
Tracking issue for the feature: #71668.
~~Blocked on #71862.~~
r? @Mark-Simulacrum cc @nikomatsakis can you confirm that those changes are desirable? Should I restrict it to only BTree for the moment?
|
|
Co-authored-by: nikomatsakis <niko@alum.mit.edu>
|
|
|
|
Minor tweaks to liballoc
|
|
Reduce pointer casts in Box::into_boxed_slice
We only need to cast the pointer once to change `Box<T>` to an array
`Box<[T; 1]>`, then we can let unsized coercion return `Box<[T]>`.
|
|
|
|
|
|
|
|
|
|
|
|
This allows us to write
fn char_to_string() -> String {
'a'.into()
}
which was not possible before.
|