about summary refs log tree commit diff
path: root/src/libcore/mem
AgeCommit message (Collapse)AuthorLines
2019-12-29Typo fixPeter Todd-1/+1
2019-12-22Format the worldMark Rousskov-9/+8
2019-12-21Require issue = "none" over issue = "0" in unstable attributesRoss MacArthur-5/+5
2019-12-18Propagate cfg bootstrapMark Rousskov-38/+12
2019-12-14Auto merge of #67136 - oli-obk:const_stability, r=Centrilbors-0/+19
Require stable/unstable annotations for the constness of all stable fns with a const modifier r? @RalfJung @Centril Every `#[stable]` const fn now needs either a `#[rustc_const_unstable]` attribute or a `#[rustc_const_stable]` attribute. You can't silently stabilize the constness of a function anymore.
2019-12-13be explicit that mem::uninitialized is the same as ↵Ralf Jung-1/+5
MaybeUninit::uninit().assume_init()
2019-12-13Require stable/unstable annotations for the constness of all stable ↵Oliver Scherer-0/+19
functions with a `const` modifier
2019-11-28Auto merge of #65013 - petertodd:2019-maybeuninit-debug, r=sfacklerbors-0/+9
Implement Debug for MaybeUninit Precedent: `UnsafeCell` implements `Debug` even though it can't actually display the value. I noticed this omission while writing the following: ``` #[derive(Debug)] pub struct SliceInitializer<'a, T> { marker: PhantomData<&'a mut T>, uninit: &'a mut [MaybeUninit<T>], written: usize, } ``` ...which currently unergonomically fails to compile. `UnsafeCell` does require `T: Debug`. Because of things like the above I think it'd be better to leave that requirement off. In fact, I'd also suggest removing that requirement for `UnsafeCell` too, which again I noticed in some low-level real world code.
2019-11-26Format libcore with rustfmtDavid Tolnay-1/+1
This commit applies rustfmt with default settings to files in src/libcore *that are not involved in any currently open PR* to minimize merge conflicts. The list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in `outstanding_files`, the relevant commands were: $ find src/libcore -name '*.rs' | xargs rustfmt --edition=2018 $ rg libcore outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of libcore.
2019-11-24Rollup merge of #66411 - RalfJung:forget, r=sfacklerMazdak Farrokhzad-3/+33
mem::forget docs: mention ManuallyDrop Cc @SimonSapin @Centril
2019-11-16Clarify transmute_copy documentation exampleAdam Schwalm-5/+5
2019-11-14mem::forget docs: mention ManuallyDropRalf Jung-3/+33
2019-11-10Rollup merge of #66217 - RalfJung:diagnostic-items, r=CentrilYuki Okushi-0/+4
invalid_value lint: use diagnostic items This adjusts the invalid_value lint to use diagnostic items. @Centril @oli-obk For some reason, this fails to recognize `transmute` -- somehow the diagnostic item is not found. Any idea why? r? @Centril Cc https://github.com/rust-lang/rust/issues/66075
2019-11-09partially port invalid_value lint to diagnostic itemsRalf Jung-0/+4
2019-11-08Rollup merge of #65580 - SimonSapin:maybeuninit-array, r=AmanieuYuki Okushi-0/+63
Add `MaybeUninit` methods `uninit_array`, `slice_get_ref`, `slice_get_mut` Eventually these will hopefully become the idiomatic way to work with partially-initialized stack buffers. All methods are unstable. Note that `uninit_array` takes a type-level `const usize` parameter, so it is blocked (at least in its current form) on const generics. Example: ```rust use std::mem::MaybeUninit; let input = b"Foo"; let f = u8::to_ascii_uppercase; let mut buffer: [MaybeUninit<u8>; 32] = MaybeUninit::uninit_array(); let vec; let output = if let Some(buffer) = buffer.get_mut(..input.len()) { buffer.iter_mut().zip(input).for_each(|(a, b)| { a.write(f(b)); }); unsafe { MaybeUninit::slice_get_ref(buffer) } } else { vec = input.iter().map(f).collect::<Vec<u8>>(); &vec }; assert_eq!(output, b"FOO"); ```
2019-11-07Implement Debug for MaybeUninitPeter Todd-0/+9
Precedent: UnsafeCell implements Debug even though it can't actually display the value.
2019-11-07Rollup merge of #63793 - oli-obk:🧹, r=dtolnayMazdak Farrokhzad-1/+20
Have tidy ensure that we document all `unsafe` blocks in libcore cc @rust-lang/libs I documented a few and added ignore flags on the other files. We can incrementally document the files, but won't regress any files this way.
2019-11-07MaybeUninit::uninit_array docs: better exampleSimon Sapin-14/+20
2019-11-07Apply docs suggestions from reviewSimon Sapin-4/+4
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-11-07Add `MaybeUninit` methods `uninit_array`, `slice_get_ref`, `slice_get_mut`Simon Sapin-0/+57
2019-11-07Rollup merge of #66044 - RalfJung:uninit-lint, r=oli-obkYuki Okushi-0/+1
Improve uninit/zeroed lint * Also warn when creating a raw pointer with a NULL vtable. * Also identify `MaybeUninit::uninit().assume_init()` and `MaybeUninit::zeroed().assume_init()` as dangerous.
2019-11-06Silence a deprecation warningOliver Scherer-0/+1
2019-11-06Halloween... time to get rid of 👻Oliver Scherer-6/+6
2019-11-06Have tidy ensure that we document all `unsafe` blocks in libcoreOliver Scherer-1/+19
2019-11-04Minor style improvementsDaniel Henry-Mantilla-13/+7
Co-Authored-By: Ralf Jung <post@ralfj.de>
2019-11-04more robust method checking through DefId and diagnostic_itemRalf Jung-0/+1
2019-10-30Added a panic-on-uninhabited guard on get_ref and get_mutDaniel Henry-Mantilla-0/+2
2019-10-30Fix doctestsDaniel Henry-Mantilla-7/+19
2019-10-29Improved MaybeUninit::get_{ref,mut} documentationDaniel Henry-Mantilla-8/+151
2019-10-18Rollup merge of #65016 - lzutao:inline-mem-constfn, r=oli-obkTyler Mandry-2/+2
Always inline `mem::{size_of,align_of}` in debug builds Those two are const fn and do not have any arguments. Inlining helps reducing generated code size in debug builds. See also #64996.
2019-10-08Stabilize mem::take (mem_take)Jon Gjengset-5/+1
Tracking issue: https://github.com/rust-lang/rust/issues/61129
2019-10-02Always inline `mem::{size_of,align_of}` in debug buildsLzu Tao-2/+2
Those two are const fn and do not have any arguments. Inlining helps reducing generated code size in debug builds.
2019-09-30Add missing links for mem::needs_dropLzu Tao-4/+6
2019-09-28Improve wording in documentation of MaybeUninitNils Liberg-6/+6
2019-09-23update testAndrew Banchich-3/+3
Use assert_eq and assert_ne over comparison operators.
2019-08-15Auto merge of #63575 - Centril:rollup-anlv9g5, r=Centrilbors-6/+6
Rollup of 11 pull requests Successful merges: - #62984 (Add lint for excess trailing semicolons) - #63075 (Miri: Check that a ptr is aligned and inbounds already when evaluating `*`) - #63490 (libsyntax: cleanup and refactor `pat.rs`) - #63507 (When needing type annotations in local bindings, account for impl Trait and closures) - #63509 (Point at the right enclosing scope when using `await` in non-async fn) - #63528 (syntax: Remove `DummyResult::expr_only`) - #63537 (expand: Unimplement `MutVisitor` on `MacroExpander`) - #63542 (Add NodeId for Arm, Field and FieldPat) - #63543 (Merge Variant and Variant_) - #63560 (move test that shouldn't be in test/run-pass/) - #63570 (Adjust tracking issues for `MaybeUninit<T>` gates) Failed merges: r? @ghost
2019-08-14Adjust tracking issues for `MaybeUninit<T>` gatesMazdak Farrokhzad-6/+6
2019-08-14Handle cfg(bootstrap) throughoutMark Rousskov-3/+3
2019-08-11Rollup merge of #63346 - RalfJung:zeroed-lint, r=eddybMark Rousskov-1/+5
Lint on some incorrect uses of mem::zeroed / mem::uninitialized Cc https://github.com/rust-lang/rust/issues/62825 and https://internals.rust-lang.org/t/make-mem-uninitialized-and-mem-zeroed-panic-for-some-types-where-0-is-a-niche/10605 This does not yet handle `NonNull`/`NonZero*`, but it is a start. I also improved some doc issues I hit on the way, and added a useful helper to `TyS`. EDIT: I added the relnotes label mostly as a proposal -- I think this is worth mentioning, but leave the decision up to the release team.
2019-08-11allow the lint if a few UB-demonstrating doc testsRalf Jung-1/+5
2019-08-11Auto merge of #63343 - ishitatsuyuki:revert-62150, r=RalfJungbors-2/+8
Back out #62150 Ref: #62825 cc @RalfJung
2019-08-10Revert "Rollup merge of #62150 - alex:mem-uninit-refactor, r=RalfJung"Tatsuyuki Ishi-2/+8
This reverts commit 1d45156866b54c3fc36edfdfcdd8149ad9cb5711, reversing changes made to 0f92eb8a4a7d8715381f5b5d748d22315f6ff9c7.
2019-08-07Rollup merge of #63034 - tmandry:reduce-generator-size-regressions, r=cramertjMazdak Farrokhzad-0/+2
Fix generator size regressions due to optimization I tested the generator optimizations in #60187 and #61922 on the Fuchsia build, and noticed that some small generators (about 8% of the async fns in our build) increased in size slightly. This is because in #60187 we split the fields into two groups, a "prefix" non-overlap region and an overlap region, and lay them out separately. This can introduce unnecessary padding bytes between the two groups. In every single case in the Fuchsia build, it was due to there being only a single variant being used in the overlap region. This means that we aren't doing any overlapping, period. So it's better to combine the two regions into one and lay out all the fields at once, which is what this change does. r? @cramertj cc @eddyb @Zoxc
2019-08-06clarifyRalf Jung-2/+2
2019-08-06be clear that 1-init Vec being valid (but not safe) is not a stable guaranteeRalf Jung-2/+4
2019-08-05assume_init: warn about valid != safeRalf Jung-0/+7
2019-08-03Rollup merge of #63215 - gnzlbg:patch-6, r=CentrilMazdak Farrokhzad-3/+6
Clarify semantics of mem::zeroed Clarifies the semantics of `mem::zeroed`. r? @Centril cc @RalfJung
2019-08-02Consistency.gnzlbg-1/+1
2019-08-02Remove trailing whitespacegnzlbg-1/+1
I had one job...
2019-08-02Clarify semantics of mem::zeroedgnzlbg-3/+6