diff --git a/config.toml.example b/config.toml.example index f12ff76284589..bfd9e18cdd41a 100644 --- a/config.toml.example +++ b/config.toml.example @@ -138,6 +138,10 @@ # specified, use this rustc binary instead as the stage0 snapshot compiler. #rustc = "/path/to/bin/rustc" +# Instead of download the src/stage0.txt version of rustfmt specified, +# use this rustfmt binary instead as the stage0 snapshot rustfmt. +#rustfmt = "/path/to/bin/rustfmt" + # Flag to specify whether any documentation is built. If false, rustdoc and # friends will still be compiled but they will not be used to generate any # documentation. @@ -406,6 +410,13 @@ # Whether to verify generated LLVM IR #verify-llvm-ir = false +# Compile the compiler with a non-default ThinLTO import limit. This import +# limit controls the maximum size of functions imported by ThinLTO. Decreasing +# will make code compile faster at the expense of lower runtime performance. +# If `incremental` is set to true above, the import limit will default to 10 +# instead of LLVM's default of 100. +#thin-lto-import-instr-limit = 100 + # Map all debuginfo paths for libstd and crates to `/rust/$sha/$crate/...`, # generally only set for releases #remap-debuginfo = false diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index a2dca66697d6d..f7d8daa75ecb5 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1183,6 +1183,21 @@ impl<'a> Builder<'a> { rustflags.arg("-Cprefer-dynamic"); } + // When building incrementally we default to a lower ThinLTO import limit + // (unless explicitly specified otherwise). This will produce a somewhat + // slower code but give way better compile times. + { + let limit = match self.config.rust_thin_lto_import_instr_limit { + Some(limit) => Some(limit), + None if self.config.incremental => Some(10), + _ => None, + }; + + if let Some(limit) = limit { + rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={}", limit)); + } + } + Cargo { command: cargo, rustflags } } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 0970a50bee47a..944df66431fe8 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -108,6 +108,7 @@ pub struct Config { pub rust_dist_src: bool, pub rust_codegen_backends: Vec>, pub rust_verify_llvm_ir: bool, + pub rust_thin_lto_import_instr_limit: Option, pub rust_remap_debuginfo: bool, pub build: Interned, @@ -202,6 +203,7 @@ struct Build { target: Vec, cargo: Option, rustc: Option, + rustfmt: Option, /* allow bootstrap.py to use rustfmt key */ docs: Option, compiler_docs: Option, submodules: Option, @@ -325,6 +327,7 @@ struct Rust { deny_warnings: Option, backtrace_on_ice: Option, verify_llvm_ir: Option, + thin_lto_import_instr_limit: Option, remap_debuginfo: Option, jemalloc: Option, test_compare_mode: Option, @@ -569,6 +572,7 @@ impl Config { set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings)); set(&mut config.backtrace_on_ice, rust.backtrace_on_ice); set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir); + config.rust_thin_lto_import_instr_limit = rust.thin_lto_import_instr_limit; set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo); if let Some(ref backends) = rust.codegen_backends { diff --git a/src/ci/docker/x86_64-gnu-llvm-7/Dockerfile b/src/ci/docker/x86_64-gnu-llvm-7/Dockerfile index a1c9c13fc471a..dc90c286f5cd1 100644 --- a/src/ci/docker/x86_64-gnu-llvm-7/Dockerfile +++ b/src/ci/docker/x86_64-gnu-llvm-7/Dockerfile @@ -25,7 +25,9 @@ RUN sh /scripts/sccache.sh ENV RUST_CONFIGURE_ARGS \ --build=x86_64-unknown-linux-gnu \ --llvm-root=/usr/lib/llvm-7 \ - --enable-llvm-link-shared + --enable-llvm-link-shared \ + --set rust.thin-lto-import-instr-limit=10 + ENV SCRIPT python2.7 ../x.py test src/tools/tidy && python2.7 ../x.py test # The purpose of this container isn't to test with debug assertions and diff --git a/src/liballoc/tests/arc.rs b/src/liballoc/tests/arc.rs index 2fbb59b0419e0..34384cfcba96b 100644 --- a/src/liballoc/tests/arc.rs +++ b/src/liballoc/tests/arc.rs @@ -142,7 +142,7 @@ fn shared_from_iter_trustedlen_normal() { // Try a ZST to make sure it is handled well. { - let iter = (0..SHARED_ITER_MAX).map(|_| ()); + let iter = (0..SHARED_ITER_MAX).map(drop); let vec = iter.clone().collect::>(); let rc = iter.collect::>(); assert_eq!(&*vec, &*rc); diff --git a/src/liballoc/tests/rc.rs b/src/liballoc/tests/rc.rs index e77c57d9a5a09..884856cd1b4d2 100644 --- a/src/liballoc/tests/rc.rs +++ b/src/liballoc/tests/rc.rs @@ -138,7 +138,7 @@ fn shared_from_iter_trustedlen_normal() { // Try a ZST to make sure it is handled well. { - let iter = (0..SHARED_ITER_MAX).map(|_| ()); + let iter = (0..SHARED_ITER_MAX).map(drop); let vec = iter.clone().collect::>(); let rc = iter.collect::>(); assert_eq!(&*vec, &*rc); diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 0d4788dfc570b..06e7e45c7014e 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -495,7 +495,7 @@ impl Ord for Reverse { /// /// An order is a total order if it is (for all `a`, `b` and `c`): /// -/// - total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b` is true; and +/// - total and asymmetric: exactly one of `a < b`, `a == b` or `a > b` is true; and /// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`. /// /// ## Derivable @@ -674,7 +674,7 @@ impl PartialOrd for Ordering { /// /// The comparison must satisfy, for all `a`, `b` and `c`: /// -/// - antisymmetry: if `a < b` then `!(a > b)`, as well as `a > b` implying `!(a < b)`; and +/// - asymmetry: if `a < b` then `!(a > b)`, as well as `a > b` implying `!(a < b)`; and /// - transitivity: `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`. /// /// Note that these requirements mean that the trait itself must be implemented symmetrically and diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs index e11072db0dcc6..9eb151cf528a5 100644 --- a/src/libcore/mem/mod.rs +++ b/src/libcore/mem/mod.rs @@ -557,7 +557,7 @@ pub fn swap(x: &mut T, y: &mut T) { } } -/// Replace `dest` with the default value of `T`, and return the previous `dest` value. +/// Replaces `dest` with the default value of `T`, returning the previous `dest` value. /// /// # Examples /// diff --git a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs index 8f6fbd27a58af..69ebbe1fd3679 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -54,7 +54,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { err.span_suggestion( fn_return_span, &format!( - "you can add a constraint to the return type to make it last \ + "you can add a bound to the return type to make it last \ less than `'static` and match {}", lifetime, ), diff --git a/src/librustc_error_codes/error_codes/E0130.md b/src/librustc_error_codes/error_codes/E0130.md index 5273f3ad14f46..539049edb33b7 100644 --- a/src/librustc_error_codes/error_codes/E0130.md +++ b/src/librustc_error_codes/error_codes/E0130.md @@ -1,4 +1,4 @@ -You declared a pattern as an argument in a foreign function declaration. +A pattern was declared as an argument in a foreign function declaration. Erroneous code example: @@ -9,7 +9,7 @@ extern { } ``` -Please replace the pattern argument with a regular one. Example: +To fix this error, replace the pattern argument with a regular one. Example: ``` struct SomeStruct { diff --git a/src/librustc_error_codes/error_codes/E0131.md b/src/librustc_error_codes/error_codes/E0131.md index a70a02925b0fb..ed798d4f881a3 100644 --- a/src/librustc_error_codes/error_codes/E0131.md +++ b/src/librustc_error_codes/error_codes/E0131.md @@ -1,8 +1,11 @@ -It is not possible to define `main` with generic parameters. -When `main` is present, it must take no arguments and return `()`. +The `main` function was defined with generic parameters. + Erroneous code example: ```compile_fail,E0131 fn main() { // error: main function is not allowed to have generic parameters } ``` + +It is not possible to define the `main` function with generic parameters. +It must not take any arguments. diff --git a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs index 58f62bf7e40b3..9a0c99b07e6f1 100644 --- a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs +++ b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs @@ -9,7 +9,7 @@ use rustc::mir::{ use rustc::ty::adjustment::PointerCast; use rustc::ty::{self, TyCtxt}; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_index::vec::IndexVec; use rustc_span::symbol::Symbol; use rustc_span::Span; @@ -206,6 +206,47 @@ impl BorrowExplanation { ), ); }; + + self.add_lifetime_bound_suggestion_to_diagnostic( + tcx, + err, + &category, + span, + region_name, + ); + } + _ => {} + } + } + pub(in crate::borrow_check) fn add_lifetime_bound_suggestion_to_diagnostic<'tcx>( + &self, + tcx: TyCtxt<'tcx>, + err: &mut DiagnosticBuilder<'_>, + category: &ConstraintCategory, + span: Span, + region_name: &RegionName, + ) { + match category { + ConstraintCategory::OpaqueType => { + if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(span) { + let suggestable_name = if region_name.was_named() { + region_name.to_string() + } else { + "'_".to_string() + }; + + err.span_suggestion( + span, + &format!( + "you can add a bound to the {}to make it last less than \ + `'static` and match `{}`", + category.description(), + region_name, + ), + format!("{} + {}", snippet, suggestable_name), + Applicability::Unspecified, + ); + } } _ => {} } diff --git a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs index f45246301d33e..09b487ba1da3f 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs @@ -815,7 +815,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { span, &format!( "to allow this `impl Trait` to capture borrowed data with lifetime \ - `{}`, add `{}` as a constraint", + `{}`, add `{}` as a bound", fr_name, suggestable_fr_name, ), format!("{} + {}", snippet, suggestable_fr_name), diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 12d75033da2cf..bbbad36e4851d 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -284,7 +284,7 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa if let Some(ty::BindByValue(hir::Mutability::Not)) = cx.tables.extract_binding_mode(cx.tcx.sess, p.hir_id, p.span) { - let pat_ty = cx.tables.pat_ty(p); + let pat_ty = cx.tables.pat_ty(p).peel_refs(); if let ty::Adt(edef, _) = pat_ty.kind { if edef.is_enum() && edef.variants.iter().any(|variant| { diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 98cd341770965..3c9f8542e51d0 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -671,12 +671,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { *local = self.make_integrate_local(local); } - fn visit_place( - &mut self, - place: &mut Place<'tcx>, - _context: PlaceContext, - _location: Location, - ) { + fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) { match &mut place.base { PlaceBase::Static(_) => {} PlaceBase::Local(l) => { @@ -689,10 +684,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { place.projection = self.tcx.intern_place_elems(&*projs); } - - *l = self.make_integrate_local(l); } } + // Handles integrating any locals that occur in the base + // or projections + self.super_place(place, context, location) } fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option> { diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index bf03f731c9f90..94785e9eff3a5 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -848,7 +848,7 @@ impl<'a> Parser<'a> { let appl = Applicability::MachineApplicable; if self.token.span == DUMMY_SP || self.prev_span == DUMMY_SP { // Likely inside a macro, can't provide meaninful suggestions. - return self.expect(&token::Semi).map(|_| ()); + return self.expect(&token::Semi).map(drop); } else if !sm.is_multiline(self.prev_span.until(self.token.span)) { // The current token is in the same line as the prior token, not recoverable. } else if self.look_ahead(1, |t| { @@ -887,7 +887,7 @@ impl<'a> Parser<'a> { .emit(); return Ok(()); } - self.expect(&token::Semi).map(|_| ()) // Error unconditionally + self.expect(&token::Semi).map(drop) // Error unconditionally } pub(super) fn parse_semi_or_incorrect_foreign_fn_body( diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index fee5a4e102be2..9e6849ba5bc39 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -232,7 +232,7 @@ impl BufReader { } } } - self.seek(SeekFrom::Current(offset)).map(|_| ()) + self.seek(SeekFrom::Current(offset)).map(drop) } } diff --git a/src/libstd/sys/unix/android.rs b/src/libstd/sys/unix/android.rs index c5e9d66e85ef9..8fc2599f0d762 100644 --- a/src/libstd/sys/unix/android.rs +++ b/src/libstd/sys/unix/android.rs @@ -93,12 +93,12 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { unsafe { match ftruncate64.get() { - Some(f) => cvt_r(|| f(fd, size as i64)).map(|_| ()), + Some(f) => cvt_r(|| f(fd, size as i64)).map(drop), None => { if size > i32::max_value() as u64 { Err(io::Error::new(io::ErrorKind::InvalidInput, "cannot truncate >2GB")) } else { - cvt_r(|| ftruncate(fd, size as i32)).map(|_| ()) + cvt_r(|| ftruncate(fd, size as i32)).map(drop) } } } @@ -107,7 +107,7 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { #[cfg(target_pointer_width = "64")] pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { - unsafe { cvt_r(|| ftruncate(fd, size as i64)).map(|_| ()) } + unsafe { cvt_r(|| ftruncate(fd, size as i64)).map(drop) } } #[cfg(target_pointer_width = "32")] diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 26fb0bf10fe3e..2a0519487c7a7 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -814,7 +814,7 @@ impl File { use crate::convert::TryInto; let size: off64_t = size.try_into().map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?; - cvt_r(|| unsafe { ftruncate64(self.0.raw(), size) }).map(|_| ()) + cvt_r(|| unsafe { ftruncate64(self.0.raw(), size) }).map(drop) } } diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index 4c23aabf49741..79b0dc02978f3 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -324,7 +324,7 @@ impl Socket { pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { let mut nonblocking = nonblocking as libc::c_int; - cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(|_| ()) + cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop) } pub fn take_error(&self) -> io::Result> { diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index b0b14725344a2..b277b3d5899b8 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -529,7 +529,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) + cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop) } } @@ -538,7 +538,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ()) + cvt(libc::unsetenv(nbuf.as_ptr())).map(drop) } } diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index 77fefef8a1802..2a861c878015e 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -99,11 +99,11 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec, p2: AnonPipe, v2: &mut Vec) -> if fds[0].revents != 0 && read(&p1, v1)? { p2.set_nonblocking(false)?; - return p2.read_to_end(v2).map(|_| ()); + return p2.read_to_end(v2).map(drop); } if fds[1].revents != 0 && read(&p2, v2)? { p1.set_nonblocking(false)?; - return p1.read_to_end(v1).map(|_| ()); + return p1.read_to_end(v1).map(drop); } } diff --git a/src/libstd/sys/unix/process/process_unix.rs b/src/libstd/sys/unix/process/process_unix.rs index 85c30abe45235..07d0fbf61fe22 100644 --- a/src/libstd/sys/unix/process/process_unix.rs +++ b/src/libstd/sys/unix/process/process_unix.rs @@ -425,7 +425,7 @@ impl Process { "invalid argument: can't kill an exited process", )) } else { - cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(|_| ()) + cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop) } } diff --git a/src/libstd/sys/vxworks/fs.rs b/src/libstd/sys/vxworks/fs.rs index 6c2dfb79d6f11..68f2c13317024 100644 --- a/src/libstd/sys/vxworks/fs.rs +++ b/src/libstd/sys/vxworks/fs.rs @@ -340,7 +340,7 @@ impl File { } pub fn truncate(&self, size: u64) -> io::Result<()> { - return cvt_r(|| unsafe { ftruncate(self.0.raw(), size as off_t) }).map(|_| ()); + return cvt_r(|| unsafe { ftruncate(self.0.raw(), size as off_t) }).map(drop); } pub fn read(&self, buf: &mut [u8]) -> io::Result { diff --git a/src/libstd/sys/vxworks/net.rs b/src/libstd/sys/vxworks/net.rs index 74cbd246fe819..7d4e5624f7e39 100644 --- a/src/libstd/sys/vxworks/net.rs +++ b/src/libstd/sys/vxworks/net.rs @@ -261,7 +261,7 @@ impl Socket { pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { let mut nonblocking = nonblocking as libc::c_int; - cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(|_| ()) + cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop) } pub fn take_error(&self) -> io::Result> { diff --git a/src/libstd/sys/vxworks/os.rs b/src/libstd/sys/vxworks/os.rs index 3f207cabf97d3..d421915449944 100644 --- a/src/libstd/sys/vxworks/os.rs +++ b/src/libstd/sys/vxworks/os.rs @@ -279,7 +279,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) + cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop) } } @@ -288,7 +288,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ()) + cvt(libc::unsetenv(nbuf.as_ptr())).map(drop) } } diff --git a/src/libstd/sys/vxworks/pipe.rs b/src/libstd/sys/vxworks/pipe.rs index b72a655455157..0990cb8e83cf8 100644 --- a/src/libstd/sys/vxworks/pipe.rs +++ b/src/libstd/sys/vxworks/pipe.rs @@ -66,11 +66,11 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec, p2: AnonPipe, v2: &mut Vec) -> if fds[0].revents != 0 && read(&p1, v1)? { p2.set_nonblocking_pipe(false)?; - return p2.read_to_end(v2).map(|_| ()); + return p2.read_to_end(v2).map(drop); } if fds[1].revents != 0 && read(&p2, v2)? { p1.set_nonblocking_pipe(false)?; - return p1.read_to_end(v1).map(|_| ()); + return p1.read_to_end(v1).map(drop); } } diff --git a/src/libstd/sys/vxworks/process/process_vxworks.rs b/src/libstd/sys/vxworks/process/process_vxworks.rs index f926dfeb6d42c..ced70dea27f99 100644 --- a/src/libstd/sys/vxworks/process/process_vxworks.rs +++ b/src/libstd/sys/vxworks/process/process_vxworks.rs @@ -138,7 +138,7 @@ impl Process { "invalid argument: can't kill an exited process", )) } else { - cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(|_| ()) + cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop) } } diff --git a/src/libstd/sys/wasi/os.rs b/src/libstd/sys/wasi/os.rs index 44a08a2f0585d..3baec6bf09924 100644 --- a/src/libstd/sys/wasi/os.rs +++ b/src/libstd/sys/wasi/os.rs @@ -151,7 +151,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) + cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop) } } @@ -160,7 +160,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ()) + cvt(libc::unsetenv(nbuf.as_ptr())).map(drop) } } diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index e9c84c4e7c9cb..427f4b684e14a 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -923,6 +923,6 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> { &mut ret, ptr::null_mut(), )) - .map(|_| ()) + .map(drop) } } diff --git a/src/libstd/sys/windows/handle.rs b/src/libstd/sys/windows/handle.rs index fd0c2350cb3ae..f2ad057b6b624 100644 --- a/src/libstd/sys/windows/handle.rs +++ b/src/libstd/sys/windows/handle.rs @@ -156,7 +156,7 @@ impl RawHandle { } pub fn cancel_io(&self) -> io::Result<()> { - unsafe { cvt(c::CancelIo(self.raw())).map(|_| ()) } + unsafe { cvt(c::CancelIo(self.raw())).map(drop) } } pub fn write(&self, buf: &[u8]) -> io::Result { diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index 58574f5723bc0..d8d4fdfce2fe4 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -355,7 +355,7 @@ impl Socket { #[cfg(not(target_vendor = "uwp"))] fn set_no_inherit(&self) -> io::Result<()> { sys::cvt(unsafe { c::SetHandleInformation(self.0 as c::HANDLE, c::HANDLE_FLAG_INHERIT, 0) }) - .map(|_| ()) + .map(drop) } #[cfg(target_vendor = "uwp")] diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index e7fa61dd0f6b9..c5354671c9843 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -247,7 +247,7 @@ pub fn chdir(p: &path::Path) -> io::Result<()> { let mut p = p.encode_wide().collect::>(); p.push(0); - cvt(unsafe { c::SetCurrentDirectoryW(p.as_ptr()) }).map(|_| ()) + cvt(unsafe { c::SetCurrentDirectoryW(p.as_ptr()) }).map(drop) } pub fn getenv(k: &OsStr) -> io::Result> { @@ -272,12 +272,12 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { let k = to_u16s(k)?; let v = to_u16s(v)?; - cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) }).map(|_| ()) + cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) }).map(drop) } pub fn unsetenv(n: &OsStr) -> io::Result<()> { let v = to_u16s(n)?; - cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(|_| ()) + cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(drop) } pub fn temp_dir() -> PathBuf { diff --git a/src/libstd/sys_common/mod.rs b/src/libstd/sys_common/mod.rs index ca8c63d62a6d6..e03e0fc83454b 100644 --- a/src/libstd/sys_common/mod.rs +++ b/src/libstd/sys_common/mod.rs @@ -36,7 +36,7 @@ macro_rules! rtunwrap { match $e { $ok(v) => v, ref err => { - let err = err.as_ref().map(|_| ()); // map Ok/Some which might not be Debug + let err = err.as_ref().map(drop); // map Ok/Some which might not be Debug rtabort!(concat!("unwrap failed: ", stringify!($e), " = {:?}"), err) } } diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index 9d40d9f0afd5c..c7d4828892c04 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -659,7 +659,7 @@ impl UdpSocket { pub fn connect(&self, addr: io::Result<&SocketAddr>) -> io::Result<()> { let (addrp, len) = addr?.into_inner(); - cvt_r(|| unsafe { c::connect(*self.inner.as_inner(), addrp, len) }).map(|_| ()) + cvt_r(|| unsafe { c::connect(*self.inner.as_inner(), addrp, len) }).map(drop) } } diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 03f1ef0000a34..0dce8f810eb13 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -153,6 +153,8 @@ pub struct Instant(time::Instant); /// | Windows | [GetSystemTimeAsFileTime] | /// /// [clock_time_get (Realtime Clock)]: https://github.com/NuxiNL/cloudabi/blob/master/cloudabi.txt +/// [`insecure_time` usercall]: https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#method.insecure_time +/// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode /// [gettimeofday]: http://man7.org/linux/man-pages/man2/gettimeofday.2.html /// [clock_gettime (Realtime Clock)]: https://linux.die.net/man/3/clock_gettime /// [__wasi_clock_time_get (Realtime Clock)]: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md#clock_time_get diff --git a/src/test/ui/async-await/issues/issue-64433.rs b/src/test/ui/async-await/issues/issue-64433.rs index 802e09c8a1f00..d900f8ed9ba12 100644 --- a/src/test/ui/async-await/issues/issue-64433.rs +++ b/src/test/ui/async-await/issues/issue-64433.rs @@ -23,7 +23,7 @@ impl B { async fn can_error(some_string: &str) -> Result<(), String> { let a = A { inner: vec![some_string, "foo"] }; let mut b = B {}; - Ok(b.something_with_a(a).await.map(|_| ())?) + Ok(b.something_with_a(a).await.map(drop)?) } fn main() { diff --git a/src/test/ui/impl-trait/does-not-live-long-enough.rs b/src/test/ui/impl-trait/does-not-live-long-enough.rs new file mode 100644 index 0000000000000..6179132b3f608 --- /dev/null +++ b/src/test/ui/impl-trait/does-not-live-long-enough.rs @@ -0,0 +1,11 @@ +struct List { + data: Vec, +} +impl List { + fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator { + self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref()) + //~^ ERROR does not live long enough + } +} + +fn main() {} diff --git a/src/test/ui/impl-trait/does-not-live-long-enough.stderr b/src/test/ui/impl-trait/does-not-live-long-enough.stderr new file mode 100644 index 0000000000000..83d0f87015bf9 --- /dev/null +++ b/src/test/ui/impl-trait/does-not-live-long-enough.stderr @@ -0,0 +1,21 @@ +error[E0597]: `prefix` does not live long enough + --> $DIR/does-not-live-long-enough.rs:6:51 + | +LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator { + | -- lifetime `'a` defined here --------------------------- opaque type requires that `prefix` is borrowed for `'a` +LL | self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref()) + | --- ^^^^^^ borrowed value does not live long enough + | | + | value captured here +LL | +LL | } + | - `prefix` dropped here while still borrowed + | +help: you can add a bound to the opaque type to make it last less than `'static` and match `'a` + | +LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator + 'a { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr index 45c5142d93f28..4c38f0a8a914d 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr @@ -5,7 +5,7 @@ LL | fn foo<'a, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { | -- lifetime `'a` defined here ^^^^^^^^^ opaque type requires that `'a` must outlive `'static` | = help: consider replacing `'a` with `'static` -help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound | LL | type E<'a, 'b> = impl Sized; + 'a | diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr index bb5a85aba9709..1806d2607a3ac 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr @@ -6,7 +6,7 @@ LL | fn elided(x: &i32) -> impl Copy { x } | | | let's call the lifetime of this reference `'1` | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound | LL | fn elided(x: &i32) -> impl Copy + '_ { x } | ^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } | lifetime `'a` defined here | = help: consider replacing `'a` with `'static` -help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound | LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } | ^^^^^^^^^^^^^^ diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr index a8341f62e1d14..7f92e709af556 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr @@ -11,7 +11,7 @@ note: ...can't outlive the anonymous lifetime #1 defined on the function body at | LL | fn elided(x: &i32) -> impl Copy { x } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the function body at 3:1 +help: you can add a bound to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the function body at 3:1 | LL | fn elided(x: &i32) -> impl Copy + '_ { x } | ^^^^^^^^^^^^^^ @@ -29,7 +29,7 @@ note: ...can't outlive the lifetime `'a` as defined on the function body at 6:13 | LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } | ^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 6:13 +help: you can add a bound to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 6:13 | LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } | ^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ note: ...can't outlive the lifetime `'a` as defined on the function body at 12:1 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } | ^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 12:15 +help: you can add a bound to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 12:15 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static + 'a { x } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr index 22f081b79f157..123ea6af6b019 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr @@ -6,7 +6,7 @@ LL | fn iter_values_anon(&self) -> impl Iterator { | | | let's call the lifetime of this reference `'1` | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound | LL | fn iter_values_anon(&self) -> impl Iterator + '_ { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator { | lifetime `'a` defined here | = help: consider replacing `'a` with `'static` -help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound | LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr index 1d6b5f56aa0cf..e550be1917474 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr @@ -15,7 +15,7 @@ LL | / fn iter_values_anon(&self) -> impl Iterator { LL | | self.x.iter().map(|a| a.0) LL | | } | |_____^ -help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 6:5 +help: you can add a bound to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 6:5 | LL | fn iter_values_anon(&self) -> impl Iterator + '_ { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -35,7 +35,7 @@ note: ...can't outlive the lifetime `'a` as defined on the method body at 10:20 | LL | fn iter_values<'a>(&'a self) -> impl Iterator { | ^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the method body at 10:20 +help: you can add a bound to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the method body at 10:20 | LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/mir/issue-67710-inline-projection.rs b/src/test/ui/mir/issue-67710-inline-projection.rs new file mode 100644 index 0000000000000..37d8f2eac9be1 --- /dev/null +++ b/src/test/ui/mir/issue-67710-inline-projection.rs @@ -0,0 +1,17 @@ +// compile-flags: -Z mir-opt-level=2 +// build-pass + +// This used to ICE due to the inling pass not examining projections +// for references to locals + +pub fn parse(version: ()) { + p(&b'.', b"0"); +} +#[inline(always)] +fn p(byte: &u8, s: &[u8]) { + !(s[0] == *byte); +} + +fn main() { + parse(()); +} diff --git a/src/test/ui/nll/issue-50343.rs b/src/test/ui/nll/issue-50343.rs index 55a2d231e19ff..dd0afbbdfc6fa 100644 --- a/src/test/ui/nll/issue-50343.rs +++ b/src/test/ui/nll/issue-50343.rs @@ -3,6 +3,6 @@ #![deny(unused_mut)] fn main() { - vec![42].iter().map(|_| ()).count(); + vec![42].iter().map(drop).count(); vec![(42, 22)].iter().map(|(_x, _y)| ()).count(); } diff --git a/src/test/ui/paths-containing-nul.rs b/src/test/ui/paths-containing-nul.rs index c9bf710b8e762..e9510b53feab8 100644 --- a/src/test/ui/paths-containing-nul.rs +++ b/src/test/ui/paths-containing-nul.rs @@ -17,7 +17,7 @@ fn assert_invalid_input(on: &str, result: io::Result) { "{} returned a strange {:?} on a path with NUL", on, e.kind()), } } - inner(on, result.map(|_| ())) + inner(on, result.map(drop)) } fn main() { diff --git a/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs new file mode 100644 index 0000000000000..6fd5768a5a26d --- /dev/null +++ b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs @@ -0,0 +1,42 @@ +// Test for issue #67776: binding named the same as enum variant +// should report a warning even when matching against a reference type + +// check-pass + +#![allow(unused_variables)] +#![allow(non_snake_case)] + +enum Foo { + Bar, + Baz, +} + + +fn fn1(e: Foo) { + match e { + Bar => {}, + //~^ WARNING named the same as one of the variants of the type `Foo` + Baz => {}, + //~^ WARNING named the same as one of the variants of the type `Foo` + } +} + +fn fn2(e: &Foo) { + match e { + Bar => {}, + //~^ WARNING named the same as one of the variants of the type `Foo` + Baz => {}, + //~^ WARNING named the same as one of the variants of the type `Foo` + } +} + +fn fn3(e: &mut &&mut Foo) { + match e { + Bar => {}, + //~^ WARNING named the same as one of the variants of the type `Foo` + Baz => {}, + //~^ WARNING named the same as one of the variants of the type `Foo` + } +} + +fn main() {} diff --git a/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.stderr b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.stderr new file mode 100644 index 0000000000000..abb8d6907e76d --- /dev/null +++ b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.stderr @@ -0,0 +1,36 @@ +warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:17:9 + | +LL | Bar => {}, + | ^^^ help: to match on the variant, qualify the path: `Foo::Bar` + +warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:19:9 + | +LL | Baz => {}, + | ^^^ help: to match on the variant, qualify the path: `Foo::Baz` + +warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:26:9 + | +LL | Bar => {}, + | ^^^ help: to match on the variant, qualify the path: `Foo::Bar` + +warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:28:9 + | +LL | Baz => {}, + | ^^^ help: to match on the variant, qualify the path: `Foo::Baz` + +warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:35:9 + | +LL | Bar => {}, + | ^^^ help: to match on the variant, qualify the path: `Foo::Bar` + +warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:37:9 + | +LL | Baz => {}, + | ^^^ help: to match on the variant, qualify the path: `Foo::Baz` + diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr index 5a63553adc5c8..f2e556c63cbf3 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr @@ -6,7 +6,7 @@ LL | async fn f(self: Pin<&Self>) -> impl Clone { self } | | | let's call the lifetime of this reference `'1` | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound | LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ^^^^^^^^^^^^^^^ diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr index b46c6b9b71309..b76966e8693f2 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr @@ -6,7 +6,7 @@ LL | fn f(self: Pin<&Self>) -> impl Clone { self } | | | let's call the lifetime of this reference `'1` | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound | LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ^^^^^^^^^^^^^^^ diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr index 5118280e7ec0c..9f5414995151b 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr @@ -11,7 +11,7 @@ note: ...can't outlive the anonymous lifetime #1 defined on the method body at 8 | LL | fn f(self: Pin<&Self>) -> impl Clone { self } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 8:5 +help: you can add a bound to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 8:5 | LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ^^^^^^^^^^^^^^^