Skip to content

Commit 4ae1e79

Browse files
committed
Auto merge of #121131 - matthiaskrgr:rollup-mo3b8nz, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #111106 (Add known issue of let binding to format_args doc) - #118749 (Make contributing to windows bindings easier) - #120982 (Add APIs for fetching foreign items ) - #121022 (rustdoc: cross-crate re-exports: correctly render late-bound params in source order even if early-bound params are present) - #121082 (Clarified docs on non-atomic oprations on owned/mut refs to atomics) - #121084 (Make sure `tcx.create_def` also depends on the forever red node, instead of just `tcx.at(span).create_def`) - #121098 (Remove unnecessary else block from `thread_local!` expanded code) - #121105 (Do not report overflow errors on ConstArgHasType goals) - #121116 (Reinstate some delayed bugs.) - #121122 (Enforce coroutine-closure layouts are identical) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bd6b336 + 829b59a commit 4ae1e79

File tree

36 files changed

+577
-166
lines changed

36 files changed

+577
-166
lines changed

Diff for: Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4588,6 +4588,7 @@ dependencies = [
45884588
"rustc_data_structures",
45894589
"rustc_hir",
45904590
"rustc_middle",
4591+
"rustc_session",
45914592
"rustc_span",
45924593
"rustc_target",
45934594
"scoped-tls",

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
323323
)
324324
}
325325
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
326-
ExprKind::Err => hir::ExprKind::Err(self.dcx().has_errors().unwrap()),
326+
ExprKind::Err => {
327+
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
328+
}
327329
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
328330

329331
ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {

Diff for: compiler/rustc_const_eval/src/transform/validate.rs

+20
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,26 @@ impl<'tcx> MirPass<'tcx> for Validator {
9898
}
9999
}
100100
}
101+
102+
// Enforce that coroutine-closure layouts are identical.
103+
if let Some(layout) = body.coroutine_layout()
104+
&& let Some(by_move_body) = body.coroutine_by_move_body()
105+
&& let Some(by_move_layout) = by_move_body.coroutine_layout()
106+
{
107+
if layout != by_move_layout {
108+
// If this turns out not to be true, please let compiler-errors know.
109+
// It is possible to support, but requires some changes to the layout
110+
// computation code.
111+
cfg_checker.fail(
112+
Location::START,
113+
format!(
114+
"Coroutine layout differs from by-move coroutine layout:\n\
115+
layout: {layout:#?}\n\
116+
by_move_layout: {by_move_layout:#?}",
117+
),
118+
);
119+
}
120+
}
101121
}
102122
}
103123

Diff for: compiler/rustc_middle/src/mir/query.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ rustc_index::newtype_index! {
8686
pub struct CoroutineSavedLocal {}
8787
}
8888

89-
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
89+
#[derive(Clone, Debug, PartialEq, Eq)]
90+
#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
9091
pub struct CoroutineSavedTy<'tcx> {
9192
pub ty: Ty<'tcx>,
9293
/// Source info corresponding to the local in the original MIR body.
@@ -96,7 +97,8 @@ pub struct CoroutineSavedTy<'tcx> {
9697
}
9798

9899
/// The layout of coroutine state.
99-
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
100+
#[derive(Clone, PartialEq, Eq)]
101+
#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
100102
pub struct CoroutineLayout<'tcx> {
101103
/// The type of every local stored inside the coroutine.
102104
pub field_tys: IndexVec<CoroutineSavedLocal, CoroutineSavedTy<'tcx>>,

