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 19 pull requests #58348

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7cdcdb5
Update reference of rlibc crate to compiler-builtins crate
king6cong Jan 2, 2019
5581207
Remove outdated comment
king6cong Jan 9, 2019
87f5a98
Use `to_ne_bytes` for converting IPv4Address to octets
JakubOnderka Jan 18, 2019
b4d3c87
Tiny improvement to docs for `core::convert`.
icefoxen Jan 26, 2019
9a460aa
some type-level docs for MaybeUninit; rename into_inner -> into_initi…
RalfJung Feb 3, 2019
760424a
expand as_[mut_]ptr docs a bit
RalfJung Feb 3, 2019
f8c7d8d
make set return a mutable reference
RalfJung Feb 3, 2019
789b4d1
typos
RalfJung Feb 4, 2019
bd4df0c
Add Cargo.lock automatically adding message
h-michael Feb 4, 2019
aaafc3c
fix doctest
RalfJung Feb 5, 2019
8d6e5fc
rustc: partially HirIdify
ljedrz Feb 4, 2019
44752c2
mir: partially HirIdify
ljedrz Feb 4, 2019
6da9129
typeck: partially HirIdify
ljedrz Feb 4, 2019
d371bce
fix test case
RalfJung Feb 5, 2019
b331b86
extend box-maybe-uninit test
RalfJung Feb 5, 2019
f3eede6
fix doctests
RalfJung Feb 6, 2019
4deb595
display sugared return types for async functions
euclio Feb 5, 2019
1d05f81
Add #[must_use] message to Fn* traits
taiki-e Feb 7, 2019
541503a
std::sys::unix::stdio: explain why we do into_raw
RalfJung Feb 8, 2019
b962ecc
Cleanup JS a bit
GuillaumeGomez Feb 8, 2019
fe27623
librustc_typeck => 2018
taiki-e Feb 8, 2019
be71fcc
librustc_codegen_ssa => 2018
taiki-e Feb 9, 2019
66adf52
miri: give non-generic functions a stable address
RalfJung Feb 9, 2019
0a16b87
Use ? in librustc macros
matthewjasper Feb 9, 2019
a01efbc
operand-to-place copies should never be overlapping
RalfJung Feb 9, 2019
3a3691f
when there are multiple filenames, print what got interpreted as 2nd …
RalfJung Feb 10, 2019
adb3300
rpath computation: explain why we pop()
RalfJung Feb 10, 2019
509d592
Rollup merge of #57259 - king6cong:master, r=alexcrichton
pietroalbini Feb 10, 2019
26947dd
Rollup merge of #57740 - JakubOnderka:ipv4addr-to_ne_bytes, r=scottmcm
pietroalbini Feb 10, 2019
b7a2e97
Rollup merge of #57926 - icefoxen:test-doc-pr, r=frewsxcv
pietroalbini Feb 10, 2019
9f00747
Rollup merge of #58129 - RalfJung:maybe-uninit, r=cramertj
pietroalbini Feb 10, 2019
384d918
Rollup merge of #58151 - ljedrz:HirIdify_rustc, r=Zoxc
pietroalbini Feb 10, 2019
fda0440
Rollup merge of #58152 - ljedrz:HirIdify_mir, r=Zoxc
pietroalbini Feb 10, 2019
108ae57
Rollup merge of #58153 - ljedrz:HirIdify_typeck, r=Zoxc
pietroalbini Feb 10, 2019
1512034
Rollup merge of #58157 - h-michael:cargo-lock, r=alexcrichton
pietroalbini Feb 10, 2019
6194cb0
Rollup merge of #58203 - euclio:rustdoc-async, r=GuillaumeGomez
pietroalbini Feb 10, 2019
f4cc05e
Rollup merge of #58262 - taiki-e:must_use, r=estebank
pietroalbini Feb 10, 2019
c0e2ab2
Rollup merge of #58295 - RalfJung:stdio, r=alexcrichton
pietroalbini Feb 10, 2019
7c5257b
Rollup merge of #58297 - GuillaumeGomez:cleanup-js, r=QuietMisdreavus
pietroalbini Feb 10, 2019
14bd021
Rollup merge of #58300 - taiki-e:librustc_typeck-2018, r=petrochenkov
pietroalbini Feb 10, 2019
c029e40
Rollup merge of #58313 - matthewjasper:use-question-in-macros, r=oli-obk
pietroalbini Feb 10, 2019
a657d89
Rollup merge of #58322 - taiki-e:librustc_codegen_ssa-2018, r=petroch…
pietroalbini Feb 10, 2019
27955b6
Rollup merge of #58324 - RalfJung:fn-ptr-eq, r=oli-obk
pietroalbini Feb 10, 2019
6023911
Rollup merge of #58332 - RalfJung:miri-copy-nonoverlapping, r=oli-obk
pietroalbini Feb 10, 2019
7a30e41
Rollup merge of #58345 - RalfJung:2nd-filename, r=matthewjasper
pietroalbini Feb 10, 2019
a5a09e3
Rollup merge of #58346 - RalfJung:rpath-pop, r=Mark-Simulacrum
pietroalbini Feb 10, 2019
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: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "adler32"
version = "1.0.3"
Expand Down
5 changes: 4 additions & 1 deletion src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
//! [`TryFrom<T>`][`TryFrom`] rather than [`Into<U>`][`Into`] or [`TryInto<U>`][`TryInto`],
//! as [`From`] and [`TryFrom`] provide greater flexibility and offer
//! equivalent [`Into`] or [`TryInto`] implementations for free, thanks to a
//! blanket implementation in the standard library.
//! blanket implementation in the standard library. However, there are some cases
//! where this is not possible, such as creating conversions into a type defined
//! outside your library, so implementing [`Into`] instead of [`From`] is
//! sometimes necessary.
//!
//! # Generic Implementations
//!
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! often generated by LLVM. Additionally, this library can make explicit
//! calls to these functions. Their signatures are the same as found in C.
//! These functions are often provided by the system libc, but can also be
//! provided by the [rlibc crate](https://crates.io/crates/rlibc).
//! provided by the [compiler-builtins crate](https://crates.io/crates/compiler_builtins).
//!
//! * `rust_begin_panic` - This function takes four arguments, a
//! `fmt::Arguments`, a `&'static str`, and two `u32`'s. These four arguments
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,12 @@ macro_rules! unimplemented {
#[macro_export]
#[unstable(feature = "maybe_uninit", issue = "53491")]
macro_rules! uninitialized_array {
// This `into_inner` is safe because an array of `MaybeUninit` does not
// This `into_initialized` is safe because an array of `MaybeUninit` does not
// require initialization.
// FIXME(#49147): Could be replaced by an array initializer, once those can
// be any const expression.
($t:ty; $size:expr) => (unsafe {
MaybeUninit::<[MaybeUninit<$t>; $size]>::uninitialized().into_inner()
MaybeUninit::<[MaybeUninit<$t>; $size]>::uninitialized().into_initialized()
});
}

Expand Down
59 changes: 52 additions & 7 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,42 @@ impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
}
}

