Skip to content

Commit 1dd4db5

Browse files
committed
Auto merge of rust-lang#118655 - compiler-errors:rollup-vrngyzn, r=compiler-errors
Rollup of 9 pull requests Successful merges: - rust-lang#117793 (Update variable name to fix `unused_variables` warning) - rust-lang#118123 (Add support for making lib features internal) - rust-lang#118268 (Pretty print `Fn<(..., ...)>` trait refs with parentheses (almost) always) - rust-lang#118346 (Add `deeply_normalize_for_diagnostics`, use it in coherence) - rust-lang#118350 (Simplify Default for tuples) - rust-lang#118450 (Use OnceCell in cell module documentation) - rust-lang#118585 (Fix parser ICE when recovering `dyn`/`impl` after `for<...>`) - rust-lang#118587 (Cleanup error handlers some more) - rust-lang#118642 (bootstrap(builder.rs): Don't explicitly warn against `semicolon_in_expressions_from_macros`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 84a554c + 0a8c0f7 commit 1dd4db5

File tree

53 files changed

+551
-571
lines changed

Some content is hidden

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

53 files changed

+551
-571
lines changed

compiler/rustc_builtin_macros/src/errors.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_errors::{
2-
AddToDiagnostic, DiagnosticBuilder, EmissionGuarantee, Handler, IntoDiagnostic, MultiSpan,
2+
AddToDiagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, MultiSpan,
33
SingleLabelManySpans,
44
};
55
use rustc_macros::{Diagnostic, Subdiagnostic};
@@ -446,9 +446,9 @@ pub(crate) struct EnvNotDefinedWithUserMessage {
446446
}
447447

