Skip to content

Commit 99b18d6

Browse files
committed
Auto merge of #142929 - workingjubilee:rollup-4p3ypz1, r=workingjubilee
Rollup of 9 pull requests Successful merges: - #140985 (Change `core::iter::Fuse`'s `Default` impl to do what its docs say it does) - #141324 (std: sys: random: uefi: Provide rdrand based fallback) - #142134 (Reject unsupported `extern "{abi}"`s consistently in all positions) - #142784 (Add codegen timing section) - #142827 (Move error code explanation removal check into tidy) - #142873 (Don't suggest changing a method inside a expansion) - #142908 (Fix install-template.sh for Solaris tr) - #142922 (Fix comment on NoMangle) - #142923 (fix `-Zmin-function-alignment` on functions without attributes) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 706f244 + b7a9cd8 commit 99b18d6

File tree

63 files changed

+1665
-2860
lines changed

Some content is hidden

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

63 files changed

+1665
-2860
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_abi::ExternAbi;
22
use rustc_ast::ptr::P;
33
use rustc_ast::visit::AssocCtxt;
44
use rustc_ast::*;
5-
use rustc_errors::ErrorGuaranteed;
5+
use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
66
use rustc_hir::def::{DefKind, PerNS, Res};
77
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
88
use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin};
@@ -1644,9 +1644,29 @@ impl<'hir> LoweringContext<'_, 'hir> {
16441644
self.error_on_invalid_abi(abi_str);
16451645
ExternAbi::Rust
16461646
});
1647-
let sess = self.tcx.sess;
1648-
let features = self.tcx.features();
1649-
gate_unstable_abi(sess, features, span, extern_abi);
1647+
let tcx = self.tcx;
1648+
1649+
// we can't do codegen for unsupported ABIs, so error now so we won't get farther
1650+
if !tcx.sess.target.is_abi_supported(extern_abi) {
1651+
let mut err = struct_span_code_err!(
1652+
tcx.dcx(),
1653+
span,
1654+
E0570,
1655+
"{extern_abi} is not a supported ABI for the current target",
1656+
);
1657+
1658+
if let ExternAbi::Stdcall { unwind } = extern_abi {
1659+
let c_abi = ExternAbi::C { unwind };
1660+
let system_abi = ExternAbi::System { unwind };
1661+
err.help(format!("if you need `extern {extern_abi}` on win32 and `extern {c_abi}` everywhere else, \
1662+
use `extern {system_abi}`"
1663+
));
1664+
}
1665+
err.emit();
1666+
}
1667+
// Show required feature gate even if we already errored, as the user is likely to build the code
1668+
// for the actually intended target next and then they will need the feature gate.
1669+
gate_unstable_abi(tcx.sess, tcx.features(), span, extern_abi);
16501670
extern_abi
16511671
}
16521672

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
146146
}
147147
}
148148

149-
// Apply the minimum function alignment here, so that individual backends don't have to.
150-
codegen_fn_attrs.alignment = Ord::max(
151-
codegen_fn_attrs.alignment,
152-
tcx.sess.opts.unstable_opts.min_function_alignment,
153-
);
154-
155149
let Some(Ident { name, .. }) = attr.ident() else {
156150
continue;
157151
};
@@ -454,6 +448,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
454448

455449
mixed_export_name_no_mangle_lint_state.lint_if_mixed(tcx);
456450

451+
// Apply the minimum function alignment here, so that individual backends don't have to.
452+
codegen_fn_attrs.alignment =
453+
Ord::max(codegen_fn_attrs.alignment, tcx.sess.opts.unstable_opts.min_function_alignment);
454+
457455
let inline_span;
458456
(codegen_fn_attrs.inline, inline_span) = if let Some((inline_attr, span)) =
459457
find_attr!(attrs, AttributeKind::Inline(i, span) => (*i, *span))

compiler/rustc_errors/src/json.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl Emitter for JsonEmitter {
129129
};
130130
let name = match record.section {
131131
TimingSection::Linking => "link",
132+
TimingSection::Codegen => "codegen",
132133
};
133134
let data = SectionTimestamp { name, event, timestamp: record.timestamp };
134135
let result = self.emit(EmitTyped::SectionTiming(data));

