Skip to content

Rollup of 6 pull requests #138155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
30703af
Enable `f16` for LoongArch
heiher Feb 26, 2025
2a4204b
Use default field values in `markdown::parse::Context`
estebank Mar 3, 2025
aae7a3c
Use default field values for `config::NextSolverConfig`
estebank Mar 3, 2025
0c4eaa5
Use default field values for `ErrorOutputType`
estebank Mar 3, 2025
8391c08
Revert #138019 after further discussion about adding this exception i…
jdonszelmann Mar 5, 2025
c5b7a9c
Factor out edge breaking code
tmiasko Mar 4, 2025
ccfbfe2
`x clippy src/librustdoc --fix`
yotamofek Mar 6, 2025
329b8a3
Implement `Ord` by-hand instead of `PartialOrd` for `Link`
yotamofek Mar 1, 2025
5d25922
Manual, post-`clippy --fix` cleanups
yotamofek Mar 1, 2025
5c1733e
Break critical edges in inline asm before code generation
tmiasko Mar 5, 2025
02d7fc1
Factor out check whether an unwind action generates invoke
tmiasko Mar 6, 2025
988eb19
library: Use size_of from the prelude instead of imported
thaliaarchi Mar 5, 2025
5dfa2f5
Use turbofish for size_of<T> and align_of<T> in docs
thaliaarchi Mar 5, 2025
6e7d135
Rollup merge of #137674 - heiher:enable-f16-loong, r=tgross35
matthiaskrgr Mar 7, 2025
b834632
Rollup merge of #138034 - thaliaarchi:use-prelude-size-of, r=tgross35
matthiaskrgr Mar 7, 2025
f42c933
Rollup merge of #138060 - jdonszelmann:revert-138019, r=compiler-errors
matthiaskrgr Mar 7, 2025
1155f01
Rollup merge of #138073 - tmiasko:inline-asm-critical-edges, r=bjorn3
matthiaskrgr Mar 7, 2025
4b6a22d
Rollup merge of #138107 - yotamofek:pr/rustdoc/clippy, r=GuillaumeGomez
matthiaskrgr Mar 7, 2025
acc7de6
Rollup merge of #138111 - estebank:use-dfv, r=nnethercote
matthiaskrgr Mar 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![feature(associated_type_defaults)]
#![feature(box_into_inner)]
#![feature(box_patterns)]
#![feature(default_field_values)]
#![feature(error_reporter)]
#![feature(if_let_guard)]
#![feature(let_chains)]
Expand Down
20 changes: 7 additions & 13 deletions compiler/rustc_errors/src/markdown/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ type ParseResult<'a> = Option<Parsed<'a>>;

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

/// Character class preceding this one
Expand All @@ -57,14 +59,6 @@ enum Prev {
Any,
}

impl Default for Context {
/// Most common setting for non top-level parsing: not top block, not at
/// line start (yes leading whitespace, not escaped)
fn default() -> Self {
Self { top_block: false, prev: Prev::Whitespace }
}
}

/// Flags to simple parser function
#[derive(Clone, Copy, Debug, PartialEq)]
enum ParseOpt {
Expand Down Expand Up @@ -248,7 +242,7 @@ fn parse_heading(buf: &[u8]) -> ParseResult<'_> {
}

let (txt, rest) = parse_to_newline(&buf[1..]);
let ctx = Context { top_block: false, prev: Prev::Whitespace };
let ctx = Context { .. };
let stream = parse_recursive(txt, ctx);

