Skip to content

Commit

Permalink
Auto merge of #40651 - frewsxcv:rollup, r=frewsxcv
Browse files Browse the repository at this point in the history
Rollup of 13 pull requests

- Successful merges: #40441, #40445, #40562, #40564, #40583, #40588, #40589, #40590, #40603, #40611, #40621, #40646, #40648
- Failed merges:
  • Loading branch information
bors committed Mar 19, 2017
2 parents 9c15de4 + 94e346b commit 38c53f3
Show file tree
Hide file tree
Showing 23 changed files with 216 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/bootstrap/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use std::path::Path;
use Build;

pub fn clean(build: &Build) {
rm_rf(build, "tmp".as_ref());
rm_rf(build, &build.out.join("tmp"));
rm_rf(build, &build.out.join("dist"));
rm_rf("tmp".as_ref());
rm_rf(&build.out.join("tmp"));
rm_rf(&build.out.join("dist"));

for host in build.config.host.iter() {
let entries = match build.out.join(host).read_dir() {
Expand All @@ -38,12 +38,12 @@ pub fn clean(build: &Build) {
continue
}
let path = t!(entry.path().canonicalize());
rm_rf(build, &path);
rm_rf(&path);
}
}
}

fn rm_rf(build: &Build, path: &Path) {
fn rm_rf(path: &Path) {
if !path.exists() {
return
}
Expand All @@ -55,7 +55,7 @@ fn rm_rf(build: &Build, path: &Path) {
let file = t!(file).path();

if file.is_dir() {
rm_rf(build, &file);
rm_rf(&file);
} else {
// On windows we can't remove a readonly file, and git will
// often clone files as readonly. As a result, we have some
Expand Down
1 change: 1 addition & 0 deletions src/doc/unstable-book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- [repr_simd](repr-simd.md)
- [rustc_attrs](rustc-attrs.md)
- [rustc_diagnostic_macros](rustc-diagnostic-macros.md)
- [rvalue_static_promotion](rvalue-static-promotion.md)
- [sanitizer_runtime](sanitizer-runtime.md)
- [simd](simd.md)
- [simd_ffi](simd-ffi.md)
Expand Down
23 changes: 23 additions & 0 deletions src/doc/unstable-book/src/rvalue-static-promotion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# `rvalue_static_promotion`

The tracking issue for this feature is: [#38865]

[#38865]: https://github.com/rust-lang/rust/issues/38865

------------------------

The `rvalue_static_promotion` feature allows directly creating `'static` references to
constant `rvalue`s, which in particular allowing for more concise code in the common case
in which a `'static` reference is all that's needed.


## Examples

```rust
#![feature(rvalue_static_promotion)]

fn main() {
let DEFAULT_VALUE: &'static u32 = &42;
assert_eq!(*DEFAULT_VALUE, 42);
}
```
16 changes: 8 additions & 8 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl<T> [T] {
core_slice::SliceExt::first_mut(self)
}

/// Returns the first and all the rest of the elements of a slice.
/// Returns the first and all the rest of the elements of a slice, or `None` if it is empty.
///
/// # Examples
///
Expand All @@ -248,7 +248,7 @@ impl<T> [T] {
core_slice::SliceExt::split_first(self)
}

/// Returns the first and all the rest of the elements of a slice.
/// Returns the first and all the rest of the elements of a slice, or `None` if it is empty.
///
/// # Examples
///
Expand All @@ -268,7 +268,7 @@ impl<T> [T] {
core_slice::SliceExt::split_first_mut(self)
}

/// Returns the last and all the rest of the elements of a slice.
/// Returns the last and all the rest of the elements of a slice, or `None` if it is empty.
///
/// # Examples
///
Expand All @@ -287,7 +287,7 @@ impl<T> [T] {

}

/// Returns the last and all the rest of the elements of a slice.
/// Returns the last and all the rest of the elements of a slice, or `None` if it is empty.
///
/// # Examples
///
Expand Down Expand Up @@ -437,8 +437,8 @@ impl<T> [T] {
/// The caller must ensure that the slice outlives the pointer this
/// function returns, or else it will end up pointing to garbage.
///
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
/// Modifying the container referenced by this slice may cause its buffer
/// to be reallocated, which would also make any pointers to it invalid.
///
/// # Examples
///
Expand All @@ -463,8 +463,8 @@ impl<T> [T] {
/// The caller must ensure that the slice outlives the pointer this
/// function returns, or else it will end up pointing to garbage.
///
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
/// Modifying the container referenced by this slice may cause its buffer
/// to be reallocated, which would also make any pointers to it invalid.
///
/// # Examples
///
Expand Down
20 changes: 17 additions & 3 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ pub struct cmt_<'tcx> {
pub type cmt<'tcx> = Rc<cmt_<'tcx>>;

impl<'tcx> cmt_<'tcx> {
pub fn get_def(&self) -> Option<ast::NodeId> {
match self.cat {
Categorization::Deref(ref cmt, ..) |
Categorization::Interior(ref cmt, _) |
Categorization::Downcast(ref cmt, _) => {
if let Categorization::Local(nid) = cmt.cat {
Some(nid)
} else {
None
}
}
_ => None
}
}

pub fn get_field(&self, name: ast::Name) -> Option<DefId> {
match self.cat {
Categorization::Deref(ref cmt, ..) |
Expand Down Expand Up @@ -843,11 +858,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
let promotable = self.tcx().rvalue_promotable_to_static.borrow().get(&id).cloned()
.unwrap_or(false);

// Only promote `[T; 0]` before an RFC for rvalue promotions
// is accepted.
// When the corresponding feature isn't toggled, only promote `[T; 0]`.
let promotable = match expr_ty.sty {
ty::TyArray(_, 0) => true,
_ => promotable & false
_ => promotable && self.tcx().sess.features.borrow().rvalue_static_promotion,
};

// Compute maximum lifetime of this rvalue. This is 'static if
Expand Down
19 changes: 19 additions & 0 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
pub fn bckerr_to_diag(&self, err: &BckError<'tcx>) -> DiagnosticBuilder<'a> {
let span = err.span.clone();
let mut immutable_field = None;
let mut local_def = None;

let msg = &match err.code {
err_mutbl => {
Expand Down Expand Up @@ -711,6 +712,14 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
}
None
});
local_def = err.cmt.get_def()
.and_then(|nid| {
if !self.tcx.hir.is_argument(nid) {
Some(self.tcx.hir.span(nid))
} else {
None
}
});

format!("cannot borrow {} as mutable", descr)
}
Expand Down Expand Up @@ -741,6 +750,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
if let Some((span, msg)) = immutable_field {
db.span_label(span, &msg);
}
if let Some(let_span) = local_def {
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(let_span) {
db.span_label(let_span, &format!("consider changing this to `mut {}`", snippet));
}
}
db
}

Expand Down Expand Up @@ -1109,6 +1123,11 @@ before rustc 1.16, this temporary lived longer - see issue #39283 \
} else {
db.span_label(*error_span, &format!("cannot borrow mutably"));
}
} else if let Categorization::Interior(ref cmt, _) = err.cmt.cat {
if let mc::MutabilityCategory::McImmutable = cmt.mutbl {
db.span_label(*error_span,
&"cannot mutably borrow immutable field");
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use {resolve_error, resolve_struct_error, ResolutionError};

use rustc::middle::cstore::LoadedMacro;
use rustc::hir::def::*;
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId};
use rustc::hir::def_id::{CrateNum, BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, DefId};
use rustc::ty;

use std::cell::Cell;
Expand Down Expand Up @@ -496,6 +496,9 @@ impl<'a> Resolver<'a> {
let def_id = self.macro_defs[&expansion];
if let Some(id) = self.definitions.as_local_node_id(def_id) {
self.local_macro_def_scopes[&id]
} else if def_id.krate == BUILTIN_MACROS_CRATE {
// FIXME(jseyfried): This happens when `include!()`ing a `$crate::` path, c.f, #40469.
self.graph_root
} else {
let module_def_id = ty::DefIdTree::parent(&*self, def_id).unwrap();
self.get_extern_crate_root(module_def_id.krate)
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
decl: decl,
abi: sig.abi(),

// trait methods canot (currently, at least) be const
// trait methods cannot (currently, at least) be const
constness: hir::Constness::NotConst,
})
} else {
Expand Down
8 changes: 5 additions & 3 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ use rustc::middle::privacy::AccessLevels;
use rustc::middle::stability;
use rustc::hir;
use rustc::util::nodemap::{FxHashMap, FxHashSet};
use rustc::session::config::nightly_options::is_nightly_build;
use rustc_data_structures::flock;

use clean::{self, AttributesExt, GetDefId, SelfTy, Mutability};
Expand Down Expand Up @@ -2316,9 +2317,10 @@ fn render_assoc_item(w: &mut fmt::Formatter,
}
};
// FIXME(#24111): remove when `const_fn` is stabilized
let vis_constness = match UnstableFeatures::from_environment() {
UnstableFeatures::Allow => constness,
_ => hir::Constness::NotConst
let vis_constness = if is_nightly_build() {
constness
} else {
hir::Constness::NotConst
};
let prefix = format!("{}{}{:#}fn {}{:#}",
ConstnessSpace(vis_constness),
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
/// resistance against HashDoS attacks. The algorithm is randomly seeded, and a
/// reasonable best-effort is made to generate this seed from a high quality,
/// secure source of randomness provided by the host without blocking the
/// program. Because of this, the randomness of the seed is dependant on the
/// quality of the system's random number generator at the time it is created.
/// program. Because of this, the randomness of the seed depends on the output
/// quality of the system's random number generator when the seed is created.
/// In particular, seeds generated when the system's entropy pool is abnormally
/// low such as during system boot may be of a lower quality.
///
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ impl FromInner<c::in_addr> for Ipv4Addr {

#[stable(feature = "ip_u32", since = "1.1.0")]
impl From<Ipv4Addr> for u32 {
/// It performs the conversion in network order (big-endian).
fn from(ip: Ipv4Addr) -> u32 {
let ip = ip.octets();
((ip[0] as u32) << 24) + ((ip[1] as u32) << 16) + ((ip[2] as u32) << 8) + (ip[3] as u32)
Expand All @@ -644,6 +645,7 @@ impl From<Ipv4Addr> for u32 {

#[stable(feature = "ip_u32", since = "1.1.0")]
impl From<u32> for Ipv4Addr {
/// It performs the conversion in network order (big-endian).
fn from(ip: u32) -> Ipv4Addr {
Ipv4Addr::new((ip >> 24) as u8, (ip >> 16) as u8, (ip >> 8) as u8, ip as u8)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ impl Path {
/// assert_eq!(path.to_string_lossy(), "foo.txt");
/// ```
///
/// Had `os_str` contained invalid unicode, the `to_string_lossy` call might
/// Had `path` contained invalid unicode, the `to_string_lossy` call might
/// have returned `"fo�.txt"`.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn to_string_lossy(&self) -> Cow<str> {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ unsafe impl<T: ?Sized + Send> Sync for Mutex<T> { }
/// An RAII implementation of a "scoped lock" of a mutex. When this structure is
/// dropped (falls out of scope), the lock will be unlocked.
///
/// The data protected by the mutex can be access through this guard via its
/// The data protected by the mutex can be accessed through this guard via its
/// [`Deref`] and [`DerefMut`] implementations.
///
/// This structure is created by the [`lock`] and [`try_lock`] methods on
Expand Down
3 changes: 3 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ declare_features! (

// Allows the `catch {...}` expression
(active, catch_expr, "1.17.0", Some(31436)),

// See rust-lang/rfcs#1414. Allows code like `let x: &'static u32 = &42` to work.
(active, rvalue_static_promotion, "1.15.1", Some(38865)),
);

declare_features! (
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ impl<'a> StringReader<'a> {
base = 16;
num_digits = self.scan_digits(16, 16);
}
'0'...'9' | '_' | '.' => {
'0'...'9' | '_' | '.' | 'e' | 'E' => {
num_digits = self.scan_digits(10, 10) + 1;
}
_ => {
Expand Down
15 changes: 15 additions & 0 deletions src/test/compile-fail/feature-gate-rvalue_static_promotion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[allow(unused_variables)]
fn main() {
let x: &'static u32 = &42; //~ error: does not live long enough
let y: &'static Option<u32> = &None; //~ error: does not live long enough
}
11 changes: 11 additions & 0 deletions src/test/run-pass/auxiliary/issue_40469.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

macro_rules! m { () => { $crate::main(); } }
20 changes: 20 additions & 0 deletions src/test/run-pass/issue-34571.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[repr(u8)]
enum Foo {
Foo(u8),
}

fn main() {
match Foo::Foo(1) {
_ => ()
}
}
16 changes: 16 additions & 0 deletions src/test/run-pass/issue-40408.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
println!("{}", 0E+10);
println!("{}", 0e+10);
println!("{}", 00e+10);
println!("{}", 00E+10);
}
Loading

0 comments on commit 38c53f3

Please sign in to comment.