diff --git a/config.toml.example b/config.toml.example index 312270532affc7bbaaaa1001f0effeb1bd229055..1c851999130a0213ae5daded08d1e8eda4f637ae 100644 --- a/config.toml.example +++ b/config.toml.example @@ -243,19 +243,36 @@ # ============================================================================= [rust] -# Indicates that the build should be optimized for debugging Rust. Note that -# this is typically not what you want as it takes an incredibly large amount of -# time to have a debug-mode rustc compile any code (notably libstd). If this -# value is set to `true` it will affect a number of configuration options below -# as well, if unconfigured. -#debug = false - -# Whether or not to optimize the compiler and standard library +# Whether or not to optimize the compiler and standard library. +# # Note: the slowness of the non optimized compiler compiling itself usually # outweighs the time gains in not doing optimizations, therefore a -# full bootstrap takes much more time with optimize set to false. +# full bootstrap takes much more time with `optimize` set to false. #optimize = true +# Indicates that the build should be configured for debugging Rust. A +# `debug`-enabled compiler and standard library will be somewhat +# slower (due to e.g. checking of debug assertions) but should remain +# usable. +# +# Note: If this value is set to `true`, it will affect a number of +# configuration options below as well, if they have been left +# unconfigured in this file. +# +# Note: changes to the `debug` setting do *not* affect `optimize` +# above. In theory, a "maximally debuggable" environment would +# set `optimize` to `false` above to assist the introspection +# facilities of debuggers like lldb and gdb. To recreate such an +# environment, explicitly set `optimize` to `false` and `debug` +# to `true`. In practice, everyone leaves `optimize` set to +# `true`, because an unoptimized rustc with debugging +# enabled becomes *unusably slow* (e.g. rust-lang/rust#24840 +# reported a 25x slowdown) and bootstrapping the supposed +# "maximally debuggable" environment (notably libstd) takes +# hours to build. +# +#debug = false + # Number of codegen units to use for each compiler invocation. A value of 0 # means "the number of cores on this machine", and 1+ is passed through to the # compiler. diff --git a/src/Cargo.lock b/src/Cargo.lock index 2719587f20e8a742956282f79388c844a4141030..c01086b3f6f2b42cc809401afbf94fbfdd979f82 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1269,7 +1269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "minifier" -version = "0.0.19" +version = "0.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2484,7 +2484,7 @@ dependencies = [ name = "rustdoc" version = "0.0.0" dependencies = [ - "minifier 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "minifier 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3289,7 +3289,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum memchr 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a3b4142ab8738a78c51896f704f83c11df047ff1bda9a92a661aa6361552d93d" "checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" -"checksum minifier 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "9908ed7c62f990c21ab41fdca53a864a3ada0da69d8729c4de727b397e27bc11" +"checksum minifier 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "96c269bb45c39b333392b2b18ad71760b34ac65666591386b0e959ed58b3f474" "checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4" "checksum miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" "checksum new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0cdc457076c78ab54d5e0d6fa7c47981757f1e34dc39ff92787f217dede586c4" diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index c3fbc8eeca6ba65ee428f6cff468f05283334219..a5ed096a735810b09a0304faa53686c3aa1bac33 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -628,6 +628,9 @@ pub fn parse(args: &[String]) -> Config { let default = false; config.llvm_assertions = llvm_assertions.unwrap_or(default); + let default = true; + config.rust_optimize = optimize.unwrap_or(default); + let default = match &config.channel[..] { "stable" | "beta" | "nightly" => true, _ => false, @@ -640,7 +643,6 @@ pub fn parse(args: &[String]) -> Config { config.debug_jemalloc = debug_jemalloc.unwrap_or(default); config.rust_debuginfo = debuginfo.unwrap_or(default); config.rust_debug_assertions = debug_assertions.unwrap_or(default); - config.rust_optimize = optimize.unwrap_or(!default); let default = config.channel == "dev"; config.ignore_git = ignore_git.unwrap_or(default); diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs index ec94f57861dbeb1efce4a827795c0dfb954f73d9..5d174719ab23e4d60ac48b14bd4f0f814b67322c 100644 --- a/src/build_helper/lib.rs +++ b/src/build_helper/lib.rs @@ -91,13 +91,13 @@ pub fn try_run_suppressed(cmd: &mut Command) -> bool { output.status.success() } -pub fn gnu_target(target: &str) -> String { +pub fn gnu_target(target: &str) -> &str { match target { - "i686-pc-windows-msvc" => "i686-pc-win32".to_string(), - "x86_64-pc-windows-msvc" => "x86_64-pc-win32".to_string(), - "i686-pc-windows-gnu" => "i686-w64-mingw32".to_string(), - "x86_64-pc-windows-gnu" => "x86_64-w64-mingw32".to_string(), - s => s.to_string(), + "i686-pc-windows-msvc" => "i686-pc-win32", + "x86_64-pc-windows-msvc" => "x86_64-pc-win32", + "i686-pc-windows-gnu" => "i686-w64-mingw32", + "x86_64-pc-windows-gnu" => "x86_64-w64-mingw32", + s => s, } } diff --git a/src/etc/htmldocck.py b/src/etc/htmldocck.py index 569788fe9c08a93cfca05915a7835ea629c34be0..91010262981e884981a46110a6acc659bc1d7e99 100644 --- a/src/etc/htmldocck.py +++ b/src/etc/htmldocck.py @@ -15,65 +15,66 @@ htmldocck.py is a custom checker script for Rustdoc HTML outputs. The principle is simple: This script receives a path to generated HTML documentation and a "template" script, which has a series of check -commands like `@has` or `@matches`. Each command can be used to check if +commands like `@has` or `@matches`. Each command is used to check if some pattern is present or not present in the particular file or in -the particular node of HTML tree. In many cases, the template script -happens to be a source code given to rustdoc. +a particular node of the HTML tree. In many cases, the template script +happens to be the source code given to rustdoc. While it indeed is possible to test in smaller portions, it has been hard to construct tests in this fashion and major rendering errors were -discovered much later. This script is designed for making the black-box -and regression testing of Rustdoc easy. This does not preclude the needs -for unit testing, but can be used to complement related tests by quickly +discovered much later. This script is designed to make black-box and +regression testing of Rustdoc easy. This does not preclude the needs for +unit testing, but can be used to complement related tests by quickly showing the expected renderings. In order to avoid one-off dependencies for this task, this script uses a reasonably working HTML parser and the existing XPath implementation -from Python's standard library. Hopefully we won't render +from Python's standard library. Hopefully, we won't render non-well-formed HTML. # Commands Commands start with an `@` followed by a command name (letters and hyphens), and zero or more arguments separated by one or more whitespace -and optionally delimited with single or double quotes. The `@` mark -cannot be preceded by a non-whitespace character. Other lines (including -every text up to the first `@`) are ignored, but it is recommended to -avoid the use of `@` in the template file. +characters and optionally delimited with single or double quotes. The `@` +mark cannot be preceded by a non-whitespace character. Other lines +(including every text up to the first `@`) are ignored, but it is +recommended to avoid the use of `@` in the template file. There are a number of supported commands: -* `@has PATH` checks for the existence of given file. +* `@has PATH` checks for the existence of the given file. `PATH` is relative to the output directory. It can be given as `-` which repeats the most recently used `PATH`. * `@has PATH PATTERN` and `@matches PATH PATTERN` checks for - the occurrence of given `PATTERN` in the given file. Only one - occurrence of given pattern is enough. + the occurrence of the given pattern `PATTERN` in the specified file. + Only one occurrence of the pattern is enough. For `@has`, `PATTERN` is a whitespace-normalized (every consecutive whitespace being replaced by one single space character) string. The entire file is also whitespace-normalized including newlines. For `@matches`, `PATTERN` is a Python-supported regular expression. - The file remains intact but the regexp is matched with no `MULTILINE` - and `IGNORECASE` option. You can still use a prefix `(?m)` or `(?i)` + The file remains intact but the regexp is matched without the `MULTILINE` + and `IGNORECASE` options. You can still use a prefix `(?m)` or `(?i)` to override them, and `\A` and `\Z` for definitely matching the beginning and end of the file. (The same distinction goes to other variants of these commands.) * `@has PATH XPATH PATTERN` and `@matches PATH XPATH PATTERN` checks for - the presence of given `XPATH` in the given HTML file, and also - the occurrence of given `PATTERN` in the matching node or attribute. - Only one occurrence of given pattern in the match is enough. + the presence of the given XPath `XPATH` in the specified HTML file, + and also the occurrence of the given pattern `PATTERN` in the matching + node or attribute. Only one occurrence of the pattern in the match + is enough. `PATH` should be a valid and well-formed HTML file. It does *not* accept arbitrary HTML5; it should have matching open and close tags and correct entity references at least. - `XPATH` is an XPath expression to match. This is fairly limited: + `XPATH` is an XPath expression to match. The XPath is fairly limited: `tag`, `*`, `.`, `//`, `..`, `[@attr]`, `[@attr='value']`, `[tag]`, `[POS]` (element located in given `POS`), `[last()-POS]`, `text()` and `@attr` (both as the last segment) are supported. Some examples: @@ -85,7 +86,7 @@ There are a number of supported commands: - `//h1[@class="fqn"]/span[1]/a[last()]/@class` matches a value of `class` attribute in the last `a` element (can be followed by more elements that are not `a`) inside the first `span` in the `h1` with - a class of `fqn`. Note that there cannot be no additional elements + a class of `fqn`. Note that there cannot be any additional elements between them due to the use of `/` instead of `//`. Do not try to use non-absolute paths, it won't work due to the flawed @@ -93,11 +94,12 @@ There are a number of supported commands: For the text matches (i.e. paths not ending with `@attr`), any subelements are flattened into one string; this is handy for ignoring - highlights for example. If you want to simply check the presence of - given node or attribute, use an empty string (`""`) as a `PATTERN`. + highlights for example. If you want to simply check for the presence of + a given node or attribute, use an empty string (`""`) as a `PATTERN`. -* `@count PATH XPATH COUNT' checks for the occurrence of given XPath - in the given file. The number of occurrences must match the given count. +* `@count PATH XPATH COUNT' checks for the occurrence of the given XPath + in the specified file. The number of occurrences must match the given + count. * `@has-dir PATH` checks for the existence of the given directory. diff --git a/src/liballoc/benches/slice.rs b/src/liballoc/benches/slice.rs index a699ff9c0a76ec61d0a427ab58bfe10c23c09d72..490320f57cbf79bd9ca681285f9f504764679095 100644 --- a/src/liballoc/benches/slice.rs +++ b/src/liballoc/benches/slice.rs @@ -13,6 +13,7 @@ use std::ptr; use rand::{Rng, SeedableRng, XorShiftRng}; +use rand::distributions::{Standard, Alphanumeric}; use test::{Bencher, black_box}; #[bench] @@ -192,18 +193,20 @@ fn gen_descending(len: usize) -> Vec { (0..len as u64).rev().collect() } +const SEED: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; + fn gen_random(len: usize) -> Vec { - let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]); - rng.gen_iter::().take(len).collect() + let mut rng = XorShiftRng::from_seed(SEED); + rng.sample_iter(&Standard).take(len).collect() } fn gen_random_bytes(len: usize) -> Vec { - let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]); - rng.gen_iter::().take(len).collect() + let mut rng = XorShiftRng::from_seed(SEED); + rng.sample_iter(&Standard).take(len).collect() } fn gen_mostly_ascending(len: usize) -> Vec { - let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]); + let mut rng = XorShiftRng::from_seed(SEED); let mut v = gen_ascending(len); for _ in (0usize..).take_while(|x| x * x <= len) { let x = rng.gen::() % len; @@ -214,7 +217,7 @@ fn gen_mostly_ascending(len: usize) -> Vec { } fn gen_mostly_descending(len: usize) -> Vec { - let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]); + let mut rng = XorShiftRng::from_seed(SEED); let mut v = gen_descending(len); for _ in (0usize..).take_while(|x| x * x <= len) { let x = rng.gen::() % len; @@ -225,18 +228,18 @@ fn gen_mostly_descending(len: usize) -> Vec { } fn gen_strings(len: usize) -> Vec { - let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]); + let mut rng = XorShiftRng::from_seed(SEED); let mut v = vec![]; for _ in 0..len { let n = rng.gen::() % 20 + 1; - v.push(rng.gen_ascii_chars().take(n).collect()); + v.push(rng.sample_iter(&Alphanumeric).take(n).collect()); } v } fn gen_big_random(len: usize) -> Vec<[u64; 16]> { - let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]); - rng.gen_iter().map(|x| [x; 16]).take(len).collect() + let mut rng = XorShiftRng::from_seed(SEED); + rng.sample_iter(&Standard).map(|x| [x; 16]).take(len).collect() } macro_rules! sort { diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 2bc037e3fee126343715212911c8b62e1d28867e..f7a0bbdceafc93325359fbb83a51b413548db0da 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -120,11 +120,17 @@ /// assert_eq!(vec, [1, 2, 3, 4]); /// ``` /// -/// It can also initialize each element of a `Vec` with a given value: +/// It can also initialize each element of a `Vec` with a given value. +/// This may be more efficient than performing allocation and initialization +/// in separate steps, especially when initializing a vector of zeros: /// /// ``` /// let vec = vec![0; 5]; /// assert_eq!(vec, [0, 0, 0, 0, 0]); +/// +/// // The following is equivalent, but potentially slower: +/// let mut vec1 = Vec::with_capacity(5); +/// vec1.resize(5, 0); /// ``` /// /// Use a `Vec` as an efficient stack: diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index 3ef03ec6d585aa268ff3e519e34aaf4a0605dc06..15283036bb49522d35aec181804831dba3fb4dce 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -20,6 +20,10 @@ #![feature(nll)] #![feature(staged_api)] #![feature(rustc_attrs)] +#![cfg_attr( + all(target_arch = "wasm32", not(target_os = "emscripten")), + feature(integer_atomics, stdsimd) +)] #![cfg_attr(any(unix, target_os = "cloudabi", target_os = "redox"), feature(libc))] #![rustc_alloc_kind = "lib"] @@ -331,29 +335,76 @@ mod platform { use core::alloc::{GlobalAlloc, Layout}; use System; - // No need for synchronization here as wasm is currently single-threaded static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::DLMALLOC_INIT; #[stable(feature = "alloc_system_type", since = "1.28.0")] unsafe impl GlobalAlloc for System { #[inline] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + let _lock = lock::lock(); DLMALLOC.malloc(layout.size(), layout.align()) } #[inline] unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + let _lock = lock::lock(); DLMALLOC.calloc(layout.size(), layout.align()) } #[inline] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { + let _lock = lock::lock(); DLMALLOC.free(ptr, layout.size(), layout.align()) } #[inline] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { + let _lock = lock::lock(); DLMALLOC.realloc(ptr, layout.size(), layout.align(), new_size) } } + + #[cfg(target_feature = "atomics")] + mod lock { + use core::arch::wasm32; + use core::sync::atomic::{AtomicI32, Ordering::SeqCst}; + + static LOCKED: AtomicI32 = AtomicI32::new(0); + + pub struct DropLock; + + pub fn lock() -> DropLock { + loop { + if LOCKED.swap(1, SeqCst) == 0 { + return DropLock + } + unsafe { + let r = wasm32::atomic::wait_i32( + &LOCKED as *const AtomicI32 as *mut i32, + 1, // expected value + -1, // timeout + ); + debug_assert!(r == 0 || r == 1); + } + } + } + + impl Drop for DropLock { + fn drop(&mut self) { + let r = LOCKED.swap(0, SeqCst); + debug_assert_eq!(r, 1); + unsafe { + wasm32::atomic::wake( + &LOCKED as *const AtomicI32 as *mut i32, + 1, // only one thread + ); + } + } + } + } + + #[cfg(not(target_feature = "atomics"))] + mod lock { + pub fn lock() {} // no atomics, no threads, that's easy! + } } diff --git a/src/librustc/macros.rs b/src/librustc/macros.rs index 759ac1a7952f7165b0ef858f42359513049c7fce..897e9cc2a381f2305c96a59bc15b3508833637d6 100644 --- a/src/librustc/macros.rs +++ b/src/librustc/macros.rs @@ -62,6 +62,16 @@ pub fn from_u32(u: u32) -> Option<$name> { }) } +#[macro_export] +macro_rules! static_assert { + ($name:ident: $test:expr) => { + // Use the bool to access an array such that if the bool is false, the access + // is out-of-bounds. + #[allow(dead_code)] + static $name: () = [()][!$test as usize]; + } +} + #[macro_export] macro_rules! __impl_stable_hash_field { ($field:ident, $ctx:expr, $hasher:expr) => ($field.hash_stable($ctx, $hasher)); diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index edb571da7dbc50c010d07079f9b45e93960e2dde..a90f03f536ad52d62cb4d7d419a92f14c997e4d7 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -167,8 +167,7 @@ pub struct FirstStatementIndex { .. } impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { private }); // compilation error if size of `ScopeData` is not the same as a `u32` -#[allow(dead_code)] -static ASSERT: () = [()][!(mem::size_of::() == 4) as usize]; +static_assert!(ASSERT_SCOPE_DATA: mem::size_of::() == 4); impl Scope { /// Returns a item-local id associated with this scope. diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 3d4ae572d0b81fb0880f6bc76a8c98c08075ef37..ab1df2d4c3bb9f3eaece7df32fef18c18ff1da4b 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -829,12 +829,9 @@ impl<'tcx> CommonTypes<'tcx> { fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> { // Ensure our type representation does not grow #[cfg(target_pointer_width = "64")] - #[allow(dead_code)] - static ASSERT_TY_KIND: () = - [()][!(::std::mem::size_of::>() <= 24) as usize]; + static_assert!(ASSERT_TY_KIND: ::std::mem::size_of::>() <= 24); #[cfg(target_pointer_width = "64")] - #[allow(dead_code)] - static ASSERT_TYS: () = [()][!(::std::mem::size_of::>() <= 32) as usize]; + static_assert!(ASSERT_TYS: ::std::mem::size_of::>() <= 32); let mk = |sty| CtxtInterners::intern_ty(interners, interners, sty); let mk_region = |r| { diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 2799f2cc81f5ab0648d078f0d19d6fdc387356ce..870eeadc081e76b856087c8d2b84c638eaaed545 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -76,9 +76,9 @@ pub enum StringPart { } impl StringPart { - pub fn content(&self) -> String { + pub fn content(&self) -> &str { match self { - &StringPart::Normal(ref s) | & StringPart::Highlighted(ref s) => s.to_owned() + &StringPart::Normal(ref s) | & StringPart::Highlighted(ref s) => s } } } @@ -398,7 +398,7 @@ pub fn get_code(&self) -> Option { } pub fn message(&self) -> String { - self.message.iter().map(|i| i.0.to_owned()).collect::() + self.message.iter().map(|i| i.0.as_str()).collect::() } pub fn styled_message(&self) -> &Vec<(String, Style)> { @@ -448,7 +448,7 @@ fn sub_with_highlights(&mut self, impl SubDiagnostic { pub fn message(&self) -> String { - self.message.iter().map(|i| i.0.to_owned()).collect::() + self.message.iter().map(|i| i.0.as_str()).collect::() } pub fn styled_message(&self) -> &Vec<(String, Style)> { diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index ae178888b6a1cda42a65a67f3ccddb11cbce2a4a..ec3c310c63c4f80c42ec88d65cfed1f1efcd2137 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -59,15 +59,17 @@ fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { } let t = cx.tables.expr_ty(&expr); - let ty_warned = match t.sty { - ty::Tuple(ref tys) if tys.is_empty() => return, - ty::Never => return, + // FIXME(varkor): replace with `t.is_unit() || t.conservative_is_uninhabited()`. + let type_permits_no_use = match t.sty { + ty::Tuple(ref tys) if tys.is_empty() => true, + ty::Never => true, ty::Adt(def, _) => { if def.variants.is_empty() { - return; + true + } else { + check_must_use(cx, def.did, s.span, "") } - check_must_use(cx, def.did, s.span, "") - }, + } _ => false, }; @@ -95,7 +97,12 @@ fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { if let Some(def) = maybe_def { let def_id = def.def_id(); fn_warned = check_must_use(cx, def_id, s.span, "return value of "); + } else if type_permits_no_use { + // We don't warn about unused unit or uninhabited types. + // (See https://github.com/rust-lang/rust/issues/43806 for details.) + return; } + let must_use_op = match expr.node { // Hardcoding operators here seemed more expedient than the // refactoring that would be needed to look up the `#[must_use]` @@ -139,7 +146,7 @@ fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { op_warned = true; } - if !(ty_warned || fn_warned || op_warned) { + if !(type_permits_no_use || fn_warned || op_warned) { cx.span_lint(UNUSED_RESULTS, s.span, "unused result"); } @@ -233,7 +240,7 @@ fn check_attribute(&mut self, cx: &LateContext, attr: &ast::Attribute) { .find(|&&(builtin, ty, _)| name == builtin && ty == AttributeType::CrateLevel) .is_some(); - // Has a plugin registered this attribute as one which must be used at + // Has a plugin registered this attribute as one that must be used at // the crate level? let plugin_crate = plugin_attributes.iter() .find(|&&(ref x, t)| name == &**x && AttributeType::CrateLevel == t) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 693cfea3c95f0d4b3cbabdaa44d944abfb407c83..ea62694f8be753c7c52e6b1c71fd8127b0af5282 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -68,6 +68,7 @@ enum GroupedMoveError<'tcx> { enum BorrowedContentSource { Arc, Rc, + DerefRawPointer, Other, } @@ -76,6 +77,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { BorrowedContentSource::Arc => write!(f, "an `Arc`"), BorrowedContentSource::Rc => write!(f, "an `Rc`"), + BorrowedContentSource::DerefRawPointer => write!(f, "dereference of raw pointer"), BorrowedContentSource::Other => write!(f, "borrowed content"), } } @@ -279,6 +281,7 @@ fn report(&mut self, error: GroupedMoveError<'tcx>) { self.prefixes(&original_path, PrefixSet::All) .any(|p| p.is_upvar_field_projection(self.mir, &self.infcx.tcx) .is_some()); + debug!("report: ty={:?}", ty); match ty.sty { ty::Array(..) | ty::Slice(..) => self.infcx.tcx.cannot_move_out_of_interior_noncopy( @@ -582,6 +585,18 @@ fn borrowed_content_source(&self, place: &Place<'tcx>) -> BorrowedContentSource } } + // If we didn't find an `Arc` or an `Rc`, then check specifically for + // a dereference of a place that has the type of a raw pointer. + // We can't use `place.ty(..).to_ty(..)` here as that strips away the raw pointer. + if let Place::Projection(box Projection { + base, + elem: ProjectionElem::Deref, + }) = place { + if base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx).is_unsafe_ptr() { + return BorrowedContentSource::DerefRawPointer; + } + } + BorrowedContentSource::Other } } diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 039a92cee2ca2fcfba65f06617ece23d6de56141..c72a5894b6ac7f54f0b83bf1f9ed7bcf70e78479 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -11,7 +11,6 @@ //! Functions concerning immediate values and operands, and reading from operands. //! All high-level functions to read from memory work on operands as sources. -use std::hash::{Hash, Hasher}; use std::convert::TryInto; use rustc::{mir, ty}; @@ -290,7 +289,7 @@ pub fn to_immediate(self) -> Value } } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] pub struct OpTy<'tcx, Tag=()> { crate op: Operand, // ideally we'd make this private, but const_prop needs this pub layout: TyLayout<'tcx>, @@ -324,26 +323,6 @@ fn from(val: ValTy<'tcx, Tag>) -> Self { } } -// Validation needs to hash OpTy, but we cannot hash Layout -- so we just hash the type -impl<'tcx, Tag> Hash for OpTy<'tcx, Tag> - where Tag: Hash -{ - fn hash(&self, state: &mut H) { - self.op.hash(state); - self.layout.ty.hash(state); - } -} -impl<'tcx, Tag> PartialEq for OpTy<'tcx, Tag> - where Tag: PartialEq -{ - fn eq(&self, other: &Self) -> bool { - self.op == other.op && self.layout.ty == other.layout.ty - } -} -impl<'tcx, Tag> Eq for OpTy<'tcx, Tag> - where Tag: Eq -{} - impl<'tcx, Tag> OpTy<'tcx, Tag> { #[inline] diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index 96eb69163220e7b33c57287bd9ac35596ab6b589..6b28fd091748f14114b21d7224e82620b5a65d55 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -874,7 +874,7 @@ pub fn scalar(cx: C, scalar: Scalar) -> Self { /// to those obtained from `layout_of(ty)`, as we need to produce /// layouts for which Rust types do not exist, such as enum variants /// or synthetic fields of enums (i.e. discriminants) and fat pointers. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub struct TyLayout<'a, Ty> { pub ty: Ty, pub details: &'a LayoutDetails diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 845bfad7807d32734be3695cd9af68e3221b66d6..8bac007b748ac20a6376f2ceb58f0e41f5d04922 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -9,6 +9,6 @@ path = "lib.rs" [dependencies] pulldown-cmark = { version = "0.1.2", default-features = false } -minifier = "0.0.19" +minifier = "0.0.20" tempfile = "3" parking_lot = "0.6.4" diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 1c61e73fae03cdd0f8346bee6244c05bfd517256..23f1e15de3c925c7c8acb3bebf9a68c2d840f875 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -4098,12 +4098,13 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { ", version)?; } + } + write!(fmt, "
")?; + if it.is_crate() { write!(fmt, "

