Skip to content

Commit

Permalink
Auto merge of rust-lang#88400 - Mark-Simulacrum:beta-next, r=Mark-Sim…
Browse files Browse the repository at this point in the history
…ulacrum

[beta] backports

This PR rolls up a number of beta backports:

* Split critical edge targeting the start block rust-lang#88124
* Make BuildHasher object safe rust-lang#88031
* Fix Windows Command::env("PATH") rust-lang#87863
* Do not ICE on HIR based WF check when involving lifetimes rust-lang#87811
* Update compiler_builtins to fix i128 shift/mul on thumbv6m rust-lang#87633
  • Loading branch information
bors committed Aug 28, 2021
2 parents 2296b16 + 88e4efd commit 27e88d3
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,9 @@ dependencies = [

[[package]]
name = "compiler_builtins"
version = "0.1.47"
version = "0.1.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd4ed89e0a5c3e50b15c0045fbe1ff8567b703bc07544faf935ddff0aaa7b65f"
checksum = "20b1438ef42c655665a8ab2c1c6d605a305f031d38d9be689ddfef41a20f3aa2"
dependencies = [
"cc",
"rustc-std-workspace-core",
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_mir/src/transform/add_call_guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ impl<'tcx> MirPass<'tcx> for AddCallGuards {

impl AddCallGuards {
pub fn add_call_guards(&self, body: &mut Body<'_>) {
let pred_count: IndexVec<_, _> = body.predecessors().iter().map(|ps| ps.len()).collect();
let mut pred_count: IndexVec<_, _> =
body.predecessors().iter().map(|ps| ps.len()).collect();
pred_count[START_BLOCK] += 1;

// We need a place to store the new blocks generated
let mut new_blocks = Vec::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let ObligationCauseCode::WellFormed(Some(wf_loc)) =
root_obligation.cause.code.peel_derives()
{
if let Some(cause) =
self.tcx.diagnostic_hir_wf_check((obligation.predicate, wf_loc.clone()))
{
if let Some(cause) = self.tcx.diagnostic_hir_wf_check((
tcx.erase_regions(obligation.predicate),
wf_loc.clone(),
)) {
obligation.cause = cause;
span = obligation.cause.span;
}
Expand Down
5 changes: 4 additions & 1 deletion library/core/src/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ pub trait BuildHasher {
/// );
/// ```
#[unstable(feature = "build_hasher_simple_hash_one", issue = "86161")]
fn hash_one<T: Hash>(&self, x: T) -> u64 {
fn hash_one<T: Hash>(&self, x: T) -> u64
where
Self: Sized,
{
let mut hasher = self.build_hasher();
x.hash(&mut hasher);
hasher.finish()
Expand Down
9 changes: 8 additions & 1 deletion library/core/tests/hash/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod sip;

use std::default::Default;
use std::hash::{Hash, Hasher};
use std::hash::{BuildHasher, Hash, Hasher};
use std::rc::Rc;

struct MyHasher {
Expand Down Expand Up @@ -139,3 +139,10 @@ fn test_indirect_hasher() {
}
assert_eq!(hasher.hash, 5);
}

#[test]
fn test_build_hasher_object_safe() {
use std::collections::hash_map::{DefaultHasher, RandomState};

let _: &dyn BuildHasher<Hasher = DefaultHasher> = &RandomState::new();
}
29 changes: 24 additions & 5 deletions library/std/src/sys/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#[cfg(test)]
mod tests;

use crate::borrow::Borrow;
use crate::cmp;
use crate::collections::BTreeMap;
use crate::convert::{TryFrom, TryInto};
Expand Down Expand Up @@ -46,6 +45,12 @@ pub struct EnvKey {
utf16: Vec<u16>,
}

impl EnvKey {
fn new<T: Into<OsString>>(key: T) -> Self {
EnvKey::from(key.into())
}
}

// Comparing Windows environment variable keys[1] are behaviourally the
// composition of two operations[2]:
//
Expand Down Expand Up @@ -100,6 +105,20 @@ impl PartialEq for EnvKey {
}
}
}
impl PartialOrd<str> for EnvKey {
fn partial_cmp(&self, other: &str) -> Option<cmp::Ordering> {
Some(self.cmp(&EnvKey::new(other)))
}
}
impl PartialEq<str> for EnvKey {
fn eq(&self, other: &str) -> bool {
if self.os_string.len() != other.len() {
false
} else {
self.cmp(&EnvKey::new(other)) == cmp::Ordering::Equal
}
}
}

// Environment variable keys should preserve their original case even though
// they are compared using a caseless string mapping.
Expand All @@ -115,9 +134,9 @@ impl From<EnvKey> for OsString {
}
}

impl Borrow<OsStr> for EnvKey {
fn borrow(&self) -> &OsStr {
&self.os_string
impl From<&OsStr> for EnvKey {
fn from(k: &OsStr) -> Self {
Self::from(k.to_os_string())
}
}

Expand Down Expand Up @@ -242,7 +261,7 @@ impl Command {
// to read the *child's* PATH if one is provided. See #15149 for more
// details.
let program = maybe_env.as_ref().and_then(|env| {
if let Some(v) = env.get(OsStr::new("PATH")) {
if let Some(v) = env.get(&EnvKey::new("PATH")) {
// Split the value and test each path to see if the
// program exists.
for path in split_paths(&v) {
Expand Down
10 changes: 6 additions & 4 deletions library/std/src/sys_common/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,18 @@ impl CommandEnv {

// The following functions build up changes
pub fn set(&mut self, key: &OsStr, value: &OsStr) {
let key = EnvKey::from(key);
self.maybe_saw_path(&key);
self.vars.insert(key.to_owned().into(), Some(value.to_owned()));
self.vars.insert(key, Some(value.to_owned()));
}

pub fn remove(&mut self, key: &OsStr) {
let key = EnvKey::from(key);
self.maybe_saw_path(&key);
if self.clear {
self.vars.remove(key);
self.vars.remove(&key);
} else {
self.vars.insert(key.to_owned().into(), None);
self.vars.insert(key, None);
}
}

Expand All @@ -87,7 +89,7 @@ impl CommandEnv {
self.saw_path || self.clear
}

fn maybe_saw_path(&mut self, key: &OsStr) {
fn maybe_saw_path(&mut self, key: &EnvKey) {
if !self.saw_path && key == "PATH" {
self.saw_path = true;
}
Expand Down
35 changes: 35 additions & 0 deletions src/test/ui/codegen/issue-88043-bb-does-not-have-terminator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// build-pass
// compile-flags: -Copt-level=0

// Regression test for #88043: LLVM crash when the RemoveZsts mir-opt pass is enabled.
// We should not see the error:
// `Basic Block in function '_ZN4main10take_until17h0067b8a660429bc9E' does not have terminator!`

fn bump() -> Option<usize> {
unreachable!()
}

fn take_until(terminate: impl Fn() -> bool) {
loop {
if terminate() {
return;
} else {
bump();
}
}
}

// CHECK-LABEL: @main
fn main() {
take_until(|| true);
f(None);
}

fn f(_a: Option<String>) -> Option<u32> {
loop {
g();
()
}
}

fn g() -> Option<u32> { None }
14 changes: 14 additions & 0 deletions src/test/ui/wf/hir-wf-check-erase-regions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Regression test for #87549.
// compile-flags: -C incremental=tmp/wf/hir-wf-check-erase-regions

pub struct Table<T, const N: usize>([Option<T>; N]);

impl<'a, T, const N: usize> IntoIterator for &'a Table<T, N> {
type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; //~ ERROR `&T` is not an iterator
type Item = &'a T;

fn into_iter(self) -> Self::IntoIter { //~ ERROR `&T` is not an iterator
unimplemented!()
}
}
fn main() {}
31 changes: 31 additions & 0 deletions src/test/ui/wf/hir-wf-check-erase-regions.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
error[E0277]: `&T` is not an iterator
--> $DIR/hir-wf-check-erase-regions.rs:7:5
|
LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&T` is not an iterator
|
::: $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL
|
LL | pub struct Flatten<I: Iterator<Item: IntoIterator>> {
| ------------ required by this bound in `Flatten`
|
= help: the trait `Iterator` is not implemented for `&T`
= note: required because of the requirements on the impl of `IntoIterator` for `&T`

error[E0277]: `&T` is not an iterator
--> $DIR/hir-wf-check-erase-regions.rs:10:27
|
LL | fn into_iter(self) -> Self::IntoIter {
| ^^^^^^^^^^^^^^ `&T` is not an iterator
|
::: $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL
|
LL | pub struct Flatten<I: Iterator<Item: IntoIterator>> {
| ------------ required by this bound in `Flatten`
|
= help: the trait `Iterator` is not implemented for `&T`
= note: required because of the requirements on the impl of `IntoIterator` for `&T`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.

0 comments on commit 27e88d3

Please sign in to comment.