Skip to content

Rollup of 9 pull requests #142929

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 30 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
669564d
std: sys: random: uefi: Provide rdrand based fallback
Ayush1325 May 21, 2025
f3d4278
Fix `core::iter::Fuse`'s `Default` impl to do what it's docs say it d…
zachs18 May 14, 2025
188023a
Don't suggest changing a method inside a expansion
Urgau Jun 22, 2025
332ae3b
Add codegen timing section
Kobzol Jun 20, 2025
66060e6
Create new `CiInfo` type in tidy checks to centralize CI related checks
GuillaumeGomez Jun 21, 2025
4780f21
Move error code explanation removal check into tidy
GuillaumeGomez Jun 21, 2025
c7bfb11
Fix install-template.sh for Solaris tr
psumbera Jun 23, 2025
2f4a55b
compiler: plug unsupported ABI leakage from the AST
workingjubilee Jun 1, 2025
e93a99b
hir_analysis: Avoid repeating unsupported ABI errors
workingjubilee Jun 13, 2025
b34c520
compiler: Remove unsupported_fn_ptr_calling_conventions lint
workingjubilee Jun 6, 2025
267ecd1
Clarify note in rustc_ast_lowering still applies
workingjubilee Jun 12, 2025
7c6b50c
unsupported_calling_conventions: print which ABI this is about
RalfJung Jun 13, 2025
a69aeaf
tests: Bless abi_gpu_kernel feature gate test
workingjubilee Jun 1, 2025
7e35b28
tests: Enhance unsupported ABI tests
workingjubilee Jun 13, 2025
a3a6d9b
tests: Update raw-dylib unsupported ABI test
workingjubilee Jun 13, 2025
0dd29e1
tests: Update and bless cmse-nonsecure ABI tests
workingjubilee Jun 1, 2025
7632fab
tests: Adopt ABI transmute tests from crashtests
workingjubilee Jun 1, 2025
78528bc
tests: Verify varargs with unsupported fn ptr ABIs must error
workingjubilee Jun 6, 2025
aa25b9b
tests: Bless cannot-be-called and dedup with unsupported ABI test
workingjubilee Jun 21, 2025
6ea79a1
Fix comment on NoMangle
JonathanBrouwer Jun 23, 2025
8147646
fix `-Zmin-function-alignment` without attributes
folkertdev Jun 23, 2025
f50da06
Rollup merge of #140985 - zachs18:fuse-default-some, r=tgross35
workingjubilee Jun 23, 2025
fc3d7ee
Rollup merge of #141324 - Ayush1325:uefi-rand-fallback, r=joboet
workingjubilee Jun 23, 2025
ff1636b
Rollup merge of #142134 - workingjubilee:reject-unsupported-abi, r=jd…
workingjubilee Jun 23, 2025
8ba69d0
Rollup merge of #142784 - Kobzol:timings-codegen, r=nnethercote
workingjubilee Jun 23, 2025
b942c6d
Rollup merge of #142827 - GuillaumeGomez:tidy-error-code-removal, r=K…
workingjubilee Jun 23, 2025
8ba8f1e
Rollup merge of #142873 - Urgau:issue-139830, r=BoxyUwU
workingjubilee Jun 23, 2025
64cfd5b
Rollup merge of #142908 - psumbera:solaris-tr, r=jieyouxu
workingjubilee Jun 23, 2025
1569f14
Rollup merge of #142922 - JonathanBrouwer:fix-rustdoc-comment, r=jdon…
workingjubilee Jun 23, 2025
b7a9cd8
Rollup merge of #142923 - folkertdev:min-function-alignment-no-attrib…
workingjubilee Jun 23, 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
28 changes: 24 additions & 4 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_abi::ExternAbi;
use rustc_ast::ptr::P;
use rustc_ast::visit::AssocCtxt;
use rustc_ast::*;
use rustc_errors::ErrorGuaranteed;
use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
use rustc_hir::def::{DefKind, PerNS, Res};
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin};
Expand Down Expand Up @@ -1644,9 +1644,29 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.error_on_invalid_abi(abi_str);
ExternAbi::Rust
});
let sess = self.tcx.sess;
let features = self.tcx.features();
gate_unstable_abi(sess, features, span, extern_abi);
let tcx = self.tcx;