See all {}'s items

", it.name.as_ref().expect("crates always have a name"))?; } - - write!(fmt, "
")?; match it.inner { clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?, clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?, diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 58ac46d22717bc7dd0af46b28d11b7335a5ce9f1..91ff03a327df4b1c78d4f866eaf4c228dfae99dc 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -908,10 +908,9 @@ span.since { padding-top: 0px; } - .sidebar { + body > .sidebar { height: 45px; min-height: 40px; - width: calc(100% + 30px); margin: 0; margin-left: -15px; padding: 0 15px; @@ -1013,6 +1012,10 @@ span.since { .anchor { display: none !important; } + + h1.fqn { + overflow: initial; + } } @media print { @@ -1112,6 +1115,18 @@ h4 > .important-traits { top: 2px; } +#all-types { + text-align: center; + border: 1px solid; + margin: 0 10px; + margin-bottom: 10px; + display: block; + border-radius: 7px; +} +#all-types > p { + margin: 5px 0; +} + @media (max-width: 700px) { h4 > .important-traits { position: absolute; @@ -1135,6 +1150,9 @@ h4 > .important-traits { background-color: rgba(0,0,0,0); height: 100%; } + .sidebar { + width: calc(100% + 30px); + } .show-it { display: block; @@ -1180,6 +1198,10 @@ h4 > .important-traits { .impl > .collapse-toggle { left: -10px; } + + #all-types { + margin: 10px; + } } @@ -1383,17 +1405,6 @@ kbd { #main > ul > li { list-style: none; } -#all-types { - text-align: center; - border: 1px solid; - margin: 0 10px; - margin-bottom: 10px; - display: block; - border-radius: 7px; -} -#all-types > p { - margin: 5px 0; -} .non-exhaustive { margin-bottom: 1em; diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index f14d55cb2d34f1ea8c443b8a197846307d3c0360..017949291bcf16e37f200141b9254d9fdbaad544 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -726,7 +726,7 @@ pub fn write(&mut self, write: bool) -> &mut OpenOptions { /// If a file is opened with both read and append access, beware that after /// opening, and after every write, the position for reading may be set at the /// end of the file. So, before writing, save the current position (using - /// [`seek`]`(`[`SeekFrom`]`::`[`Current`]`(0))`, and restore it before the next read. + /// [`seek`]`(`[`SeekFrom`]`::`[`Current`]`(0))`), and restore it before the next read. /// /// ## Note /// diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 48a9b2f4a93de558e18ca361cd203d46333c1512..5c87035d8e929214e11ced115b76469307e2923a 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -79,7 +79,7 @@ /// /// Simply put, a type `T` implements `UnwindSafe` if it cannot easily allow /// witnessing a broken invariant through the use of `catch_unwind` (catching a -/// panic). This trait is a marker trait, so it is automatically implemented for +/// panic). This trait is an auto trait, so it is automatically implemented for /// many types, and it is also structurally composed (e.g. a struct is unwind /// safe if all of its components are unwind safe). /// diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index 8d54728a75f42ff3e93918feeda1bf9c596e00c3..3b432d05132095adc8206d36e022275c51ebb321 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -908,11 +908,36 @@ mod prim_usize { } /// `&mut T` references can be freely coerced into `&T` references with the same referent type, and /// references with longer lifetimes can be freely coerced into references with shorter ones. /// +/// Reference equality by address, instead of comparing the values pointed to, is accomplished via +/// implicit reference-pointer coercion and raw pointer equality via [`ptr::eq`], while +/// [`PartialEq`] compares values. +/// +/// [`ptr::eq`]: ptr/fn.eq.html +/// [`PartialEq`]: cmp/trait.PartialEq.html +/// +/// ``` +/// use std::ptr; +/// +/// let five = 5; +/// let other_five = 5; +/// let five_ref = &five; +/// let same_five_ref = &five; +/// let other_five_ref = &other_five; +/// +/// assert!(five_ref == same_five_ref); +/// assert!(five_ref == other_five_ref); +/// +/// assert!(ptr::eq(five_ref, same_five_ref)); +/// assert!(!ptr::eq(five_ref, other_five_ref)); +/// ``` +/// /// For more information on how to use references, see [the book's section on "References and /// Borrowing"][book-refs]. /// /// [book-refs]: ../book/second-edition/ch04-02-references-and-borrowing.html /// +/// # Trait implementations +/// /// The following traits are implemented for all `&T`, regardless of the type of its referent: /// /// * [`Copy`] diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 17cb614ba11ff7ae12b573a4264bf3463c0936f5..98845e457b25c8a25dd1ee5b9554cafbfa5269a8 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -329,7 +329,7 @@ pub fn call_once_force(&self, f: F) where F: FnOnce(&OnceState) { /// assert!(handle.join().is_err()); /// assert_eq!(INIT.is_completed(), false); /// ``` - #[unstable(feature = "once_is_completed", issue = "42")] + #[unstable(feature = "once_is_completed", issue = "54890")] #[inline] pub fn is_completed(&self) -> bool { // An `Acquire` load is enough because that makes all the initialization diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6c375799c38ad5cd83cbf1cc33e9bd5f8652318e..b5896f37c00b8b11eba35ac4798c7440e8bc5f2a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -772,6 +772,11 @@ fn tokens_to_string(tokens: &[TokenType]) -> String { // | expected one of 8 possible tokens here err.span_label(self.span, label_exp); } + _ if self.prev_span == syntax_pos::DUMMY_SP => { + // Account for macro context where the previous span might not be + // available to avoid incorrect output (#54841). + err.span_label(self.span, "unexpected token"); + } _ => { err.span_label(sp, label_exp); err.span_label(self.span, "unexpected token"); diff --git a/src/test/rustdoc/inline_cross/issue-31948-1.rs b/src/test/rustdoc/inline_cross/issue-31948-1.rs index e953b66fce15dd351ea4dcf6fa4d984d463c2001..677aa529f9f349b0823c7744edf64d3cd5f37db5 100644 --- a/src/test/rustdoc/inline_cross/issue-31948-1.rs +++ b/src/test/rustdoc/inline_cross/issue-31948-1.rs @@ -22,13 +22,13 @@ pub use rustdoc_nonreachable_impls::hidden::Wobble; // @has issue_31948_1/trait.Bark.html -// FIXME(33025): has - '//code' 'for Foo' +// @has - '//code' 'for Foo' // @has - '//code' 'for Wobble' // @!has - '//code' 'for Wibble' pub use rustdoc_nonreachable_impls::Bark; // @has issue_31948_1/trait.Woof.html -// FIXME(33025): has - '//code' 'for Foo' +// @has - '//code' 'for Foo' // @has - '//code' 'for Wobble' // @!has - '//code' 'for Wibble' pub use rustdoc_nonreachable_impls::Woof; diff --git a/src/test/rustdoc/inline_cross/issue-31948-2.rs b/src/test/rustdoc/inline_cross/issue-31948-2.rs index 0423fa1de3b4c56fc55da4bf8b45c4ae4d5aa77c..7b42ed378ef5cbaf3feecf895f897021b2f33f59 100644 --- a/src/test/rustdoc/inline_cross/issue-31948-2.rs +++ b/src/test/rustdoc/inline_cross/issue-31948-2.rs @@ -22,7 +22,7 @@ pub use rustdoc_nonreachable_impls::hidden::Wobble; // @has issue_31948_2/trait.Qux.html -// FIXME(33025): has - '//code' 'for Foo' +// @has - '//code' 'for Foo' // @has - '//code' 'for Wobble' pub use rustdoc_nonreachable_impls::hidden::Qux; diff --git a/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.nll.stderr b/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.nll.stderr index f823a6f08d789485e47546b7e9fa34f4ec5f1f34..c3a2180b9f082e062f9afab0ede465a7511ac8f3 100644 --- a/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.nll.stderr +++ b/src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.nll.stderr @@ -1,10 +1,10 @@ -error[E0507]: cannot move out of borrowed content +error[E0507]: cannot move out of dereference of raw pointer --> $DIR/borrowck-move-from-unsafe-ptr.rs:13:13 | LL | let y = *x; //~ ERROR cannot move out of dereference of raw pointer | ^^ | | - | cannot move out of borrowed content + | cannot move out of dereference of raw pointer | help: consider removing the `*`: `x` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-20801.nll.stderr b/src/test/ui/issues/issue-20801.nll.stderr index 3a6784eed67dd35d3adaaadb90b1bcd59d38ebc7..362778b26c861911d2624046c87cd15c65d575ea 100644 --- a/src/test/ui/issues/issue-20801.nll.stderr +++ b/src/test/ui/issues/issue-20801.nll.stderr @@ -16,22 +16,22 @@ LL | let b = unsafe { *imm_ref() }; | cannot move out of borrowed content | help: consider removing the `*`: `imm_ref()` -error[E0507]: cannot move out of borrowed content +error[E0507]: cannot move out of dereference of raw pointer --> $DIR/issue-20801.rs:42:22 | LL | let c = unsafe { *mut_ptr() }; | ^^^^^^^^^^ | | - | cannot move out of borrowed content + | cannot move out of dereference of raw pointer | help: consider removing the `*`: `mut_ptr()` -error[E0507]: cannot move out of borrowed content +error[E0507]: cannot move out of dereference of raw pointer --> $DIR/issue-20801.rs:45:22 | LL | let d = unsafe { *const_ptr() }; | ^^^^^^^^^^^^ | | - | cannot move out of borrowed content + | cannot move out of dereference of raw pointer | help: consider removing the `*`: `const_ptr()` error: aborting due to 4 previous errors diff --git a/src/test/ui/lint/must_use-unit.rs b/src/test/ui/lint/must_use-unit.rs new file mode 100644 index 0000000000000000000000000000000000000000..92568252164f683d0b7e57ee78c564143553dffd --- /dev/null +++ b/src/test/ui/lint/must_use-unit.rs @@ -0,0 +1,17 @@ +#![feature(never_type)] + +#![deny(unused_must_use)] + +#[must_use] +fn foo() {} + +#[must_use] +fn bar() -> ! { + unimplemented!() +} + +fn main() { + foo(); //~ unused return value of `foo` + + bar(); //~ unused return value of `bar` +} diff --git a/src/test/ui/lint/must_use-unit.stderr b/src/test/ui/lint/must_use-unit.stderr new file mode 100644 index 0000000000000000000000000000000000000000..0a956f74611b53839bf9b052eeecca967ae33696 --- /dev/null +++ b/src/test/ui/lint/must_use-unit.stderr @@ -0,0 +1,20 @@ +error: unused return value of `foo` which must be used + --> $DIR/must_use-unit.rs:14:5 + | +LL | foo(); //~ unused return value of `foo` + | ^^^^^^ + | +note: lint level defined here + --> $DIR/must_use-unit.rs:3:9 + | +LL | #![deny(unused_must_use)] + | ^^^^^^^^^^^^^^^ + +error: unused return value of `bar` which must be used + --> $DIR/must_use-unit.rs:16:5 + | +LL | bar(); //~ unused return value of `bar` + | ^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/macros/issue-54441.stderr b/src/test/ui/macros/issue-54441.stderr index aa1edb2cf893fdd26ed2b99911ad8a5caf95c594..e27056b412a0fb5383b93ba47d5642133f8d5011 100644 --- a/src/test/ui/macros/issue-54441.stderr +++ b/src/test/ui/macros/issue-54441.stderr @@ -1,9 +1,6 @@ error: expected one of `crate`, `fn`, `pub`, `static`, or `type`, found `let` --> $DIR/issue-54441.rs:5:9 | -LL | #![feature(macros_in_extern)] - | - expected one of `crate`, `fn`, `pub`, `static`, or `type` here -... LL | let //~ ERROR expected | ^^^ unexpected token ...