Skip to content

Commit 883f9f7

Browse files
committed
Auto merge of rust-lang#139949 - matthiaskrgr:rollup-pxc5tsx, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#138632 (Stabilize `cfg_boolean_literals`) - rust-lang#139416 (unstable book; document `macro_metavar_expr_concat`) - rust-lang#139782 (Consistent with treating Ctor Call as Struct in liveness analysis) - rust-lang#139885 (document RUSTC_BOOTSTRAP, RUSTC_OVERRIDE_VERSION_STRING, and -Z allow-features in the unstable book) - rust-lang#139904 (Explicitly annotate edition for `unpretty=expanded` and `unpretty=hir` tests) - rust-lang#139932 (transmutability: Refactor tests for simplicity) - rust-lang#139944 (Move eager translation to a method on Diag) - rust-lang#139948 (git: ignore `60600a6fa403216bfd66e04f948b1822f6450af7` for blame purposes) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 94015d3 + 7650fe9 commit 883f9f7

File tree

240 files changed

+1038
-978
lines changed

Some content is hidden

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

240 files changed

+1038
-978
lines changed

Diff for: .git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ ec2cc761bc7067712ecc7734502f703fe3b024c8
3131
c682aa162b0d41e21cc6748f4fecfe01efb69d1f
3232
# reformat with updated edition 2024
3333
1fcae03369abb4c2cc180cd5a49e1f4440a81300
34+
# Breaking up of compiletest runtest.rs
35+
60600a6fa403216bfd66e04f948b1822f6450af7

Diff for: compiler/rustc_ast_passes/src/errors.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc_ast::ParamKindOrd;
44
use rustc_errors::codes::*;
5-
use rustc_errors::{Applicability, Diag, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic};
5+
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
66
use rustc_macros::{Diagnostic, Subdiagnostic};
77
use rustc_span::{Ident, Span, Symbol};
88

@@ -394,11 +394,7 @@ pub(crate) struct EmptyLabelManySpans(pub Vec<Span>);
394394

395395
// The derive for `Vec<Span>` does multiple calls to `span_label`, adding commas between each
396396
impl Subdiagnostic for EmptyLabelManySpans {
397-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
398-
self,
399-
diag: &mut Diag<'_, G>,
400-
_: &F,
401-
) {
397+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
402398
diag.span_labels(self.0, "");
403399
}
404400
}
@@ -749,11 +745,7 @@ pub(crate) struct StableFeature {
749745
}
750746

