Skip to content

Commit 03eb454

Browse files
committed
Auto merge of #138155 - matthiaskrgr:rollup-xq5buio, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #137674 (Enable `f16` for LoongArch) - #138034 (library: Use `size_of` from the prelude instead of imported) - #138060 (Revert #138019 after further discussion about how hir-pretty printing should work) - #138073 (Break critical edges in inline asm before code generation) - #138107 (`librustdoc`: clippy fixes) - #138111 (Use `default_field_values` for `rustc_errors::Context`, `rustc_session::config::NextSolverConfig` and `rustc_session::config::ErrorOutputType`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 59a9b9e + acc7de6 commit 03eb454

File tree

145 files changed

+579
-691
lines changed

Some content is hidden

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

145 files changed

+579
-691
lines changed

compiler/rustc_errors/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![feature(associated_type_defaults)]
1515
#![feature(box_into_inner)]
1616
#![feature(box_patterns)]
17+
#![feature(default_field_values)]
1718
#![feature(error_reporter)]
1819
#![feature(if_let_guard)]
1920
#![feature(let_chains)]

compiler/rustc_errors/src/markdown/parse.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ type ParseResult<'a> = Option<Parsed<'a>>;
4040

4141
/// Parsing context
4242
#[derive(Clone, Copy, Debug, PartialEq)]
43+
// The default values are the most common setting for non top-level parsing: not top block, not at
44+
// line start (yes leading whitespace, not escaped).
4345
struct Context {
4446
/// If true, we are at a the topmost level (not recursing a nested tt)
45-
top_block: bool,
47+
top_block: bool = false,
4648
/// Previous character
47-
prev: Prev,
49+
prev: Prev = Prev::Whitespace,
4850
}
4951

5052
/// Character class preceding this one
@@ -57,14 +59,6 @@ enum Prev {
5759
Any,
5860
}
5961

60-
impl Default for Context {
61-
/// Most common setting for non top-level parsing: not top block, not at
62-
/// line start (yes leading whitespace, not escaped)
63-
fn default() -> Self {
64-
Self { top_block: false, prev: Prev::Whitespace }
65-
}
66-
}
67-
6862
/// Flags to simple parser function
6963
#[derive(Clone, Copy, Debug, PartialEq)]
7064
enum ParseOpt {
@@ -248,7 +242,7 @@ fn parse_heading(buf: &[u8]) -> ParseResult<'_> {
248242
}
249243

250244
let (txt, rest) = parse_to_newline(&buf[1..]);
251-
let ctx = Context { top_block: false, prev: Prev::Whitespace };
245+
let ctx = Context { .. };
252246
let stream = parse_recursive(txt, ctx);
253247

254248
Some((MdTree::Heading(level.try_into().unwrap(), stream), rest))
@@ -257,7 +251,7 @@ fn parse_heading(buf: &[u8]) -> ParseResult<'_> {
257251
/// Bulleted list
258252
fn parse_unordered_li(buf: &[u8]) -> Parsed<'_> {
259253
let (txt, rest) = get_indented_section(&buf[2..]);
260-
let ctx = Context { top_block: false, prev: Prev::Whitespace };
254+
let ctx = Context { .. };
261255
let stream = parse_recursive(trim_ascii_start(txt), ctx);
262256
(MdTree::UnorderedListItem(stream), rest)
263257
}
@@ -266,7 +260,7 @@ fn parse_unordered_li(buf: &[u8]) -> Parsed<'_> {
266260
fn parse_ordered_li(buf: &[u8]) -> Parsed<'_> {
267261
let (num, pos) = ord_list_start(buf).unwrap(); // success tested in caller
268262
let (txt, rest) = get_indented_section(&buf[pos..]);
269-
let ctx = Context { top_block: false, prev: Prev::Whitespace };
263+
let ctx = Context { .. };
270264
let stream = parse_recursive(trim_ascii_start(txt), ctx);
271265
(MdTree::OrderedListItem(num, stream), rest)
272266
}

compiler/rustc_hir_pretty/src/lib.rs

