Skip to content

Rollup of 9 pull requests #142180

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

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eec894d
Fix future-incompatible lint group test
Urgau May 1, 2025
80c6a08
Allow `#![doc(test(attr(..)))]` at module level too
Urgau May 1, 2025
9d9705f
Collect and use `#![doc(test(attr(..)))]` at module level too
Urgau May 1, 2025
041d95d
Allow `#![doc(test(attr(..)))]` doctests to be again merged together
Urgau May 1, 2025
316e62a
Allow `#![doc(test(attr(..)))]` at every level
Urgau May 5, 2025
d96d3be
Collect and use `#[doc(test(attr(..)))]` at every level
Urgau May 5, 2025
a08f6f1
document representation of `Option<unsafe fn()>`
y86-dev May 23, 2025
2579d41
add (back) unsupported_calling_conventions lint to reject more invali…
RalfJung May 23, 2025
638d170
raw dylib: ensure that we have applied standard ABI checks
RalfJung May 23, 2025
7c3fa82
avoid repeating error annotations in test file
RalfJung May 23, 2025
207b14a
add specific help messages for stdcall and cdecl
RalfJung May 29, 2025
53c1301
Stabilize `const_eq_ignore_ascii_case`
paolobarbolini Jun 5, 2025
46a936a
bootstrap: fix tracing imports
jieyouxu Jun 6, 2025
7efd90a
Treat normalizing consts like normalizing types in deeply normalize
compiler-errors Jun 6, 2025
aa1b296
Unify normalization of terms in deeply normalize
compiler-errors Jun 6, 2025
8aafcc8
compiler: Sort and doc ExternAbi variants
workingjubilee Jun 7, 2025
f66487b
compiler: Remove superfluous renaming import of ExternAbi
workingjubilee Jun 7, 2025
5bab0d2
compiler: Treat ForceWarning as a Warning for diagnostic level
workingjubilee Jun 7, 2025
6a6c595
get rid of spurious cfg(bootstrap)
RalfJung Jun 7, 2025
ec6dfb0
Rollup merge of #140560 - Urgau:test_attr-module-level, r=GuillaumeGomez
GuillaumeGomez Jun 7, 2025
208e6e9
Rollup merge of #141435 - RalfJung:unsupported_calling_conventions, r…
GuillaumeGomez Jun 7, 2025
4d1e42a
Rollup merge of #141447 - y86-dev:option-layout-docs, r=RalfJung
GuillaumeGomez Jun 7, 2025
692ed4c
Rollup merge of #142065 - paolobarbolini:stabilize-const_eq_ignore_as…
GuillaumeGomez Jun 7, 2025
6b6eced
Rollup merge of #142116 - jieyouxu:fix-tracing, r=Mark-Simulacrum
GuillaumeGomez Jun 7, 2025
7a1bad7
Rollup merge of #142126 - compiler-errors:normalize-uv-via-relate, r=…
GuillaumeGomez Jun 7, 2025
0acdd54
Rollup merge of #142140 - workingjubilee:sort-extern-abi-variants, r=…
GuillaumeGomez Jun 7, 2025
165bed5
Rollup merge of #142148 - workingjubilee:dont-ice-on-force-warn, r=Urgau
GuillaumeGomez Jun 7, 2025
292562e
Rollup merge of #142154 - RalfJung:no-more-cfg-bootstrap, r=oli-obk
GuillaumeGomez Jun 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 Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3786,6 +3786,7 @@ dependencies = [
"rustc_middle",
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"smallvec",
"tracing",
Expand Down
99 changes: 63 additions & 36 deletions compiler/rustc_abi/src/extern_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,66 +12,93 @@ use crate::AbiFromStrErr;
#[cfg(test)]
mod tests;

use ExternAbi as Abi;

/// ABI we expect to see within `extern "{abi}"`
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable))]
pub enum ExternAbi {
// Some of the ABIs come first because every time we add a new ABI, we have to re-bless all the
// hashing tests. These are used in many places, so giving them stable values reduces test
// churn. The specific values are meaningless.
Rust,
/* universal */
/// presumed C ABI for the platform
C {
unwind: bool,
},
Cdecl {
/// ABI of the "system" interface, e.g. the Win32 API, always "aliasing"
System {
unwind: bool,
},
Stdcall {

/// that's us!
Rust,
/// the mostly-unused `unboxed_closures` ABI, effectively now an impl detail unless someone
/// puts in the work to make it viable again... but would we need a special ABI?
RustCall,
/// For things unlikely to be called, where reducing register pressure in
/// `extern "Rust"` callers is worth paying extra cost in the callee.
/// Stronger than just `#[cold]` because `fn` pointers might be incompatible.
RustCold,

/// Unstable impl detail that directly uses Rust types to describe the ABI to LLVM.
/// Even normally-compatible Rust types can become ABI-incompatible with this ABI!
Unadjusted,

/// UEFI ABI, usually an alias of C, but sometimes an arch-specific alias
/// and only valid on platforms that have a UEFI standard
EfiApi,

/* arm */
/// Arm Architecture Procedure Call Standard, sometimes `ExternAbi::C` is an alias for this
Aapcs {
unwind: bool,
},
Fastcall {
/// extremely constrained barely-C ABI for TrustZone
CCmseNonSecureCall,
/// extremely constrained barely-C ABI for TrustZone
CCmseNonSecureEntry,

/* gpu */
/// An entry-point function called by the GPU's host
// FIXME: should not be callable from Rust on GPU targets, is for host's use only
GpuKernel,
/// An entry-point function called by the GPU's host
// FIXME: why do we have two of these?
PtxKernel,

/* interrupt */
AvrInterrupt,
AvrNonBlockingInterrupt,
Msp430Interrupt,
RiscvInterruptM,
RiscvInterruptS,
X86Interrupt,

/* x86 */
/// `ExternAbi::C` but spelled funny because x86
Cdecl {
unwind: bool,
},
Vectorcall {
/// gnu-stdcall on "unix" and win-stdcall on "windows"
Stdcall {
unwind: bool,
},
Thiscall {
/// gnu-fastcall on "unix" and win-fastcall on "windows"
Fastcall {
unwind: bool,
},
Aapcs {
/// windows C++ ABI
Thiscall {
unwind: bool,
},
Win64 {
/// uses AVX and stuff
Vectorcall {
unwind: bool,
},

/* x86_64 */
SysV64 {
unwind: bool,
},
PtxKernel,
Msp430Interrupt,
X86Interrupt,
/// An entry-point function called by the GPU's host
// FIXME: should not be callable from Rust on GPU targets, is for host's use only
GpuKernel,
EfiApi,
AvrInterrupt,
AvrNonBlockingInterrupt,
CCmseNonSecureCall,
CCmseNonSecureEntry,
System {
Win64 {
unwind: bool,
},
RustCall,
/// *Not* a stable ABI, just directly use the Rust types to describe the ABI for LLVM. Even
/// normally ABI-compatible Rust types can become ABI-incompatible with this ABI!
Unadjusted,
/// For things unlikely to be called, where reducing register pressure in
/// `extern "Rust"` callers is worth paying extra cost in the callee.
/// Stronger than just `#[cold]` because `fn` pointers might be incompatible.
RustCold,
RiscvInterruptM,
RiscvInterruptS,
}

macro_rules! abi_impls {
Expand Down Expand Up @@ -224,7 +251,7 @@ pub fn all_names() -> Vec<&'static str> {

impl ExternAbi {
/// Default ABI chosen for `extern fn` declarations without an explicit ABI.
pub const FALLBACK: Abi = Abi::C { unwind: false };
pub const FALLBACK: ExternAbi = ExternAbi::C { unwind: false };

pub fn name(self) -> &'static str {
self.as_str()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ impl DiagCtxtInner {
// Future breakages aren't emitted if they're `Level::Allow` or
// `Level::Expect`, but they still need to be constructed and
// stashed below, so they'll trigger the must_produce_diag check.
assert_matches!(diagnostic.level, Error | Warning | Allow | Expect);
assert_matches!(diagnostic.level, Error | ForceWarning | Warning | Allow | Expect);
self.future_breakage_diagnostics.push(diagnostic.clone());
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rustc_macros = { path = "../rustc_macros" }
rustc_middle = { path = "../rustc_middle" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tracing = "0.1"
Expand Down
69 changes: 51 additions & 18 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use std::ops::ControlFlow;
use rustc_abi::FieldIdx;
use rustc_attr_data_structures::ReprAttr::ReprPacked;
use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_errors::MultiSpan;
use rustc_errors::codes::*;
use rustc_errors::{EmissionGuarantee, MultiSpan};
use rustc_hir::def::{CtorKind, DefKind};
use rustc_hir::{LangItem, Node, intravisit};
use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
use rustc_infer::traits::{Obligation, ObligationCauseCode};
use rustc_lint_defs::builtin::{
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS, UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
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 All @@ -24,6 +25,7 @@ use rustc_middle::ty::{
TypeVisitable, TypeVisitableExt, fold_regions,
};
use rustc_session::lint::builtin::UNINHABITED_STATIC;
use rustc_target::spec::{AbiMap, AbiMapping};
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplementedDirective;
use rustc_trait_selection::traits;
Expand All @@ -35,25 +37,56 @@ use {rustc_attr_data_structures as attrs, rustc_hir as hir};
use super::compare_impl_item::check_type_bounds;
use super::*;

pub fn check_abi(tcx: TyCtxt<'_>, span: Span, abi: ExternAbi) {
if !tcx.sess.target.is_abi_supported(abi) {
struct_span_code_err!(
tcx.dcx(),
span,
E0570,
"`{abi}` is not a supported ABI for the current target",
)
.emit();
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.
fn add_help<T: EmissionGuarantee>(abi: ExternAbi, diag: &mut Diag<'_, T>) {
if let ExternAbi::Cdecl { unwind } = abi {
let c_abi = ExternAbi::C { unwind };
diag.help(format!("use `extern {c_abi}` instead",));
} else if let ExternAbi::Stdcall { unwind } = abi {
let c_abi = ExternAbi::C { unwind };
let system_abi = ExternAbi::System { unwind };
diag.help(format!(
"if you need `extern {abi}` on win32 and `extern {c_abi}` everywhere else, \
use `extern {system_abi}`"
));
}
}

match AbiMap::from_target(&tcx.sess.target).canonize_abi(abi, false) {
AbiMapping::Direct(..) => (),
AbiMapping::Invalid => {
let mut err = struct_span_code_err!(
tcx.dcx(),
span,
E0570,
"`{abi}` is not a supported ABI for the current target",
);
add_help(abi, &mut err);
err.emit();
}
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_help(abi, lint);
});
}
}
}

pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi) {
if !tcx.sess.target.is_abi_supported(abi) {
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"
));
});
// 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(..) => (),
AbiMapping::Deprecated(..) | 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"
));
});
}
}
}

Expand Down Expand Up @@ -779,7 +812,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.span, abi);
check_abi(tcx, it.hir_id(), it.span, abi);