751747
impl Subdiagnostic for StableFeature {
752-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
753-
self,
754-
diag: &mut Diag<'_, G>,
755-
_: &F,
756-
) {
748+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
757749
diag.arg("name", self.name);
758750
diag.arg("since", self.since);
759751
diag.help(fluent::ast_passes_stable_since);

Diff for: compiler/rustc_attr_parsing/src/attributes/cfg.rs

-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_session::config::ExpectedValues;
77
use rustc_session::lint::BuiltinLintDiag;
88
use rustc_session::lint::builtin::UNEXPECTED_CFGS;
99
use rustc_session::parse::feature_err;
10-
use rustc_span::symbol::kw;
1110
use rustc_span::{Span, Symbol, sym};
1211

1312
use crate::session_diagnostics::{self, UnsupportedLiteralReason};
@@ -89,20 +88,6 @@ pub fn eval_condition(
8988
let cfg = match cfg {
9089
MetaItemInner::MetaItem(meta_item) => meta_item,
9190
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => {
92-
if let Some(features) = features {
93-
// we can't use `try_gate_cfg` as symbols don't differentiate between `r#true`
94-
// and `true`, and we want to keep the former working without feature gate
95-
gate_cfg(
96-
&(
97-
if *b { kw::True } else { kw::False },
98-
sym::cfg_boolean_literals,
99-
|features: &Features| features.cfg_boolean_literals(),
100-
),
101-
cfg.span(),
102-
sess,
103-
features,
104-
);
105-
}
10691
return *b;
10792
}
10893
_ => {

Diff for: compiler/rustc_builtin_macros/src/errors.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_errors::codes::*;
22
use rustc_errors::{
33
Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans,
4-
SubdiagMessageOp, Subdiagnostic,
4+
Subdiagnostic,
55
};
66
use rustc_macros::{Diagnostic, Subdiagnostic};
77
use rustc_span::{Ident, Span, Symbol};
@@ -684,13 +684,9 @@ pub(crate) struct FormatUnusedArg {
684684
// Allow the singular form to be a subdiagnostic of the multiple-unused
685685
// form of diagnostic.
686686
impl Subdiagnostic for FormatUnusedArg {
687-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
688-
self,
689-
diag: &mut Diag<'_, G>,
690-
f: &F,
691-
) {
687+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
692688
diag.arg("named", self.named);
693-
let msg = f(diag, crate::fluent_generated::builtin_macros_format_unused_arg.into());
689+
let msg = diag.eagerly_translate(crate::fluent_generated::builtin_macros_format_unused_arg);
694690
diag.span_label(self.span, msg);
695691
}
696692
}

Diff for: compiler/rustc_const_eval/src/errors.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_abi::WrappingRange;
66
use rustc_errors::codes::*;
77
use rustc_errors::{
88
Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, Diagnostic, EmissionGuarantee, Level,
9-
MultiSpan, SubdiagMessageOp, Subdiagnostic,
9+
MultiSpan, Subdiagnostic,
1010
};
1111
use rustc_hir::ConstContext;
1212
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
@@ -290,19 +290,15 @@ pub struct FrameNote {
290290
}
291291

292292
impl Subdiagnostic for FrameNote {
293-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
294-
self,
295-
diag: &mut Diag<'_, G>,
296-
f: &F,
297-
) {
293+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
298294
diag.arg("times", self.times);
299295
diag.arg("where_", self.where_);
300296
diag.arg("instance", self.instance);
301297
let mut span: MultiSpan = self.span.into();
302298
if self.has_label && !self.span.is_dummy() {
303299
span.push_span_label(self.span, fluent::const_eval_frame_note_last);
304300
}
305-
let msg = f(diag, fluent::const_eval_frame_note.into());
301+
let msg = diag.eagerly_translate(fluent::const_eval_frame_note);
306302
diag.span_note(span, msg);
307303
}
308304
}

Diff for: compiler/rustc_errors/src/diagnostic.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,9 @@ where
181181
Self: Sized,
182182
{
183183
/// Add a subdiagnostic to an existing diagnostic.
184-
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
185-
self.add_to_diag_with(diag, &|_, m| m);
186-
}
187-
188-
/// Add a subdiagnostic to an existing diagnostic where `f` is invoked on every message used
189-
/// (to optionally perform eager translation).
190-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
191-
self,
192-
diag: &mut Diag<'_, G>,
193-
f: &F,
194-
);
184+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>);
195185
}
196186

197-
pub trait SubdiagMessageOp<G: EmissionGuarantee> =
198-
Fn(&mut Diag<'_, G>, SubdiagMessage) -> SubdiagMessage;
199-
200187
/// Trait implemented by lint types. This should not be implemented manually. Instead, use
201188
/// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic].
202189
#[rustc_diagnostic_item = "LintDiagnostic"]
@@ -1227,15 +1214,21 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
12271214
/// interpolated variables).
12281215
#[rustc_lint_diagnostics]
12291216
pub fn subdiagnostic(&mut self, subdiagnostic: impl Subdiagnostic) -> &mut Self {
1230-
let dcx = self.dcx;
1231-
subdiagnostic.add_to_diag_with(self, &|diag, msg| {
1232-
let args = diag.args.iter();
1233-
let msg = diag.subdiagnostic_message_to_diagnostic_message(msg);
1234-
dcx.eagerly_translate(msg, args)
1235-
});
1217+
subdiagnostic.add_to_diag(self);
12361218
self
12371219
}
12381220

1221+
/// Fluent variables are not namespaced from each other, so when
1222+
/// `Diagnostic`s and `Subdiagnostic`s use the same variable name,
1223+
/// one value will clobber the other. Eagerly translating the
1224+
/// diagnostic uses the variables defined right then, before the
1225+
/// clobbering occurs.
1226+
pub fn eagerly_translate(&self, msg: impl Into<SubdiagMessage>) -> SubdiagMessage {
1227+
let args = self.args.iter();
1228+
let msg = self.subdiagnostic_message_to_diagnostic_message(msg.into());
1229+
self.dcx.eagerly_translate(msg, args)
1230+
}
1231+
12391232
with_fn! { with_span,
12401233
/// Add a span.
12411234
#[rustc_lint_diagnostics]

Diff for: compiler/rustc_errors/src/diagnostic_impls.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use {rustc_ast as ast, rustc_hir as hir};
1919
use crate::diagnostic::DiagLocation;
2020
use crate::{
2121
Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, ErrCode, IntoDiagArg, Level,
22-
SubdiagMessageOp, Subdiagnostic, fluent_generated as fluent,
22+
Subdiagnostic, fluent_generated as fluent,
2323
};
2424

2525
pub struct DiagArgFromDisplay<'a>(pub &'a dyn fmt::Display);
@@ -384,11 +384,7 @@ pub struct SingleLabelManySpans {
384384
pub label: &'static str,
385385
}
386386
impl Subdiagnostic for SingleLabelManySpans {
387-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
388-
self,
389-
diag: &mut Diag<'_, G>,
390-
_: &F,
391-
) {
387+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
392388
diag.span_labels(self.spans, self.label);
393389
}
394390
}

