Skip to content

Commit

Permalink
Auto merge of rust-lang#74957 - Manishearth:rollup-3wudwlg, r=Manishe…
Browse files Browse the repository at this point in the history
…arth

Rollup of 9 pull requests

Successful merges:

 - rust-lang#74751 (Clean up E0730 explanation)
 - rust-lang#74782 (Don't use "weak count" around Weak::from_raw_ptr)
 - rust-lang#74835 (Clean up E0734 explanation)
 - rust-lang#74871 (Enable docs on dist-x86_64-musl)
 - rust-lang#74905 (Avoid bool-like naming)
 - rust-lang#74907 (Clean up E0740 explanation)
 - rust-lang#74915 (rustc: Ignore fs::canonicalize errors in metadata)
 - rust-lang#74934 (Improve diagnostics when constant pattern is too generic)
 - rust-lang#74951 (Cherry-pick the release notes for 1.45.1)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Jul 30, 2020
2 parents 438c59f + 9eb5026 commit cfc572c
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 81 deletions.
13 changes: 13 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -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)
==========================

Expand Down
20 changes: 11 additions & 9 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1692,8 +1692,9 @@ impl<T> Weak<T> {

/// Consumes the `Weak<T>` 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<T>` 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<T>` with [`from_raw`].
///
/// The same restrictions of accessing the target of the pointer as with
/// [`as_ptr`] apply.
Expand Down Expand Up @@ -1728,17 +1729,18 @@ impl<T> Weak<T> {
/// This can be used to safely get a strong reference (by calling [`upgrade`]
/// later) or to deallocate the weak count by dropping the `Weak<T>`.
///
/// 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<T>` (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
///
Expand Down
22 changes: 11 additions & 11 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,8 +1462,9 @@ impl<T> Weak<T> {

/// Consumes the `Weak<T>` 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<T>` 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<T>` with [`from_raw`].
///
/// The same restrictions of accessing the target of the pointer as with
/// [`as_ptr`] apply.
Expand Down Expand Up @@ -1493,24 +1494,23 @@ impl<T> Weak<T> {
result
}

/// Converts a raw pointer previously created by [`into_raw`] back into
/// `Weak<T>`.
/// Converts a raw pointer previously created by [`into_raw`] back into `Weak<T>`.
///
/// This can be used to safely get a strong reference (by calling [`upgrade`]
/// later) or to deallocate the weak count by dropping the `Weak<T>`.
///
/// 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<T>` (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
///
/// ```
Expand Down
1 change: 0 additions & 1 deletion src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/etc/test-float-parse/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 21 additions & 7 deletions src/librustc_error_codes/error_codes/E0730.md
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -14,14 +14,28 @@ fn is_123<const N: usize>(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
}
}
```
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0734.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_error_codes/error_codes/E0740.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
A `union` cannot have fields with destructors.
A `union` was declared with fields with destructors.

Erroneous code example:

Expand All @@ -14,3 +14,5 @@ impl Drop for A {
fn drop(&mut self) { println!("A"); }
}
```

A `union` cannot have fields with destructors.
6 changes: 3 additions & 3 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
32 changes: 15 additions & 17 deletions src/librustc_metadata/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/librustc_mir_build/hair/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 13 additions & 19 deletions src/librustc_session/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>) -> Option<PathBuf> {
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),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/consts/issue-73976-polymorphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ impl<T: 'static> GetTypeId<T> {

const fn check_type_id<T: 'static>() -> bool {
matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::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>(T);
Expand All @@ -29,8 +29,8 @@ impl<T: 'static> GetTypeNameLen<T> {

const fn check_type_name_len<T: 'static>() -> bool {
matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::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() {
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/consts/issue-73976-polymorphic.stderr
Original file line number Diff line number Diff line change
@@ -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::<T>::VALUE, GetTypeId::<T>::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::<T>::VALUE, GetTypeNameLen::<T>::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::<T>::VALUE, GetTypeId::<T>::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::<T>::VALUE, GetTypeNameLen::<T>::VALUE)
Expand Down

0 comments on commit cfc572c

Please sign in to comment.