compiler/rustc_errors/src/timings.rs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
use std::time::Instant;
22

3+
use rustc_data_structures::fx::FxHashSet;
4+
use rustc_data_structures::sync::Lock;
5+
36
use crate::DiagCtxtHandle;
47

58
/// A high-level section of the compilation process.
6-
#[derive(Copy, Clone, Debug)]
9+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
710
pub enum TimingSection {
11+
/// Time spent doing codegen.
12+
Codegen,
813
/// Time spent linking.
914
Linking,
1015
}
@@ -36,23 +41,59 @@ pub struct TimingSectionHandler {
3641
/// Time when the compilation session started.
3742
/// If `None`, timing is disabled.
3843
origin: Option<Instant>,
44+
/// Sanity check to ensure that we open and close sections correctly.
45+
opened_sections: Lock<FxHashSet<TimingSection>>,
3946
}
4047

4148
impl TimingSectionHandler {
4249
pub fn new(enabled: bool) -> Self {
4350
let origin = if enabled { Some(Instant::now()) } else { None };
44-
Self { origin }
51+
Self { origin, opened_sections: Lock::new(FxHashSet::default()) }
4552
}
4653

4754
/// Returns a RAII guard that will immediately emit a start the provided section, and then emit
4855
/// its end when it is dropped.
49-
pub fn start_section<'a>(
56+
pub fn section_guard<'a>(
5057
&self,
5158
diag_ctxt: DiagCtxtHandle<'a>,
5259
section: TimingSection,
5360
) -> TimingSectionGuard<'a> {
61+
if self.is_enabled() && self.opened_sections.borrow().contains(&section) {
62+
diag_ctxt
63+
.bug(format!("Section `{section:?}` was started again before it was finished"));
64+
}
65+
5466
TimingSectionGuard::create(diag_ctxt, section, self.origin)
5567
}
68+
69+
/// Start the provided section.
70+
pub fn start_section(&self, diag_ctxt: DiagCtxtHandle<'_>, section: TimingSection) {
71+
if let Some(origin) = self.origin {
72+
let mut opened = self.opened_sections.borrow_mut();
73+
if !opened.insert(section) {
74+
diag_ctxt
75+
.bug(format!("Section `{section:?}` was started again before it was finished"));
76+
}
77+
78+
diag_ctxt.emit_timing_section_start(TimingRecord::from_origin(origin, section));
79+
}
80+
}
81+
82+
/// End the provided section.
83+
pub fn end_section(&self, diag_ctxt: DiagCtxtHandle<'_>, section: TimingSection) {
84+
if let Some(origin) = self.origin {
85+
let mut opened = self.opened_sections.borrow_mut();
86+
if !opened.remove(&section) {
87+
diag_ctxt.bug(format!("Section `{section:?}` was ended before being started"));
88+
}
89+
90+
diag_ctxt.emit_timing_section_end(TimingRecord::from_origin(origin, section));
91+
}
92+
}
93+
94+
fn is_enabled(&self) -> bool {
95+
self.origin.is_some()
96+
}
5697
}
5798

5899
/// RAII wrapper for starting and ending section timings.

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::cell::LazyCell;
22
use std::ops::ControlFlow;
33

4-
use rustc_abi::FieldIdx;
4+
use rustc_abi::{ExternAbi, FieldIdx};
55
use rustc_attr_data_structures::ReprAttr::ReprPacked;
66
use rustc_attr_data_structures::{AttributeKind, find_attr};
77
use rustc_data_structures::unord::{UnordMap, UnordSet};
@@ -13,7 +13,6 @@ use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
1313
use rustc_infer::traits::{Obligation, ObligationCauseCode};
1414
use rustc_lint_defs::builtin::{
1515
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS, UNSUPPORTED_CALLING_CONVENTIONS,
16-
UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
1716
};
1817
use rustc_middle::hir::nested_filter;
1918
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
@@ -53,49 +52,22 @@ fn add_abi_diag_help<T: EmissionGuarantee>(abi: ExternAbi, diag: &mut Diag<'_, T
5352
}
5453

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

