Skip to content

Commit 8ce4540

Browse files
committed
Auto merge of rust-lang#116275 - matthiaskrgr:rollup-prx5fto, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#112123 (fix(suggestion): insert projection to associated types) - rust-lang#116024 (Implement Region for smir) - rust-lang#116030 (run abi/compatibility test against a whole bunch of targets) - rust-lang#116216 (ci: upgrade to crosstool-ng 1.26.0) - rust-lang#116241 (Add Exclusive forwarding impls (FnOnce, FnMut, Generator)) - rust-lang#116263 (More fixes for running the test suite on a bare metal target) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 56ada88 + 3ee2c52 commit 8ce4540

File tree

24 files changed

+450
-80
lines changed

24 files changed

+450
-80
lines changed

Diff for: compiler/rustc_hir_analysis/src/check/mod.rs

+39-28
Original file line numberDiff line numberDiff line change
@@ -329,41 +329,52 @@ fn bounds_from_generic_predicates<'tcx>(
329329
_ => {}
330330
}
331331
}
332-
let generics = if types.is_empty() {
333-
"".to_string()
334-
} else {
335-
format!(
336-
"<{}>",
337-
types
338-
.keys()
339-
.filter_map(|t| match t.kind() {
340-
ty::Param(_) => Some(t.to_string()),
341-
// Avoid suggesting the following:
342-
// fn foo<T, <T as Trait>::Bar>(_: T) where T: Trait, <T as Trait>::Bar: Other {}
343-
_ => None,
344-
})
345-
.collect::<Vec<_>>()
346-
.join(", ")
347-
)
348-
};
332+
349333
let mut where_clauses = vec![];
334+
let mut types_str = vec![];
350335
for (ty, bounds) in types {
351-
where_clauses
352-
.extend(bounds.into_iter().map(|bound| format!("{}: {}", ty, tcx.def_path_str(bound))));
353-
}
354-
for projection in &projections {
355-
let p = projection.skip_binder();
356-
// FIXME: this is not currently supported syntax, we should be looking at the `types` and
357-
// insert the associated types where they correspond, but for now let's be "lazy" and
358-
// propose this instead of the following valid resugaring:
359-
// `T: Trait, Trait::Assoc = K` → `T: Trait<Assoc = K>`
360-
where_clauses.push(format!("{} = {}", tcx.def_path_str(p.projection_ty.def_id), p.term));
336+
if let ty::Param(_) = ty.kind() {
337+
let mut bounds_str = vec![];
338+
for bound in bounds {
339+
let mut projections_str = vec![];
340+
for projection in &projections {
341+
let p = projection.skip_binder();
342+
let alias_ty = p.projection_ty;
343+
if bound == tcx.parent(alias_ty.def_id) && alias_ty.self_ty() == ty {
344+
let name = tcx.item_name(alias_ty.def_id);
345+
projections_str.push(format!("{} = {}", name, p.term));
346+
}
347+
}
348+
let bound_def_path = tcx.def_path_str(bound);
349+
if projections_str.is_empty() {
350+
where_clauses.push(format!("{}: {}", ty, bound_def_path));
351+
} else {
352+
bounds_str.push(format!("{}<{}>", bound_def_path, projections_str.join(", ")));
353+
}
354+
}
355+
if bounds_str.is_empty() {
356+
types_str.push(ty.to_string());
357+
} else {
358+
types_str.push(format!("{}: {}", ty, bounds_str.join(" + ")));
359+
}
360+
} else {
361+
// Avoid suggesting the following:
362+
// fn foo<T, <T as Trait>::Bar>(_: T) where T: Trait, <T as Trait>::Bar: Other {}
363+
where_clauses.extend(
364+
bounds.into_iter().map(|bound| format!("{}: {}", ty, tcx.def_path_str(bound))),
365+
);
366+
}
361367
}
368+
369+
let generics =
370+
if types_str.is_empty() { "".to_string() } else { format!("<{}>", types_str.join(", ")) };
371+
362372
let where_clauses = if where_clauses.is_empty() {
363-
String::new()
373+
"".to_string()
364374
} else {
365375
format!(" where {}", where_clauses.join(", "))
366376
};
377+
367378
(generics, where_clauses)
368379
}
369380

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

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