/// A newtype to construct uninitialized instances of `T`
/// A newtype to construct uninitialized instances of `T`.
///
/// The compiler, in general, assumes that variables are properly initialized
/// at their respective type. For example, a variable of reference type must
/// be aligned and non-NULL. This is an invariant that must *always* be upheld,
/// even in unsafe code. As a consequence, 0-initializing a variable of reference
/// type causes instantaneous undefined behavior, no matter whether that reference
/// ever gets used to access memory:
/// ```rust,no_run
/// use std::mem;
///
/// let x: &i32 = unsafe { mem::zeroed() }; // undefined behavior!
/// ```
/// This is exploited by the compiler for various optimizations, such as eliding
/// run-time checks and optimizing `enum` layout.
///
/// Not initializing memory at all (instead of 0-initializing it) causes the same
/// issue: after all, the initial value of the variable might just happen to be
/// one that violates the invariant.
///
/// `MaybeUninit` serves to enable unsafe code to deal with uninitialized data:
/// it is a signal to the compiler indicating that the data here might *not*
/// be initialized:
/// ```rust
/// #![feature(maybe_uninit)]
/// use std::mem::MaybeUninit;
///
/// // Create an explicitly uninitialized reference.
/// let mut x = MaybeUninit::<&i32>::uninitialized();
/// // Set it to a valid value.
/// x.set(&0);
/// // Extract the initialized data -- this is only allowed *after* properly
/// // initializing `x`!
/// let x = unsafe { x.into_initialized() };
/// ```
/// The compiler then knows to not optimize this code.
#[allow(missing_debug_implementations)]
#[unstable(feature = "maybe_uninit", issue = "53491")]
// NOTE after stabilizing `MaybeUninit` proceed to deprecate `mem::{uninitialized,zeroed}`
Expand Down Expand Up @@ -1084,11 +1119,14 @@ impl<T> MaybeUninit<T> {
}