// we can't do codegen for unsupported ABIs, so error now so we won't get farther
if !tcx.sess.target.is_abi_supported(extern_abi) {
let mut err = struct_span_code_err!(
tcx.dcx(),
span,
E0570,
"{extern_abi} is not a supported ABI for the current target",
);

if let ExternAbi::Stdcall { unwind } = extern_abi {
let c_abi = ExternAbi::C { unwind };
let system_abi = ExternAbi::System { unwind };
err.help(format!("if you need `extern {extern_abi}` on win32 and `extern {c_abi}` everywhere else, \
use `extern {system_abi}`"
));
}
err.emit();
}
// Show required feature gate even if we already errored, as the user is likely to build the code
// for the actually intended target next and then they will need the feature gate.
gate_unstable_abi(tcx.sess, tcx.features(), span, extern_abi);
extern_abi
}

Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
}
}

// Apply the minimum function alignment here, so that individual backends don't have to.
codegen_fn_attrs.alignment = Ord::max(
codegen_fn_attrs.alignment,
tcx.sess.opts.unstable_opts.min_function_alignment,
);

let Some(Ident { name, .. }) = attr.ident() else {
continue;
};
Expand Down Expand Up @@ -454,6 +448,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {

mixed_export_name_no_mangle_lint_state.lint_if_mixed(tcx);

// Apply the minimum function alignment here, so that individual backends don't have to.
codegen_fn_attrs.alignment =
Ord::max(codegen_fn_attrs.alignment, tcx.sess.opts.unstable_opts.min_function_alignment);

let inline_span;
(codegen_fn_attrs.inline, inline_span) = if let Some((inline_attr, span)) =
find_attr!(attrs, AttributeKind::Inline(i, span) => (*i, *span))
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl Emitter for JsonEmitter {
};
let name = match record.section {
TimingSection::Linking => "link",
TimingSection::Codegen => "codegen",
};
let data = SectionTimestamp { name, event, timestamp: record.timestamp };
let result = self.emit(EmitTyped::SectionTiming(data));
Expand Down
47 changes: 44 additions & 3 deletions compiler/rustc_errors/src/timings.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use std::time::Instant;

use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lock;

use crate::DiagCtxtHandle;

/// A high-level section of the compilation process.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum TimingSection {
/// Time spent doing codegen.
Codegen,
/// Time spent linking.
Linking,
}
Expand Down Expand Up @@ -36,23 +41,59 @@ pub struct TimingSectionHandler {
/// Time when the compilation session started.
/// If `None`, timing is disabled.
origin: Option<Instant>,
/// Sanity check to ensure that we open and close sections correctly.
opened_sections: Lock<FxHashSet<TimingSection>>,
}

impl TimingSectionHandler {
pub fn new(enabled: bool) -> Self {
let origin = if enabled { Some(Instant::now()) } else { None };
Self { origin }
Self { origin, opened_sections: Lock::new(FxHashSet::default()) }
}

/// Returns a RAII guard that will immediately emit a start the provided section, and then emit
/// its end when it is dropped.
pub fn start_section<'a>(
pub fn section_guard<'a>(
&self,
diag_ctxt: DiagCtxtHandle<'a>,
section: TimingSection,
) -> TimingSectionGuard<'a> {
if self.is_enabled() && self.opened_sections.borrow().contains(&section) {
diag_ctxt
.bug(format!("Section `{section:?}` was started again before it was finished"));
}

TimingSectionGuard::create(diag_ctxt, section, self.origin)
}

/// Start the provided section.
pub fn start_section(&self, diag_ctxt: DiagCtxtHandle<'_>, section: TimingSection) {
if let Some(origin) = self.origin {
let mut opened = self.opened_sections.borrow_mut();
if !opened.insert(section) {
diag_ctxt
.bug(format!("Section `{section:?}` was started again before it was finished"));
}

diag_ctxt.emit_timing_section_start(TimingRecord::from_origin(origin, section));
}
}

/// End the provided section.
pub fn end_section(&self, diag_ctxt: DiagCtxtHandle<'_>, section: TimingSection) {
if let Some(origin) = self.origin {
let mut opened = self.opened_sections.borrow_mut();
if !opened.remove(&section) {
diag_ctxt.bug(format!("Section `{section:?}` was ended before being started"));
}

diag_ctxt.emit_timing_section_end(TimingRecord::from_origin(origin, section));
}
}

