Skip to content

Commit af8604f

Browse files
committed
Auto merge of #94845 - Dylan-DPC:rollup-3phylaq, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #93283 (Fix for localized windows editions in testcase fn read_link() Issue#93211) - #94592 (Fallback to top-level config.toml if not present in current directory, and remove fallback for env vars and CLI flags) - #94776 (Optimize ascii::escape_default) - #94840 (update `replace_bound_vars_with_placeholders` doc comment) - #94842 (Remove unnecessary try_opt for operations that cannot fail) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f58d51b + fb3d126 commit af8604f

File tree

7 files changed

+49
-30
lines changed

7 files changed

+49
-30
lines changed

compiler/rustc_infer/src/infer/higher_ranked/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,11 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
5858
}
5959

6060
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
61-
/// Replaces all regions (resp. types) bound by `binder` with placeholder
62-
/// regions (resp. types) and return a map indicating which bound-region
63-
/// placeholder region. This is the first step of checking subtyping
64-
/// when higher-ranked things are involved.
61+
/// Replaces all bound variables (lifetimes, types, and constants) bound by
62+
/// `binder` with placeholder variables.
6563
///
66-
/// **Important:** You have to be careful to not leak these placeholders,
67-
/// for more information about how placeholders and HRTBs work, see
68-
/// the [rustc dev guide].
64+
/// This is the first step of checking subtyping when higher-ranked things are involved.
65+
/// For more details visit the relevant sections of the [rustc dev guide].
6966
///
7067
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
7168
pub fn replace_bound_vars_with_placeholders<T>(&self, binder: ty::Binder<'tcx, T>) -> T

library/core/src/ascii.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,20 @@ pub fn escape_default(c: u8) -> EscapeDefault {
9898
b'\'' => ([b'\\', b'\'', 0, 0], 2),
9999
b'"' => ([b'\\', b'"', 0, 0], 2),
100100
b'\x20'..=b'\x7e' => ([c, 0, 0, 0], 1),
101-
_ => ([b'\\', b'x', hexify(c >> 4), hexify(c & 0xf)], 4),
101+
_ => {
102+
let hex_digits: &[u8; 16] = b"0123456789abcdef";
103+
([b'\\', b'x', hex_digits[(c >> 4) as usize], hex_digits[(c & 0xf) as usize]], 4)
104+
}
102105
};
103106

104107
return EscapeDefault { range: 0..len, data };
105-
106-
fn hexify(b: u8) -> u8 {
107-
match b {
108-
0..=9 => b'0' + b,
109-
_ => b'a' + b - 10,
110-
}
111-
}
112108
}
113109