-74
Original file line numberDiff line numberDiff line change
@@ -117,80 +117,6 @@ impl<'a> State<'a> {
117117
));
118118
self.hardbreak()
119119
}
120-
hir::Attribute::Parsed(AttributeKind::Deprecation { deprecation, .. }) => {
121-
self.word("#[deprecated");
122-
123-
// There are three possible forms here:
124-
// 1. a form with explicit components like
125-
// `#[deprecated(since = "1.2.3", note = "some note", suggestion = "something")]`
126-
// where each component may be present or absent.
127-
// 2. `#[deprecated = "message"]`
128-
// 3. `#[deprecated]`
129-
//
130-
// Let's figure out which we need.
131-
// If there's a `since` or `suggestion` value, we're definitely in form 1.
132-
if matches!(
133-
deprecation.since,
134-
rustc_attr_parsing::DeprecatedSince::RustcVersion(..)
135-
| rustc_attr_parsing::DeprecatedSince::Future
136-
| rustc_attr_parsing::DeprecatedSince::NonStandard(..)
137-
) || deprecation.suggestion.is_some()
138-
{
139-
self.word("(");
140-
let mut use_comma = false;
141-
142-
match &deprecation.since {
143-
rustc_attr_parsing::DeprecatedSince::RustcVersion(rustc_version) => {
144-
self.word("since = \"");
145-
self.word(format!(
146-
"{}.{}.{}",
147-
rustc_version.major, rustc_version.minor, rustc_version.patch
148-
));
149-
self.word("\"");
150-
use_comma = true;
151-
}
152-
rustc_attr_parsing::DeprecatedSince::Future => {
153-
self.word("since = \"future\"");
154-
use_comma = true;
155-
}
156-
rustc_attr_parsing::DeprecatedSince::NonStandard(symbol) => {
157-
self.word("since = \"");
158-
self.word(symbol.to_ident_string());
159-
self.word("\"");
160-
use_comma = true;
161-
}
162-
_ => {}
163-
}
164-
165-
if let Some(note) = &deprecation.note {
166-
if use_comma {
167-
self.word(", ");
168-
}
169-
self.word("note = \"");
170-
self.word(note.to_ident_string());
171-
self.word("\"");
172-
use_comma = true;
173-
}
174-
175-
if let Some(suggestion) = &deprecation.suggestion {
176-
if use_comma {
177-
self.word(", ");
178-
}
179-
self.word("suggestion = \"");
180-
self.word(suggestion.to_ident_string());
181-
self.word("\"");
182-
}
183-
} else if let Some(note) = &deprecation.note {
184-
// We're in form 2: `#[deprecated = "message"]`.
185-
self.word(" = \"");
186-
self.word(note.to_ident_string());
187-
self.word("\"");
188-
} else {
189-
// We're in form 3: `#[deprecated]`. Nothing to do here.
190-
}
191-
192-
self.word("]");
193-
}
194120
hir::Attribute::Parsed(pa) => {
195121
self.word("#[attr=\"");
196122
pa.print_attribute(self);

compiler/rustc_mir_transform/src/add_call_guards.rs

+44-17
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,51 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
4040
let mut new_blocks = Vec::new();
4141

4242
let cur_len = body.basic_blocks.len();
43+
let mut new_block = |source_info: SourceInfo, is_cleanup: bool, target: BasicBlock| {
44+
let block = BasicBlockData {
45+
statements: vec![],
46+
is_cleanup,
47+
terminator: Some(Terminator { source_info, kind: TerminatorKind::Goto { target } }),
48+
};
49+
let idx = cur_len + new_blocks.len();
50+
new_blocks.push(block);
51+
BasicBlock::new(idx)
52+
};
4353

4454
for block in body.basic_blocks_mut() {
4555
match block.terminator {
4656
Some(Terminator {
4757
kind: TerminatorKind::Call { target: Some(ref mut destination), unwind, .. },
4858
source_info,
4959
}) if pred_count[*destination] > 1
50-
&& (matches!(
51-
unwind,
52-
UnwindAction::Cleanup(_) | UnwindAction::Terminate(_)
53-
) || self == &AllCallEdges) =>
60+
&& (generates_invoke(unwind) || self == &AllCallEdges) =>
5461
{
5562
// It's a critical edge, break it
56-
let call_guard = BasicBlockData {
57-
statements: vec![],
58-
is_cleanup: block.is_cleanup,
59-
terminator: Some(Terminator {
60-
source_info,
61-
kind: TerminatorKind::Goto { target: *destination },
62-
}),
63-
};
64-
65-
// Get the index it will be when inserted into the MIR
66-
let idx = cur_len + new_blocks.len();
67-
new_blocks.push(call_guard);
68-
*destination = BasicBlock::new(idx);
63+
*destination = new_block(source_info, block.is_cleanup, *destination);
64+
}
65+
Some(Terminator {
66+
kind:
67+
TerminatorKind::InlineAsm {
68+
asm_macro: InlineAsmMacro::Asm,
69+
ref mut targets,
70+
ref operands,
71+
unwind,
72+
..
73+
},
74+
source_info,
75+
}) if self == &CriticalCallEdges => {
76+
let has_outputs = operands.iter().any(|op| {
77+
matches!(op, InlineAsmOperand::InOut { .. } | InlineAsmOperand::Out { .. })
78+
});
79+
let has_labels =
80+
operands.iter().any(|op| matches!(op, InlineAsmOperand::Label { .. }));
81+
if has_outputs && (has_labels || generates_invoke(unwind)) {
82+
for target in targets.iter_mut() {
83+
if pred_count[*target] > 1 {
84+
*target = new_block(source_info, block.is_cleanup, *target);
85+
}
86+
}
87+
}
6988
}
7089
_ => {}
7190
}
@@ -80,3 +99,11 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
8099
true
81100
}
82101
}
102+
103+
/// Returns true if this unwind action is code generated as an invoke as opposed to a call.
104+
fn generates_invoke(unwind: UnwindAction) -> bool {
105+
match unwind {
106+
UnwindAction::Continue | UnwindAction::Unreachable => false,
107+
UnwindAction::Cleanup(_) | UnwindAction::Terminate(_) => true,
108+
}
109+
}