448448
// Hand-written implementation to support custom user messages.
449-
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for EnvNotDefinedWithUserMessage {
449+
impl<'a> IntoDiagnostic<'a> for EnvNotDefinedWithUserMessage {
450450
#[track_caller]
451-
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, G> {
451+
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
452452
#[expect(
453453
rustc::untranslatable_diagnostic,
454454
reason = "cannot translate user-provided messages"
@@ -801,8 +801,8 @@ pub(crate) struct AsmClobberNoReg {
801801
pub(crate) clobbers: Vec<Span>,
802802
}
803803

804-
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg {
805-
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, G> {
804+
impl<'a> IntoDiagnostic<'a> for AsmClobberNoReg {
805+
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
806806
let mut diag =
807807
handler.struct_diagnostic(crate::fluent_generated::builtin_macros_asm_clobber_no_reg);
808808
diag.set_span(self.spans.clone());

compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl ConcurrencyLimiter {
6464
// Make sure to drop the mutex guard first to prevent poisoning the mutex.
6565
drop(state);
6666
if let Some(err) = err {
67-
handler.fatal(err).raise();
67+
handler.fatal(err);
6868
} else {
6969
// The error was already emitted, but compilation continued. Raise a silent
7070
// fatal error.

compiler/rustc_codegen_gcc/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
111111
pub(crate) struct MissingFeatures;
112112

113113
impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
114-
fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
115-
let mut diag = sess.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable);
114+
fn into_diagnostic(self, handler: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
115+
let mut diag = handler.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable);
116116
if let Some(span) = self.span {
117117
diag.set_span(span);
118118
};

compiler/rustc_codegen_llvm/src/errors.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::Path;
55
use crate::fluent_generated as fluent;
66
use rustc_data_structures::small_c_str::SmallCStr;
77
use rustc_errors::{
8-
DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed, Handler, IntoDiagnostic,
8+
DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed, FatalError, Handler, IntoDiagnostic,
99
};
1010
use rustc_macros::{Diagnostic, Subdiagnostic};
1111
use rustc_span::Span;
@@ -101,13 +101,13 @@ pub(crate) struct DynamicLinkingWithLTO;
101101

102102
pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
103103

104-
impl<EM: EmissionGuarantee> IntoDiagnostic<'_, EM> for ParseTargetMachineConfig<'_> {
105-
fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, EM> {
106-
let diag: DiagnosticBuilder<'_, EM> = self.0.into_diagnostic(sess);
104+
impl IntoDiagnostic<'_, FatalError> for ParseTargetMachineConfig<'_> {
105+
fn into_diagnostic(self, handler: &'_ Handler) -> DiagnosticBuilder<'_, FatalError> {
106+
let diag: DiagnosticBuilder<'_, FatalError> = self.0.into_diagnostic(handler);
107107
let (message, _) = diag.styled_message().first().expect("`LlvmError` with no message");
108-
let message = sess.eagerly_translate_to_string(message.clone(), diag.args());
108+
let message = handler.eagerly_translate_to_string(message.clone(), diag.args());
109109

110-
let mut diag = sess.struct_diagnostic(fluent::codegen_llvm_parse_target_machine_config);
110+
let mut diag = handler.struct_diagnostic(fluent::codegen_llvm_parse_target_machine_config);
111111
diag.set_arg("error", message);
112112
diag
113113
}
@@ -124,8 +124,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
124124
pub(crate) struct MissingFeatures;
125125

126126
impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
127-
fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
128-
let mut diag = sess.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable);
127+
fn into_diagnostic(self, handler: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
128+
let mut diag = handler.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable);
129129
if let Some(span) = self.span {
130130
diag.set_span(span);
131131
};
@@ -183,8 +183,8 @@ pub enum LlvmError<'a> {
183183

184184
pub(crate) struct WithLlvmError<'a>(pub LlvmError<'a>, pub String);
185185

186-
impl<EM: EmissionGuarantee> IntoDiagnostic<'_, EM> for WithLlvmError<'_> {
187-
fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, EM> {
186+
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for WithLlvmError<'_> {
187+
fn into_diagnostic(self, handler: &'_ Handler) -> DiagnosticBuilder<'_, G> {
188188
use LlvmError::*;
189189
let msg_with_llvm_err = match &self.0 {
190190
WriteOutput { .. } => fluent::codegen_llvm_write_output_with_llvm_err,
@@ -201,7 +201,7 @@ impl<EM: EmissionGuarantee> IntoDiagnostic<'_, EM> for WithLlvmError<'_> {
201201
PrepareThinLtoModule => fluent::codegen_llvm_prepare_thin_lto_module_with_llvm_err,
202202
ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err,
203203
};
204-
let mut diag = self.0.into_diagnostic(sess);
204+
let mut diag = self.0.into_diagnostic(handler);
205205
diag.set_primary_message(msg_with_llvm_err);
206206
diag.set_arg("llvm_err", self.1);
207207
diag

compiler/rustc_errors/src/diagnostic.rs

+6-37
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl Diagnostic {
239239
}
240240

241241
#[track_caller]
242-
pub fn new_with_code<M: Into<DiagnosticMessage>>(
242+
pub(crate) fn new_with_code<M: Into<DiagnosticMessage>>(
243243
level: Level,
244244
code: Option<DiagnosticId>,
245245
message: M,
@@ -281,7 +281,7 @@ impl Diagnostic {
281281
}
282282
}
283283

284-
pub fn update_unstable_expectation_id(
284+
pub(crate) fn update_unstable_expectation_id(
285285
&mut self,
286286
unstable_to_stable: &FxHashMap<LintExpectationId, LintExpectationId>,
287287
) {
@@ -307,14 +307,14 @@ impl Diagnostic {
307307
}
308308

309309
/// Indicates whether this diagnostic should show up in cargo's future breakage report.
310-
pub fn has_future_breakage(&self) -> bool {
310+
pub(crate) fn has_future_breakage(&self) -> bool {
311311
match self.code {
312312
Some(DiagnosticId::Lint { has_future_breakage, .. }) => has_future_breakage,
313313
_ => false,
314314
}
315315
}
316316

317-
pub fn is_force_warn(&self) -> bool {
317+
pub(crate) fn is_force_warn(&self) -> bool {
318318
match self.code {
319319
Some(DiagnosticId::Lint { is_force_warn, .. }) => is_force_warn,
320320
_ => false,
@@ -391,29 +391,6 @@ impl Diagnostic {
391391
self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"")
392392
}
393393

394-
pub fn note_unsuccessful_coercion(
395-
&mut self,
396-
expected: DiagnosticStyledString,
397-
found: DiagnosticStyledString,
398-
) -> &mut Self {
399-
let mut msg: Vec<_> =
400-
vec![(Cow::from("required when trying to coerce from type `"), Style::NoStyle)];
401-
msg.extend(expected.0.iter().map(|x| match *x {
402-
StringPart::Normal(ref s) => (Cow::from(s.clone()), Style::NoStyle),
403-
StringPart::Highlighted(ref s) => (Cow::from(s.clone()), Style::Highlight),
404-
}));
405-
msg.push((Cow::from("` to type '"), Style::NoStyle));
406-
msg.extend(found.0.iter().map(|x| match *x {
407-
StringPart::Normal(ref s) => (Cow::from(s.clone()), Style::NoStyle),
408-
StringPart::Highlighted(ref s) => (Cow::from(s.clone()), Style::Highlight),
409-
}));
410-
msg.push((Cow::from("`"), Style::NoStyle));
411-
412-
// For now, just attach these as notes
413-
self.highlighted_note(msg);
414-
self
415-
}
416-
417394
pub fn note_expected_found_extra(
418395
&mut self,
419396
expected_label: &dyn fmt::Display,
@@ -475,7 +452,7 @@ impl Diagnostic {
475452
self
476453
}
477454

478-
pub fn highlighted_note<M: Into<SubdiagnosticMessage>>(
455+
fn highlighted_note<M: Into<SubdiagnosticMessage>>(
479456
&mut self,
480457
msg: Vec<(M, Style)>,
481458
) -> &mut Self {
@@ -572,14 +549,6 @@ impl Diagnostic {
572549
self
573550
}
574551

575-
/// Clear any existing suggestions.
576-
pub fn clear_suggestions(&mut self) -> &mut Self {
577-
if let Ok(suggestions) = &mut self.suggestions {
578-
suggestions.clear();
579-
}
580-
self
581-
}
582-
583552
/// Helper for pushing to `self.suggestions`, if available (not disable).
584553
fn push_suggestion(&mut self, suggestion: CodeSuggestion) {
585554
if let Ok(suggestions) = &mut self.suggestions {
@@ -992,7 +961,7 @@ impl Diagnostic {
992961
/// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by
993962
/// combining it with the primary message of the diagnostic (if translatable, otherwise it just
994963
/// passes the user's string along).
995-
pub(crate) fn subdiagnostic_message_to_diagnostic_message(
964+
fn subdiagnostic_message_to_diagnostic_message(
996965
&self,
997966
attr: impl Into<SubdiagnosticMessage>,
998967
) -> DiagnosticMessage {

0 commit comments

Comments
 (0)