Skip to content
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

Rollup of 8 pull requests #69827

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cbf52b1
remove non-sysroot sources from rust-src component
RalfJung Mar 2, 2020
a9259fb
Try to ensure usize marker does not get merged
Mark-Simulacrum Mar 3, 2020
db75c97
unix: Don't override existing SIGSEGV/BUS handlers
cuviper Mar 3, 2020
9384cba
Documentation and slight simplification of BTreeMap's internals
ssomers Mar 3, 2020
13d5ee1
Cleanup E0390 explanation
GuillaumeGomez Mar 6, 2020
31183bb
Fix missing ` in doc for File::with_options
lukas-code Mar 6, 2020
6548be2
'fieldless enums' is not what I meant -- it's empty/uninhabited enums…
RalfJung Mar 2, 2020
d47196b
miri value visitor: detect primitives by type, not layout
RalfJung Mar 2, 2020
aa1435b
const validation ub tests: use transmute instead of unions
RalfJung Mar 2, 2020
4807e93
test that we validate boxes
RalfJung Mar 2, 2020
f481547
test some more kinds of enums with uninhabited variants
RalfJung Mar 2, 2020
4584e75
better error messages for invalid boxes (and a few more tests)
RalfJung Mar 2, 2020
f0586f9
please tidy
RalfJung Mar 2, 2020
58f8cc2
rename visit_primitive -> try_visit_primitive, and comments
RalfJung Mar 2, 2020
295c2d6
bug on ty::GeneratorWitness
RalfJung Mar 2, 2020
b1b558f
refactor: Exhaustive matching in method/probe.rs
Mar 7, 2020
6095fa1
refactor: Move a borrow_mut and unwrap out of a loop
Mar 7, 2020
a95f00f
fix type size mismatch on 32bit
RalfJung Mar 8, 2020
efad0cb
Rollup merge of #69631 - RalfJung:rust-src, r=Mark-Simulacrum
Centril Mar 8, 2020
8d25f2b
Rollup merge of #69646 - RalfJung:layout-visitor, r=eddyb
Centril Mar 8, 2020
850e515
Rollup merge of #69651 - Mark-Simulacrum:black-box-marker, r=eddyb
Centril Mar 8, 2020
8a30198
Rollup merge of #69668 - ssomers:btreemap_even_more_comments, r=Mark-…
Centril Mar 8, 2020
d9b718f
Rollup merge of #69685 - cuviper:soft-segv, r=sfackler
Centril Mar 8, 2020
919ae59
Rollup merge of #69771 - GuillaumeGomez:cleanup-e0390, r=Dylan-DPC
Centril Mar 8, 2020
9ea18a6
Rollup merge of #69777 - lukas-code:patch-1, r=jonas-schievink
Centril Mar 8, 2020
eb125f3
Rollup merge of #69812 - Marwes:refactor, r=petrochenkov
Centril Mar 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,6 @@ impl Step for Src {
"src/tools/rustc-std-workspace-core",
"src/tools/rustc-std-workspace-alloc",
"src/tools/rustc-std-workspace-std",
"src/librustc",
"src/librustc_ast",
];

copy_src_dirs(builder, &std_src_dirs[..], &[], &dst_src);
Expand Down
33 changes: 19 additions & 14 deletions src/liballoc/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,15 @@ impl<K, V> InternalNode<K, V> {
}
}

/// An owned pointer to a node. This basically is either `Box<LeafNode<K, V>>` or
/// `Box<InternalNode<K, V>>`. However, it contains no information as to which of the two types
/// of nodes is actually behind the box, and, partially due to this lack of information, has no
/// destructor.
/// A managed, non-null pointer to a node. This is either an owned pointer to
/// `LeafNode<K, V>`, an owned pointer to `InternalNode<K, V>`, or a (not owned)
/// pointer to `NodeHeader<(), ()` (more specifically, the pointer to EMPTY_ROOT_NODE).
/// All of these types have a `NodeHeader<K, V>` prefix, meaning that they have at
/// least the same size as `NodeHeader<K, V>` and store the same kinds of data at the same
/// offsets; and they have a pointer alignment at least as large as `NodeHeader<K, V>`'s.
/// However, `BoxedNode` contains no information as to which of the three types
/// of nodes it actually contains, and, partially due to this lack of information,
/// has no destructor.
struct BoxedNode<K, V> {
ptr: Unique<LeafNode<K, V>>,
}
Expand All @@ -167,9 +172,7 @@ impl<K, V> BoxedNode<K, V> {
}

fn from_internal(node: Box<InternalNode<K, V>>) -> Self {
unsafe {
BoxedNode { ptr: Unique::new_unchecked(Box::into_raw(node) as *mut LeafNode<K, V>) }
}
BoxedNode { ptr: Box::into_unique(node).cast() }
}

unsafe fn from_ptr(ptr: NonNull<LeafNode<K, V>>) -> Self {
Expand All @@ -181,32 +184,33 @@ impl<K, V> BoxedNode<K, V> {
}
}

/// An owned tree. Note that despite being owned, this does not have a destructor,
/// and must be cleaned up manually.
/// Either an owned tree or a shared, empty tree. Note that this does not have a destructor,
/// and must be cleaned up manually if it is an owned tree.
pub struct Root<K, V> {
node: BoxedNode<K, V>,
/// The number of levels below the root node.
height: usize,
}

unsafe impl<K: Sync, V: Sync> Sync for Root<K, V> {}
unsafe impl<K: Send, V: Send> Send for Root<K, V> {}

impl<K, V> Root<K, V> {
/// Whether the instance of `Root` wraps a shared, empty root node. If not,
/// the entire tree is uniquely owned by the owner of the `Root` instance.
pub fn is_shared_root(&self) -> bool {
self.as_ref().is_shared_root()
}

/// Returns a shared tree, wrapping a shared root node that is eternally empty.
pub fn shared_empty_root() -> Self {
Root {
node: unsafe {
BoxedNode::from_ptr(NonNull::new_unchecked(
&EMPTY_ROOT_NODE as *const _ as *const LeafNode<K, V> as *mut _,
))
},
node: unsafe { BoxedNode::from_ptr(NonNull::from(&EMPTY_ROOT_NODE).cast()) },
height: 0,
}
}

/// Returns a new owned tree, with its own root node that is initially empty.
pub fn new_leaf() -> Self {
Root { node: BoxedNode::from_leaf(Box::new(unsafe { LeafNode::new() })), height: 0 }
}
Expand Down Expand Up @@ -310,6 +314,7 @@ impl<K, V> Root<K, V> {
/// so '&LeafNode` or `&InternalNode` pointing to the shared root is undefined behavior.
/// Turning this into a `NodeHeader` reference is always safe.
pub struct NodeRef<BorrowType, K, V, Type> {
/// The number of levels below the node.
height: usize,
node: NonNull<LeafNode<K, V>>,
// `root` is null unless the borrow type is `Mut`
Expand Down
12 changes: 11 additions & 1 deletion src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,18 @@ pub struct ArgumentV1<'a> {
// could have been miscompiled. In practice, we never call as_usize on non-usize
// containing data (as a matter of static generation of the formatting
// arguments), so this is merely an additional check.
//
// We primarily want to ensure that the function pointer at `USIZE_MARKER` has
// an address corresponding *only* to functions that also take `&usize` as their
// first argument. The read_volatile here ensures that we can safely ready out a
// usize from the passed reference and that this address does not point at a
// non-usize taking function.
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
static USIZE_MARKER: fn(&usize, &mut Formatter<'_>) -> Result = |_, _| loop {};
static USIZE_MARKER: fn(&usize, &mut Formatter<'_>) -> Result = |ptr, _| {
// SAFETY: ptr is a reference
let _v: usize = unsafe { crate::ptr::read_volatile(ptr) };
loop {}
};

impl<'a> ArgumentV1<'a> {
#[doc(hidden)]
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_error_codes/error_codes/E0390.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
You tried to implement methods for a primitive type. Erroneous code example:
A method was implemented on a primitive type.

Erroneous code example:

```compile_fail,E0390
struct Foo {
Expand Down
Loading