Skip to content

Commit 5f8a240

Browse files
committed
Auto merge of rust-lang#133527 - matthiaskrgr:rollup-kyre1df, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#132979 (use `--exact` on `--skip` to avoid unintended substring matches) - rust-lang#133248 (CI: split x86_64-msvc-ext job) - rust-lang#133449 (std: expose `const_io_error!` as `const_error!`) - rust-lang#133453 (Commit license-metadata.json to git and check it's correct in CI) - rust-lang#133457 (miri: implement `TlsFree`) - rust-lang#133493 (do not constrain infer vars in `find_best_leaf_obligation`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 83965ef + 762a661 commit 5f8a240

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+752
-434
lines changed

REUSE.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ path = [
2828
"COPYRIGHT",
2929
"INSTALL.md",
3030
"LICENSE-APACHE",
31+
"license-metadata.json",
3132
"LICENSE-MIT",
3233
"README.md",
3334
"RELEASES.md",

compiler/rustc_trait_selection/src/solve/fulfill.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,21 @@ fn find_best_leaf_obligation<'tcx>(
346346
consider_ambiguities: bool,
347347
) -> PredicateObligation<'tcx> {
348348
let obligation = infcx.resolve_vars_if_possible(obligation.clone());
349+
// FIXME: we use a probe here as the `BestObligation` visitor does not
350+
// check whether it uses candidates which get shadowed by where-bounds.
351+
//
352+
// We should probably fix the visitor to not do so instead, as this also
353+
// means the leaf obligation may be incorrect.
349354
infcx
350-
.visit_proof_tree(obligation.clone().into(), &mut BestObligation {
351-
obligation: obligation.clone(),
352-
consider_ambiguities,
355+
.fudge_inference_if_ok(|| {
356+
infcx
357+
.visit_proof_tree(obligation.clone().into(), &mut BestObligation {
358+
obligation: obligation.clone(),
359+
consider_ambiguities,
360+
})
361+
.break_value()
362+
.ok_or(())
353363
})
354-
.break_value()
355364
.unwrap_or(obligation)
356365
}
357366

library/std/src/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3020,7 +3020,7 @@ impl DirBuilder {
30203020
match path.parent() {
30213021
Some(p) => self.create_dir_all(p)?,
30223022
None => {
3023-
return Err(io::const_io_error!(
3023+
return Err(io::const_error!(
30243024
io::ErrorKind::Uncategorized,
30253025
"failed to create whole tree",
30263026
));

library/std/src/io/buffered/bufreader/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Buffer {
4141
match Box::try_new_uninit_slice(capacity) {
4242
Ok(buf) => Ok(Self { buf, pos: 0, filled: 0, initialized: 0 }),
4343
Err(_) => {
44-
Err(io::const_io_error!(ErrorKind::OutOfMemory, "failed to allocate read buffer"))
44+
Err(io::const_error!(ErrorKind::OutOfMemory, "failed to allocate read buffer"))
4545
}
4646
}
4747
}

library/std/src/io/buffered/bufwriter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<W: Write> BufWriter<W> {
9696

9797
pub(crate) fn try_new_buffer() -> io::Result<Vec<u8>> {
9898
Vec::try_with_capacity(DEFAULT_BUF_SIZE).map_err(|_| {
99-
io::const_io_error!(ErrorKind::OutOfMemory, "failed to allocate write buffer")
99+
io::const_error!(ErrorKind::OutOfMemory, "failed to allocate write buffer")
100100
})
101101
}
102102

@@ -238,7 +238,7 @@ impl<W: ?Sized + Write> BufWriter<W> {
238238

239239
match r {
240240
Ok(0) => {
241-
return Err(io::const_io_error!(
241+
return Err(io::const_error!(
242242
ErrorKind::WriteZero,
243243
"failed to write the buffered data",
244244
));

library/std/src/io/cursor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ where
304304
self.pos = n;
305305
Ok(self.pos)
306306
}
307-
None => Err(io::const_io_error!(
307+
None => Err(io::const_error!(
308308
ErrorKind::InvalidInput,
309309
"invalid seek to a negative or overflowing position",
310310
)),
@@ -446,7 +446,7 @@ fn reserve_and_pad<A: Allocator>(
446446
buf_len: usize,
447447
) -> io::Result<usize> {
448448
let pos: usize = (*pos_mut).try_into().map_err(|_| {
449-
io::const_io_error!(
449+
io::const_error!(
450450
ErrorKind::InvalidInput,
451451
"cursor position exceeds maximum possible vector length",
452452
)

library/std/src/io/error.rs

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,31 @@ impl fmt::Debug for Error {
7676
#[allow(dead_code)]
7777
impl Error {
7878
pub(crate) const INVALID_UTF8: Self =
79-
const_io_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8");
79+
const_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8");
8080

8181
pub(crate) const READ_EXACT_EOF: Self =
82-
const_io_error!(ErrorKind::UnexpectedEof, "failed to fill whole buffer");
82+
const_error!(ErrorKind::UnexpectedEof, "failed to fill whole buffer");
8383

84-
pub(crate) const UNKNOWN_THREAD_COUNT: Self = const_io_error!(
84+
pub(crate) const UNKNOWN_THREAD_COUNT: Self = const_error!(
8585
ErrorKind::NotFound,
8686
"The number of hardware threads is not known for the target platform"
8787
);
8888

8989
pub(crate) const UNSUPPORTED_PLATFORM: Self =
90-
const_io_error!(ErrorKind::Unsupported, "operation not supported on this platform");
90+
const_error!(ErrorKind::Unsupported, "operation not supported on this platform");
9191

9292
pub(crate) const WRITE_ALL_EOF: Self =
93-
const_io_error!(ErrorKind::WriteZero, "failed to write whole buffer");
93+
const_error!(ErrorKind::WriteZero, "failed to write whole buffer");
9494

9595
pub(crate) const ZERO_TIMEOUT: Self =
96-
const_io_error!(ErrorKind::InvalidInput, "cannot set a 0 duration timeout");
96+
const_error!(ErrorKind::InvalidInput, "cannot set a 0 duration timeout");
9797
}
9898

9999
#[stable(feature = "rust1", since = "1.0.0")]
100100
impl From<alloc::ffi::NulError> for Error {
101101
/// Converts a [`alloc::ffi::NulError`] into a [`Error`].
102102
fn from(_: alloc::ffi::NulError) -> Error {
103-
const_io_error!(ErrorKind::InvalidInput, "data provided contains a nul byte")
103+
const_error!(ErrorKind::InvalidInput, "data provided contains a nul byte")
104104
}
105105
}
106106

@@ -151,27 +151,38 @@ pub type RawOsError = sys::RawOsError;
151151
// (For the sake of being explicit: the alignment requirement here only matters
152152
// if `error/repr_bitpacked.rs` is in use — for the unpacked repr it doesn't
153153
// matter at all)
154+
#[doc(hidden)]
155+
#[unstable(feature = "io_const_error_internals", issue = "none")]
154156
#[repr(align(4))]
155157
#[derive(Debug)]
156-
pub(crate) struct SimpleMessage {
157-
kind: ErrorKind,
158-
message: &'static str,
159-
}
160-
161-
impl SimpleMessage {
162-
pub(crate) const fn new(kind: ErrorKind, message: &'static str) -> Self {
163-
Self { kind, message }
164-
}
158+
pub struct SimpleMessage {
159+
pub kind: ErrorKind,
160+
pub message: &'static str,
165161
}
166162

167-
/// Creates and returns an `io::Error` for a given `ErrorKind` and constant
168-
/// message. This doesn't allocate.
169-
pub(crate) macro const_io_error($kind:expr, $message:expr $(,)?) {
170-
$crate::io::error::Error::from_static_message({
171-
const MESSAGE_DATA: $crate::io::error::SimpleMessage =
172-
$crate::io::error::SimpleMessage::new($kind, $message);
173-
&MESSAGE_DATA
174-
})
163+
/// Creates a new I/O error from a known kind of error and a string literal.
164+
///
165+
/// Contrary to [`Error::new`], this macro does not allocate and can be used in
166+
/// `const` contexts.
167+
///
168+
/// # Example
169+
/// ```
170+
/// #![feature(io_const_error)]
171+
/// use std::io::{const_error, Error, ErrorKind};
172+
///
173+
/// const FAIL: Error = const_error!(ErrorKind::Unsupported, "tried something that never works");
174+
///
175+
/// fn not_here() -> Result<(), Error> {
176+
/// Err(FAIL)
177+
/// }
178+
/// ```
179+
#[rustc_macro_transparency = "semitransparent"]
180+
#[unstable(feature = "io_const_error", issue = "133448")]
181+
#[allow_internal_unstable(hint_must_use, io_const_error_internals)]
182+
pub macro const_error($kind:expr, $message:expr $(,)?) {
183+
$crate::hint::must_use($crate::io::Error::from_static_message(
184+
const { &$crate::io::SimpleMessage { kind: $kind, message: $message } },
185+
))
175186
}
176187

177188
// As with `SimpleMessage`: `#[repr(align(4))]` here is just because
@@ -592,13 +603,15 @@ impl Error {
592603
///
593604
/// This function does not allocate.
594605
///
595-
/// You should not use this directly, and instead use the `const_io_error!`
596-
/// macro: `io::const_io_error!(ErrorKind::Something, "some_message")`.
606+
/// You should not use this directly, and instead use the `const_error!`
607+
/// macro: `io::const_error!(ErrorKind::Something, "some_message")`.
597608
///
598609
/// This function should maybe change to `from_static_message<const MSG: &'static
599610
/// str>(kind: ErrorKind)` in the future, when const generics allow that.
600611
#[inline]
601-
pub(crate) const fn from_static_message(msg: &'static SimpleMessage) -> Error {
612+
#[doc(hidden)]
613+
#[unstable(feature = "io_const_error_internals", issue = "none")]
614+
pub const fn from_static_message(msg: &'static SimpleMessage) -> Error {
602615
Self { repr: Repr::new_simple_message(msg) }
603616
}
604617

library/std/src/io/error/tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Custom, Error, ErrorData, ErrorKind, Repr, SimpleMessage, const_io_error};
1+
use super::{Custom, Error, ErrorData, ErrorKind, Repr, SimpleMessage, const_error};
22
use crate::assert_matches::assert_matches;
33
use crate::mem::size_of;
44
use crate::sys::decode_error_kind;
@@ -60,7 +60,7 @@ fn test_downcasting() {
6060

6161
#[test]
6262
fn test_const() {
63-
const E: Error = const_io_error!(ErrorKind::NotFound, "hello");
63+
const E: Error = const_error!(ErrorKind::NotFound, "hello");
6464

6565
assert_eq!(E.kind(), ErrorKind::NotFound);
6666
assert_eq!(E.to_string(), "hello");
@@ -110,13 +110,13 @@ fn test_simple_message_packing() {
110110
}};
111111
}
112112

113-
let not_static = const_io_error!(Uncategorized, "not a constant!");
113+
let not_static = const_error!(Uncategorized, "not a constant!");
114114
check_simple_msg!(not_static, Uncategorized, "not a constant!");
115115

116-
const CONST: Error = const_io_error!(NotFound, "definitely a constant!");
116+
const CONST: Error = const_error!(NotFound, "definitely a constant!");
117117
check_simple_msg!(CONST, NotFound, "definitely a constant!");
118118

119-
static STATIC: Error = const_io_error!(BrokenPipe, "a constant, sort of!");
119+
static STATIC: Error = const_error!(BrokenPipe, "a constant, sort of!");
120120
check_simple_msg!(STATIC, BrokenPipe, "a constant, sort of!");
121121
}
122122

library/std/src/io/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,15 @@ mod tests;
301301
pub use core::io::{BorrowedBuf, BorrowedCursor};
302302
use core::slice::memchr;
303303

304-
pub(crate) use error::const_io_error;
305-
306304
#[stable(feature = "bufwriter_into_parts", since = "1.56.0")]
307305
pub use self::buffered::WriterPanicked;
308306
#[unstable(feature = "raw_os_error_ty", issue = "107792")]
309307
pub use self::error::RawOsError;
308+
#[doc(hidden)]
309+
#[unstable(feature = "io_const_error_internals", issue = "none")]
310+
pub use self::error::SimpleMessage;
311+
#[unstable(feature = "io_const_error", issue = "133448")]
312+
pub use self::error::const_error;
310313
#[stable(feature = "is_terminal", since = "1.70.0")]
311314
pub use self::stdio::IsTerminal;
312315
pub(crate) use self::stdio::attempt_print_to_stderr;

library/std/src/io/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ fn take_eof() {
225225

226226
impl Read for R {
227227
fn read(&mut self, _: &mut [u8]) -> io::Result<usize> {
228-
Err(io::const_io_error!(io::ErrorKind::Other, ""))
228+
Err(io::const_error!(io::ErrorKind::Other, ""))
229229
}
230230
}
231231
impl BufRead for R {
232232
fn fill_buf(&mut self) -> io::Result<&[u8]> {
233-
Err(io::const_io_error!(io::ErrorKind::Other, ""))
233+
Err(io::const_error!(io::ErrorKind::Other, ""))
234234
}
235235
fn consume(&mut self, _amt: usize) {}
236236
}

0 commit comments

Comments
 (0)