Skip to content

Commit cfc572c

Browse files
committed
Auto merge of #74957 - Manishearth:rollup-3wudwlg, r=Manishearth
Rollup of 9 pull requests Successful merges: - #74751 (Clean up E0730 explanation) - #74782 (Don't use "weak count" around Weak::from_raw_ptr) - #74835 (Clean up E0734 explanation) - #74871 (Enable docs on dist-x86_64-musl) - #74905 (Avoid bool-like naming) - #74907 (Clean up E0740 explanation) - #74915 (rustc: Ignore fs::canonicalize errors in metadata) - #74934 (Improve diagnostics when constant pattern is too generic) - #74951 (Cherry-pick the release notes for 1.45.1) Failed merges: r? @ghost
2 parents 438c59f + 9eb5026 commit cfc572c

File tree

14 files changed

+108
-81
lines changed

14 files changed

+108
-81
lines changed

Diff for: RELEASES.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
Version 1.45.1 (2020-07-30)
2+
==========================
3+
4+
* [Fix const propagation with references.][73613]
5+
* [rustfmt accepts rustfmt_skip in cfg_attr again.][73078]
6+
* [Avoid spurious implicit region bound.][74509]
7+
* [Install clippy on x.py install][74457]
8+
9+
[73613]: https://github.com/rust-lang/rust/pull/73613
10+
[73078]: https://github.com/rust-lang/rust/issues/73078
11+
[74509]: https://github.com/rust-lang/rust/pull/74509
12+
[74457]: https://github.com/rust-lang/rust/pull/74457
13+
114
Version 1.45.0 (2020-07-16)
215
==========================
316