compiler/rustc_session/src/config.rs

+24-32
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,14 @@ impl OutputType {
681681
}
682682

683683
/// The type of diagnostics output to generate.
684-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
684+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
685685
pub enum ErrorOutputType {
686686
/// Output meant for the consumption of humans.
687-
HumanReadable(HumanReadableErrorType, ColorConfig),
687+
#[default]
688+
HumanReadable {
689+
kind: HumanReadableErrorType = HumanReadableErrorType::Default,
690+
color_config: ColorConfig = ColorConfig::Auto,
691+
},
688692
/// Output that's consumed by other tools such as `rustfix` or the `RLS`.
689693
Json {
690694
/// Render the JSON in a human readable way (with indents and newlines).
@@ -696,12 +700,6 @@ pub enum ErrorOutputType {
696700
},
697701
}
698702

699-
impl Default for ErrorOutputType {
700-
fn default() -> Self {
701-
Self::HumanReadable(HumanReadableErrorType::Default, ColorConfig::Auto)
702-
}
703-
}
704-
705703
#[derive(Clone, Hash, Debug)]
706704
pub enum ResolveDocLinks {
707705
/// Do not resolve doc links.
@@ -898,18 +896,13 @@ pub enum PrintKind {
898896
DeploymentTarget,
899897
}
900898

901-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
899+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Default)]
902900
pub struct NextSolverConfig {
903901
/// Whether the new trait solver should be enabled in coherence.
904-
pub coherence: bool,
902+
pub coherence: bool = true,
905903
/// Whether the new trait solver should be enabled everywhere.
906904
/// This is only `true` if `coherence` is also enabled.
907-
pub globally: bool,
908-
}
909-
impl Default for NextSolverConfig {
910-
fn default() -> Self {
911-
NextSolverConfig { coherence: true, globally: false }
912-
}
905+
pub globally: bool = false,
913906
}
914907

