Skip to content

Rollup of 6 pull requests #71491

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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
37514de
Document unsafety in `core::option`
LeSeulArtichaut Apr 11, 2020
d1ce7ff
Document unsafety in `src/libcore/hash/mod.rs`
LeSeulArtichaut Apr 11, 2020
b84f981
Document unsafety in `src/libcore/hash/sip.rs`
LeSeulArtichaut Apr 12, 2020
3eea7b3
Make the `structural_match` error diagnostic for const generics clearer
varkor Apr 6, 2020
f8b796b
Add error message for using type parameter as the type of a const par…
varkor Apr 20, 2020
13c1dae
Tweak `'static` suggestion code
estebank Apr 17, 2020
1f43fc0
Tweak wording
estebank Apr 17, 2020
322b204
Revert old span change
estebank Apr 17, 2020
ad379cd
review comment
estebank Apr 18, 2020
59c816d
fix test
estebank Apr 22, 2020
25f8966
Sort `MultiSpan`s on creation
estebank Apr 23, 2020
c16b6e0
Add leading 0x to offset in Debug fmt of Pointer
divergentdave Apr 23, 2020
baac961
fix error code for E0751
contrun Apr 22, 2020
3029e9e
Add note about padding
LeSeulArtichaut Apr 23, 2020
0658259
Set RUSTDOCFLAGS in `cargo` invocation
ecstatic-morse Apr 23, 2020
a694315
Add a note about fat pointers
LeSeulArtichaut Apr 23, 2020
7a282eb
Rollup merge of #70845 - varkor:const-generics-derive-eq-diagnostic, …
Dylan-DPC Apr 23, 2020
d8c235d
Rollup merge of #71063 - LeSeulArtichaut:document-unsafe, r=Mark-Simu…
Dylan-DPC Apr 23, 2020
1ba8b13
Rollup merge of #71235 - estebank:lt-sugg-2, r=ecstatic-morse
Dylan-DPC Apr 23, 2020
368de4b
Rollup merge of #71426 - contrun:fix-e0751-explanation, r=estebank
Dylan-DPC Apr 23, 2020
c250419
Rollup merge of #71458 - ecstatic-morse:bootstrap-cfg-doc, r=Mark-Sim…
Dylan-DPC Apr 23, 2020
a9da98f
Rollup merge of #71459 - divergentdave:pointer-offset-0x, r=RalfJung
Dylan-DPC Apr 23, 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
11 changes: 9 additions & 2 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,11 @@ impl<'a> Builder<'a> {
rustflags.arg("--cfg=bootstrap");
}

// FIXME: It might be better to use the same value for both `RUSTFLAGS` and `RUSTDOCFLAGS`,
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
// #71458.
let rustdocflags = rustflags.clone();

if let Ok(s) = env::var("CARGOFLAGS") {
cargo.args(s.split_whitespace());
}
Expand Down Expand Up @@ -1269,7 +1274,7 @@ impl<'a> Builder<'a> {
}
}

Cargo { command: cargo, rustflags }
Cargo { command: cargo, rustflags, rustdocflags }
}