89+
pub fn region_def(&mut self, did: DefId) -> stable_mir::ty::RegionDef {
90+
stable_mir::ty::RegionDef(self.create_def_id(did))
91+
}
92+
8993
pub fn prov(&mut self, aid: AllocId) -> stable_mir::ty::Prov {
9094
stable_mir::ty::Prov(self.create_alloc_id(aid))
9195
}

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

+35-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
//!
88
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
10-
use hir::def::DefKind;
10+
use crate::rustc_smir::hir::def::DefKind;
11+
use crate::rustc_smir::stable_mir::ty::{BoundRegion, EarlyBoundRegion, Region};
1112
use rustc_hir as hir;
1213
use rustc_middle::mir;
1314
use rustc_middle::mir::interpret::{alloc_range, AllocId};
@@ -1500,9 +1501,39 @@ impl<'tcx> Stable<'tcx> for ty::ImplPolarity {
15001501
impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
15011502
type T = stable_mir::ty::Region;
15021503

1503-
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
1504-
// FIXME: add a real implementation of stable regions
1505-
opaque(self)
1504+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
1505+
Region { kind: self.kind().stable(tables) }
1506+
}
1507+
}
1508+
1509+
impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
1510+
type T = stable_mir::ty::RegionKind;
1511+
1512+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
1513+
use stable_mir::ty::RegionKind;
1514+
match self {
1515+
ty::ReEarlyBound(early_reg) => RegionKind::ReEarlyBound(EarlyBoundRegion {
1516+
def_id: tables.region_def(early_reg.def_id),
1517+
index: early_reg.index,
1518+
name: early_reg.name.to_string(),
1519+
}),
1520+
ty::ReLateBound(db_index, bound_reg) => RegionKind::ReLateBound(
1521+
db_index.as_u32(),
1522+
BoundRegion { var: bound_reg.var.as_u32(), kind: bound_reg.kind.stable(tables) },
1523+
),
1524+
ty::ReStatic => RegionKind::ReStatic,
1525+
ty::RePlaceholder(place_holder) => {
1526+
RegionKind::RePlaceholder(stable_mir::ty::Placeholder {
1527+
universe: place_holder.universe.as_u32(),
1528+
bound: BoundRegion {
1529+
var: place_holder.bound.var.as_u32(),
1530+
kind: place_holder.bound.kind.stable(tables),
1531+
},
1532+
})
1533+
}
1534+
ty::ReErased => RegionKind::ReErased,
1535+
_ => unreachable!("{self:?}"),
1536+
}
15061537
}
15071538
}
15081539

Diff for: compiler/stable_mir/src/fold.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ use crate::Opaque;
44

55
use super::ty::{
66
Allocation, Binder, Const, ConstDef, ConstantKind, ExistentialPredicate, FnSig, GenericArgKind,
7-
GenericArgs, Promoted, RigidTy, TermKind, Ty, TyKind, UnevaluatedConst,
7+
GenericArgs, Promoted, Region, RigidTy, TermKind, Ty, TyKind, UnevaluatedConst,
88
};
99