for item in items {
let def_id = item.id.owner_id.def_id;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn typeck_with_inspect<'tcx>(
tcx.fn_sig(def_id).instantiate_identity()
};

check_abi(tcx, span, fn_sig.abi());
check_abi(tcx, id, span, fn_sig.abi());

// Compute the function signature from point of view of inside the fn.
let mut fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,13 @@ impl<'tcx> InferCtxt<'tcx> {
ty::Region::new_var(self.tcx, region_var)
}

pub fn next_term_var_of_kind(&self, term: ty::Term<'tcx>, span: Span) -> ty::Term<'tcx> {
match term.kind() {
ty::TermKind::Ty(_) => self.next_ty_var(span).into(),
ty::TermKind::Const(_) => self.next_const_var(span).into(),
}
}

/// Return the universe that the region `r` was created in. For
/// most regions (e.g., `'static`, named regions from the user,
/// etc) this is the root universe U0. For inference variables or
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,6 @@ fn register_builtins(store: &mut LintStore) {
"converted into hard error, see PR #125380 \
<https://github.com/rust-lang/rust/pull/125380> for more information",
);
store.register_removed("unsupported_calling_conventions", "converted into hard error");
store.register_removed(
"cenum_impl_drop_cast",
"converted into hard error, \
Expand Down
48 changes: 48 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3621,6 +3621,54 @@ declare_lint! {
crate_level_only
}

declare_lint! {
/// The `unsupported_calling_conventions` lint is output whenever there is a use of the
/// `stdcall`, `fastcall`, and `cdecl` calling conventions (or their unwind
/// variants) on targets that cannot meaningfully be supported for the requested target.
///
/// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
/// code, because this calling convention was never specified for those targets.
///
/// Historically MSVC toolchains have fallen back to the regular C calling convention for
/// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
/// hack across many more targets.
///
/// ### Example
///
/// ```rust,ignore (needs specific targets)
/// extern "stdcall" fn stdcall() {}
/// ```
///
/// This will produce:
///
/// ```text
/// warning: use of calling convention not supported on this target
/// --> $DIR/unsupported.rs:39:1
/// |
/// LL | extern "stdcall" fn stdcall() {}
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/// |
/// = note: `#[warn(unsupported_calling_conventions)]` on by default
/// = warning: this was previously accepted by the compiler but is being phased out;
/// it will become a hard error in a future release!
/// = note: for more information, see issue ...
/// ```
///
/// ### Explanation
///
/// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
/// defined at all, but was previously accepted due to a bug in the implementation of the
/// compiler.
pub UNSUPPORTED_CALLING_CONVENTIONS,
Warn,
"use of unsupported calling convention",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseError,
report_in_deps: true,
reference: "issue #137018 <https://github.com/rust-lang/rust/issues/137018>",
};
}

declare_lint! {
/// The `unsupported_fn_ptr_calling_conventions` lint is output whenever there is a use of
/// a target dependent calling convention on a target that does not support this calling
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_metadata/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ metadata_raw_dylib_no_nul =
metadata_raw_dylib_only_windows =
link kind `raw-dylib` is only supported on Windows targets

metadata_raw_dylib_unsupported_abi =
ABI not supported by `#[link(kind = "raw-dylib")]` on this architecture

metadata_renaming_no_link =
renaming of the library `{$lib_name}` was specified, however this crate contains no `#[link(...)]` attributes referencing this library

Expand Down Expand Up @@ -319,12 +322,6 @@ metadata_unknown_link_modifier =

metadata_unknown_target_modifier_unsafe_allowed = unknown target modifier `{$flag_name}`, requested by `-Cunsafe-allow-abi-mismatch={$flag_name}`

metadata_unsupported_abi =
ABI not supported by `#[link(kind = "raw-dylib")]` on this architecture

metadata_unsupported_abi_i686 =
ABI not supported by `#[link(kind = "raw-dylib")]` on i686

metadata_wasm_c_abi =
older versions of the `wasm-bindgen` crate are incompatible with current versions of Rust; please update to `wasm-bindgen` v0.2.88

Expand Down
11 changes: 2 additions & 9 deletions compiler/rustc_metadata/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,8 @@ pub struct NoLinkModOverride {
}

#[derive(Diagnostic)]
#[diag(metadata_unsupported_abi_i686)]
pub struct UnsupportedAbiI686 {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(metadata_unsupported_abi)]
pub struct UnsupportedAbi {
#[diag(metadata_raw_dylib_unsupported_abi)]
pub struct RawDylibUnsupportedAbi {
#[primary_span]
pub span: Span,
}
Expand Down
Loading
Loading