Some((MdTree::Heading(level.try_into().unwrap(), stream), rest))
Expand All @@ -257,7 +251,7 @@ fn parse_heading(buf: &[u8]) -> ParseResult<'_> {
/// Bulleted list
fn parse_unordered_li(buf: &[u8]) -> Parsed<'_> {
let (txt, rest) = get_indented_section(&buf[2..]);
let ctx = Context { top_block: false, prev: Prev::Whitespace };
let ctx = Context { .. };
let stream = parse_recursive(trim_ascii_start(txt), ctx);
(MdTree::UnorderedListItem(stream), rest)
}
Expand All @@ -266,7 +260,7 @@ fn parse_unordered_li(buf: &[u8]) -> Parsed<'_> {
fn parse_ordered_li(buf: &[u8]) -> Parsed<'_> {
let (num, pos) = ord_list_start(buf).unwrap(); // success tested in caller
let (txt, rest) = get_indented_section(&buf[pos..]);
let ctx = Context { top_block: false, prev: Prev::Whitespace };
let ctx = Context { .. };
let stream = parse_recursive(trim_ascii_start(txt), ctx);
(MdTree::OrderedListItem(num, stream), rest)
}
Expand Down
74 changes: 0 additions & 74 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,80 +117,6 @@ impl<'a> State<'a> {
));
self.hardbreak()
}
hir::Attribute::Parsed(AttributeKind::Deprecation { deprecation, .. }) => {
self.word("#[deprecated");

// There are three possible forms here:
// 1. a form with explicit components like
// `#[deprecated(since = "1.2.3", note = "some note", suggestion = "something")]`
// where each component may be present or absent.
// 2. `#[deprecated = "message"]`
// 3. `#[deprecated]`
//
// Let's figure out which we need.
// If there's a `since` or `suggestion` value, we're definitely in form 1.
if matches!(
deprecation.since,
rustc_attr_parsing::DeprecatedSince::RustcVersion(..)
| rustc_attr_parsing::DeprecatedSince::Future
| rustc_attr_parsing::DeprecatedSince::NonStandard(..)
) || deprecation.suggestion.is_some()
{
self.word("(");
let mut use_comma = false;

match &deprecation.since {
rustc_attr_parsing::DeprecatedSince::RustcVersion(rustc_version) => {
self.word("since = \"");
self.word(format!(
"{}.{}.{}",
rustc_version.major, rustc_version.minor, rustc_version.patch
));
self.word("\"");
use_comma = true;
}
rustc_attr_parsing::DeprecatedSince::Future => {
self.word("since = \"future\"");
use_comma = true;
}
rustc_attr_parsing::DeprecatedSince::NonStandard(symbol) => {
self.word("since = \"");
self.word(symbol.to_ident_string());
self.word("\"");
use_comma = true;
}
_ => {}
}

if let Some(note) = &deprecation.note {
if use_comma {
self.word(", ");
}
self.word("note = \"");
self.word(note.to_ident_string());
self.word("\"");
use_comma = true;
}

if let Some(suggestion) = &deprecation.suggestion {
if use_comma {
self.word(", ");
}
self.word("suggestion = \"");
self.word(suggestion.to_ident_string());
self.word("\"");
}
} else if let Some(note) = &deprecation.note {
// We're in form 2: `#[deprecated = "message"]`.
self.word(" = \"");
self.word(note.to_ident_string());
self.word("\"");
} else {
// We're in form 3: `#[deprecated]`. Nothing to do here.
}

self.word("]");
}
hir::Attribute::Parsed(pa) => {
self.word("#[attr=\"");
pa.print_attribute(self);
Expand Down
61 changes: 44 additions & 17 deletions compiler/rustc_mir_transform/src/add_call_guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,51 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
let mut new_blocks = Vec::new();

let cur_len = body.basic_blocks.len();
let mut new_block = |source_info: SourceInfo, is_cleanup: bool, target: BasicBlock| {
let block = BasicBlockData {
statements: vec![],
is_cleanup,
terminator: Some(Terminator { source_info, kind: TerminatorKind::Goto { target } }),
};
let idx = cur_len + new_blocks.len();
new_blocks.push(block);
BasicBlock::new(idx)
};

for block in body.basic_blocks_mut() {
match block.terminator {
Some(Terminator {
kind: TerminatorKind::Call { target: Some(ref mut destination), unwind, .. },
source_info,
}) if pred_count[*destination] > 1
&& (matches!(
unwind,
UnwindAction::Cleanup(_) | UnwindAction::Terminate(_)
) || self == &AllCallEdges) =>
&& (generates_invoke(unwind) || self == &AllCallEdges) =>
{
// It's a critical edge, break it
let call_guard = BasicBlockData {
statements: vec![],
is_cleanup: block.is_cleanup,
terminator: Some(Terminator {
source_info,
kind: TerminatorKind::Goto { target: *destination },
}),
};

// Get the index it will be when inserted into the MIR
let idx = cur_len + new_blocks.len();
new_blocks.push(call_guard);
*destination = BasicBlock::new(idx);
*destination = new_block(source_info, block.is_cleanup, *destination);
}
Some(Terminator {
kind:
TerminatorKind::InlineAsm {
asm_macro: InlineAsmMacro::Asm,
ref mut targets,
ref operands,
unwind,
..
},
source_info,
}) if self == &CriticalCallEdges => {
let has_outputs = operands.iter().any(|op| {
matches!(op, InlineAsmOperand::InOut { .. } | InlineAsmOperand::Out { .. })
});
let has_labels =
operands.iter().any(|op| matches!(op, InlineAsmOperand::Label { .. }));
if has_outputs && (has_labels || generates_invoke(unwind)) {
for target in targets.iter_mut() {
if pred_count[*target] > 1 {
*target = new_block(source_info, block.is_cleanup, *target);
}
}
}
}
_ => {}
}
Expand All @@ -80,3 +99,11 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
true
}
}