1010
pub trait Folder: Sized {
1111
type Break;
12-
fn visit_ty(&mut self, ty: &Ty) -> ControlFlow<Self::Break, Ty> {
12+
fn fold_ty(&mut self, ty: &Ty) -> ControlFlow<Self::Break, Ty> {
1313
ty.super_fold(self)
1414
}
1515
fn fold_const(&mut self, c: &Const) -> ControlFlow<Self::Break, Const> {
1616
c.super_fold(self)
1717
}
18+
fn fold_reg(&mut self, reg: &Region) -> ControlFlow<Self::Break, Region> {
19+
reg.super_fold(self)
20+
}
1821
}
1922

2023
pub trait Foldable: Sized + Clone {
@@ -26,7 +29,7 @@ pub trait Foldable: Sized + Clone {
2629

2730
impl Foldable for Ty {
2831
fn fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
29-
folder.visit_ty(self)
32+
folder.fold_ty(self)
3033
}
3134
fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
3235
let mut kind = self.kind();
@@ -106,6 +109,15 @@ impl Foldable for GenericArgs {
106109
}
107110
}
108111

112+
impl Foldable for Region {
113+
fn fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
114+
folder.fold_reg(self)
115+
}
116+
fn super_fold<V: Folder>(&self, _: &mut V) -> ControlFlow<V::Break, Self> {
117+
ControlFlow::Continue(self.clone())
118+
}
119+
}
120+
109121
impl Foldable for GenericArgKind {
110122
fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
111123
let mut this = self.clone();
@@ -136,7 +148,10 @@ impl Foldable for RigidTy {
136148
}
137149
RigidTy::Slice(inner) => *inner = inner.fold(folder)?,
138150
RigidTy::RawPtr(ty, _) => *ty = ty.fold(folder)?,
139-
RigidTy::Ref(_, ty, _) => *ty = ty.fold(folder)?,
151+
RigidTy::Ref(reg, ty, _) => {
152+
*reg = reg.fold(folder)?;
153+
*ty = ty.fold(folder)?
154+
}
140155
RigidTy::FnDef(_, args) => *args = args.fold(folder)?,
141156
RigidTy::FnPtr(sig) => *sig = sig.fold(folder)?,
142157
RigidTy::Closure(_, args) => *args = args.fold(folder)?,
@@ -214,7 +229,7 @@ pub enum Never {}
214229
impl Folder for GenericArgs {
215230
type Break = Never;
216231

217-
fn visit_ty(&mut self, ty: &Ty) -> ControlFlow<Self::Break, Ty> {
232+
fn fold_ty(&mut self, ty: &Ty) -> ControlFlow<Self::Break, Ty> {
218233
ControlFlow::Continue(match ty.kind() {
219234
TyKind::Param(p) => self[p],
220235
_ => *ty,

Diff for: compiler/stable_mir/src/ty.rs

+44-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{
22
mir::Safety,
33
mir::{Body, Mutability},
4-
with, AllocId, DefId,
4+
with, AllocId, DefId, Symbol,
55
};
66
use crate::Opaque;
77
use std::fmt::{self, Debug, Formatter};
@@ -34,7 +34,46 @@ pub struct Const {
3434
}
3535

3636
type Ident = Opaque;
37-
pub type Region = Opaque;
37+
38+
#[derive(Debug, Clone)]
39+
pub struct Region {
40+
pub kind: RegionKind,
41+
}
42+
43+
#[derive(Debug, Clone)]
44+
pub enum RegionKind {
45+
ReEarlyBound(EarlyBoundRegion),
46+
ReLateBound(DebruijnIndex, BoundRegion),
47+
ReStatic,
48+
RePlaceholder(Placeholder<BoundRegion>),
49+
ReErased,
50+
}
51+
52+
pub(crate) type DebruijnIndex = u32;
53+
54+
#[derive(Debug, Clone)]
55+
pub struct EarlyBoundRegion {
56+
pub def_id: RegionDef,
57+
pub index: u32,
58+
pub name: Symbol,
59+
}
60+
61+
pub(crate) type BoundVar = u32;
62+
63+
#[derive(Debug, Clone)]
64+
pub struct BoundRegion {
65+
pub var: BoundVar,
66+
pub kind: BoundRegionKind,
67+
}
68+
69+
pub(crate) type UniverseIndex = u32;
70+
71+
#[derive(Debug, Clone)]
72+
pub struct Placeholder<T> {
73+
pub universe: UniverseIndex,
74+
pub bound: T,
75+
}
76+
3877
#[derive(Clone, Copy, PartialEq, Eq)]
3978
pub struct Span(pub usize);
4079

@@ -152,6 +191,9 @@ pub struct ConstDef(pub DefId);
152191
#[derive(Clone, PartialEq, Eq, Debug)]
153192
pub struct ImplDef(pub DefId);
154193

194+
#[derive(Clone, PartialEq, Eq, Debug)]
195+
pub struct RegionDef(pub DefId);
196+
155197
#[derive(Clone, Debug)]
156198
pub struct GenericArgs(pub Vec<GenericArgKind>);
157199

Diff for: compiler/stable_mir/src/visitor.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::Opaque;
44

55
use super::ty::{
66
Allocation, Binder, Const, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, GenericArgs,
7-
Promoted, RigidTy, TermKind, Ty, UnevaluatedConst,
7+
Promoted, Region, RigidTy, TermKind, Ty, UnevaluatedConst,
88
};
99

1010
pub trait Visitor: Sized {
@@ -15,6 +15,9 @@ pub trait Visitor: Sized {
1515
fn visit_const(&mut self, c: &Const) -> ControlFlow<Self::Break> {
1616
c.super_visit(self)
1717
}
18+
fn visit_reg(&mut self, reg: &Region) -> ControlFlow<Self::Break> {
19+
reg.super_visit(self)
20+
}
1821
}
1922

2023
pub trait Visitable {
@@ -101,6 +104,16 @@ impl Visitable for GenericArgs {
101104
}
102105
}
103106

107+
impl Visitable for Region {
108+
fn visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
109+
visitor.visit_reg(self)
110+
}
111+
112+
fn super_visit<V: Visitor>(&self, _: &mut V) -> ControlFlow<V::Break> {
113+
ControlFlow::Continue(())
114+
}
115+
}
116+
104117
impl Visitable for GenericArgKind {
105118
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
106119
match self {
@@ -128,7 +141,10 @@ impl Visitable for RigidTy {
128141
}
129142
RigidTy::Slice(inner) => inner.visit(visitor),
130143
RigidTy::RawPtr(ty, _) => ty.visit(visitor),
131-
RigidTy::Ref(_, ty, _) => ty.visit(visitor),
144+
RigidTy::Ref(reg, ty, _) => {
145+
reg.visit(visitor);
146+
ty.visit(visitor)
147+
}
132148
RigidTy::FnDef(_, args) => args.visit(visitor),
133149
RigidTy::FnPtr(sig) => sig.visit(visitor),
134150
RigidTy::Closure(_, args) => args.visit(visitor),

Diff for: library/core/src/sync/exclusive.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use core::fmt;
44
use core::future::Future;
5+
use core::marker::Tuple;
6+
use core::ops::{Generator, GeneratorState};
57
use core::pin::Pin;
68
use core::task::{Context, Poll};
79

@@ -168,10 +170,52 @@ impl<T> From<T> for Exclusive<T> {
168170
}
169171

170172
#[unstable(feature = "exclusive_wrapper", issue = "98407")]
171-
impl<T: Future + ?Sized> Future for Exclusive<T> {
173+
impl<F, Args> FnOnce<Args> for Exclusive<F>
174+
where
175+
F: FnOnce<Args>,
176+
Args: Tuple,
177+
{
178+
type Output = F::Output;
179+
180+
extern "rust-call" fn call_once(self, args: Args) -> Self::Output {
181+
self.into_inner().call_once(args)
182+
}
183+
}
184+
185+
#[unstable(feature = "exclusive_wrapper", issue = "98407")]
186+
impl<F, Args> FnMut<Args> for Exclusive<F>
187+
where
188+
F: FnMut<Args>,
189+
Args: Tuple,
190+
{
191+
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output {
192+
self.get_mut().call_mut(args)
193+
}
194+
}
195+
196+
#[unstable(feature = "exclusive_wrapper", issue = "98407")]
197+
impl<T> Future for Exclusive<T>
198+
where
199+
T: Future + ?Sized,
200+
{
172201
type Output = T::Output;
202+
173203
#[inline]
174204
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
175205
self.get_pin_mut().poll(cx)
176206
}
177207
}
208+
209+
#[unstable(feature = "generator_trait", issue = "43122")] // also #98407
210+
impl<R, G> Generator<R> for Exclusive<G>
211+
where
212+
G: Generator<R> + ?Sized,
213+
{
214+
type Yield = G::Yield;
215+
type Return = G::Return;
216+
217+
#[inline]
218+
fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
219+
G::resume(self.get_pin_mut(), arg)
220+
}
221+
}

0 commit comments

Comments
 (0)