diff --git a/RELEASES.md b/RELEASES.md index f36cdee0975a0..b47f64d2fafc9 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,16 @@ +Version 1.45.1 (2020-07-30) +========================== + +* [Fix const propagation with references.][73613] +* [rustfmt accepts rustfmt_skip in cfg_attr again.][73078] +* [Avoid spurious implicit region bound.][74509] +* [Install clippy on x.py install][74457] + +[73613]: https://github.com/rust-lang/rust/pull/73613 +[73078]: https://github.com/rust-lang/rust/issues/73078 +[74509]: https://github.com/rust-lang/rust/pull/74509 +[74457]: https://github.com/rust-lang/rust/pull/74457 + Version 1.45.0 (2020-07-16) ========================== diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index d3450cfbc814e..116df63f94b69 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1692,8 +1692,9 @@ impl Weak { /// Consumes the `Weak` and turns it into a raw pointer. /// - /// This converts the weak pointer into a raw pointer, preserving the original weak count. It - /// can be turned back into the `Weak` with [`from_raw`]. + /// This converts the weak pointer into a raw pointer, while still preserving the ownership of + /// one weak reference (the weak count is not modified by this operation). It can be turned + /// back into the `Weak` with [`from_raw`]. /// /// The same restrictions of accessing the target of the pointer as with /// [`as_ptr`] apply. @@ -1728,17 +1729,18 @@ impl Weak { /// This can be used to safely get a strong reference (by calling [`upgrade`] /// later) or to deallocate the weak count by dropping the `Weak`. /// - /// It takes ownership of one weak count (with the exception of pointers created by [`new`], - /// as these don't have any corresponding weak count). + /// It takes ownership of one weak reference (with the exception of pointers created by [`new`], + /// as these don't own anything; the method still works on them). /// /// # Safety /// - /// The pointer must have originated from the [`into_raw`] and must still own its potential - /// weak reference count. + /// The pointer must have originated from the [`into_raw`] and must still own its potential + /// weak reference. /// - /// It is allowed for the strong count to be 0 at the time of calling this, but the weak count - /// must be non-zero or the pointer must have originated from a dangling `Weak` (one created - /// by [`new`]). + /// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this + /// takes ownership of one weak reference currently represented as a raw pointer (the weak + /// count is not modified by this operation) and therefore it must be paired with a previous + /// call to [`into_raw`]. /// /// # Examples /// diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 906beba2a6296..58cab9c5c6388 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -1462,8 +1462,9 @@ impl Weak { /// Consumes the `Weak` and turns it into a raw pointer. /// - /// This converts the weak pointer into a raw pointer, preserving the original weak count. It - /// can be turned back into the `Weak` with [`from_raw`]. + /// This converts the weak pointer into a raw pointer, while still preserving the ownership of + /// one weak reference (the weak count is not modified by this operation). It can be turned + /// back into the `Weak` with [`from_raw`]. /// /// The same restrictions of accessing the target of the pointer as with /// [`as_ptr`] apply. @@ -1493,24 +1494,23 @@ impl Weak { result } - /// Converts a raw pointer previously created by [`into_raw`] back into - /// `Weak`. + /// Converts a raw pointer previously created by [`into_raw`] back into `Weak`. /// /// This can be used to safely get a strong reference (by calling [`upgrade`] /// later) or to deallocate the weak count by dropping the `Weak`. /// - /// It takes ownership of one weak count (with the exception of pointers created by [`new`], - /// as these don't have any corresponding weak count). + /// It takes ownership of one weak reference (with the exception of pointers created by [`new`], + /// as these don't own anything; the method still works on them). /// /// # Safety /// /// The pointer must have originated from the [`into_raw`] and must still own its potential - /// weak reference count. - /// - /// It is allowed for the strong count to be 0 at the time of calling this, but the weak count - /// must be non-zero or the pointer must have originated from a dangling `Weak` (one created - /// by [`new`]). + /// weak reference. /// + /// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this + /// takes ownership of one weak reference currently represented as a raw pointer (the weak + /// count is not modified by this operation) and therefore it must be paired with a previous + /// call to [`into_raw`]. /// # Examples /// /// ``` diff --git a/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile index c026506b10661..ab6515cd1fa95 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile @@ -33,7 +33,6 @@ ENV HOSTS=x86_64-unknown-linux-musl ENV RUST_CONFIGURE_ARGS \ --musl-root-x86_64=/usr/local/x86_64-linux-musl \ --enable-extended \ - --disable-docs \ --enable-lld \ --set target.x86_64-unknown-linux-musl.crt-static=false \ --build $HOSTS diff --git a/src/etc/test-float-parse/runtests.py b/src/etc/test-float-parse/runtests.py index 7106078f897cf..4d2902e986f56 100644 --- a/src/etc/test-float-parse/runtests.py +++ b/src/etc/test-float-parse/runtests.py @@ -195,9 +195,8 @@ def main(): global MAILBOX tests = [os.path.splitext(f)[0] for f in glob('*.rs') if not f.startswith('_')] - listed = sys.argv[1:] - if listed: - tests = [test for test in tests if test in listed] + args = sys.argv[1:] + tests = [test for test in tests if test in args] if not tests: print("Error: No tests to run") sys.exit(1) diff --git a/src/librustc_error_codes/error_codes/E0730.md b/src/librustc_error_codes/error_codes/E0730.md index c2a71ca5669a1..016b3f38aa310 100644 --- a/src/librustc_error_codes/error_codes/E0730.md +++ b/src/librustc_error_codes/error_codes/E0730.md @@ -1,6 +1,6 @@ An array without a fixed length was pattern-matched. -Example of erroneous code: +Erroneous code example: ```compile_fail,E0730 #![feature(const_generics)] @@ -14,14 +14,28 @@ fn is_123(x: [u32; N]) -> bool { } ``` -Ensure that the pattern is consistent with the size of the matched -array. Additional elements can be matched with `..`: +To fix this error, you have two solutions: + 1. Use an array with a fixed length. + 2. Use a slice. +Example with an array with a fixed length: + +``` +fn is_123(x: [u32; 3]) -> bool { // We use an array with a fixed size + match x { + [1, 2, ..] => true, // ok! + _ => false + } +} ``` -let r = &[1, 2, 3, 4]; -match r { - &[a, b, ..] => { // ok! - println!("a={}, b={}", a, b); + +Example with a slice: + +``` +fn is_123(x: &[u32]) -> bool { // We use a slice + match x { + [1, 2, ..] => true, // ok! + _ => false } } ``` diff --git a/src/librustc_error_codes/error_codes/E0734.md b/src/librustc_error_codes/error_codes/E0734.md index 7506c8e693ed8..4b8e89a70604d 100644 --- a/src/librustc_error_codes/error_codes/E0734.md +++ b/src/librustc_error_codes/error_codes/E0734.md @@ -1,6 +1,6 @@ A stability attribute has been used outside of the standard library. -Erroneous code examples: +Erroneous code example: ```compile_fail,E0734 #[rustc_deprecated(since = "b", reason = "text")] // invalid diff --git a/src/librustc_error_codes/error_codes/E0740.md b/src/librustc_error_codes/error_codes/E0740.md index 3777678518964..6240099a99f67 100644 --- a/src/librustc_error_codes/error_codes/E0740.md +++ b/src/librustc_error_codes/error_codes/E0740.md @@ -1,4 +1,4 @@ -A `union` cannot have fields with destructors. +A `union` was declared with fields with destructors. Erroneous code example: @@ -14,3 +14,5 @@ impl Drop for A { fn drop(&mut self) { println!("A"); } } ``` + +A `union` cannot have fields with destructors. diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 25320a8d6a785..a4ccc8c74c849 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -248,9 +248,9 @@ impl<'a> CrateLoader<'a> { // Only use `--extern crate_name=path` here, not `--extern crate_name`. if let Some(mut files) = entry.files() { if files.any(|l| { - let l = fs::canonicalize(l).ok(); - source.dylib.as_ref().map(|p| &p.0) == l.as_ref() - || source.rlib.as_ref().map(|p| &p.0) == l.as_ref() + let l = fs::canonicalize(l).unwrap_or(l.clone().into()); + source.dylib.as_ref().map(|p| &p.0) == Some(&l) + || source.rlib.as_ref().map(|p| &p.0) == Some(&l) }) { ret = Some(cnum); } diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index 371ec4cd91148..8828b318d1ea6 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -426,20 +426,17 @@ impl<'a> CrateLocator<'a> { info!("lib candidate: {}", spf.path.display()); let (rlibs, rmetas, dylibs) = candidates.entry(hash.to_string()).or_default(); - fs::canonicalize(&spf.path) - .map(|p| { - if seen_paths.contains(&p) { - return FileDoesntMatch; - }; - seen_paths.insert(p.clone()); - match found_kind { - CrateFlavor::Rlib => rlibs.insert(p, kind), - CrateFlavor::Rmeta => rmetas.insert(p, kind), - CrateFlavor::Dylib => dylibs.insert(p, kind), - }; - FileMatches - }) - .unwrap_or(FileDoesntMatch) + let path = fs::canonicalize(&spf.path).unwrap_or_else(|_| spf.path.clone()); + if seen_paths.contains(&path) { + return FileDoesntMatch; + }; + seen_paths.insert(path.clone()); + match found_kind { + CrateFlavor::Rlib => rlibs.insert(path, kind), + CrateFlavor::Rmeta => rmetas.insert(path, kind), + CrateFlavor::Dylib => dylibs.insert(path, kind), + }; + FileMatches }); self.rejected_via_kind.extend(staticlibs); @@ -688,12 +685,13 @@ impl<'a> CrateLocator<'a> { && file.ends_with(&self.target.options.dll_suffix) { // Make sure there's at most one rlib and at most one dylib. + let loc = fs::canonicalize(&loc).unwrap_or_else(|_| loc.clone()); if loc.file_name().unwrap().to_str().unwrap().ends_with(".rlib") { - rlibs.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag); + rlibs.insert(loc, PathKind::ExternFlag); } else if loc.file_name().unwrap().to_str().unwrap().ends_with(".rmeta") { - rmetas.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag); + rmetas.insert(loc, PathKind::ExternFlag); } else { - dylibs.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag); + dylibs.insert(loc, PathKind::ExternFlag); } } else { self.rejected_via_filename diff --git a/src/librustc_mir_build/hair/pattern/mod.rs b/src/librustc_mir_build/hair/pattern/mod.rs index a5c87bc963f49..f813ba0c077ca 100644 --- a/src/librustc_mir_build/hair/pattern/mod.rs +++ b/src/librustc_mir_build/hair/pattern/mod.rs @@ -16,7 +16,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator; use rustc_hir::RangeEnd; use rustc_index::vec::Idx; use rustc_middle::mir::interpret::{get_slice_bytes, sign_extend, ConstValue}; -use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput}; +use rustc_middle::mir::interpret::{ErrorHandled, LitToConstError, LitToConstInput}; use rustc_middle::mir::UserTypeProjection; use rustc_middle::mir::{BorrowKind, Field, Mutability}; use rustc_middle::ty::subst::{GenericArg, SubstsRef}; @@ -834,6 +834,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { pattern } } + Err(ErrorHandled::TooGeneric) => { + // While `Reported | Linted` cases will have diagnostics emitted already + // it is not true for TooGeneric case, so we need to give user more information. + self.tcx.sess.span_err(span, "constant pattern depends on a generic parameter"); + pat_from_kind(PatKind::Wild) + } Err(_) => { self.tcx.sess.span_err(span, "could not evaluate constant pattern"); pat_from_kind(PatKind::Wild) diff --git a/src/librustc_session/filesearch.rs b/src/librustc_session/filesearch.rs index 27396c524f4e6..504490d938cfa 100644 --- a/src/librustc_session/filesearch.rs +++ b/src/librustc_session/filesearch.rs @@ -117,28 +117,22 @@ pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf { pub fn get_or_default_sysroot() -> PathBuf { // Follow symlinks. If the resolved path is relative, make it absolute. - fn canonicalize(path: Option) -> Option { - path.and_then(|path| { - match fs::canonicalize(&path) { - // See comments on this target function, but the gist is that - // gcc chokes on verbatim paths which fs::canonicalize generates - // so we try to avoid those kinds of paths. - Ok(canon) => Some(fix_windows_verbatim_for_gcc(&canon)), - Err(e) => panic!("failed to get realpath: {}", e), - } - }) + fn canonicalize(path: PathBuf) -> PathBuf { + let path = fs::canonicalize(&path).unwrap_or(path); + // See comments on this target function, but the gist is that + // gcc chokes on verbatim paths which fs::canonicalize generates + // so we try to avoid those kinds of paths. + fix_windows_verbatim_for_gcc(&path) } match env::current_exe() { - Ok(exe) => match canonicalize(Some(exe)) { - Some(mut p) => { - p.pop(); - p.pop(); - p - } - None => panic!("can't determine value for sysroot"), - }, - Err(ref e) => panic!(format!("failed to get current_exe: {}", e)), + Ok(exe) => { + let mut p = canonicalize(exe); + p.pop(); + p.pop(); + p + } + Err(e) => panic!("failed to get current_exe: {}", e), } } diff --git a/src/test/ui/consts/issue-73976-polymorphic.rs b/src/test/ui/consts/issue-73976-polymorphic.rs index 7cf20296062ab..518036c9dbeec 100644 --- a/src/test/ui/consts/issue-73976-polymorphic.rs +++ b/src/test/ui/consts/issue-73976-polymorphic.rs @@ -17,8 +17,8 @@ impl GetTypeId { const fn check_type_id() -> bool { matches!(GetTypeId::::VALUE, GetTypeId::::VALUE) - //~^ ERROR could not evaluate constant pattern - //~| ERROR could not evaluate constant pattern + //~^ ERROR constant pattern depends on a generic parameter + //~| ERROR constant pattern depends on a generic parameter } pub struct GetTypeNameLen(T); @@ -29,8 +29,8 @@ impl GetTypeNameLen { const fn check_type_name_len() -> bool { matches!(GetTypeNameLen::::VALUE, GetTypeNameLen::::VALUE) - //~^ ERROR could not evaluate constant pattern - //~| ERROR could not evaluate constant pattern + //~^ ERROR constant pattern depends on a generic parameter + //~| ERROR constant pattern depends on a generic parameter } fn main() { diff --git a/src/test/ui/consts/issue-73976-polymorphic.stderr b/src/test/ui/consts/issue-73976-polymorphic.stderr index 971573e14aad8..250f1536d85fc 100644 --- a/src/test/ui/consts/issue-73976-polymorphic.stderr +++ b/src/test/ui/consts/issue-73976-polymorphic.stderr @@ -1,22 +1,22 @@ -error: could not evaluate constant pattern +error: constant pattern depends on a generic parameter --> $DIR/issue-73976-polymorphic.rs:19:37 | LL | matches!(GetTypeId::::VALUE, GetTypeId::::VALUE) | ^^^^^^^^^^^^^^^^^^^^^ -error: could not evaluate constant pattern +error: constant pattern depends on a generic parameter --> $DIR/issue-73976-polymorphic.rs:31:42 | LL | matches!(GetTypeNameLen::::VALUE, GetTypeNameLen::::VALUE) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: could not evaluate constant pattern +error: constant pattern depends on a generic parameter --> $DIR/issue-73976-polymorphic.rs:19:37 | LL | matches!(GetTypeId::::VALUE, GetTypeId::::VALUE) | ^^^^^^^^^^^^^^^^^^^^^ -error: could not evaluate constant pattern +error: constant pattern depends on a generic parameter --> $DIR/issue-73976-polymorphic.rs:31:42 | LL | matches!(GetTypeNameLen::::VALUE, GetTypeNameLen::::VALUE)