Skip to content

Commit 6d0c9e2

Browse files
committed
Auto merge of #142817 - matthiaskrgr:rollup-mrobovy, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #142502 (rustdoc_json: improve handling of generic args) - #142597 (error on calls to ABIs that cannot be called) - #142785 (fix(linkcheck): Build using the lockfile) - #142787 (Add diagnostic items for Clippy) - #142788 (add doc(alias("AsciiChar")) to core::ascii::Char) - #142801 (Use gen blocks in the compiler instead of `from_coroutine`) - #142804 (Rename `LayoutS` to `LayoutData` in comments) r? `@ghost` `@rustbot` modify labels: rollup
2 parents df4ad9e + 4e87031 commit 6d0c9e2

Some content is hidden

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

57 files changed

+1635
-425
lines changed

compiler/rustc_abi/src/layout.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
432432
align = align.min(AbiAlign::new(pack));
433433
}
434434
// The unadjusted ABI alignment does not include repr(align), but does include repr(pack).
435-
// See documentation on `LayoutS::unadjusted_abi_align`.
435+
// See documentation on `LayoutData::unadjusted_abi_align`.
436436
let unadjusted_abi_align = align.abi;
437437
if let Some(repr_align) = repr.align {
438438
align = align.max(AbiAlign::new(repr_align));
@@ -602,10 +602,10 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
602602
dont_niche_optimize_enum: bool,
603603
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F> {
604604
// Until we've decided whether to use the tagged or
605-
// niche filling LayoutS, we don't want to intern the
605+
// niche filling LayoutData, we don't want to intern the
606606
// variant layouts, so we can't store them in the
607-
// overall LayoutS. Store the overall LayoutS
608-
// and the variant LayoutSs here until then.
607+
// overall LayoutData. Store the overall LayoutData
608+
// and the variant LayoutDatas here until then.
609609
struct TmpLayout<FieldIdx: Idx, VariantIdx: Idx> {
610610
layout: LayoutData<FieldIdx, VariantIdx>,
611611
variants: IndexVec<VariantIdx, LayoutData<FieldIdx, VariantIdx>>,
@@ -1214,7 +1214,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
12141214

12151215
match kind {
12161216
StructKind::AlwaysSized | StructKind::MaybeUnsized => {
1217-
// Currently `LayoutS` only exposes a single niche so sorting is usually
1217+
// Currently `LayoutData` only exposes a single niche so sorting is usually
12181218
// sufficient to get one niche into the preferred position. If it ever
12191219
// supported multiple niches then a more advanced pick-and-pack approach could
12201220
// provide better results. But even for the single-niche cache it's not
@@ -1333,7 +1333,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
13331333
}
13341334

13351335
// The unadjusted ABI alignment does not include repr(align), but does include repr(pack).
1336-
// See documentation on `LayoutS::unadjusted_abi_align`.
1336+
// See documentation on `LayoutData::unadjusted_abi_align`.
13371337
let unadjusted_abi_align = align.abi;
13381338
if let Some(repr_align) = repr.align {
13391339
align = align.max(AbiAlign::new(repr_align));

compiler/rustc_abi/src/layout/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub struct Layout<'a>(pub Interned<'a, LayoutData<FieldIdx, VariantIdx>>);
7171

7272
impl<'a> fmt::Debug for Layout<'a> {
7373
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74-
// See comment on `<LayoutS as Debug>::fmt` above.
74+
// See comment on `<LayoutData as Debug>::fmt` above.
7575
self.0.0.fmt(f)
7676
}
7777
}

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ where
17851785
{
17861786
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17871787
// This is how `Layout` used to print before it become
1788-
// `Interned<LayoutS>`. We print it like this to avoid having to update
1788+
// `Interned<LayoutData>`. We print it like this to avoid having to update
17891789
// expected output in a lot of tests.
17901790
let LayoutData {
17911791
size,

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 64 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,84 +2177,80 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
21772177
/// Walk the generics of the item for a trait bound whose self type
21782178
/// corresponds to the expected res, and return the trait def id.
21792179
fn for_each_trait_bound_on_res(&self, expected_res: Res) -> impl Iterator<Item = DefId> {
2180-
std::iter::from_coroutine(
2181-
#[coroutine]
2182-
move || {
2183-
let mut scope = self.scope;
2184-
loop {
2185-
let hir_id = match *scope {
2186-
Scope::Binder { hir_id, .. } => Some(hir_id),
2187-
Scope::Root { opt_parent_item: Some(parent_def_id) } => {
2188-
Some(self.tcx.local_def_id_to_hir_id(parent_def_id))
2189-
}
2190-
Scope::Body { .. }
2191-
| Scope::ObjectLifetimeDefault { .. }
2192-
| Scope::Supertrait { .. }
2193-
| Scope::TraitRefBoundary { .. }
2194-
| Scope::LateBoundary { .. }
2195-
| Scope::Opaque { .. }
2196-
| Scope::Root { opt_parent_item: None } => None,
2197-
};
2180+
gen move {
2181+
let mut scope = self.scope;
2182+
loop {
2183+
let hir_id = match *scope {
2184+
Scope::Binder { hir_id, .. } => Some(hir_id),
2185+
Scope::Root { opt_parent_item: Some(parent_def_id) } => {
2186+
Some(self.tcx.local_def_id_to_hir_id(parent_def_id))
2187+
}
2188+
Scope::Body { .. }
2189+
| Scope::ObjectLifetimeDefault { .. }
2190+
| Scope::Supertrait { .. }
2191+
| Scope::TraitRefBoundary { .. }
2192+
| Scope::LateBoundary { .. }
2193+
| Scope::Opaque { .. }
2194+
| Scope::Root { opt_parent_item: None } => None,
2195+
};
21982196

2199-
if let Some(hir_id) = hir_id {
2200-
let node = self.tcx.hir_node(hir_id);
2201-
// If this is a `Self` bound in a trait, yield the trait itself.
2202-
// Specifically, we don't need to look at any supertraits since
2203-
// we already do that in `BoundVarContext::supertrait_hrtb_vars`.
2204-
if let Res::SelfTyParam { trait_: _ } = expected_res
2205-
&& let hir::Node::Item(item) = node
2206-
&& let hir::ItemKind::Trait(..) = item.kind
2207-
{
2208-
// Yield the trait's def id. Supertraits will be
2209-
// elaborated from that.
2210-
yield item.owner_id.def_id.to_def_id();
2211-
} else if let Some(generics) = node.generics() {
2212-
for pred in generics.predicates {
2213-
let hir::WherePredicateKind::BoundPredicate(pred) = pred.kind
2214-
else {
2215-
continue;
2216-
};
2217-
let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
2218-
pred.bounded_ty.kind
2219-
else {
2220-
continue;
2221-
};
2222-
// Match the expected res.
2223-
if bounded_path.res != expected_res {
2224-
continue;
2225-
}
2226-
for pred in pred.bounds {
2227-
match pred {
2228-
hir::GenericBound::Trait(poly_trait_ref) => {
2229-
if let Some(def_id) =
2230-
poly_trait_ref.trait_ref.trait_def_id()
2231-
{
2232-
yield def_id;
2233-
}
2197+
if let Some(hir_id) = hir_id {
2198+
let node = self.tcx.hir_node(hir_id);
2199+
// If this is a `Self` bound in a trait, yield the trait itself.
2200+
// Specifically, we don't need to look at any supertraits since
2201+
// we already do that in `BoundVarContext::supertrait_hrtb_vars`.
2202+
if let Res::SelfTyParam { trait_: _ } = expected_res
2203+
&& let hir::Node::Item(item) = node
2204+
&& let hir::ItemKind::Trait(..) = item.kind
2205+
{
2206+
// Yield the trait's def id. Supertraits will be
2207+
// elaborated from that.
2208+
yield item.owner_id.def_id.to_def_id();
2209+
} else if let Some(generics) = node.generics() {
2210+
for pred in generics.predicates {
2211+
let hir::WherePredicateKind::BoundPredicate(pred) = pred.kind else {
2212+
continue;
2213+
};
2214+
let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
2215+
pred.bounded_ty.kind
2216+
else {
2217+
continue;
2218+
};
2219+
// Match the expected res.
2220+
if bounded_path.res != expected_res {
2221+
continue;
2222+
}
2223+
for pred in pred.bounds {
2224+
match pred {
2225+
hir::GenericBound::Trait(poly_trait_ref) => {
2226+
if let Some(def_id) =
2227+
poly_trait_ref.trait_ref.trait_def_id()
2228+
{
2229+
yield def_id;
22342230
}
2235-
hir::GenericBound::Outlives(_)
2236-
| hir::GenericBound::Use(_, _) => {}
22372231
}
2232+
hir::GenericBound::Outlives(_)
2233+
| hir::GenericBound::Use(_, _) => {}
22382234
}
22392235
}
22402236
}
22412237
}
2238+
}
22422239

2243-
match *scope {
2244-
Scope::Binder { s, .. }
2245-
| Scope::Body { s, .. }
2246-
| Scope::ObjectLifetimeDefault { s, .. }
2247-
| Scope::Supertrait { s, .. }
2248-
| Scope::TraitRefBoundary { s }
2249-
| Scope::LateBoundary { s, .. }
2250-
| Scope::Opaque { s, .. } => {
2251-
scope = s;
2252-
}
2253-
Scope::Root { .. } => break,
2240+
match *scope {
2241+
Scope::Binder { s, .. }
2242+
| Scope::Body { s, .. }
2243+
| Scope::ObjectLifetimeDefault { s, .. }
2244+
| Scope::Supertrait { s, .. }
2245+
| Scope::TraitRefBoundary { s }
2246+
| Scope::LateBoundary { s, .. }
2247+
| Scope::Opaque { s, .. } => {
2248+
scope = s;
22542249
}
2250+
Scope::Root { .. } => break,
22552251
}
2256-
},
2257-
)
2252+
}
2253+
}
22582254
}
22592255
}
22602256

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ This API is completely unstable and subject to change.
6262
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
6363
#![doc(rust_logo)]
6464
#![feature(assert_matches)]
65-
#![feature(coroutines)]
6665
#![feature(debug_closure_helpers)]
66+
#![feature(gen_blocks)]
6767
#![feature(if_let_guard)]
6868
#![feature(iter_from_coroutine)]
6969
#![feature(iter_intersperse)]

compiler/rustc_hir_typeck/messages.ftl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
hir_typeck_abi_custom_call =
2-
functions with the `"custom"` ABI cannot be called
3-
.note = an `extern "custom"` function can only be called from within inline assembly
1+
hir_typeck_abi_cannot_be_called =
2+
functions with the {$abi} ABI cannot be called
3+
.note = an `extern {$abi}` function can only be called using inline assembly
44
55
hir_typeck_add_missing_parentheses_in_range = you must surround the range in parentheses to call its `{$func_name}` function
66

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::iter;
22

3-
use rustc_abi::ExternAbi;
3+
use rustc_abi::{CanonAbi, ExternAbi};
44
use rustc_ast::util::parser::ExprPrecedence;
55
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey};
66
use rustc_hir::def::{self, CtorKind, Namespace, Res};
@@ -16,6 +16,7 @@ use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt};
1616
use rustc_middle::{bug, span_bug};
1717
use rustc_span::def_id::LocalDefId;
1818
use rustc_span::{Span, sym};
19+
use rustc_target::spec::{AbiMap, AbiMapping};
1920
use rustc_trait_selection::error_reporting::traits::DefIdOrName;
2021
use rustc_trait_selection::infer::InferCtxtExt as _;
2122
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
@@ -84,7 +85,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8485
while result.is_none() && autoderef.next().is_some() {
8586
result = self.try_overloaded_call_step(call_expr, callee_expr, arg_exprs, &autoderef);
8687
}
87-
self.check_call_custom_abi(autoderef.final_ty(false), call_expr.span);
88+
89+
match autoderef.final_ty(false).kind() {
90+
ty::FnDef(def_id, _) => {
91+
let abi = self.tcx.fn_sig(def_id).skip_binder().skip_binder().abi;
92+
self.check_call_abi(abi, call_expr.span);
93+
}
94+
ty::FnPtr(_, header) => {
95+
self.check_call_abi(header.abi, call_expr.span);
96+
}
97+
_ => { /* cannot have a non-rust abi */ }
98+
}
99+
88100
self.register_predicates(autoderef.into_obligations());
89101

90102
let output = match result {
@@ -137,19 +149,37 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
137149
output
138150
}
139151

140-
/// Functions of type `extern "custom" fn(/* ... */)` cannot be called using `ExprKind::Call`.
152+
/// Can a function with this ABI be called with a rust call expression?
141153
///
142-
/// These functions have a calling convention that is unknown to rust, hence it cannot generate
143-
/// code for the call. The only way to execute such a function is via inline assembly.
144-
fn check_call_custom_abi(&self, callee_ty: Ty<'tcx>, span: Span) {
145-
let abi = match callee_ty.kind() {
146-
ty::FnDef(def_id, _) => self.tcx.fn_sig(def_id).skip_binder().skip_binder().abi,
147-
ty::FnPtr(_, header) => header.abi,
148-
_ => return,
154+
/// Some ABIs cannot be called from rust, either because rust does not know how to generate
155+
/// code for the call, or because a call does not semantically make sense.
156+
pub(crate) fn check_call_abi(&self, abi: ExternAbi, span: Span) {
157+
let canon_abi = match AbiMap::from_target(&self.sess().target).canonize_abi(abi, false) {
158+
AbiMapping::Direct(canon_abi) | AbiMapping::Deprecated(canon_abi) => canon_abi,
159+
AbiMapping::Invalid => return,
160+
};
161+
162+
let valid = match canon_abi {
163+
// Rust doesn't know how to call functions with this ABI.
164+
CanonAbi::Custom => false,
165+
166+
// These is an entry point for the host, and cannot be called on the GPU.
167+
CanonAbi::GpuKernel => false,
168+
169+
// The interrupt ABIs should only be called by the CPU. They have complex
170+
// pre- and postconditions, and can use non-standard instructions like `iret` on x86.
171+
CanonAbi::Interrupt(_) => false,
172+
173+
CanonAbi::C
174+
| CanonAbi::Rust
175+
| CanonAbi::RustCold
176+
| CanonAbi::Arm(_)
177+
| CanonAbi::X86(_) => true,
149178
};
150179

151-
if let ExternAbi::Custom = abi {
152-
self.tcx.dcx().emit_err(errors::AbiCustomCall { span });
180+
if !valid {
181+
let err = crate::errors::AbiCannotBeCalled { span, abi };
182+
self.tcx.dcx().emit_err(err);
153183
}
154184
}
155185

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::borrow::Cow;
44

5+
use rustc_abi::ExternAbi;
56
use rustc_ast::Label;
67
use rustc_errors::codes::*;
78
use rustc_errors::{
@@ -1159,8 +1160,10 @@ pub(crate) struct NakedFunctionsMustNakedAsm {
11591160
}
11601161

11611162
#[derive(Diagnostic)]
1162-
#[diag(hir_typeck_abi_custom_call)]
1163-
pub(crate) struct AbiCustomCall {
1163+
#[diag(hir_typeck_abi_cannot_be_called)]
1164+
pub(crate) struct AbiCannotBeCalled {
11641165
#[primary_span]
1166+
#[note]
11651167
pub span: Span,
1168+
pub abi: ExternAbi,
11661169
}

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//!
66
//! See [`rustc_hir_analysis::check`] for more context on type checking in general.
77
8-
use rustc_abi::{ExternAbi, FIRST_VARIANT, FieldIdx};
8+
use rustc_abi::{FIRST_VARIANT, FieldIdx};
99
use rustc_ast::util::parser::ExprPrecedence;
1010
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1111
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -1650,13 +1650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16501650
Some(method.def_id),
16511651
);
16521652

1653-
// Functions of type `extern "custom" fn(/* ... */)` cannot be called using
1654-
// `ExprKind::MethodCall`. These functions have a calling convention that is
1655-
// unknown to rust, hence it cannot generate code for the call. The only way
1656-
// to execute such a function is via inline assembly.
1657-
if let ExternAbi::Custom = method.sig.abi {
1658-
self.tcx.dcx().emit_err(crate::errors::AbiCustomCall { span: expr.span });
1659-
}
1653+
self.check_call_abi(method.sig.abi, expr.span);
16601654

16611655
method.sig.output()
16621656
}

compiler/rustc_metadata/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#![allow(internal_features)]
33
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
44
#![doc(rust_logo)]
5-
#![feature(coroutines)]
65
#![feature(decl_macro)]
76
#![feature(error_iter)]
87
#![feature(file_buffered)]
8+
#![feature(gen_blocks)]
99
#![feature(if_let_guard)]
1010
#![feature(iter_from_coroutine)]
1111
#![feature(macro_metavar_expr)]

0 commit comments

Comments
 (0)