Diff for: library/alloc/src/rc.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1692,8 +1692,9 @@ impl<T> Weak<T> {
16921692

16931693
/// Consumes the `Weak<T>` and turns it into a raw pointer.
16941694
///
1695-
/// This converts the weak pointer into a raw pointer, preserving the original weak count. It
1696-
/// can be turned back into the `Weak<T>` with [`from_raw`].
1695+
/// This converts the weak pointer into a raw pointer, while still preserving the ownership of
1696+
/// one weak reference (the weak count is not modified by this operation). It can be turned
1697+
/// back into the `Weak<T>` with [`from_raw`].
16971698
///
16981699
/// The same restrictions of accessing the target of the pointer as with
16991700
/// [`as_ptr`] apply.
@@ -1728,17 +1729,18 @@ impl<T> Weak<T> {
17281729
/// This can be used to safely get a strong reference (by calling [`upgrade`]
17291730
/// later) or to deallocate the weak count by dropping the `Weak<T>`.
17301731
///
1731-
/// It takes ownership of one weak count (with the exception of pointers created by [`new`],
1732-
/// as these don't have any corresponding weak count).
1732+
/// It takes ownership of one weak reference (with the exception of pointers created by [`new`],
1733+
/// as these don't own anything; the method still works on them).
17331734
///
17341735
/// # Safety
17351736
///
1736-
/// The pointer must have originated from the [`into_raw`] and must still own its potential
1737-
/// weak reference count.
1737+
/// The pointer must have originated from the [`into_raw`] and must still own its potential
1738+
/// weak reference.
17381739
///
1739-
/// It is allowed for the strong count to be 0 at the time of calling this, but the weak count
1740-
/// must be non-zero or the pointer must have originated from a dangling `Weak<T>` (one created
1741-
/// by [`new`]).
1740+
/// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this
1741+
/// takes ownership of one weak reference currently represented as a raw pointer (the weak
1742+
/// count is not modified by this operation) and therefore it must be paired with a previous
1743+
/// call to [`into_raw`].
17421744
///
17431745
/// # Examples
17441746
///

Diff for: library/alloc/src/sync.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1462,8 +1462,9 @@ impl<T> Weak<T> {
14621462

14631463
/// Consumes the `Weak<T>` and turns it into a raw pointer.
14641464
///
1465-
/// This converts the weak pointer into a raw pointer, preserving the original weak count. It
1466-
/// can be turned back into the `Weak<T>` with [`from_raw`].
1465+
/// This converts the weak pointer into a raw pointer, while still preserving the ownership of
1466+
/// one weak reference (the weak count is not modified by this operation). It can be turned
1467+
/// back into the `Weak<T>` with [`from_raw`].
14671468
///
14681469
/// The same restrictions of accessing the target of the pointer as with
14691470
/// [`as_ptr`] apply.
@@ -1493,24 +1494,23 @@ impl<T> Weak<T> {
14931494
result
14941495
}
14951496

1496-
/// Converts a raw pointer previously created by [`into_raw`] back into
1497-
/// `Weak<T>`.
1497+
/// Converts a raw pointer previously created by [`into_raw`] back into `Weak<T>`.
14981498
///
14991499
/// This can be used to safely get a strong reference (by calling [`upgrade`]
15001500
/// later) or to deallocate the weak count by dropping the `Weak<T>`.
15011501
///
1502-
/// It takes ownership of one weak count (with the exception of pointers created by [`new`],
1503-
/// as these don't have any corresponding weak count).
1502+
/// It takes ownership of one weak reference (with the exception of pointers created by [`new`],
1503+
/// as these don't own anything; the method still works on them).
15041504
///
15051505
/// # Safety
15061506
///
15071507
/// The pointer must have originated from the [`into_raw`] and must still own its potential
1508-
/// weak reference count.
1509-
///
1510-
/// It is allowed for the strong count to be 0 at the time of calling this, but the weak count
1511-
/// must be non-zero or the pointer must have originated from a dangling `Weak<T>` (one created
1512-
/// by [`new`]).
1508+
/// weak reference.
15131509
///
1510+
/// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this
1511+
/// takes ownership of one weak reference currently represented as a raw pointer (the weak
1512+
/// count is not modified by this operation) and therefore it must be paired with a previous
1513+
/// call to [`into_raw`].
15141514
/// # Examples
15151515
///
15161516
/// ```

Diff for: src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ ENV HOSTS=x86_64-unknown-linux-musl
3333
ENV RUST_CONFIGURE_ARGS \
3434
--musl-root-x86_64=/usr/local/x86_64-linux-musl \
3535
--enable-extended \
36-
--disable-docs \
3736
--enable-lld \
3837
--set target.x86_64-unknown-linux-musl.crt-static=false \
3938
--build $HOSTS

Diff for: src/etc/test-float-parse/runtests.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,8 @@ def main():
195195
global MAILBOX
196196
tests = [os.path.splitext(f)[0] for f in glob('*.rs')
197197
if not f.startswith('_')]
198-
listed = sys.argv[1:]
199-
if listed:
200-
tests = [test for test in tests if test in listed]
198+
args = sys.argv[1:]
199+
tests = [test for test in tests if test in args]
201200
if not tests:
202201
print("Error: No tests to run")
203202
sys.exit(1)

Diff for: src/librustc_error_codes/error_codes/E0730.md

+21-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
An array without a fixed length was pattern-matched.
22

3-
Example of erroneous code:
3+
Erroneous code example:
44

55
```compile_fail,E0730
66
#![feature(const_generics)]
@@ -14,14 +14,28 @@ fn is_123<const N: usize>(x: [u32; N]) -> bool {
1414
}
1515
```
1616

17-
Ensure that the pattern is consistent with the size of the matched
18-
array. Additional elements can be matched with `..`:
17+
To fix this error, you have two solutions:
18+
1. Use an array with a fixed length.
19+
2. Use a slice.
1920

21+
Example with an array with a fixed length:
22+
23+
```
24+
fn is_123(x: [u32; 3]) -> bool { // We use an array with a fixed size
25+
match x {
26+
[1, 2, ..] => true, // ok!
27+
_ => false
28+
}
29+
}
2030
```
21-
let r = &[1, 2, 3, 4];
22-
match r {
23-
&[a, b, ..] => { // ok!
24-
println!("a={}, b={}", a, b);
31+
32+
Example with a slice:
33+
34+
```
35+
fn is_123(x: &[u32]) -> bool { // We use a slice
36+
match x {
37+
[1, 2, ..] => true, // ok!
38+
_ => false
2539
}
2640
}
2741
```

Diff for: src/librustc_error_codes/error_codes/E0734.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
A stability attribute has been used outside of the standard library.
22

3-
Erroneous code examples:
3+
Erroneous code example:
44

55
```compile_fail,E0734
66
#[rustc_deprecated(since = "b", reason = "text")] // invalid

Diff for: src/librustc_error_codes/error_codes/E0740.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
A `union` cannot have fields with destructors.
1+
A `union` was declared with fields with destructors.
22

33
Erroneous code example:
44

@@ -14,3 +14,5 @@ impl Drop for A {
1414
fn drop(&mut self) { println!("A"); }
1515
}
1616
```
17+
18+
A `union` cannot have fields with destructors.

Diff for: src/librustc_metadata/creader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ impl<'a> CrateLoader<'a> {
248248
// Only use `--extern crate_name=path` here, not `--extern crate_name`.
249249
if let Some(mut files) = entry.files() {
250250
if files.any(|l| {
251-
let l = fs::canonicalize(l).ok();
252-
source.dylib.as_ref().map(|p| &p.0) == l.as_ref()
253-
|| source.rlib.as_ref().map(|p| &p.0) == l.as_ref()
251+
let l = fs::canonicalize(l).unwrap_or(l.clone().into());
252+
source.dylib.as_ref().map(|p| &p.0) == Some(&l)
253+
|| source.rlib.as_ref().map(|p| &p.0) == Some(&l)
254254
}) {
255255
ret = Some(cnum);
256256
}

Diff for: src/librustc_metadata/locator.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -426,20 +426,17 @@ impl<'a> CrateLocator<'a> {
426426
info!("lib candidate: {}", spf.path.display());
427427

428428
let (rlibs, rmetas, dylibs) = candidates.entry(hash.to_string()).or_default();
429-
fs::canonicalize(&spf.path)
430-
.map(|p| {
431-
if seen_paths.contains(&p) {
432-
return FileDoesntMatch;
433-
};
434-
seen_paths.insert(p.clone());
435-
match found_kind {
436-
CrateFlavor::Rlib => rlibs.insert(p, kind),
437-
CrateFlavor::Rmeta => rmetas.insert(p, kind),
438-
CrateFlavor::Dylib => dylibs.insert(p, kind),
439-
};
440-
FileMatches
441-
})
442-
.unwrap_or(FileDoesntMatch)
429+
let path = fs::canonicalize(&spf.path).unwrap_or_else(|_| spf.path.clone());
430+
if seen_paths.contains(&path) {
431+
return FileDoesntMatch;
432+
};
433+
seen_paths.insert(path.clone());
434+
match found_kind {
435+
CrateFlavor::Rlib => rlibs.insert(path, kind),
436+
CrateFlavor::Rmeta => rmetas.insert(path, kind),
437+
CrateFlavor::Dylib => dylibs.insert(path, kind),
438+
};
439+
FileMatches
443440
});
444441
self.rejected_via_kind.extend(staticlibs);
445442

@@ -688,12 +685,13 @@ impl<'a> CrateLocator<'a> {
688685
&& file.ends_with(&self.target.options.dll_suffix)
689686
{
690687
// Make sure there's at most one rlib and at most one dylib.
688+
let loc = fs::canonicalize(&loc).unwrap_or_else(|_| loc.clone());
691689
if loc.file_name().unwrap().to_str().unwrap().ends_with(".rlib") {
692-
rlibs.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag);
690+
rlibs.insert(loc, PathKind::ExternFlag);
693691
} else if loc.file_name().unwrap().to_str().unwrap().ends_with(".rmeta") {
694-
rmetas.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag);
692+
rmetas.insert(loc, PathKind::ExternFlag);
695693
} else {
696-
dylibs.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag);
694+
dylibs.insert(loc, PathKind::ExternFlag);
697695
}
698696
} else {
699697
self.rejected_via_filename

Diff for: src/librustc_mir_build/hair/pattern/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator;
1616
use rustc_hir::RangeEnd;
1717
use rustc_index::vec::Idx;
1818
use rustc_middle::mir::interpret::{get_slice_bytes, sign_extend, ConstValue};
19-
use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
19+
use rustc_middle::mir::interpret::{ErrorHandled, LitToConstError, LitToConstInput};
2020
use rustc_middle::mir::UserTypeProjection;
2121
use rustc_middle::mir::{BorrowKind, Field, Mutability};
2222
use rustc_middle::ty::subst::{GenericArg, SubstsRef};
@@ -834,6 +834,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
834834
pattern
835835
}
836836
}
837+
Err(ErrorHandled::TooGeneric) => {
838+
// While `Reported | Linted` cases will have diagnostics emitted already
839+
// it is not true for TooGeneric case, so we need to give user more information.
840+
self.tcx.sess.span_err(span, "constant pattern depends on a generic parameter");
841+
pat_from_kind(PatKind::Wild)
842+
}
837843
Err(_) => {
838844
self.tcx.sess.span_err(span, "could not evaluate constant pattern");
839845
pat_from_kind(PatKind::Wild)

Diff for: src/librustc_session/filesearch.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -117,28 +117,22 @@ pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
117117

118118
pub fn get_or_default_sysroot() -> PathBuf {
119119
// Follow symlinks. If the resolved path is relative, make it absolute.
120-
fn canonicalize(path: Option<PathBuf>) -> Option<PathBuf> {
121-
path.and_then(|path| {
122-
match fs::canonicalize(&path) {
123-
// See comments on this target function, but the gist is that
124-
// gcc chokes on verbatim paths which fs::canonicalize generates
125-
// so we try to avoid those kinds of paths.
126-
Ok(canon) => Some(fix_windows_verbatim_for_gcc(&canon)),
127-
Err(e) => panic!("failed to get realpath: {}", e),
128-
}
129-
})
120+
fn canonicalize(path: PathBuf) -> PathBuf {
121+
let path = fs::canonicalize(&path).unwrap_or(path);
122+
// See comments on this target function, but the gist is that
123+
// gcc chokes on verbatim paths which fs::canonicalize generates
124+
// so we try to avoid those kinds of paths.
125+
fix_windows_verbatim_for_gcc(&path)
130126
}
131127

132128
match env::current_exe() {
133-
Ok(exe) => match canonicalize(Some(exe)) {
134-
Some(mut p) => {
135-
p.pop();
136-
p.pop();
137-
p
138-
}
139-
None => panic!("can't determine value for sysroot"),
140-
},
141-
Err(ref e) => panic!(format!("failed to get current_exe: {}", e)),
129+
Ok(exe) => {
130+
let mut p = canonicalize(exe);
131+
p.pop();
132+
p.pop();
133+
p
134+
}
135+
Err(e) => panic!("failed to get current_exe: {}", e),
142136
}
143137
}
144138

Diff for: src/test/ui/consts/issue-73976-polymorphic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ impl<T: 'static> GetTypeId<T> {
1717

1818
const fn check_type_id<T: 'static>() -> bool {
1919
matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
20-
//~^ ERROR could not evaluate constant pattern
21-
//~| ERROR could not evaluate constant pattern
20+
//~^ ERROR constant pattern depends on a generic parameter
21+
//~| ERROR constant pattern depends on a generic parameter
2222
}
2323

2424
pub struct GetTypeNameLen<T>(T);
@@ -29,8 +29,8 @@ impl<T: 'static> GetTypeNameLen<T> {
2929

3030
const fn check_type_name_len<T: 'static>() -> bool {
3131
matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::VALUE)
32-
//~^ ERROR could not evaluate constant pattern
33-
//~| ERROR could not evaluate constant pattern
32+
//~^ ERROR constant pattern depends on a generic parameter
33+
//~| ERROR constant pattern depends on a generic parameter
3434
}
3535

3636
fn main() {

Diff for: src/test/ui/consts/issue-73976-polymorphic.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
error: could not evaluate constant pattern
1+
error: constant pattern depends on a generic parameter
22
--> $DIR/issue-73976-polymorphic.rs:19:37
33
|
44
LL | matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
55
| ^^^^^^^^^^^^^^^^^^^^^
66

7-
error: could not evaluate constant pattern
7+
error: constant pattern depends on a generic parameter
88
--> $DIR/issue-73976-polymorphic.rs:31:42
99
|
1010
LL | matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::VALUE)
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: could not evaluate constant pattern
13+
error: constant pattern depends on a generic parameter
1414
--> $DIR/issue-73976-polymorphic.rs:19:37
1515
|
1616
LL | matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
1717
| ^^^^^^^^^^^^^^^^^^^^^
1818

19-
error: could not evaluate constant pattern
19+
error: constant pattern depends on a generic parameter
2020
--> $DIR/issue-73976-polymorphic.rs:31:42
2121
|
2222
LL | matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::VALUE)

0 commit comments

Comments
 (0)