From 1d2e3fff69b654c3dfd6a810e193db29bb1868fa Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 25 Jul 2020 18:57:42 +0200 Subject: [PATCH 01/12] Clean up E0730 explanation --- src/librustc_error_codes/error_codes/E0730.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0730.md b/src/librustc_error_codes/error_codes/E0730.md index c2a71ca5669a1..d385009063f78 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,8 +14,8 @@ 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 `..`: +Ensure that the pattern is consistent with the size of the matched array. +Additional elements can be matched with `..`: ``` let r = &[1, 2, 3, 4]; From f22a34e84d4dba9b17bb3e68051ee82bd85f3c94 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 27 Jul 2020 20:55:30 +0200 Subject: [PATCH 02/12] Clean up E0734 explanation --- src/librustc_error_codes/error_codes/E0734.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From ad6d63ef01e37a1a05acdba50985b01d178d7c11 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Sun, 26 Jul 2020 15:31:58 +0200 Subject: [PATCH 03/12] Don't use "weak count" around Weak::from_raw_ptr As `Rc/Arc::weak_count` returns 0 when having no strong counts, this could be confusing and it's better to avoid using that completely. Closes #73840. --- library/alloc/src/rc.rs | 20 +++++++++++--------- library/alloc/src/sync.rs | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 96dfc2f42519b..431672865dcc1 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1715,8 +1715,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. @@ -1751,17 +1752,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 8a5f1ee5076b9..a06dad77c4422 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -1485,8 +1485,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. @@ -1516,24 +1517,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 /// /// ``` From b5d143b126cd73c873fc8feff7dee0a0b077cc84 Mon Sep 17 00:00:00 2001 From: David Sonder Date: Tue, 28 Jul 2020 13:28:43 +0200 Subject: [PATCH 04/12] Enable docs on dist-x86_64-musl Add the rust-docs component to toolchain x86_64-unknown-linux-musl, which allows people using rustup on their musl-based linux distribution to download the rust-docs. --- src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile | 1 - 1 file changed, 1 deletion(-) 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 From 0374006d79114824d8eec020a9d771ca8cf712ff Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 29 Jul 2020 10:48:00 +0000 Subject: [PATCH 05/12] Avoid bool-like naming --- src/etc/test-float-parse/runtests.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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) From 759de11f534b940f090ff94cf1829935c1eb4e7d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 29 Jul 2020 14:06:29 +0200 Subject: [PATCH 06/12] Clean up E0740 explanation --- src/librustc_error_codes/error_codes/E0740.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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. From 8046fea62263d50fc196ce07ccdc4534af321441 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Thu, 30 Jul 2020 06:17:18 +0100 Subject: [PATCH 07/12] Improve diagnostics when constant pattern is too generic --- src/librustc_mir_build/hair/pattern/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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) From 4e963d58c7d94270697c2765f23993e40757292f Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Thu, 30 Jul 2020 06:34:16 +0100 Subject: [PATCH 08/12] Fix ui tests --- src/test/ui/consts/issue-73976-polymorphic.rs | 8 ++++---- src/test/ui/consts/issue-73976-polymorphic.stderr | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) 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) From 89e4fe33130a17888a2add6baadd850653263242 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 30 Jul 2020 13:51:22 +0200 Subject: [PATCH 09/12] Improve E0730 explanation --- src/librustc_error_codes/error_codes/E0730.md | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0730.md b/src/librustc_error_codes/error_codes/E0730.md index d385009063f78..016b3f38aa310 100644 --- a/src/librustc_error_codes/error_codes/E0730.md +++ b/src/librustc_error_codes/error_codes/E0730.md @@ -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 } } ``` From cd8bdb5eb9a7440fa64500218f43b04429e64fc1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 29 Jul 2020 09:10:07 -0700 Subject: [PATCH 10/12] rustc: Ignore fs::canonicalize errors in metadata This commit updates the metadata location logic to ignore errors when calling `fs::canonicalize`. Canonicalization was added historically so multiple `-L` paths to the same directory don't print errors about multiple candidates (since rustc can deduplicate same-named paths), but canonicalization doesn't work on all filesystems. Cargo, for example, always uses this sort of fallback where it will opportunitistically try to canonicalize but fall back to using the input path if it otherwise doesn't work. If rustc is run on a filesystem that doesn't support canonicalization then the effect of this change will be that `-L` paths which logically point to the same directory will cause errors, but that's a rare enough occurrence it shouldn't cause much issue in practice. Otherwise rustc doesn't work at all today on those sorts of filesystem where canonicalization isn't supported! --- src/librustc_metadata/creader.rs | 6 +++--- src/librustc_metadata/locator.rs | 32 ++++++++++++++---------------- src/librustc_session/filesearch.rs | 32 ++++++++++++------------------ 3 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 724b4123fab6c..8dc842cc9d496 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -236,9 +236,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_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), } } From e1e01f72a5e5f4ebcf455a2df72781aa1cbb2016 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 20 Jul 2020 08:58:10 -0400 Subject: [PATCH 11/12] 1.45.1 release (cherry picked from commit 9e5fb40807f97fe47d2eaca99daeb1f1f6ff07a7) --- RELEASES.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index f36cdee0975a0..fec48b043612a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,14 @@ +Version 1.45.1 (2020-07-30) +========================== + +* [rustfmt accepts rustfmt_skip in cfg_attr again.][73078] +* [Avoid spurious implicit region bound.][74509] +* [Install clippy on x.py install][74457] + +[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) ========================== From 19d191bb02d1566096493a26904826d4e81beeda Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 25 Jul 2020 11:01:44 -0400 Subject: [PATCH 12/12] Update release notes (cherry picked from commit 32166ab1ebec2e5e5454221f0d3238c21382de9f) --- RELEASES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index fec48b043612a..b47f64d2fafc9 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,10 +1,12 @@ 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