fn is_enabled(&self) -> bool {
self.origin.is_some()
}
}

/// RAII wrapper for starting and ending section timings.
Expand Down
45 changes: 9 additions & 36 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::cell::LazyCell;
use std::ops::ControlFlow;

use rustc_abi::FieldIdx;
use rustc_abi::{ExternAbi, FieldIdx};
use rustc_attr_data_structures::ReprAttr::ReprPacked;
use rustc_attr_data_structures::{AttributeKind, find_attr};
use rustc_data_structures::unord::{UnordMap, UnordSet};
Expand All @@ -13,7 +13,6 @@ use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
use rustc_infer::traits::{Obligation, ObligationCauseCode};
use rustc_lint_defs::builtin::{
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS, UNSUPPORTED_CALLING_CONVENTIONS,
UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
};
use rustc_middle::hir::nested_filter;
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
Expand Down Expand Up @@ -53,49 +52,22 @@ fn add_abi_diag_help<T: EmissionGuarantee>(abi: ExternAbi, diag: &mut Diag<'_, T
}

pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi) {
// FIXME: this should be checked earlier, e.g. in `rustc_ast_lowering`, to fix
// things like #86232.
// FIXME: This should be checked earlier, e.g. in `rustc_ast_lowering`, as this
// currently only guards function imports, function definitions, and function pointer types.
// Functions in trait declarations can still use "deprecated" ABIs without any warning.

match AbiMap::from_target(&tcx.sess.target).canonize_abi(abi, false) {
AbiMapping::Direct(..) => (),
// already erred in rustc_ast_lowering
AbiMapping::Invalid => {
let mut err = struct_span_code_err!(
tcx.dcx(),
span,
E0570,
"`{abi}` is not a supported ABI for the current target",
);
add_abi_diag_help(abi, &mut err);
err.emit();
tcx.dcx().span_delayed_bug(span, format!("{abi} should be rejected in ast_lowering"));
}
AbiMapping::Deprecated(..) => {
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
lint.primary_message("use of calling convention not supported on this target");
add_abi_diag_help(abi, lint);
});
}
}
}

pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi) {
// This is always an FCW, even for `AbiMapping::Invalid`, since we started linting later than
// in `check_abi` above.
match AbiMap::from_target(&tcx.sess.target).canonize_abi(abi, false) {
AbiMapping::Direct(..) => (),
// This is not a redundant match arm: these ABIs started linting after introducing
// UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS already existed and we want to
// avoid expanding the scope of that lint so it can move to a hard error sooner.
AbiMapping::Deprecated(..) => {
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
lint.primary_message("use of calling convention not supported on this target");
add_abi_diag_help(abi, lint);
});
}
AbiMapping::Invalid => {
tcx.node_span_lint(UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, hir_id, span, |lint| {
lint.primary_message(format!(
"the calling convention {abi} is not supported on this target"
"{abi} is not a supported ABI for the current target"
));
add_abi_diag_help(abi, lint);
});
}
}
Expand Down Expand Up @@ -868,6 +840,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let hir::ItemKind::ForeignMod { abi, items } = it.kind else {
return;
};

check_abi(tcx, it.hir_id(), it.span, abi);

