Commit graph

100 commits

Author SHA1 Message Date
Eric Huss
9bb414faff Fix ptr doc warnings. 2020-06-23 16:25:01 -07:00
Manish Goregaokar
ae38698e7f
Rollup merge of #73398 - oli-obk:const_raw_ptr_cmp, r=varkor,RalfJung,nagisa
A way forward for pointer equality in const eval

r? @varkor on the first commit and @RalfJung on the second commit

cc #53020
2020-06-23 00:33:54 -07:00
Ralf Jung
467415d50c deprecate wrapping_offset_from 2020-06-21 13:50:06 +02:00
Oliver Scherer
98e97a46e2 Address review comments 2020-06-20 14:58:15 +02:00
Oliver Scherer
e09b620339 Add fuzzy pointer comparison intrinsics 2020-06-19 18:13:41 +02:00
Ralf Jung
125c196bca
Rollup merge of #73054 - RalfJung:dont-panic, r=Mark-Simulacrum
memory access sanity checks: abort instead of panic

Suggested by @Mark-Simulacrum, this should help reduce the performance impact of these checks.
2020-06-19 14:29:24 +02:00
Manish Goregaokar
49ab0cab61
Rollup merge of #72279 - RalfJung:raw-ref-macros, r=nikomatsakis
add raw_ref macros

In https://github.com/rust-lang/rust/issues/64490, various people were in favor of exposing `&raw` as a macro first before making the actual syntax stable. So this PR (unstably) introduces those macros.

I'll create the tracking issue if we're okay moving forward with this.
2020-06-18 15:20:39 -07:00
Ralf Jung
f0a42332b8 memory access sanity checks: abort instead of panic 2020-06-16 16:01:30 -04:00
Ralf Jung
0265e4e61b add tracking issue 2020-06-16 09:25:29 +02:00
Ralf Jung
f0d2e78d39 add raw_ref macros 2020-06-12 19:10:58 +02:00
Dylan DPC
c06799e4c4
Rollup merge of #72906 - lzutao:migrate-numeric-assoc-consts, r=dtolnay
Migrate to numeric associated consts

The deprecation PR is #72885