Diff for: compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub use codes::*;
4747
pub use diagnostic::{
4848
BugAbort, Diag, DiagArg, DiagArgMap, DiagArgName, DiagArgValue, DiagInner, DiagStyledString,
4949
Diagnostic, EmissionGuarantee, FatalAbort, IntoDiagArg, LintDiagnostic, StringPart, Subdiag,
50-
SubdiagMessageOp, Subdiagnostic,
50+
Subdiagnostic,
5151
};
5252
pub use diagnostic_impls::{
5353
DiagArgFromDisplay, DiagSymbolList, ElidedLifetimeInPathSubdiag, ExpectedLifetimeParameter,

Diff for: compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ declare_features! (
9595
(accepted, c_unwind, "1.81.0", Some(74990)),
9696
/// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
9797
(accepted, cfg_attr_multi, "1.33.0", Some(54881)),
98+
/// Allows the use of `#[cfg(<true/false>)]`.
99+
(accepted, cfg_boolean_literals, "CURRENT_RUSTC_VERSION", Some(131204)),
98100
/// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests.
99101
(accepted, cfg_doctest, "1.40.0", Some(62210)),
100102
/// Enables `#[cfg(panic = "...")]` config key.

Diff for: compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,6 @@ declare_features! (
391391
(unstable, async_trait_bounds, "1.85.0", Some(62290)),
392392
/// Allows using C-variadics.
393393
(unstable, c_variadic, "1.34.0", Some(44930)),
394-
/// Allows the use of `#[cfg(<true/false>)]`.
395-
(unstable, cfg_boolean_literals, "1.83.0", Some(131204)),
396394
/// Allows the use of `#[cfg(contract_checks)` to check if contract checks are enabled.
397395
(unstable, cfg_contract_checks, "1.86.0", Some(128044)),
398396
/// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.

Diff for: compiler/rustc_hir_typeck/src/errors.rs

+8-24
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::borrow::Cow;
55
use rustc_errors::codes::*;
66
use rustc_errors::{
77
Applicability, Diag, DiagArgValue, DiagSymbolList, EmissionGuarantee, IntoDiagArg, MultiSpan,
8-
SubdiagMessageOp, Subdiagnostic,
8+
Subdiagnostic,
99
};
1010
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
1111
use rustc_middle::ty::{self, Ty};
@@ -270,11 +270,7 @@ pub(crate) struct SuggestAnnotations {
270270
pub suggestions: Vec<SuggestAnnotation>,
271271
}
272272
impl Subdiagnostic for SuggestAnnotations {
273-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
274-
self,
275-
diag: &mut Diag<'_, G>,
276-
_: &F,
277-
) {
273+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
278274
if self.suggestions.is_empty() {
279275
return;
280276
}
@@ -337,11 +333,7 @@ pub(crate) struct TypeMismatchFruTypo {
337333
}
338334

339335
impl Subdiagnostic for TypeMismatchFruTypo {
340-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
341-
self,
342-
diag: &mut Diag<'_, G>,
343-
_f: &F,
344-
) {
336+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
345337
diag.arg("expr", self.expr.as_deref().unwrap_or("NONE"));
346338

347339
// Only explain that `a ..b` is a range if it's split up
@@ -599,11 +591,7 @@ pub(crate) struct RemoveSemiForCoerce {
599591
}
600592

601593
impl Subdiagnostic for RemoveSemiForCoerce {
602-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
603-
self,
604-
diag: &mut Diag<'_, G>,
605-
_f: &F,
606-
) {
594+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
607595
let mut multispan: MultiSpan = self.semi.into();
608596
multispan.push_span_label(self.expr, fluent::hir_typeck_remove_semi_for_coerce_expr);
609597
multispan.push_span_label(self.ret, fluent::hir_typeck_remove_semi_for_coerce_ret);
@@ -778,20 +766,16 @@ pub(crate) enum CastUnknownPointerSub {
778766
}
779767

780768
impl rustc_errors::Subdiagnostic for CastUnknownPointerSub {
781-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
782-
self,
783-
diag: &mut Diag<'_, G>,
784-
f: &F,
785-
) {
769+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
786770
match self {
787771
CastUnknownPointerSub::To(span) => {
788-
let msg = f(diag, crate::fluent_generated::hir_typeck_label_to);
772+
let msg = diag.eagerly_translate(fluent::hir_typeck_label_to);
789773
diag.span_label(span, msg);
790-
let msg = f(diag, crate::fluent_generated::hir_typeck_note);
774+
let msg = diag.eagerly_translate(fluent::hir_typeck_note);
791775
diag.note(msg);
792776
}
793777
CastUnknownPointerSub::From(span) => {
794-
let msg = f(diag, crate::fluent_generated::hir_typeck_label_from);
778+
let msg = diag.eagerly_translate(fluent::hir_typeck_label_from);
795779
diag.span_label(span, msg);
796780
}
797781
}

Diff for: compiler/rustc_lint/src/errors.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_errors::codes::*;
2-
use rustc_errors::{Diag, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic};
2+
use rustc_errors::{Diag, EmissionGuarantee, Subdiagnostic};
33
use rustc_macros::{Diagnostic, Subdiagnostic};
44
use rustc_session::lint::Level;
55
use rustc_span::{Span, Symbol};
@@ -26,11 +26,7 @@ pub(crate) enum OverruledAttributeSub {
2626
}
2727

2828
impl Subdiagnostic for OverruledAttributeSub {
29-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
30-
self,
31-
diag: &mut Diag<'_, G>,
32-
_f: &F,
33-
) {
29+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
3430
match self {
3531
OverruledAttributeSub::DefaultSource { id } => {
3632
diag.note(fluent::lint_default_source);

Diff for: compiler/rustc_lint/src/if_let_rescope.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use std::ops::ControlFlow;
33

44
use hir::intravisit::{self, Visitor};
55
use rustc_ast::Recovered;
6-
use rustc_errors::{
7-
Applicability, Diag, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic, SuggestionStyle,
8-
};
6+
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic, SuggestionStyle};
97
use rustc_hir::{self as hir, HirIdSet};
108
use rustc_macros::{LintDiagnostic, Subdiagnostic};
119
use rustc_middle::ty::adjustment::Adjust;
@@ -327,11 +325,7 @@ struct IfLetRescopeRewrite {
327325
}
328326

329327
impl Subdiagnostic for IfLetRescopeRewrite {
330-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
331-
self,
332-
diag: &mut Diag<'_, G>,
333-
f: &F,
334-
) {
328+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
335329
let mut suggestions = vec![];
336330
for match_head in self.match_heads {
337331
match match_head {
@@ -360,7 +354,7 @@ impl Subdiagnostic for IfLetRescopeRewrite {
360354
.chain(repeat('}').take(closing_brackets.count))
361355
.collect(),
362356
));
363-
let msg = f(diag, crate::fluent_generated::lint_suggestion);
357+
let msg = diag.eagerly_translate(crate::fluent_generated::lint_suggestion);
364358
diag.multipart_suggestion_with_style(
365359
msg,
366360
suggestions,

0 commit comments

Comments
 (0)