for item in items {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ pub mod wfcheck;

use std::num::NonZero;

pub use check::{check_abi, check_abi_fn_ptr, check_custom_abi};
use rustc_abi::{ExternAbi, VariantIdx};
pub use check::{check_abi, check_custom_abi};
use rustc_abi::VariantIdx;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_errors::{Diag, ErrorGuaranteed, pluralize, struct_span_code_err};
use rustc_hir::LangItem;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use rustc_trait_selection::traits::wf::object_region_bounds;
use rustc_trait_selection::traits::{self, FulfillmentError};
use tracing::{debug, instrument};

use crate::check::check_abi_fn_ptr;
use crate::check::check_abi;
use crate::errors::{AmbiguousLifetimeBound, BadReturnTypeNotation};
use crate::hir_ty_lowering::errors::{GenericsArgsErrExtend, prohibit_assoc_item_constraint};
use crate::hir_ty_lowering::generics::{check_generic_arg_count, lower_generic_args};
Expand Down Expand Up @@ -2660,7 +2660,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
if let hir::Node::Ty(hir::Ty { kind: hir::TyKind::BareFn(bare_fn_ty), span, .. }) =
tcx.hir_node(hir_id)
{
check_abi_fn_ptr(tcx, hir_id, *span, bare_fn_ty.abi);
check_abi(tcx, hir_id, *span, bare_fn_ty.abi);
}

// reject function types that violate cmse ABI requirements
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1723,8 +1723,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Don't emit a suggestion if we found an actual method
// that had unsatisfied trait bounds
if unsatisfied_predicates.is_empty()
// ...or if we already suggested that name because of `rustc_confusable` annotation.
// ...or if we already suggested that name because of `rustc_confusable` annotation
&& Some(similar_candidate.name()) != confusable_suggested
// and if the we aren't in an expansion.
&& !span.from_expansion()
{
self.find_likely_intended_associated_item(
&mut err,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_data_structures::jobserver::Proxy;
use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, WorkerLocal};
use rustc_data_structures::{parallel, thousands};
use rustc_errors::timings::TimingSection;
use rustc_expand::base::{ExtCtxt, LintStoreExpand};
use rustc_feature::Features;
use rustc_fs_util::try_canonicalize;
Expand Down Expand Up @@ -1176,6 +1177,8 @@ pub(crate) fn start_codegen<'tcx>(
codegen_backend: &dyn CodegenBackend,
tcx: TyCtxt<'tcx>,
) -> (Box<dyn Any>, EncodedMetadata) {
tcx.sess.timings.start_section(tcx.sess.dcx(), TimingSection::Codegen);

// Hook for tests.
if let Some((def_id, _)) = tcx.entry_fn(())
&& tcx.has_attr(def_id, sym::rustc_delayed_bug_from_inside_query)
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl Linker {
let (codegen_results, work_products) = sess.time("finish_ongoing_codegen", || {
codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.output_filenames)
});
sess.timings.end_section(sess.dcx(), TimingSection::Codegen);

sess.dcx().abort_if_errors();

Expand Down Expand Up @@ -89,7 +90,7 @@ impl Linker {
}

let _timer = sess.prof.verbose_generic_activity("link_crate");
let _timing = sess.timings.start_section(sess.dcx(), TimingSection::Linking);
let _timing = sess.timings.section_guard(sess.dcx(), TimingSection::Linking);
codegen_backend.link(sess, codegen_results, self.metadata, &self.output_filenames)
}
}
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ fn register_builtins(store: &mut LintStore) {
"converted into hard error, see issue #127323 \
<https://github.com/rust-lang/rust/issues/127323> for more information",
);
store.register_removed("unsupported_fn_ptr_calling_conventions", "converted into hard error");
store.register_removed(
"undefined_naked_function_abi",
"converted into hard error, see PR #139001 \
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ declare_lint_pass! {
UNSAFE_OP_IN_UNSAFE_FN,
UNSTABLE_NAME_COLLISIONS,
UNSTABLE_SYNTAX_PRE_EXPANSION,
UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
UNUSED_ASSIGNMENTS,
UNUSED_ASSOCIATED_TYPE_BOUNDS,
UNUSED_ATTRIBUTES,
Expand Down
24 changes: 23 additions & 1 deletion library/core/src/iter/adapters/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,30 @@ impl<I: Default> Default for Fuse<I> {
/// let iter: Fuse<slice::Iter<'_, u8>> = Default::default();
/// assert_eq!(iter.len(), 0);
/// ```
///
/// This is equivalent to `I::default().fuse()`[^fuse_note]; e.g. if
/// `I::default()` is not an empty iterator, then this will not be
/// an empty iterator.
///
/// ```
/// # use std::iter::Fuse;
/// #[derive(Default)]
/// struct Fourever;
///
/// impl Iterator for Fourever {
/// type Item = u32;
/// fn next(&mut self) -> Option<u32> {
/// Some(4)
/// }
/// }
///
/// let mut iter: Fuse<Fourever> = Default::default();
/// assert_eq!(iter.next(), Some(4));
/// ```
///
/// [^fuse_note]: if `I` does not override `Iterator::fuse`'s default implementation
fn default() -> Self {
Fuse { iter: Default::default() }
Fuse { iter: Some(I::default()) }
}
}

Expand Down
Loading
Loading