Diff for: compiler/rustc_middle/src/ty/context.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,22 @@ impl<'tcx> TyCtxtAt<'tcx> {
10531053
name: Symbol,
10541054
def_kind: DefKind,
10551055
) -> TyCtxtFeed<'tcx, LocalDefId> {
1056+
let feed = self.tcx.create_def(parent, name, def_kind);
1057+
1058+
feed.def_span(self.span);
1059+
feed
1060+
}
1061+
}
1062+
1063+
impl<'tcx> TyCtxt<'tcx> {
1064+
/// `tcx`-dependent operations performed for every created definition.
1065+
pub fn create_def(
1066+
self,
1067+
parent: LocalDefId,
1068+
name: Symbol,
1069+
def_kind: DefKind,
1070+
) -> TyCtxtFeed<'tcx, LocalDefId> {
1071+
let data = def_kind.def_path_data(name);
10561072
// The following call has the side effect of modifying the tables inside `definitions`.
10571073
// These very tables are relied on by the incr. comp. engine to decode DepNodes and to
10581074
// decode the on-disk cache.
@@ -1067,18 +1083,6 @@ impl<'tcx> TyCtxtAt<'tcx> {
10671083
// This is fine because:
10681084
// - those queries are `eval_always` so we won't miss their result changing;
10691085
// - this write will have happened before these queries are called.
1070-
let def_id = self.tcx.create_def(parent, name, def_kind);
1071-
1072-
let feed = self.tcx.feed_local_def_id(def_id);
1073-
feed.def_span(self.span);
1074-
feed
1075-
}
1076-
}
1077-
1078-
impl<'tcx> TyCtxt<'tcx> {
1079-
/// `tcx`-dependent operations performed for every created definition.
1080-
pub fn create_def(self, parent: LocalDefId, name: Symbol, def_kind: DefKind) -> LocalDefId {
1081-
let data = def_kind.def_path_data(name);
10821086
let def_id = self.untracked.definitions.write().create_def(parent, data);
10831087

10841088
// This function modifies `self.definitions` using a side-effect.
@@ -1098,7 +1102,7 @@ impl<'tcx> TyCtxt<'tcx> {
10981102
feed.visibility(ty::Visibility::Restricted(parent_mod));
10991103
}
11001104

1101-
def_id
1105+
feed
11021106
}
11031107

11041108
pub fn iter_local_def_id(self) -> impl Iterator<Item = LocalDefId> + 'tcx {

Diff for: compiler/rustc_mir_transform/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def: LocalDefId) -> ConstQualifs {
265265
let body = &tcx.mir_const(def).borrow();
266266

267267
if body.return_ty().references_error() {
268-
assert!(tcx.dcx().has_errors().is_some(), "mir_const_qualif: MIR had errors");
268+
// It's possible to reach here without an error being emitted (#121103).
269+
tcx.dcx().span_delayed_bug(body.span, "mir_const_qualif: MIR had errors");
269270
return Default::default();
270271
}
271272

Diff for: compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
12451245
);
12461246

12471247
// FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()`
1248-
let def_id = self.tcx.create_def(parent, name, def_kind);
1248+
let def_id = self.tcx.create_def(parent, name, def_kind).def_id();
12491249

12501250
// Create the definition.
12511251
if expn_id != ExpnId::root() {

Diff for: compiler/rustc_smir/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ rustc_abi = { path = "../rustc_abi" }
99
rustc_data_structures = { path = "../rustc_data_structures" }
1010
rustc_hir = { path = "../rustc_hir" }
1111
rustc_middle = { path = "../rustc_middle" }
12+
rustc_session = { path = "../rustc_session" }
1213
rustc_span = { path = "../rustc_span" }
1314
rustc_target = { path = "../rustc_target" }
1415
scoped-tls = "1.0"

Diff for: compiler/rustc_smir/src/rustc_internal/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ impl<'tcx> Tables<'tcx> {
8585
stable_mir::ty::AdtDef(self.create_def_id(did))
8686
}
8787

88+
pub fn foreign_module_def(&mut self, did: DefId) -> stable_mir::ty::ForeignModuleDef {
89+
stable_mir::ty::ForeignModuleDef(self.create_def_id(did))
90+
}
91+
8892
pub fn foreign_def(&mut self, did: DefId) -> stable_mir::ty::ForeignDef {
8993
stable_mir::ty::ForeignDef(self.create_def_id(did))
9094
}

Diff for: compiler/rustc_smir/src/rustc_smir/context.rs

+51-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ use stable_mir::mir::mono::{InstanceDef, StaticDef};
2222
use stable_mir::mir::Body;
2323
use stable_mir::target::{MachineInfo, MachineSize};
2424
use stable_mir::ty::{
25-
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, GenericArgs,
26-
LineInfo, PolyFnSig, RigidTy, Span, Ty, TyKind, VariantDef,
25+
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, ForeignDef,
26+
ForeignItemKind, GenericArgs, LineInfo, PolyFnSig, RigidTy, Span, Ty, TyKind, VariantDef,
2727
};
28-
use stable_mir::{Crate, CrateItem, CrateNum, DefId, Error, Filename, ItemKind, Symbol};
28+
use stable_mir::{Crate, CrateDef, CrateItem, CrateNum, DefId, Error, Filename, ItemKind, Symbol};
2929
use std::cell::RefCell;
3030
use std::iter;
3131

@@ -67,6 +67,39 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
6767
tables.tcx.is_mir_available(def_id)
6868
}
6969

