Skip to content

Commit c0983a9

Browse files
committed
Auto merge of #102975 - Dylan-DPC:rollup-vzuwsh2, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #102623 (translation: eager translation) - #102719 (Enforce alphabetical sorting with tidy) - #102830 (Unify `tcx.constness` query and param env constness checks) - #102883 (Fix stabilization of `feature(half_open_range_patterns)`) - #102927 (Fix `let` keyword removal suggestion in structs) - #102936 (rustdoc: remove unused CSS `nav.sum`) - #102940 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 538f118 + f2c4810 commit c0983a9

File tree

60 files changed

+957
-459
lines changed

Some content is hidden

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

60 files changed

+957
-459
lines changed

Diff for: compiler/rustc_ast/src/ast.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,7 @@ pub type ForeignItem = Item<ForeignItemKind>;
30393039
mod size_asserts {
30403040
use super::*;
30413041
use rustc_data_structures::static_assert_size;
3042-
// These are in alphabetical order, which is easy to maintain.
3042+
// tidy-alphabetical-start
30433043
static_assert_size!(AssocItem, 104);
30443044
static_assert_size!(AssocItemKind, 32);
30453045
static_assert_size!(Attribute, 32);
@@ -3060,11 +3060,12 @@ mod size_asserts {
30603060
static_assert_size!(Local, 72);
30613061
static_assert_size!(Param, 40);
30623062
static_assert_size!(Pat, 120);
3063-
static_assert_size!(PatKind, 96);
30643063
static_assert_size!(Path, 40);
30653064
static_assert_size!(PathSegment, 24);
3065+
static_assert_size!(PatKind, 96);
30663066
static_assert_size!(Stmt, 32);
30673067
static_assert_size!(StmtKind, 16);
30683068
static_assert_size!(Ty, 96);
30693069
static_assert_size!(TyKind, 72);
3070+
// tidy-alphabetical-end
30703071
}

Diff for: compiler/rustc_ast/src/token.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,11 @@ where
889889
mod size_asserts {
890890
use super::*;
891891
use rustc_data_structures::static_assert_size;
892-
// These are in alphabetical order, which is easy to maintain.
892+
// tidy-alphabetical-start
893893
static_assert_size!(Lit, 12);
894894
static_assert_size!(LitKind, 2);
895895
static_assert_size!(Nonterminal, 16);
896896
static_assert_size!(Token, 24);
897897
static_assert_size!(TokenKind, 16);
898+
// tidy-alphabetical-end
898899
}

Diff for: compiler/rustc_ast/src/tokenstream.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,11 @@ impl DelimSpan {
646646
mod size_asserts {
647647
use super::*;
648648
use rustc_data_structures::static_assert_size;
649-
// These are in alphabetical order, which is easy to maintain.
649+
// tidy-alphabetical-start
650650
static_assert_size!(AttrTokenStream, 8);
651651
static_assert_size!(AttrTokenTree, 32);
652652
static_assert_size!(LazyAttrTokenStream, 8);
653653
static_assert_size!(TokenStream, 8);
654654
static_assert_size!(TokenTree, 32);
655+
// tidy-alphabetical-end
655656
}

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay};
1+
use rustc_errors::{
2+
fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay,
3+
SubdiagnosticMessage,
4+
};
25
use rustc_macros::{Diagnostic, Subdiagnostic};
36
use rustc_span::{symbol::Ident, Span, Symbol};
47

@@ -19,7 +22,10 @@ pub struct UseAngleBrackets {
1922
}
2023

2124
impl AddToDiagnostic for UseAngleBrackets {
22-
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
25+
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
26+
where
27+
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
28+
{
2329
diag.multipart_suggestion(
2430
fluent::ast_lowering::use_angle_brackets,
2531
vec![(self.open_param, String::from("<")), (self.close_param, String::from(">"))],
@@ -69,7 +75,10 @@ pub enum AssocTyParenthesesSub {
6975
}
7076

7177
impl AddToDiagnostic for AssocTyParenthesesSub {
72-
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
78+
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
79+
where
80+
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
81+
{
7382
match self {
7483
Self::Empty { parentheses_span } => diag.multipart_suggestion(
7584
fluent::ast_lowering::remove_parentheses,

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Errors emitted by ast_passes.
22
3-
use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic};
3+
use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic, SubdiagnosticMessage};
44
use rustc_macros::{Diagnostic, Subdiagnostic};
55
use rustc_span::{Span, Symbol};
66

@@ -17,7 +17,10 @@ pub struct ForbiddenLet {
1717
}
1818

1919
impl AddToDiagnostic for ForbiddenLetReason {
20-
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
20+
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
21+
where
22+
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
23+
{
2124
match self {
2225
Self::GenericForbidden => {}
2326
Self::NotSupportedOr(span) => {
@@ -228,7 +231,10 @@ pub struct ExternBlockSuggestion {
228231
}
229232

230233
impl AddToDiagnostic for ExternBlockSuggestion {
231-
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
234+
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
235+
where
236+
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
237+
{
232238
let start_suggestion = if let Some(abi) = self.abi {
233239
format!("extern \"{}\" {{", abi)
234240
} else {

Diff for: compiler/rustc_codegen_ssa/src/back/write.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ use rustc_data_structures::profiling::TimingGuard;
1515
use rustc_data_structures::profiling::VerboseTimingGuard;
1616
use rustc_data_structures::sync::Lrc;
1717
use rustc_errors::emitter::Emitter;
18-
use rustc_errors::{translation::Translate, DiagnosticId, FatalError, Handler, Level};
18+
use rustc_errors::{
19+
translation::{to_fluent_args, Translate},
20+
DiagnosticId, FatalError, Handler, Level,
21+
};
1922
use rustc_fs_util::link_or_copy;
2023
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
2124
use rustc_incremental::{
@@ -1740,7 +1743,7 @@ impl Translate for SharedEmitter {
17401743

17411744
impl Emitter for SharedEmitter {
17421745
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
1743-
let fluent_args = self.to_fluent_args(diag.args());
1746+
let fluent_args = to_fluent_args(diag.args());
17441747
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
17451748
msg: self.translate_messages(&diag.message, &fluent_args).to_string(),
17461749
code: diag.code.clone(),

Diff for: compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+56-16
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
2525
/// report whether said intrinsic has a `rustc_const_{un,}stable` attribute. Otherwise, return
2626
/// `Constness::NotConst`.
2727
fn constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness {
28-
let def_id = def_id.expect_local();
29-
let node = tcx.hir().get_by_def_id(def_id);
30-
31-
match node {
28+
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
29+
match tcx.hir().get(hir_id) {
3230
hir::Node::Ctor(_) => hir::Constness::Const,
33-
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) => impl_.constness,
31+
3432
hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) => {
3533
// Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other
3634
// foreign items cannot be evaluated at compile-time.
@@ -41,20 +39,62 @@ fn constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness {
4139
};
4240
if is_const { hir::Constness::Const } else { hir::Constness::NotConst }
4341
}
44-
_ => {
45-
if let Some(fn_kind) = node.fn_kind() {
46-
if fn_kind.constness() == hir::Constness::Const {
47-
return hir::Constness::Const;
48-
}
4942

50-
// If the function itself is not annotated with `const`, it may still be a `const fn`
51-
// if it resides in a const trait impl.
52-
let is_const = is_parent_const_impl_raw(tcx, def_id);
53-
if is_const { hir::Constness::Const } else { hir::Constness::NotConst }
54-
} else {
55-
hir::Constness::NotConst
43+
hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. })
44+
if tcx.is_const_default_method(def_id) =>
45+
{
46+
hir::Constness::Const
47+
}
48+
49+
hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(..), .. })
50+
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Static(..), .. })
51+
| hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Const(..), .. })
52+
| hir::Node::AnonConst(_)
53+
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(..), .. })
54+
| hir::Node::ImplItem(hir::ImplItem {
55+
kind:
56+
hir::ImplItemKind::Fn(
57+
hir::FnSig {
58+
header: hir::FnHeader { constness: hir::Constness::Const, .. },
59+
..
60+
},
61+
..,
62+
),
63+
..
64+
}) => hir::Constness::Const,
65+
66+
hir::Node::ImplItem(hir::ImplItem {
67+
kind: hir::ImplItemKind::Type(..) | hir::ImplItemKind::Fn(..),
68+
..
69+
}) => {
70+
let parent_hir_id = tcx.hir().get_parent_node(hir_id);
71+
match tcx.hir().get(parent_hir_id) {
72+
hir::Node::Item(hir::Item {
73+
kind: hir::ItemKind::Impl(hir::Impl { constness, .. }),
74+
..
75+
}) => *constness,
76+
_ => span_bug!(
77+
tcx.def_span(parent_hir_id.owner),
78+
"impl item's parent node is not an impl",
79+
),
5680
}
5781
}
82+
83+
hir::Node::Item(hir::Item {
84+
kind: hir::ItemKind::Fn(hir::FnSig { header: hir::FnHeader { constness, .. }, .. }, ..),
85+
..
86+
})
87+
| hir::Node::TraitItem(hir::TraitItem {
88+
kind:
89+
hir::TraitItemKind::Fn(hir::FnSig { header: hir::FnHeader { constness, .. }, .. }, ..),
90+
..
91+
})
92+
| hir::Node::Item(hir::Item {
93+
kind: hir::ItemKind::Impl(hir::Impl { constness, .. }),
94+
..
95+
}) => *constness,
96+
97+
_ => hir::Constness::NotConst,
5898
}
5999
}
60100

Diff for: compiler/rustc_const_eval/src/interpret/operand.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
788788
mod size_asserts {
789789
use super::*;
790790
use rustc_data_structures::static_assert_size;
791-
// These are in alphabetical order, which is easy to maintain.
791+
// tidy-alphabetical-start
792792
static_assert_size!(Immediate, 48);
793793
static_assert_size!(ImmTy<'_>, 64);
794794
static_assert_size!(Operand, 56);
795795
static_assert_size!(OpTy<'_>, 80);
796+
// tidy-alphabetical-end
796797
}

Diff for: compiler/rustc_const_eval/src/interpret/place.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,11 @@ where
892892
mod size_asserts {
893893
use super::*;
894894
use rustc_data_structures::static_assert_size;
895-
// These are in alphabetical order, which is easy to maintain.
896-
static_assert_size!(MemPlaceMeta, 24);
895+
// tidy-alphabetical-start
897896
static_assert_size!(MemPlace, 40);
897+
static_assert_size!(MemPlaceMeta, 24);
898898
static_assert_size!(MPlaceTy<'_>, 64);
899899
static_assert_size!(Place, 40);
900900
static_assert_size!(PlaceTy<'_>, 64);
901+
// tidy-alphabetical-end
901902
}

Diff for: compiler/rustc_error_messages/locales/en-US/query_system.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ query_system_cycle_usage = cycle used when {$usage}
1212
1313
query_system_cycle_stack_single = ...which immediately requires {$stack_bottom} again
1414
15+
query_system_cycle_stack_middle = ...which requires {$desc}...
16+
1517
query_system_cycle_stack_multiple = ...which again requires {$stack_bottom}, completing the cycle
1618
1719
query_system_cycle_recursive_ty_alias = type aliases cannot be recursive

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

+30-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub use unic_langid::{langid, LanguageIdentifier};
3535

3636
// Generates `DEFAULT_LOCALE_RESOURCES` static and `fluent_generated` module.
3737
fluent_messages! {
38+
// tidy-alphabetical-start
3839
ast_lowering => "../locales/en-US/ast_lowering.ftl",
3940
ast_passes => "../locales/en-US/ast_passes.ftl",
4041
attr => "../locales/en-US/attr.ftl",
@@ -64,6 +65,7 @@ fluent_messages! {
6465
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",
6566
trait_selection => "../locales/en-US/trait_selection.ftl",
6667
ty_utils => "../locales/en-US/ty_utils.ftl",
68+
// tidy-alphabetical-end
6769
}
6870

6971
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};
@@ -277,6 +279,18 @@ pub enum SubdiagnosticMessage {
277279
/// Non-translatable diagnostic message.
278280
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
279281
Str(String),
282+
/// Translatable message which has already been translated eagerly.
283+
///
284+
/// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
285+
/// be instantiated multiple times with different values. As translation normally happens
286+
/// immediately prior to emission, after the diagnostic and subdiagnostic derive logic has run,
287+
/// the setting of diagnostic arguments in the derived code will overwrite previous variable
288+
/// values and only the final value will be set when translation occurs - resulting in
289+
/// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
290+
/// happening immediately after the subdiagnostic derive's logic has been run. This variant
291+
/// stores messages which have been translated eagerly.
292+
// FIXME(#100717): can a `Cow<'static, str>` be used here?
293+
Eager(String),
280294
/// Identifier of a Fluent message. Instances of this variant are generated by the
281295
/// `Subdiagnostic` derive.
282296
FluentIdentifier(FluentId),
@@ -304,8 +318,20 @@ impl<S: Into<String>> From<S> for SubdiagnosticMessage {
304318
#[rustc_diagnostic_item = "DiagnosticMessage"]
305319
pub enum DiagnosticMessage {
306320
/// Non-translatable diagnostic message.
307-
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
321+
// FIXME(#100717): can a `Cow<'static, str>` be used here?
308322
Str(String),
323+
/// Translatable message which has already been translated eagerly.
324+
///
325+
/// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
326+
/// be instantiated multiple times with different values. As translation normally happens
327+
/// immediately prior to emission, after the diagnostic and subdiagnostic derive logic has run,
328+
/// the setting of diagnostic arguments in the derived code will overwrite previous variable
329+
/// values and only the final value will be set when translation occurs - resulting in
330+
/// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
331+
/// happening immediately after the subdiagnostic derive's logic has been run. This variant
332+
/// stores messages which have been translated eagerly.
333+
// FIXME(#100717): can a `Cow<'static, str>` be used here?
334+
Eager(String),
309335
/// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic
310336
/// message.
311337
///
@@ -324,6 +350,7 @@ impl DiagnosticMessage {
324350
pub fn with_subdiagnostic_message(&self, sub: SubdiagnosticMessage) -> Self {
325351
let attr = match sub {
326352
SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s),
353+
SubdiagnosticMessage::Eager(s) => return DiagnosticMessage::Eager(s),
327354
SubdiagnosticMessage::FluentIdentifier(id) => {
328355
return DiagnosticMessage::FluentIdentifier(id, None);
329356
}
@@ -332,6 +359,7 @@ impl DiagnosticMessage {
332359

333360
match self {
334361
DiagnosticMessage::Str(s) => DiagnosticMessage::Str(s.clone()),
362+
DiagnosticMessage::Eager(s) => DiagnosticMessage::Eager(s.clone()),
335363
DiagnosticMessage::FluentIdentifier(id, _) => {
336364
DiagnosticMessage::FluentIdentifier(id.clone(), Some(attr))
337365
}
@@ -367,6 +395,7 @@ impl Into<SubdiagnosticMessage> for DiagnosticMessage {
367395
fn into(self) -> SubdiagnosticMessage {
368396
match self {
369397
DiagnosticMessage::Str(s) => SubdiagnosticMessage::Str(s),
398+
DiagnosticMessage::Eager(s) => SubdiagnosticMessage::Eager(s),
370399
DiagnosticMessage::FluentIdentifier(id, None) => {
371400
SubdiagnosticMessage::FluentIdentifier(id)
372401
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
use crate::emitter::FileWithAnnotatedLines;
99
use crate::snippet::Line;
10-
use crate::translation::Translate;
10+
use crate::translation::{to_fluent_args, Translate};
1111
use crate::{
1212
CodeSuggestion, Diagnostic, DiagnosticId, DiagnosticMessage, Emitter, FluentBundle,
1313
LazyFallbackBundle, Level, MultiSpan, Style, SubDiagnostic,
@@ -46,7 +46,7 @@ impl Translate for AnnotateSnippetEmitterWriter {
4646
impl Emitter for AnnotateSnippetEmitterWriter {
4747
/// The entry point for the diagnostics generation
4848
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
49-
let fluent_args = self.to_fluent_args(diag.args());
49+
let fluent_args = to_fluent_args(diag.args());
5050

5151
let mut children = diag.children.clone();
5252
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag, &fluent_args);

0 commit comments

Comments
 (0)