/// Returns true if this unwind action is code generated as an invoke as opposed to a call.
fn generates_invoke(unwind: UnwindAction) -> bool {
match unwind {
UnwindAction::Continue | UnwindAction::Unreachable => false,
UnwindAction::Cleanup(_) | UnwindAction::Terminate(_) => true,
}
}
56 changes: 24 additions & 32 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,14 @@ impl OutputType {
}

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

impl Default for ErrorOutputType {
fn default() -> Self {
Self::HumanReadable(HumanReadableErrorType::Default, ColorConfig::Auto)
}
}

#[derive(Clone, Hash, Debug)]
pub enum ResolveDocLinks {
/// Do not resolve doc links.
Expand Down Expand Up @@ -898,18 +896,13 @@ pub enum PrintKind {
DeploymentTarget,
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Default)]
pub struct NextSolverConfig {
/// Whether the new trait solver should be enabled in coherence.
pub coherence: bool,
pub coherence: bool = true,
/// Whether the new trait solver should be enabled everywhere.
/// This is only `true` if `coherence` is also enabled.
pub globally: bool,
}
impl Default for NextSolverConfig {
fn default() -> Self {
NextSolverConfig { coherence: true, globally: false }
}
pub globally: bool = false,
}

#[derive(Clone)]
Expand Down Expand Up @@ -1825,7 +1818,7 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
pub fn parse_error_format(
early_dcx: &mut EarlyDiagCtxt,
matches: &getopts::Matches,
color: ColorConfig,
color_config: ColorConfig,
json_color: ColorConfig,
json_rendered: HumanReadableErrorType,
) -> ErrorOutputType {
Expand All @@ -1835,35 +1828,34 @@ pub fn parse_error_format(
// `opt_present` because the latter will panic.
let error_format = if matches.opts_present(&["error-format".to_owned()]) {
match matches.opt_str("error-format").as_deref() {
None | Some("human") => {
ErrorOutputType::HumanReadable(HumanReadableErrorType::Default, color)
}
Some("human-annotate-rs") => {
ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet, color)
}
None | Some("human") => ErrorOutputType::HumanReadable { color_config, .. },
Some("human-annotate-rs") => ErrorOutputType::HumanReadable {
kind: HumanReadableErrorType::AnnotateSnippet,
color_config,
},
Some("json") => {
ErrorOutputType::Json { pretty: false, json_rendered, color_config: json_color }
}
Some("pretty-json") => {
ErrorOutputType::Json { pretty: true, json_rendered, color_config: json_color }
}
Some("short") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Short, color),
Some("human-unicode") => {
ErrorOutputType::HumanReadable(HumanReadableErrorType::Unicode, color)
Some("short") => {
ErrorOutputType::HumanReadable { kind: HumanReadableErrorType::Short, color_config }
}
Some("human-unicode") => ErrorOutputType::HumanReadable {
kind: HumanReadableErrorType::Unicode,
color_config,
},
Some(arg) => {
early_dcx.set_error_format(ErrorOutputType::HumanReadable(
HumanReadableErrorType::Default,
color,
));
early_dcx.set_error_format(ErrorOutputType::HumanReadable { color_config, .. });
early_dcx.early_fatal(format!(
"argument for `--error-format` must be `human`, `human-annotate-rs`, \
`human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
))
}
}
} else {
ErrorOutputType::HumanReadable(HumanReadableErrorType::Default, color)
ErrorOutputType::HumanReadable { color_config, .. }
};

match error_format {
Expand Down Expand Up @@ -1918,7 +1910,7 @@ fn check_error_format_stability(
}
let format = match format {
ErrorOutputType::Json { pretty: true, .. } => "pretty-json",
ErrorOutputType::HumanReadable(format, _) => match format {
ErrorOutputType::HumanReadable { kind, .. } => match kind {
HumanReadableErrorType::AnnotateSnippet => "human-annotate-rs",
HumanReadableErrorType::Unicode => "human-unicode",
_ => return,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_session/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// tidy-alphabetical-start
#![allow(internal_features)]
#![feature(default_field_values)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(rustc_attrs)]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ fn default_emitter(
let source_map = if sopts.unstable_opts.link_only { None } else { Some(source_map) };

match sopts.error_format {
config::ErrorOutputType::HumanReadable(kind, color_config) => {
config::ErrorOutputType::HumanReadable { kind, color_config } => {
let short = kind.short();

if let HumanReadableErrorType::AnnotateSnippet = kind {
Expand Down Expand Up @@ -1430,7 +1430,7 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
let fallback_bundle =
fallback_fluent_bundle(vec![rustc_errors::DEFAULT_LOCALE_RESOURCE], false);
let emitter: Box<DynEmitter> = match output {
config::ErrorOutputType::HumanReadable(kind, color_config) => {
config::ErrorOutputType::HumanReadable { kind, color_config } => {
let short = kind.short();
Box::new(
HumanEmitter::new(stderr_destination(color_config), fallback_bundle)
Expand Down
Loading
Loading