70+
fn foreign_modules(&self, crate_num: CrateNum) -> Vec<stable_mir::ty::ForeignModuleDef> {
71+
let mut tables = self.0.borrow_mut();
72+
let tcx = tables.tcx;
73+
tcx.foreign_modules(crate_num.internal(&mut *tables, tcx))
74+
.keys()
75+
.map(|mod_def_id| tables.foreign_module_def(*mod_def_id))
76+
.collect()
77+
}
78+
79+
fn foreign_module(
80+
&self,
81+
mod_def: stable_mir::ty::ForeignModuleDef,
82+
) -> stable_mir::ty::ForeignModule {
83+
let mut tables = self.0.borrow_mut();
84+
let def_id = tables[mod_def.def_id()];
85+
let mod_def = tables.tcx.foreign_modules(def_id.krate).get(&def_id).unwrap();
86+
mod_def.stable(&mut *tables)
87+
}
88+
89+
fn foreign_items(&self, mod_def: stable_mir::ty::ForeignModuleDef) -> Vec<ForeignDef> {
90+
let mut tables = self.0.borrow_mut();
91+
let def_id = tables[mod_def.def_id()];
92+
tables
93+
.tcx
94+
.foreign_modules(def_id.krate)
95+
.get(&def_id)
96+
.unwrap()
97+
.foreign_items
98+
.iter()
99+
.map(|item_def| tables.foreign_def(*item_def))
100+
.collect()
101+
}
102+
70103
fn all_trait_decls(&self) -> stable_mir::TraitDecls {
71104
let mut tables = self.0.borrow_mut();
72105
tables.tcx.all_traits().map(|trait_def_id| tables.trait_def(trait_def_id)).collect()
@@ -225,6 +258,21 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
225258
tables.tcx.is_foreign_item(tables[item])
226259
}
227260

261+
fn foreign_item_kind(&self, def: ForeignDef) -> ForeignItemKind {
262+
let mut tables = self.0.borrow_mut();
263+
let def_id = tables[def.def_id()];
264+
let tcx = tables.tcx;
265+
use rustc_hir::def::DefKind;
266+
match tcx.def_kind(def_id) {
267+
DefKind::Fn => ForeignItemKind::Fn(tables.fn_def(def_id)),
268+
DefKind::Static(..) => ForeignItemKind::Static(tables.static_def(def_id)),
269+
DefKind::ForeignTy => ForeignItemKind::Type(
270+
tables.intern_ty(rustc_middle::ty::Ty::new_foreign(tcx, def_id)),
271+
),
272+
def_kind => unreachable!("Unexpected kind for a foreign item: {:?}", def_kind),
273+
}
274+
}
275+
228276
fn adt_kind(&self, def: AdtDef) -> AdtKind {
229277
let mut tables = self.0.borrow_mut();
230278
let tcx = tables.tcx;

Diff for: compiler/rustc_smir/src/rustc_smir/convert/ty.rs

+50-30
Original file line numberDiff line numberDiff line change
@@ -202,41 +202,13 @@ where
202202
impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> {
203203
type T = stable_mir::ty::FnSig;
204204
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
205-
use rustc_target::spec::abi;
206-
use stable_mir::ty::{Abi, FnSig};
205+
use stable_mir::ty::FnSig;
207206

208207
FnSig {
209208
inputs_and_output: self.inputs_and_output.iter().map(|ty| ty.stable(tables)).collect(),
210209
c_variadic: self.c_variadic,
211210
unsafety: self.unsafety.stable(tables),
212-
abi: match self.abi {
213-
abi::Abi::Rust => Abi::Rust,
214-
abi::Abi::C { unwind } => Abi::C { unwind },
215-
abi::Abi::Cdecl { unwind } => Abi::Cdecl { unwind },
216-
abi::Abi::Stdcall { unwind } => Abi::Stdcall { unwind },
217-
abi::Abi::Fastcall { unwind } => Abi::Fastcall { unwind },
218-
abi::Abi::Vectorcall { unwind } => Abi::Vectorcall { unwind },
219-
abi::Abi::Thiscall { unwind } => Abi::Thiscall { unwind },
220-
abi::Abi::Aapcs { unwind } => Abi::Aapcs { unwind },
221-
abi::Abi::Win64 { unwind } => Abi::Win64 { unwind },
222-
abi::Abi::SysV64 { unwind } => Abi::SysV64 { unwind },
223-
abi::Abi::PtxKernel => Abi::PtxKernel,
224-
abi::Abi::Msp430Interrupt => Abi::Msp430Interrupt,
225-
abi::Abi::X86Interrupt => Abi::X86Interrupt,
226-
abi::Abi::EfiApi => Abi::EfiApi,
227-
abi::Abi::AvrInterrupt => Abi::AvrInterrupt,
228-
abi::Abi::AvrNonBlockingInterrupt => Abi::AvrNonBlockingInterrupt,
229-
abi::Abi::CCmseNonSecureCall => Abi::CCmseNonSecureCall,
230-
abi::Abi::Wasm => Abi::Wasm,
231-
abi::Abi::System { unwind } => Abi::System { unwind },
232-
abi::Abi::RustIntrinsic => Abi::RustIntrinsic,
233-
abi::Abi::RustCall => Abi::RustCall,
234-
abi::Abi::PlatformIntrinsic => Abi::PlatformIntrinsic,
235-
abi::Abi::Unadjusted => Abi::Unadjusted,
236-
abi::Abi::RustCold => Abi::RustCold,
237-
abi::Abi::RiscvInterruptM => Abi::RiscvInterruptM,
238-
abi::Abi::RiscvInterruptS => Abi::RiscvInterruptS,
239-
},
211+
abi: self.abi.stable(tables),
240212
}
241213
}
242214
}
@@ -832,3 +804,51 @@ impl<'tcx> Stable<'tcx> for ty::Movability {
832804
}
833805
}
834806
}
807+
808+
impl<'tcx> Stable<'tcx> for rustc_target::spec::abi::Abi {
809+
type T = stable_mir::ty::Abi;
810+
811+
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
812+
use rustc_target::spec::abi;
813+
use stable_mir::ty::Abi;
814+
match *self {
815+
abi::Abi::Rust => Abi::Rust,
816+
abi::Abi::C { unwind } => Abi::C { unwind },
817+
abi::Abi::Cdecl { unwind } => Abi::Cdecl { unwind },
818+
abi::Abi::Stdcall { unwind } => Abi::Stdcall { unwind },
819+
abi::Abi::Fastcall { unwind } => Abi::Fastcall { unwind },
820+
abi::Abi::Vectorcall { unwind } => Abi::Vectorcall { unwind },
821+
abi::Abi::Thiscall { unwind } => Abi::Thiscall { unwind },
822+
abi::Abi::Aapcs { unwind } => Abi::Aapcs { unwind },
823+
abi::Abi::Win64 { unwind } => Abi::Win64 { unwind },
824+
abi::Abi::SysV64 { unwind } => Abi::SysV64 { unwind },
825+
abi::Abi::PtxKernel => Abi::PtxKernel,
826+
abi::Abi::Msp430Interrupt => Abi::Msp430Interrupt,
827+
abi::Abi::X86Interrupt => Abi::X86Interrupt,
828+
abi::Abi::EfiApi => Abi::EfiApi,
829+
abi::Abi::AvrInterrupt => Abi::AvrInterrupt,
830+
abi::Abi::AvrNonBlockingInterrupt => Abi::AvrNonBlockingInterrupt,
831+
abi::Abi::CCmseNonSecureCall => Abi::CCmseNonSecureCall,
832+
abi::Abi::Wasm => Abi::Wasm,
833+
abi::Abi::System { unwind } => Abi::System { unwind },
834+
abi::Abi::RustIntrinsic => Abi::RustIntrinsic,
835+
abi::Abi::RustCall => Abi::RustCall,
836+
abi::Abi::PlatformIntrinsic => Abi::PlatformIntrinsic,
837+
abi::Abi::Unadjusted => Abi::Unadjusted,
838+
abi::Abi::RustCold => Abi::RustCold,
839+
abi::Abi::RiscvInterruptM => Abi::RiscvInterruptM,
840+
abi::Abi::RiscvInterruptS => Abi::RiscvInterruptS,
841+
}
842+
}
843+
}
844+
845+
impl<'tcx> Stable<'tcx> for rustc_session::cstore::ForeignModule {
846+
type T = stable_mir::ty::ForeignModule;
847+
848+
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
849+
stable_mir::ty::ForeignModule {
850+
def_id: tables.foreign_module_def(self.def_id),
851+
abi: self.abi.stable(tables),
852+
}
853+
}
854+
}