5959
match AbiMap::from_target(&tcx.sess.target).canonize_abi(abi, false) {
6060
AbiMapping::Direct(..) => (),
61+
// already erred in rustc_ast_lowering
6162
AbiMapping::Invalid => {
62-
let mut err = struct_span_code_err!(
63-
tcx.dcx(),
64-
span,
65-
E0570,
66-
"`{abi}` is not a supported ABI for the current target",
67-
);
68-
add_abi_diag_help(abi, &mut err);
69-
err.emit();
63+
tcx.dcx().span_delayed_bug(span, format!("{abi} should be rejected in ast_lowering"));
7064
}
7165
AbiMapping::Deprecated(..) => {
7266
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
73-
lint.primary_message("use of calling convention not supported on this target");
74-
add_abi_diag_help(abi, lint);
75-
});
76-
}
77-
}
78-
}
79-
80-
pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi) {
81-
// This is always an FCW, even for `AbiMapping::Invalid`, since we started linting later than
82-
// in `check_abi` above.
83-
match AbiMap::from_target(&tcx.sess.target).canonize_abi(abi, false) {
84-
AbiMapping::Direct(..) => (),
85-
// This is not a redundant match arm: these ABIs started linting after introducing
86-
// UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS already existed and we want to
87-
// avoid expanding the scope of that lint so it can move to a hard error sooner.
88-
AbiMapping::Deprecated(..) => {
89-
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
90-
lint.primary_message("use of calling convention not supported on this target");
91-
add_abi_diag_help(abi, lint);
92-
});
93-
}
94-
AbiMapping::Invalid => {
95-
tcx.node_span_lint(UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, hir_id, span, |lint| {
9667
lint.primary_message(format!(
97-
"the calling convention {abi} is not supported on this target"
68+
"{abi} is not a supported ABI for the current target"
9869
));
70+
add_abi_diag_help(abi, lint);
9971
});
10072
}
10173
}
@@ -868,6 +840,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
868840
let hir::ItemKind::ForeignMod { abi, items } = it.kind else {
869841
return;
870842
};
843+
871844
check_abi(tcx, it.hir_id(), it.span, abi);
872845

873846
for item in items {

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ pub mod wfcheck;
7272

7373
use std::num::NonZero;
7474

75-
pub use check::{check_abi, check_abi_fn_ptr, check_custom_abi};
76-
use rustc_abi::{ExternAbi, VariantIdx};
75+
pub use check::{check_abi, check_custom_abi};
76+
use rustc_abi::VariantIdx;
7777
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
7878
use rustc_errors::{Diag, ErrorGuaranteed, pluralize, struct_span_code_err};
7979
use rustc_hir::LangItem;

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use rustc_trait_selection::traits::wf::object_region_bounds;
5151
use rustc_trait_selection::traits::{self, FulfillmentError};
5252
use tracing::{debug, instrument};
5353

54-
use crate::check::check_abi_fn_ptr;
54+
use crate::check::check_abi;
5555
use crate::errors::{AmbiguousLifetimeBound, BadReturnTypeNotation};
5656
use crate::hir_ty_lowering::errors::{GenericsArgsErrExtend, prohibit_assoc_item_constraint};
5757
use crate::hir_ty_lowering::generics::{check_generic_arg_count, lower_generic_args};
@@ -2660,7 +2660,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
26602660
if let hir::Node::Ty(hir::Ty { kind: hir::TyKind::BareFn(bare_fn_ty), span, .. }) =
26612661
tcx.hir_node(hir_id)
26622662
{
2663-
check_abi_fn_ptr(tcx, hir_id, *span, bare_fn_ty.abi);
2663+
check_abi(tcx, hir_id, *span, bare_fn_ty.abi);
26642664
}
26652665

26662666
// reject function types that violate cmse ABI requirements

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,8 +1723,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17231723
// Don't emit a suggestion if we found an actual method
17241724
// that had unsatisfied trait bounds
17251725
if unsatisfied_predicates.is_empty()
1726-
// ...or if we already suggested that name because of `rustc_confusable` annotation.
1726+
// ...or if we already suggested that name because of `rustc_confusable` annotation
17271727
&& Some(similar_candidate.name()) != confusable_suggested
1728+
// and if the we aren't in an expansion.
1729+
&& !span.from_expansion()
17281730
{
17291731
self.find_likely_intended_associated_item(
17301732
&mut err,

compiler/rustc_interface/src/passes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_data_structures::jobserver::Proxy;
1111
use rustc_data_structures::steal::Steal;
1212
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, WorkerLocal};
1313
use rustc_data_structures::{parallel, thousands};
14+
use rustc_errors::timings::TimingSection;
1415
use rustc_expand::base::{ExtCtxt, LintStoreExpand};
1516
use rustc_feature::Features;
1617
use rustc_fs_util::try_canonicalize;
@@ -1176,6 +1177,8 @@ pub(crate) fn start_codegen<'tcx>(
11761177
codegen_backend: &dyn CodegenBackend,
11771178
tcx: TyCtxt<'tcx>,
11781179
) -> (Box<dyn Any>, EncodedMetadata) {
1180+
tcx.sess.timings.start_section(tcx.sess.dcx(), TimingSection::Codegen);
1181+
11791182
// Hook for tests.
11801183
if let Some((def_id, _)) = tcx.entry_fn(())
11811184
&& tcx.has_attr(def_id, sym::rustc_delayed_bug_from_inside_query)

compiler/rustc_interface/src/queries.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl Linker {
4848
let (codegen_results, work_products) = sess.time("finish_ongoing_codegen", || {
4949
codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.output_filenames)
5050
});
51+
sess.timings.end_section(sess.dcx(), TimingSection::Codegen);
5152

5253
sess.dcx().abort_if_errors();
5354

@@ -89,7 +90,7 @@ impl Linker {
8990
}
9091

9192
let _timer = sess.prof.verbose_generic_activity("link_crate");
92-
let _timing = sess.timings.start_section(sess.dcx(), TimingSection::Linking);
93+
let _timing = sess.timings.section_guard(sess.dcx(), TimingSection::Linking);
9394
codegen_backend.link(sess, codegen_results, self.metadata, &self.output_filenames)
9495
}
9596
}