/// Set the value of the `MaybeUninit`. This overwrites any previous value without dropping it.
/// For your convenience, this also returns a mutable reference to the (now
/// safely initialized) content of `self`.
#[unstable(feature = "maybe_uninit", issue = "53491")]
#[inline(always)]
pub fn set(&mut self, val: T) {
pub fn set(&mut self, val: T) -> &mut T {
unsafe {
self.value = ManuallyDrop::new(val);
self.get_mut()
}
}

Expand All @@ -1102,11 +1140,18 @@ impl<T> MaybeUninit<T> {
/// state, otherwise this will immediately cause undefined behavior.
#[unstable(feature = "maybe_uninit", issue = "53491")]
#[inline(always)]
pub unsafe fn into_inner(self) -> T {
pub unsafe fn into_initialized(self) -> T {
intrinsics::panic_if_uninhabited::<T>();
ManuallyDrop::into_inner(self.value)
}

/// Deprecated alternative to `into_initialized`. Will never get stabilized.
/// Exists only to transition stdsimd to `into_initialized`.
#[inline(always)]
pub(crate) unsafe fn into_inner(self) -> T {
self.into_initialized()
}

/// Get a reference to the contained value.
///
/// # Unsafety
Expand Down Expand Up @@ -1134,16 +1179,16 @@ impl<T> MaybeUninit<T> {
&mut *self.value
}

/// Get a pointer to the contained value. Reading from this pointer will be undefined
/// behavior unless the `MaybeUninit` is initialized.
/// Get a pointer to the contained value. Reading from this pointer or turning it
/// into a reference will be undefined behavior unless the `MaybeUninit` is initialized.
#[unstable(feature = "maybe_uninit", issue = "53491")]
#[inline(always)]
pub fn as_ptr(&self) -> *const T {
unsafe { &*self.value as *const T }
}

/// Get a mutable pointer to the contained value. Reading from this pointer will be undefined
/// behavior unless the `MaybeUninit` is initialized.
/// Get a mutable pointer to the contained value. Reading from this pointer or turning it
/// into a reference will be undefined behavior unless the `MaybeUninit` is initialized.
#[unstable(feature = "maybe_uninit", issue = "53491")]
#[inline(always)]
pub fn as_mut_ptr(&mut self) -> *mut T {
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/ops/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
label="expected an `Fn<{Args}>` closure, found `{Self}`",
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use]
#[must_use = "closures are lazy and do nothing unless called"]
pub trait Fn<Args> : FnMut<Args> {
/// Performs the call operation.
#[unstable(feature = "fn_traits", issue = "29625")]
Expand Down Expand Up @@ -141,7 +141,7 @@ pub trait Fn<Args> : FnMut<Args> {
label="expected an `FnMut<{Args}>` closure, found `{Self}`",
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use]
#[must_use = "closures are lazy and do nothing unless called"]
pub trait FnMut<Args> : FnOnce<Args> {
/// Performs the call operation.
#[unstable(feature = "fn_traits", issue = "29625")]
Expand Down Expand Up @@ -220,7 +220,7 @@ pub trait FnMut<Args> : FnOnce<Args> {
label="expected an `FnOnce<{Args}>` closure, found `{Self}`",
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use]
#[must_use = "closures are lazy and do nothing unless called"]
pub trait FnOnce<Args> {
/// The returned type after the call operator is used.
#[stable(feature = "fn_once_output", since = "1.12.0")]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
pub unsafe fn read<T>(src: *const T) -> T {
let mut tmp = MaybeUninit::<T>::uninitialized();
copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
tmp.into_inner()
tmp.into_initialized()
}

/// Reads the value from `src` without moving it. This leaves the
Expand Down Expand Up @@ -642,7 +642,7 @@ pub unsafe fn read_unaligned<T>(src: *const T) -> T {
copy_nonoverlapping(src as *const u8,
tmp.as_mut_ptr() as *mut u8,
mem::size_of::<T>());
tmp.into_inner()
tmp.into_initialized()
}

/// Overwrites a memory location with the given value without reading or
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,9 @@ impl<'hir> Map<'hir> {
}
}

pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData {
pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData {
let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible

match self.find(id) {
Some(Node::Item(i)) => {
match i.node {
Expand All @@ -949,7 +951,9 @@ impl<'hir> Map<'hir> {
}
}

pub fn expect_variant(&self, id: NodeId) -> &'hir Variant {
pub fn expect_variant(&self, id: HirId) -> &'hir Variant {
let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible

match self.find(id) {
Some(Node::Variant(variant)) => variant,
_ => bug!("expected variant, found {}", self.node_to_string(id)),
Expand Down
18 changes: 8 additions & 10 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ use crate::hir::def_id::DefId;
use crate::hir::Node;
use crate::middle::region;
use std::{cmp, fmt};
use syntax::ast::DUMMY_NODE_ID;
use syntax_pos::{Pos, Span};
use crate::traits::{ObligationCause, ObligationCauseCode};
use crate::ty::error::TypeError;
Expand Down Expand Up @@ -182,8 +181,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let cm = self.sess.source_map();

let scope = region.free_region_binding_scope(self);
let node = self.hir().as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID);
let tag = match self.hir().find(node) {
let node = self.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
let tag = match self.hir().find_by_hir_id(node) {
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
Some(Node::Item(it)) => Self::item_scope_tag(&it),
Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it),
Expand All @@ -192,7 +191,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
};
let (prefix, span) = match *region {
ty::ReEarlyBound(ref br) => {
let mut sp = cm.def_span(self.hir().span(node));
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
if let Some(param) = self.hir()
.get_generics(scope)
.and_then(|generics| generics.get_named(&br.name))
Expand All @@ -205,7 +204,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
bound_region: ty::BoundRegion::BrNamed(_, ref name),
..
}) => {
let mut sp = cm.def_span(self.hir().span(node));
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
if let Some(param) = self.hir()
.get_generics(scope)
.and_then(|generics| generics.get_named(&name))
Expand All @@ -217,15 +216,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
ty::ReFree(ref fr) => match fr.bound_region {
ty::BrAnon(idx) => (
format!("the anonymous lifetime #{} defined on", idx + 1),
self.hir().span(node),
self.hir().span_by_hir_id(node),
),
ty::BrFresh(_) => (
"an anonymous lifetime defined on".to_owned(),
self.hir().span(node),
self.hir().span_by_hir_id(node),
),
_ => (
format!("the lifetime {} as defined on", fr.bound_region),
cm.def_span(self.hir().span(node)),
cm.def_span(self.hir().span_by_hir_id(node)),
),
},
_ => bug!(),
Expand Down Expand Up @@ -1451,8 +1450,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
format!(" for lifetime parameter `{}` in coherence check", name)
}
infer::UpvarRegion(ref upvar_id, _) => {
let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id);
let var_name = self.tcx.hir().name(var_node_id);
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
format!(" for capture of `{}` by closure", var_name)
}
infer::NLL(..) => bug!("NLL variable found in lexical phase"),
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
"...so that reference does not outlive borrowed content");
}
infer::ReborrowUpvar(span, ref upvar_id) => {
let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id);
let var_name = self.tcx.hir().name(var_node_id);
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
err.span_note(span,
&format!("...so that closure can access `{}`", var_name));
}
Expand Down Expand Up @@ -164,8 +163,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err
}
infer::ReborrowUpvar(span, ref upvar_id) => {
let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id);
let var_name = self.tcx.hir().name(var_node_id);
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
let mut err = struct_span_err!(self.tcx.sess,
span,
E0313,
Expand Down
Loading