Skip to content

Commit c70f4a2

Browse files
committed
Auto merge of #153232 - JonathanBrouwer:rollup-rdNJcbm, r=<try>
Rollup of 9 pull requests try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1
2 parents ba15679 + 453fe91 commit c70f4a2

38 files changed

Lines changed: 242 additions & 357 deletions

compiler/rustc_abi/src/layout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
348348
always_sized: bool,
349349
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F> {
350350
let (present_first, present_second) = {
351-
let mut present_variants = variants
352-
.iter_enumerated()
353-
.filter_map(|(i, v)| if !repr.c() && absent(v) { None } else { Some(i) });
351+
let mut present_variants = variants.iter_enumerated().filter_map(|(i, v)| {
352+
if !repr.inhibit_enum_layout_opt() && absent(v) { None } else { Some(i) }
353+
});
354354
(present_variants.next(), present_variants.next())
355355
};
356356
let present_first = match present_first {

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//! [annotate_snippets]: https://docs.rs/crate/annotate-snippets/
77
88
use std::borrow::Cow;
9-
use std::error::Report;
109
use std::fmt::Debug;
1110
use std::io;
1211
use std::io::Write;
@@ -361,10 +360,7 @@ impl AnnotateSnippetEmitter {
361360
if substitutions.is_empty() {
362361
continue;
363362
}
364-
let mut msg = format_diag_message(&suggestion.msg, args)
365-
.map_err(Report::new)
366-
.unwrap()
367-
.to_string();
363+
let mut msg = format_diag_message(&suggestion.msg, args).to_string();
368364

369365
let lo = substitutions
370366
.iter()
@@ -547,7 +543,7 @@ impl AnnotateSnippetEmitter {
547543
) -> String {
548544
msgs.iter()
549545
.filter_map(|(m, style)| {
550-
let text = format_diag_message(m, args).map_err(Report::new).unwrap();
546+
let text = format_diag_message(m, args);
551547
let style = style.anstyle(level);
552548
if text.is_empty() { None } else { Some(format!("{style}{text}{style:#}")) }
553549
})
@@ -694,9 +690,7 @@ fn collect_annotations(
694690

695691
let kind = if is_primary { AnnotationKind::Primary } else { AnnotationKind::Context };
696692

697-
let label = label.as_ref().map(|m| {
698-
normalize_whitespace(&format_diag_message(m, args).map_err(Report::new).unwrap())
699-
});
693+
let label = label.as_ref().map(|m| normalize_whitespace(&format_diag_message(m, args)));
700694

701695
let ann = Annotation { kind, span, label };
702696
if sm.is_valid_span(ann.span).is_ok() {

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
//! The output types are defined in `rustc_session::config::ErrorOutputType`.
99
1010
use std::borrow::Cow;
11-
use std::error::Report;
1211
use std::io::prelude::*;
1312
use std::io::{self, IsTerminal};
1413
use std::iter;
@@ -106,7 +105,7 @@ pub trait Emitter {
106105
fluent_args: &FluentArgs<'_>,
107106
) {
108107
if let Some((sugg, rest)) = suggestions.split_first() {
109-
let msg = format_diag_message(&sugg.msg, fluent_args).map_err(Report::new).unwrap();
108+
let msg = format_diag_message(&sugg.msg, fluent_args);
110109
if rest.is_empty()
111110
// ^ if there is only one suggestion
112111
// don't display multi-suggestions as labels

compiler/rustc_errors/src/error.rs

Lines changed: 0 additions & 139 deletions
This file was deleted.

compiler/rustc_errors/src/json.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
1010
// FIXME: spec the JSON output properly.
1111

12-
use std::error::Report;
1312
use std::io::{self, Write};
1413
use std::path::{Path, PathBuf};
1514
use std::sync::{Arc, Mutex};
@@ -301,8 +300,7 @@ impl Diagnostic {
301300
fn from_errors_diagnostic(diag: crate::DiagInner, je: &JsonEmitter) -> Diagnostic {
302301
let args = to_fluent_args(diag.args.iter());
303302
let sugg_to_diag = |sugg: &CodeSuggestion| {
304-
let translated_message =
305-
format_diag_message(&sugg.msg, &args).map_err(Report::new).unwrap();
303+
let translated_message = format_diag_message(&sugg.msg, &args);
306304
Diagnostic {
307305
message: translated_message.to_string(),
308306
code: None,
@@ -417,10 +415,7 @@ impl DiagnosticSpan {
417415
Self::from_span_etc(
418416
span.span,
419417
span.is_primary,
420-
span.label
421-
.as_ref()
422-
.map(|m| format_diag_message(m, args).unwrap())
423-
.map(|m| m.to_string()),
418+
span.label.as_ref().map(|m| format_diag_message(m, args)).map(|m| m.to_string()),
424419
suggestion,
425420
je,
426421
)

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ extern crate self as rustc_errors;
2121
use std::backtrace::{Backtrace, BacktraceStatus};
2222
use std::borrow::Cow;
2323
use std::cell::Cell;
24-
use std::error::Report;
2524
use std::ffi::OsStr;
2625
use std::hash::Hash;
2726
use std::io::Write;
@@ -78,7 +77,6 @@ mod decorate_diag;
7877
mod diagnostic;
7978
mod diagnostic_impls;
8079
pub mod emitter;
81-
pub mod error;
8280
pub mod json;
8381
mod lock;
8482
pub mod markdown;
@@ -1437,7 +1435,7 @@ impl DiagCtxtInner {
14371435
args: impl Iterator<Item = DiagArg<'a>>,
14381436
) -> String {
14391437
let args = crate::translation::to_fluent_args(args);
1440-
format_diag_message(&message, &args).map_err(Report::new).unwrap().to_string()
1438+
format_diag_message(&message, &args).to_string()
14411439
}
14421440

14431441
fn eagerly_translate_for_subdiag(

compiler/rustc_errors/src/translation.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use std::borrow::Cow;
2-
use std::error::Report;
32

43
pub use rustc_error_messages::FluentArgs;
54
use rustc_error_messages::{langid, register_functions};
65
use tracing::{debug, trace};
76

8-
use crate::error::TranslateError;
97
use crate::fluent_bundle::FluentResource;
108
use crate::{DiagArg, DiagMessage, Style, fluent_bundle};
119

@@ -33,22 +31,14 @@ pub fn format_diag_messages(
3331
messages: &[(DiagMessage, Style)],
3432
args: &FluentArgs<'_>,
3533
) -> Cow<'static, str> {
36-
Cow::Owned(
37-
messages
38-
.iter()
39-
.map(|(m, _)| format_diag_message(m, args).map_err(Report::new).unwrap())
40-
.collect::<String>(),
41-
)
34+
Cow::Owned(messages.iter().map(|(m, _)| format_diag_message(m, args)).collect::<String>())
4235
}
4336

4437
/// Convert a `DiagMessage` to a string
45-
pub fn format_diag_message<'a>(
46-
message: &'a DiagMessage,
47-
args: &'a FluentArgs<'_>,
48-
) -> Result<Cow<'a, str>, TranslateError<'a>> {
38+
pub fn format_diag_message<'a>(message: &'a DiagMessage, args: &'a FluentArgs<'_>) -> Cow<'a, str> {
4939
trace!(?message, ?args);
5040
match message {
51-
DiagMessage::Str(msg) => Ok(Cow::Borrowed(msg)),
41+
DiagMessage::Str(msg) => Cow::Borrowed(msg),
5242
// This translates an inline fluent diagnostic message
5343
// It does this by creating a new `FluentBundle` with only one message,
5444
// and then translating using this bundle.
@@ -67,9 +57,9 @@ pub fn format_diag_message<'a>(
6757
let translated = bundle.format_pattern(value, Some(args), &mut errs).to_string();
6858
debug!(?translated, ?errs);
6959
if errs.is_empty() {
70-
Ok(Cow::Owned(translated))
60+
Cow::Owned(translated)
7161
} else {
72-
Err(TranslateError::fluent(&Cow::Borrowed(GENERATED_MSG_ID), args, errs))
62+
panic!("Fluent errors while formatting message: {errs:?}");
7363
}
7464
}
7565
}

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,13 @@ impl DepGraph {
826826
where
827827
F: FnOnce() -> String,
828828
{
829-
let dep_node_debug = &self.data.as_ref().unwrap().dep_node_debug;
829+
// Early queries (e.g., `-Z query-dep-graph` on empty crates) can reach here
830+
// before the graph is initialized. Return early to prevent an ICE.
831+
let data = match &self.data {
832+
Some(d) => d,
833+
None => return,
834+
};
835+
let dep_node_debug = &data.dep_node_debug;
830836

831837
if dep_node_debug.borrow().contains_key(&dep_node) {
832838
return;

compiler/rustc_middle/src/ty/consts/valtree.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,24 @@ impl<'tcx> Value<'tcx> {
136136
ty::Ref(_, inner_ty, _) => match inner_ty.kind() {
137137
// `&str` can be interpreted as raw bytes
138138
ty::Str => {}
139-
// `&[u8]` can be interpreted as raw bytes
140-
ty::Slice(slice_ty) if *slice_ty == tcx.types.u8 => {}
139+
// `&[T]` can be interpreted as raw bytes if elements are `u8`
140+
ty::Slice(_) => {}
141141
// other `&_` can't be interpreted as raw bytes
142142
_ => return None,
143143
},
144-
// `[u8; N]` can be interpreted as raw bytes
145-
ty::Array(array_ty, _) if *array_ty == tcx.types.u8 => {}
144+
// `[T; N]` can be interpreted as raw bytes if elements are `u8`
145+
ty::Array(_, _) => {}
146146
// Otherwise, type cannot be interpreted as raw bytes
147147
_ => return None,
148148
}
149149

150150
// We create an iterator that yields `Option<u8>`
151-
let iterator = self.to_branch().into_iter().map(|ct| Some(ct.try_to_leaf()?.to_u8()));
151+
let iterator = self.to_branch().into_iter().map(|ct| {
152+
(*ct)
153+
.try_to_value()
154+
.and_then(|value| (value.ty == tcx.types.u8).then_some(value))
155+
.and_then(|value| value.try_to_leaf().map(|leaf| leaf.to_u8()))
156+
});
152157
// If there is `None` in the iterator, then the array is not a valid array of u8s and we return `None`
153158
let bytes: Vec<u8> = iterator.collect::<Option<Vec<u8>>>()?;
154159

library/core/src/convert/num.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ macro_rules! impl_float_from_bool {
198198
/// # Examples
199199
/// ```
200200
$($(#[doc = $doctest_prefix])*)?
201-
#[doc = concat!("let x: ", stringify!($float)," = false.into();")]
201+
#[doc = concat!("let x = ", stringify!($float), "::from(false);")]
202202
/// assert_eq!(x, 0.0);
203203
/// assert!(x.is_sign_positive());
204204
///
205-
#[doc = concat!("let y: ", stringify!($float)," = true.into();")]
205+
#[doc = concat!("let y = ", stringify!($float), "::from(true);")]
206206
/// assert_eq!(y, 1.0);
207207
$($(#[doc = $doctest_suffix])*)?
208208
/// ```
@@ -343,11 +343,11 @@ macro_rules! impl_try_from_integer_for_bool {
343343
/// # Examples
344344
///
345345
/// ```
346-
#[doc = concat!("assert_eq!(0_", stringify!($int), ".try_into(), Ok(false));")]
346+
#[doc = concat!("assert_eq!(bool::try_from(0_", stringify!($int), "), Ok(false));")]
347347
///
348-
#[doc = concat!("assert_eq!(1_", stringify!($int), ".try_into(), Ok(true));")]
348+
#[doc = concat!("assert_eq!(bool::try_from(1_", stringify!($int), "), Ok(true));")]
349349
///
350-
#[doc = concat!("assert!(<", stringify!($int), " as TryInto<bool>>::try_into(2).is_err());")]
350+
#[doc = concat!("assert!(bool::try_from(2_", stringify!($int), ").is_err());")]
351351
/// ```
352352
#[inline]
353353
fn try_from(i: $int) -> Result<Self, Self::Error> {

0 commit comments

Comments
 (0)