compiler/rustc_lint/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ fn register_builtins(store: &mut LintStore) {
608608
"converted into hard error, see issue #127323 \
609609
<https://github.com/rust-lang/rust/issues/127323> for more information",
610610
);
611+
store.register_removed("unsupported_fn_ptr_calling_conventions", "converted into hard error");
611612
store.register_removed(
612613
"undefined_naked_function_abi",
613614
"converted into hard error, see PR #139001 \

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ declare_lint_pass! {
122122
UNSAFE_OP_IN_UNSAFE_FN,
123123
UNSTABLE_NAME_COLLISIONS,
124124
UNSTABLE_SYNTAX_PRE_EXPANSION,
125-
UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
126125
UNUSED_ASSIGNMENTS,
127126
UNUSED_ASSOCIATED_TYPE_BOUNDS,
128127
UNUSED_ATTRIBUTES,

library/core/src/iter/adapters/fuse.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,30 @@ impl<I: Default> Default for Fuse<I> {
198198
/// let iter: Fuse<slice::Iter<'_, u8>> = Default::default();
199199
/// assert_eq!(iter.len(), 0);
200200
/// ```
201+
///
202+
/// This is equivalent to `I::default().fuse()`[^fuse_note]; e.g. if
203+
/// `I::default()` is not an empty iterator, then this will not be
204+
/// an empty iterator.
205+
///
206+
/// ```
207+
/// # use std::iter::Fuse;
208+
/// #[derive(Default)]
209+
/// struct Fourever;
210+
///
211+
/// impl Iterator for Fourever {
212+
/// type Item = u32;
213+
/// fn next(&mut self) -> Option<u32> {
214+
/// Some(4)
215+
/// }
216+
/// }
217+
///
218+
/// let mut iter: Fuse<Fourever> = Default::default();
219+
/// assert_eq!(iter.next(), Some(4));
220+
/// ```
221+
///
222+
/// [^fuse_note]: if `I` does not override `Iterator::fuse`'s default implementation
201223
fn default() -> Self {
202-
Fuse { iter: Default::default() }
224+
Fuse { iter: Some(I::default()) }
203225
}
204226
}
205227

0 commit comments

Comments
 (0)