/// Ensure that a given step is built, returning its output. This will
Expand Down Expand Up @@ -1327,7 +1332,7 @@ impl<'a> Builder<'a> {
#[cfg(test)]
mod tests;

#[derive(Debug)]
#[derive(Debug, Clone)]
struct Rustflags(String);

impl Rustflags {
Expand Down Expand Up @@ -1367,6 +1372,7 @@ impl Rustflags {
pub struct Cargo {
command: Command,
rustflags: Rustflags,
rustdocflags: Rustflags,
}

impl Cargo {
Expand Down Expand Up @@ -1400,6 +1406,7 @@ impl Cargo {
impl From<Cargo> for Command {
fn from(mut cargo: Cargo) -> Command {
cargo.command.env("RUSTFLAGS", &cargo.rustflags.0);
cargo.command.env("RUSTDOCFLAGS", &cargo.rustdocflags.0);
cargo.command
}
}
16 changes: 14 additions & 2 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@
//! }
//! ```

// ignore-tidy-undocumented-unsafe

#![stable(feature = "rust1", since = "1.0.0")]

use crate::fmt;
Expand Down Expand Up @@ -572,6 +570,10 @@ mod impls {
fn hash_slice<H: Hasher>(data: &[$ty], state: &mut H) {
let newlen = data.len() * mem::size_of::<$ty>();
let ptr = data.as_ptr() as *const u8;
// SAFETY: `ptr` is valid and aligned, as this macro is only used
// for numeric primitives which have no padding. The new slice only
// spans across `data` and is never mutated, and its total size is the
// same as the original `data` so it can't be over `isize::MAX`.
state.write(unsafe { slice::from_raw_parts(ptr, newlen) })
}
}
Expand Down Expand Up @@ -691,6 +693,11 @@ mod impls {
state.write_usize(*self as *const () as usize);
} else {
// Fat pointer
// SAFETY: we are accessing the memory occupied by `self`
// which is guaranteed to be valid.
// This assumes a fat pointer can be represented by a `(usize, usize)`,
// which is safe to do in `std` because it is shipped and kept in sync
// with the implementation of fat pointers in `rustc`.
let (a, b) = unsafe { *(self as *const Self as *const (usize, usize)) };
state.write_usize(a);
state.write_usize(b);
Expand All @@ -706,6 +713,11 @@ mod impls {
state.write_usize(*self as *const () as usize);
} else {
// Fat pointer
// SAFETY: we are accessing the memory occupied by `self`
// which is guaranteed to be valid.
// This assumes a fat pointer can be represented by a `(usize, usize)`,
// which is safe to do in `std` because it is shipped and kept in sync
// with the implementation of fat pointers in `rustc`.
let (a, b) = unsafe { *(self as *const Self as *const (usize, usize)) };
state.write_usize(a);
state.write_usize(b);
Expand Down
11 changes: 8 additions & 3 deletions src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! An implementation of SipHash.

// ignore-tidy-undocumented-unsafe

#![allow(deprecated)] // the types in this module are deprecated

use crate::cmp;
Expand Down Expand Up @@ -265,6 +263,7 @@ impl<S: Sip> super::Hasher for Hasher<S> {

if self.ntail != 0 {
needed = 8 - self.ntail;
// SAFETY: `cmp::min(length, needed)` is guaranteed to not be over `length`
self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << (8 * self.ntail);
if length < needed {
self.ntail += length;
Expand All @@ -279,10 +278,13 @@ impl<S: Sip> super::Hasher for Hasher<S> {

// Buffered tail is now flushed, process new input.
let len = length - needed;
let left = len & 0x7;
let left = len & 0x7; // len % 8

let mut i = needed;
while i < len - left {
// SAFETY: because `len - left` is the biggest multiple of 8 under
// `len`, and because `i` starts at `needed` where `len` is `length - needed`,
// `i + 8` is guaranteed to be less than or equal to `length`.
let mi = unsafe { load_int_le!(msg, i, u64) };

self.state.v3 ^= mi;
Expand All @@ -292,6 +294,9 @@ impl<S: Sip> super::Hasher for Hasher<S> {
i += 8;
}

// SAFETY: `i` is now `needed + len.div_euclid(8) * 8`,
// so `i + left` = `needed + len` = `length`, which is by
// definition equal to `msg.len()`.
self.tail = unsafe { u8to64_le(msg, i, left) };
self.ntail = left;
}
Expand Down
8 changes: 6 additions & 2 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@
//! [`Box<T>`]: ../../std/boxed/struct.Box.html
//! [`i32`]: ../../std/primitive.i32.html

// ignore-tidy-undocumented-unsafe

#![stable(feature = "rust1", since = "1.0.0")]

use crate::iter::{FromIterator, FusedIterator, TrustedLen};
Expand Down Expand Up @@ -301,6 +299,8 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "pin", since = "1.33.0")]
pub fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
// SAFETY: `x` is guaranteed to be pinned because it comes from `self`
// which is pinned.
unsafe { Pin::get_ref(self).as_ref().map(|x| Pin::new_unchecked(x)) }
}

Expand All @@ -310,6 +310,8 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "pin", since = "1.33.0")]
pub fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>> {
// SAFETY: `get_unchecked_mut` is never used to move the `Option` inside `self`.
// `x` is guaranteed to be pinned because it comes from `self` which is pinned.
unsafe { Pin::get_unchecked_mut(self).as_mut().map(|x| Pin::new_unchecked(x)) }
}

Expand Down Expand Up @@ -858,6 +860,8 @@ impl<T> Option<T> {

match *self {
Some(ref mut v) => v,
// SAFETY: a `None` variant for `self` would have been replaced by a `Some`
// variant in the code above.
None => unsafe { hint::unreachable_unchecked() },
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_ast_lowering/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
.next();
if !generic_args.parenthesized && !has_lifetimes {
generic_args.args = self
.elided_path_lifetimes(path_span, expected_lifetimes)
.elided_path_lifetimes(
first_generic_span.map(|s| s.shrink_to_lo()).unwrap_or(segment.ident.span),
expected_lifetimes,
)
.map(GenericArg::Lifetime)
.chain(generic_args.args.into_iter())
.collect();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0751.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ There are both a positive and negative trait implementation for the same type.

Erroneous code example:

```compile_fail,E0748
```compile_fail,E0751
trait MyTrait {}
impl MyTrait for i32 { }
impl !MyTrait for i32 { }
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ static_assert_size!(Pointer, 16);

impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Pointer<Tag, Id> {
default fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}+{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
write!(f, "{:?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
}
}
// Specialization for no tag
impl<Id: fmt::Debug> fmt::Debug for Pointer<(), Id> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}+{:x}", self.alloc_id, self.offset.bytes())
write!(f, "{:?}+0x{:x}", self.alloc_id, self.offset.bytes())
}
}

Expand Down
Loading