cc #68490
cc rust-lang/rfcs#2700
2020-06-12 12:28:23 +02:00
Lzu Tao
fff822fead Migrate to numeric associated consts 2020-06-10 01:35:47 +00:00
Dylan McKay
91bff8ccdf [AVR] Fix debug printing of function pointers
This commit fixes debug printing of function pointers on AVR. AVR does
not support `addrspacecast` instructions, and so this patch modifies
libcore so that a `ptrtoint` IR instruction is used and the address
space cast is avoided.
2020-06-09 17:34:07 +12:00
Joe Richey
9b3dfd8ea9 core: Make pointer offset methods "const fn"
Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-25 13:09:02 -07:00
Simon Sapin
861dfaa855 Apply suggestions from code review
Co-authored-by: kennytm <kennytm@gmail.com>
2020-05-18 21:29:43 +02:00
Simon Sapin
49d5f5a977 Add len and slice_from_raw_parts to NonNull<[T]>
This follows the precedent of the recently-added `<*const [T]>::len`
(adding to its tracking issue https://github.com/rust-lang/rust/issues/71146)
and `ptr::slice_from_raw_parts`.
2020-05-18 21:29:43 +02:00
Steve Klabnik
aea0186fe5 make many ptr functions must_use
https://djugei.github.io/bad-at-unsafe/ describes an error a user had when trying to use offset:

> At first I just assumed that the .add() and .offset() methods on pointers would mutate the pointer. They do not. Instead they return a new pointer, which gets dropped silently if you don't use it. Unlike for example Result, which is must_use annotated.
2020-05-17 10:35:57 -05:00
Dylan DPC
9c32e7ac22
Rollup merge of #71625 - Diggsey:improve-manually-drop-docs, r=RalfJung
Improve the documentation for ManuallyDrop to resolve conflicting usage of terminology

cc @RalfJung

Follow-up from https://github.com/rust-lang/unsafe-code-guidelines/issues/233
2020-05-16 12:42:55 +02:00
Diggory Blake
7433c4ddf3 Improve the documentation for ManuallyDrop to resolve conflicting usage of terminology. 2020-05-15 19:53:05 +01:00
LeSeulArtichaut
d61debac64 Document unsafety for *const T and *mut T 2020-05-01 19:49:56 +02:00
cohenarthur
eda7f8fdff rename-unique: Rename Unique::empty() to Unique::dangling()
rename-unique: Change calls and doc in raw_vec.rs

rename-unique: Change empty() -> dangling() in const-ptr-unique-rpass.rs
2020-04-30 11:00:45 +02:00
Dylan DPC
d9761daa57
Rollup merge of #71507 - CohenArthur:document-unsafe-libcore-ptr, r=Mark-Simulacrum
Document unsafety in core::ptr

Contributes to #66219

I have yet to document all the `unsafe` blocks in the lib and would like to know if I'm headed in the right direction

r? @steveklabnik
2020-04-29 19:39:28 +02:00
cohenarthur
8558ccd5c4 safety-ptr: Add SAFETY on some unsafe blocks from libcore/ptr
Add documentation example to slice_from_raw_parts_mut()
Add SAFETY explanations to some unsafe blocks in libcore/ptr

* libcore/ptr/mod.rs
* libcore/ptr/unique.rs
* libcore/ptr/non_null.rs

safety-mod.rs: Add SAFETY to slice_from_raw_parts(),
slice_from_raw_parts_mut()

slice_from_raw_parts_mut: Add documentation example

safety-ptr-unique.rs: Add SAFETY to new() and cast()

safety-ptr-non_null.rs: Add SAFETY to new()

safety-ptr-non_null.rs: Add SAFETY to cast()

safety-ptr-non_null.rs: Add SAFETY to from() impls

safety-ptr-unique.rs: Add SAFETY to from() impls

safety-ptr-non_null.rs: Add SAFETY to new()

safety-ptr-unique.rs: Add SAFETY to new()

safety-ptr-mod.rs: Fix safety explanation

https://github.com/rust-lang/rust/pull/71507#discussion_r414488884

safety-prt-non_null.rs: Fix SAFETY comment syntax

safety-ptr-unique.rs: Fix syntax for empty()

safety-ptr-non_null.rs: Fix misuse of non-null for align_of()

safety-ptr-non_null.rs: Remove incorrect SAFETY comment

safety-ptr-unique.rs: Remove unsound SAFETY comment

safety-ptr-mod.rs: Add std comment on slice_from_raw_parts guarantee

safety-ptr-unique.rs: Remove incorrect safety comment

Creating a Unique from a NonNull has strict guarantees that the current
implementation does not guarantee

https://github.com/rust-lang/rust/pull/71507#discussion_r415035952

safety-ptr: Re-adding ignore-tidy directive
2020-04-29 11:18:31 +02:00
Ralf Jung
7aebdb639a remove Unique::from for shared pointer types 2020-04-26 19:00:57 +02:00
Mark Rousskov
93eed402ad Bump bootstrap compiler 2020-04-25 09:25:33 -04:00
cohenarthur
b4a11d4dd9 doc-example: Refactor pointer name to avoid confusion
Changed raw pointer name from ptr to raw_pointer to avoid confusion with
the `use std::ptr` statement a few lines above. This way the crate name
and pointer name are well differenciated.
2020-04-23 22:22:27 +02:00
Dylan MacKenzie
b3c26de25e Inline some function docs re-exported in std::ptr 2020-04-22 18:01:26 -07:00
Matthias Schiffer
dfd68441be
ptr: add tracking issue for len() method on raw slices 2020-04-14 21:34:27 +02:00
Matthias Schiffer
2a29f8f89d
ptr: introduce len() method on raw slices
It is already possible to extract the pointer part of a raw slice by a
simple cast, but retrieving the length is not possible without relying
on the representation of the raw slice when it is not valid to convert
the raw slice into a slice reference (i.e. the pointer is null or
unaligned).

Introduce a len() method on raw slices to add this missing feature.
2020-04-14 18:49:29 +02:00
Matthias Schiffer
43612e21a6
ptr: implement "const_slice_ptr" and "mut_slice_ptr" lang items 2020-04-14 18:49:29 +02:00
Linus Färnstrand
c0ec0a27b3 Replace max/min_value() with MAX/MIN assoc consts 2020-04-03 09:33:10 +02:00
Ralf Jung
058ff728dc debug-assert ptr sanity in ptr::write 2020-03-14 14:05:26 +01:00
Matthias Krüger
136ad015b6 fix various typos 2020-03-06 15:19:31 +01:00
bors
5703b7aafb Auto merge of #69208 - RalfJung:debug-assert, r=Mark-Simulacrum
debug_assert a few more raw pointer methods

Makes progress for https://github.com/rust-lang/rust/issues/53871
2020-02-29 00:20:44 +00:00
Ralf Jung
d1d0de94db disable debug assertion in ptr::write for now 2020-02-27 09:43:33 +01:00
Ralf Jung
bec5d37ee1 debug_assert a few more raw pointer methods 2020-02-16 14:44:16 +01:00
Amos Onn
943e65396d Improve #Safety of core::ptr::drop_in_place
Added missing conditions:
- Valid for writes
- Valid for destructing
2020-02-16 13:12:34 +01:00
Amos Onn
40ca167944 Improve #Safety in various methods in core::ptr
For all methods which read a value of type T, `read`, `read_unaligned`,
`read_volatile` and `replace`, added missing
constraint:
The value they point to must be properly initialized
2020-02-15 14:00:21 +01:00
Amos Onn
351782d30a Improve #Safety of core::ptr::replace
Added missing condition:
`dst` must be readable
2020-02-15 14:00:10 +01:00
Amos Onn
302b9e4b54 Improve #Safety in various methods in core::ptr
s/for reads and writes/for both ...
2020-02-15 13:58:54 +01:00
Amos Onn
22b263ae18 Optimize core::ptr::align_offset
- As explained in the comment inside mod_inv, it is valid to work mod
  `usize::max_value()` right until the end.
2020-02-03 01:03:33 +01:00
Amos Onn
3173cd1473 Optimize core::ptr::align_offset
- When calculating the inverse, it's enough to work `mod a/g` instead
  of `mod a`.
2020-02-03 01:03:33 +01:00
Amos Onn
e835d0d761 Optimize core::ptr::align_offset
- Stopping condition inside mod_inv can be >= instead of >
- Remove intrinsics::unchecked_rem, we are working modulu powers-of-2 so
we can simply mask
2020-02-03 01:03:33 +01:00
bors
82018665a5 Auto merge of #68234 - CAD97:slice-from-raw-parts, r=KodrAus
Stabilize ptr::slice_from_raw_parts[_mut]

Closes #36925, the tracking issue.
Initial impl: #60667

r? @rust-lang/libs

In addition to stabilizing, I've adjusted the example of `ptr::slice_from_raw_parts` to use `slice_from_raw_parts` instead of `slice_from_raw_parts_mut`, which was unnecessary for the example as written.
2020-01-28 05:31:34 +00:00
Ralf Jung
79359315d6 get rid of real_drop_in_place again 2020-01-18 11:15:56 +01:00
CAD97
1c0d4851a6 Fix incorrect slice->ptr conversion in slice_from_raw_parts docs 2020-01-15 17:00:36 -05:00
CAD97
f76177ce43 Stabilize ptr::slice_from_raw_parts[_mut] 2020-01-14 20:15:39 -05:00
Trevor Spiteri
f8428cf8d8 doc: add Null-unchecked version section to mut pointer as_mut method
The as_ref method already has a Null-unchecked version section, its
example is a modification of the example in the main as_ref section.
Similarly the example in this commit is a modification of the example
in main as_mut section.
2020-01-09 14:51:58 +01:00
jumbatm
f6faf0b2e7 Clean up const-hack from #63810 2019-12-27 23:21:27 +10:00
Mark Rousskov
a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00