915908
#[derive(Clone)]
@@ -1825,7 +1818,7 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
18251818
pub fn parse_error_format(
18261819
early_dcx: &mut EarlyDiagCtxt,
18271820
matches: &getopts::Matches,
1828-
color: ColorConfig,
1821+
color_config: ColorConfig,
18291822
json_color: ColorConfig,
18301823
json_rendered: HumanReadableErrorType,
18311824
) -> ErrorOutputType {
@@ -1835,35 +1828,34 @@ pub fn parse_error_format(
18351828
// `opt_present` because the latter will panic.
18361829
let error_format = if matches.opts_present(&["error-format".to_owned()]) {
18371830
match matches.opt_str("error-format").as_deref() {
1838-
None | Some("human") => {
1839-
ErrorOutputType::HumanReadable(HumanReadableErrorType::Default, color)
1840-
}
1841-
Some("human-annotate-rs") => {
1842-
ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet, color)
1843-
}
1831+
None | Some("human") => ErrorOutputType::HumanReadable { color_config, .. },
1832+
Some("human-annotate-rs") => ErrorOutputType::HumanReadable {
1833+
kind: HumanReadableErrorType::AnnotateSnippet,
1834+
color_config,
1835+
},
18441836
Some("json") => {
18451837
ErrorOutputType::Json { pretty: false, json_rendered, color_config: json_color }
18461838
}
18471839
Some("pretty-json") => {
18481840
ErrorOutputType::Json { pretty: true, json_rendered, color_config: json_color }
18491841
}
1850-
Some("short") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Short, color),
1851-
Some("human-unicode") => {
1852-
ErrorOutputType::HumanReadable(HumanReadableErrorType::Unicode, color)
1842+
Some("short") => {
1843+
ErrorOutputType::HumanReadable { kind: HumanReadableErrorType::Short, color_config }
18531844
}
1845+
Some("human-unicode") => ErrorOutputType::HumanReadable {
1846+
kind: HumanReadableErrorType::Unicode,
1847+
color_config,
1848+
},
18541849
Some(arg) => {
1855-
early_dcx.set_error_format(ErrorOutputType::HumanReadable(
1856-
HumanReadableErrorType::Default,
1857-
color,
1858-
));
1850+
early_dcx.set_error_format(ErrorOutputType::HumanReadable { color_config, .. });
18591851
early_dcx.early_fatal(format!(
18601852
"argument for `--error-format` must be `human`, `human-annotate-rs`, \
18611853
`human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
18621854
))
18631855
}
18641856
}
18651857
} else {
1866-
ErrorOutputType::HumanReadable(HumanReadableErrorType::Default, color)
1858+
ErrorOutputType::HumanReadable { color_config, .. }
18671859
};
18681860

18691861
match error_format {
@@ -1918,7 +1910,7 @@ fn check_error_format_stability(
19181910
}
19191911
let format = match format {
19201912
ErrorOutputType::Json { pretty: true, .. } => "pretty-json",
1921-
ErrorOutputType::HumanReadable(format, _) => match format {
1913+
ErrorOutputType::HumanReadable { kind, .. } => match kind {
19221914
HumanReadableErrorType::AnnotateSnippet => "human-annotate-rs",
19231915
HumanReadableErrorType::Unicode => "human-unicode",
19241916
_ => return,

compiler/rustc_session/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// tidy-alphabetical-start
22
#![allow(internal_features)]
3+
#![feature(default_field_values)]
34
#![feature(iter_intersperse)]
45
#![feature(let_chains)]
56
#![feature(rustc_attrs)]

compiler/rustc_session/src/session.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ fn default_emitter(
913913
let source_map = if sopts.unstable_opts.link_only { None } else { Some(source_map) };
914914

915915
match sopts.error_format {
916-
config::ErrorOutputType::HumanReadable(kind, color_config) => {
916+
config::ErrorOutputType::HumanReadable { kind, color_config } => {
917917
let short = kind.short();
918918

919919
if let HumanReadableErrorType::AnnotateSnippet = kind {
@@ -1430,7 +1430,7 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
14301430
let fallback_bundle =
14311431
fallback_fluent_bundle(vec![rustc_errors::DEFAULT_LOCALE_RESOURCE], false);
14321432
let emitter: Box<DynEmitter> = match output {
1433-
config::ErrorOutputType::HumanReadable(kind, color_config) => {
1433+
config::ErrorOutputType::HumanReadable { kind, color_config } => {
14341434
let short = kind.short();
14351435
Box::new(
14361436
HumanEmitter::new(stderr_destination(color_config), fallback_bundle)

0 commit comments

Comments
 (0)