114110
#[stable(feature = "rust1", since = "1.0.0")]
115111
impl Iterator for EscapeDefault {
116112
type Item = u8;
113+
114+
#[inline]
117115
fn next(&mut self) -> Option<u8> {
118116
self.range.next().map(|i| self.data[i as usize])
119117
}

library/core/src/num/int_macros.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2166,15 +2166,17 @@ macro_rules! int_impl {
21662166

21672167
let r = try_opt!(self.checked_rem(rhs));
21682168
let m = if (r > 0 && rhs < 0) || (r < 0 && rhs > 0) {
2169-
try_opt!(r.checked_add(rhs))
2169+
// r + rhs cannot overflow because they have opposite signs
2170+
r + rhs
21702171
} else {
21712172
r
21722173
};
21732174

21742175
if m == 0 {
21752176
Some(self)
21762177
} else {
2177-
self.checked_add(try_opt!(rhs.checked_sub(m)))
2178+
// rhs - m cannot overflow because m has the same sign as rhs
2179+
self.checked_add(rhs - m)
21782180
}
21792181
}
21802182

library/core/src/num/uint_macros.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,8 @@ macro_rules! uint_impl {
21192119
pub const fn checked_next_multiple_of(self, rhs: Self) -> Option<Self> {
21202120
match try_opt!(self.checked_rem(rhs)) {
21212121
0 => Some(self),
2122-
r => self.checked_add(try_opt!(rhs.checked_sub(r)))
2122+
// rhs - r cannot overflow because r is smaller than rhs
2123+
r => self.checked_add(rhs - r)
21232124
}
21242125
}
21252126

library/std/src/fs/tests.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::io::prelude::*;
22

3+
use crate::env;
34
use crate::fs::{self, File, OpenOptions};
45
use crate::io::{ErrorKind, SeekFrom};
56
use crate::path::Path;
@@ -906,7 +907,14 @@ fn read_link() {
906907
// junction
907908
assert_eq!(check!(fs::read_link(r"C:\Users\Default User")), Path::new(r"C:\Users\Default"));
908909
// junction with special permissions
909-
assert_eq!(check!(fs::read_link(r"C:\Documents and Settings\")), Path::new(r"C:\Users"));
910+
// Since not all localized windows versions contain the folder "Documents and Settings" in english,
911+
// we will briefly check, if it exists and otherwise skip the test. Except during CI we will always execute the test.
912+
if Path::new(r"C:\Documents and Settings\").exists() || env::var_os("CI").is_some() {
913+
assert_eq!(
914+
check!(fs::read_link(r"C:\Documents and Settings\")),
915+
Path::new(r"C:\Users")
916+
);
917+
}
910918
}
911919
let tmpdir = tmpdir();
912920
let link = tmpdir.join("link");

src/bootstrap/bootstrap.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1233,16 +1233,18 @@ def bootstrap(help_triggered):
12331233
build.verbose = args.verbose
12341234
build.clean = args.clean
12351235

1236-
# Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then fallback to `config.toml` (if it
1237-
# exists).
1236+
# Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then `./config.toml`,
1237+
# then `config.toml` in the root directory.
12381238
toml_path = args.config or os.getenv('RUST_BOOTSTRAP_CONFIG')
1239-
if not toml_path and os.path.exists('config.toml'):
1239+
using_default_path = toml_path is None
1240+
if using_default_path:
12401241
toml_path = 'config.toml'
1241-
1242-
if toml_path:
12431242
if not os.path.exists(toml_path):
12441243
toml_path = os.path.join(build.rust_root, toml_path)
12451244

1245+
# Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path,
1246+
# but not if `config.toml` hasn't been created.
1247+
if not using_default_path or os.path.exists(toml_path):
12461248
with open(toml_path) as config:
12471249
build.config_toml = config.read()
12481250

src/bootstrap/config.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ impl Config {
647647
let get_toml = |file: &Path| {
648648
use std::process;
649649

650-
let contents = t!(fs::read_to_string(file), "`include` config not found");
650+
let contents =
651+
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
651652
match toml::from_str(&contents) {
652653
Ok(table) => table,
653654
Err(err) => {
@@ -657,14 +658,24 @@ impl Config {
657658
}
658659
};
659660

660-
// check --config first, then `$RUST_BOOTSTRAP_CONFIG` first, then `config.toml`
661+
// Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then `./config.toml`, then `config.toml` in the root directory.
661662
let toml_path = flags
662663
.config
663664
.clone()
664-
.or_else(|| env::var_os("RUST_BOOTSTRAP_CONFIG").map(PathBuf::from))
665-
.unwrap_or_else(|| PathBuf::from("config.toml"));
666-
let mut toml =
667-
if toml_path.exists() { get_toml(&toml_path) } else { TomlConfig::default() };
665+
.or_else(|| env::var_os("RUST_BOOTSTRAP_CONFIG").map(PathBuf::from));
666+
let using_default_path = toml_path.is_none();
667+
let mut toml_path = toml_path.unwrap_or_else(|| PathBuf::from("config.toml"));
668+
if using_default_path && !toml_path.exists() {
669+
toml_path = config.src.join(toml_path);
670+
}
671+
672+
// Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path,
673+
// but not if `config.toml` hasn't been created.
674+
let mut toml = if !using_default_path || toml_path.exists() {
675+
get_toml(&toml_path)
676+
} else {
677+
TomlConfig::default()
678+
};
668679

669680
if let Some(include) = &toml.profile {
670681
let mut include_path = config.src.clone();

0 commit comments

Comments
 (0)