Diff for: compiler/rustc_trait_selection/src/traits/fulfill.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,21 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
423423
ty::PredicateKind::AliasRelate(..) => {
424424
bug!("AliasRelate is only used by the new solver")
425425
}
426+
// Compute `ConstArgHasType` above the overflow check below.
427+
// This is because this is not ever a useful obligation to report
428+
// as the cause of an overflow.
429+
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
430+
match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
431+
DefineOpaqueTypes::No,
432+
ct.ty(),
433+
ty,
434+
) {
435+
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
436+
Err(_) => ProcessResult::Error(FulfillmentErrorCode::SelectionError(
437+
SelectionError::Unimplemented,
438+
)),
439+
}
440+
}
426441

427442
// General case overflow check. Allow `process_trait_obligation`
428443
// and `process_projection_obligation` to handle checking for
@@ -650,18 +665,6 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
650665
}
651666
}
652667
}
653-
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
654-
match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
655-
DefineOpaqueTypes::No,
656-
ct.ty(),
657-
ty,
658-
) {
659-
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
660-
Err(_) => ProcessResult::Error(FulfillmentErrorCode::SelectionError(
661-
SelectionError::Unimplemented,
662-
)),
663-
}
664-
}
665668
},
666669
}
667670
}

0 commit comments

Comments
 (0)