Skip to content

Commit 27e88d3

Browse files
committed
Auto merge of rust-lang#88400 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[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
2 parents 2296b16 + 88e4efd commit 27e88d3

File tree

10 files changed

+131
-17
lines changed

10 files changed

+131
-17
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,9 @@ dependencies = [
646646

647647
[[package]]
648648
name = "compiler_builtins"
649-
version = "0.1.47"
649+
version = "0.1.49"
650650
source = "registry+https://github.com/rust-lang/crates.io-index"
651-
checksum = "fd4ed89e0a5c3e50b15c0045fbe1ff8567b703bc07544faf935ddff0aaa7b65f"
651+
checksum = "20b1438ef42c655665a8ab2c1c6d605a305f031d38d9be689ddfef41a20f3aa2"
652652
dependencies = [
653653
"cc",
654654
"rustc-std-workspace-core",

compiler/rustc_mir/src/transform/add_call_guards.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ impl<'tcx> MirPass<'tcx> for AddCallGuards {
3838

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

4345
// We need a place to store the new blocks generated
4446
let mut new_blocks = Vec::new();

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
245245
if let ObligationCauseCode::WellFormed(Some(wf_loc)) =
246246
root_obligation.cause.code.peel_derives()
247247
{
248-
if let Some(cause) =
249-
self.tcx.diagnostic_hir_wf_check((obligation.predicate, wf_loc.clone()))
250-
{
248+
if let Some(cause) = self.tcx.diagnostic_hir_wf_check((
249+
tcx.erase_regions(obligation.predicate),
250+
wf_loc.clone(),
251+
)) {
251252
obligation.cause = cause;
252253
span = obligation.cause.span;
253254
}

library/core/src/hash/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,10 @@ pub trait BuildHasher {
520520
/// );
521521
/// ```
522522
#[unstable(feature = "build_hasher_simple_hash_one", issue = "86161")]
523-
fn hash_one<T: Hash>(&self, x: T) -> u64 {
523+
fn hash_one<T: Hash>(&self, x: T) -> u64
524+
where
525+
Self: Sized,
526+
{
524527
let mut hasher = self.build_hasher();
525528
x.hash(&mut hasher);
526529
hasher.finish()

library/core/tests/hash/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod sip;
22

33
use std::default::Default;
4-
use std::hash::{Hash, Hasher};
4+
use std::hash::{BuildHasher, Hash, Hasher};
55
use std::rc::Rc;
66

77
struct MyHasher {
@@ -139,3 +139,10 @@ fn test_indirect_hasher() {
139139
}
140140
assert_eq!(hasher.hash, 5);
141141
}
142+
143+
#[test]
144+
fn test_build_hasher_object_safe() {
145+
use std::collections::hash_map::{DefaultHasher, RandomState};
146+
147+
let _: &dyn BuildHasher<Hasher = DefaultHasher> = &RandomState::new();
148+
}

library/std/src/sys/windows/process.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#[cfg(test)]
44
mod tests;
55

6-
use crate::borrow::Borrow;
76
use crate::cmp;
87
use crate::collections::BTreeMap;
98
use crate::convert::{TryFrom, TryInto};
@@ -46,6 +45,12 @@ pub struct EnvKey {
4645
utf16: Vec<u16>,
4746
}
4847

48+
impl EnvKey {
49+
fn new<T: Into<OsString>>(key: T) -> Self {
50+
EnvKey::from(key.into())
51+
}
52+
}
53+
4954
// Comparing Windows environment variable keys[1] are behaviourally the
5055
// composition of two operations[2]:
5156
//
@@ -100,6 +105,20 @@ impl PartialEq for EnvKey {
100105
}
101106
}
102107
}
108+
impl PartialOrd<str> for EnvKey {
109+
fn partial_cmp(&self, other: &str) -> Option<cmp::Ordering> {
110+
Some(self.cmp(&EnvKey::new(other)))
111+
}
112+
}
113+
impl PartialEq<str> for EnvKey {
114+
fn eq(&self, other: &str) -> bool {
115+
if self.os_string.len() != other.len() {
116+
false
117+
} else {
118+
self.cmp(&EnvKey::new(other)) == cmp::Ordering::Equal
119+
}
120+
}
121+
}
103122

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

118-
impl Borrow<OsStr> for EnvKey {
119-
fn borrow(&self) -> &OsStr {
120-
&self.os_string
137+
impl From<&OsStr> for EnvKey {
138+
fn from(k: &OsStr) -> Self {
139+
Self::from(k.to_os_string())
121140
}
122141
}
123142

@@ -242,7 +261,7 @@ impl Command {
242261
// to read the *child's* PATH if one is provided. See #15149 for more
243262
// details.
244263
let program = maybe_env.as_ref().and_then(|env| {
245-
if let Some(v) = env.get(OsStr::new("PATH")) {
264+
if let Some(v) = env.get(&EnvKey::new("PATH")) {
246265
// Split the value and test each path to see if the
247266
// program exists.
248267
for path in split_paths(&v) {

library/std/src/sys_common/process.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,18 @@ impl CommandEnv {
6565

6666
// The following functions build up changes
6767
pub fn set(&mut self, key: &OsStr, value: &OsStr) {
68+
let key = EnvKey::from(key);
6869
self.maybe_saw_path(&key);
69-
self.vars.insert(key.to_owned().into(), Some(value.to_owned()));
70+
self.vars.insert(key, Some(value.to_owned()));
7071
}
7172

7273
pub fn remove(&mut self, key: &OsStr) {
74+
let key = EnvKey::from(key);
7375
self.maybe_saw_path(&key);
7476
if self.clear {
75-
self.vars.remove(key);
77+
self.vars.remove(&key);
7678
} else {
77-
self.vars.insert(key.to_owned().into(), None);
79+
self.vars.insert(key, None);
7880
}
7981
}
8082

@@ -87,7 +89,7 @@ impl CommandEnv {
8789
self.saw_path || self.clear
8890
}
8991

90-
fn maybe_saw_path(&mut self, key: &OsStr) {
92+
fn maybe_saw_path(&mut self, key: &EnvKey) {
9193
if !self.saw_path && key == "PATH" {
9294
self.saw_path = true;
9395
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// build-pass
2+
// compile-flags: -Copt-level=0
3+
4+
// Regression test for #88043: LLVM crash when the RemoveZsts mir-opt pass is enabled.
5+
// We should not see the error:
6+
// `Basic Block in function '_ZN4main10take_until17h0067b8a660429bc9E' does not have terminator!`
7+
8+
fn bump() -> Option<usize> {
9+
unreachable!()
10+
}
11+
12+
fn take_until(terminate: impl Fn() -> bool) {
13+
loop {
14+
if terminate() {
15+
return;
16+
} else {
17+
bump();
18+
}
19+
}
20+
}
21+
22+
// CHECK-LABEL: @main
23+
fn main() {
24+
take_until(|| true);
25+
f(None);
26+
}
27+
28+
fn f(_a: Option<String>) -> Option<u32> {
29+
loop {
30+
g();
31+
()
32+
}
33+
}
34+
35+
fn g() -> Option<u32> { None }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for #87549.
2+
// compile-flags: -C incremental=tmp/wf/hir-wf-check-erase-regions
3+
4+
pub struct Table<T, const N: usize>([Option<T>; N]);
5+
6+
impl<'a, T, const N: usize> IntoIterator for &'a Table<T, N> {
7+
type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; //~ ERROR `&T` is not an iterator
8+
type Item = &'a T;
9+
10+
fn into_iter(self) -> Self::IntoIter { //~ ERROR `&T` is not an iterator
11+
unimplemented!()
12+
}
13+
}
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0277]: `&T` is not an iterator
2+
--> $DIR/hir-wf-check-erase-regions.rs:7:5
3+
|
4+
LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&T` is not an iterator
6+
|
7+
::: $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL
8+
|
9+
LL | pub struct Flatten<I: Iterator<Item: IntoIterator>> {
10+
| ------------ required by this bound in `Flatten`
11+
|
12+
= help: the trait `Iterator` is not implemented for `&T`
13+
= note: required because of the requirements on the impl of `IntoIterator` for `&T`
14+
15+
error[E0277]: `&T` is not an iterator
16+
--> $DIR/hir-wf-check-erase-regions.rs:10:27
17+
|
18+
LL | fn into_iter(self) -> Self::IntoIter {
19+
| ^^^^^^^^^^^^^^ `&T` is not an iterator
20+
|
21+
::: $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL
22+
|
23+
LL | pub struct Flatten<I: Iterator<Item: IntoIterator>> {
24+
| ------------ required by this bound in `Flatten`
25+
|
26+
= help: the trait `Iterator` is not implemented for `&T`
27+
= note: required because of the requirements on the impl of `IntoIterator` for `&T`
28+
29+
error: aborting due to 2 previous errors
30+
31+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)