Skip to content

Commit 3aa766a

Browse files
Fix tools
1 parent 285ab06 commit 3aa766a

File tree

18 files changed

+102
-9
lines changed

18 files changed

+102
-9
lines changed

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,9 @@ pub(crate) fn codegen_place<'tcx>(
964964
cplace = cplace.place_deref(fx);
965965
}
966966
PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"),
967-
PlaceElem::Subtype(ty) => cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty)),
967+
PlaceElem::Subtype(ty) | PlaceElem::UnsafeBinderCast(_, ty) => {
968+
cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty));
969+
}
968970
PlaceElem::Field(field, _ty) => {
969971
cplace = cplace.place_field(fx, field);
970972
}

src/librustdoc/clean/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,9 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18551855
DynTrait(bounds, lifetime)
18561856
}
18571857
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
1858+
TyKind::UnsafeBinder(unsafe_binder_ty) => {
1859+
UnsafeBinder(Box::new(clean_unsafe_binder_ty(unsafe_binder_ty, cx)))
1860+
}
18581861
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
18591862
TyKind::Infer | TyKind::Err(_) | TyKind::Typeof(..) | TyKind::InferDelegation(..) => Infer,
18601863
TyKind::AnonAdt(..) => {
@@ -2080,6 +2083,11 @@ pub(crate) fn clean_middle_ty<'tcx>(
20802083
abi: sig.abi(),
20812084
}))
20822085
}
2086+
ty::UnsafeBinder(inner) => {
2087+
let generic_params = clean_bound_vars(inner.bound_vars());
2088+
let ty = clean_middle_ty(inner.into(), cx, None, None);
2089+
UnsafeBinder(Box::new(UnsafeBinderTy { generic_params, ty }))
2090+
}
20832091
ty::Adt(def, args) => {
20842092
let did = def.did();
20852093
let kind = match def.adt_kind() {
@@ -2577,6 +2585,21 @@ fn clean_bare_fn_ty<'tcx>(
25772585
BareFunctionDecl { safety: bare_fn.safety, abi: bare_fn.abi, decl, generic_params }
25782586
}
25792587

2588+
fn clean_unsafe_binder_ty<'tcx>(
2589+
unsafe_binder_ty: &hir::UnsafeBinderTy<'tcx>,
2590+
cx: &mut DocContext<'tcx>,
2591+
) -> UnsafeBinderTy {
2592+
// NOTE: generics must be cleaned before args
2593+
let generic_params = unsafe_binder_ty
2594+
.generic_params
2595+
.iter()
2596+
.filter(|p| !is_elided_lifetime(p))
2597+
.map(|x| clean_generic_param(cx, None, x))
2598+
.collect();
2599+
let ty = clean_ty(unsafe_binder_ty.inner_ty, cx);
2600+
UnsafeBinderTy { generic_params, ty }
2601+
}
2602+
25802603
pub(crate) fn reexport_chain(
25812604
tcx: TyCtxt<'_>,
25822605
import_def_id: LocalDefId,

src/librustdoc/clean/types.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use {rustc_ast as ast, rustc_hir as hir};
3737
pub(crate) use self::ItemKind::*;
3838
pub(crate) use self::Type::{
3939
Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive, QPath,
40-
RawPointer, SelfTy, Slice, Tuple,
40+
RawPointer, SelfTy, Slice, Tuple, UnsafeBinder,
4141
};
4242
use crate::clean::cfg::Cfg;
4343
use crate::clean::clean_middle_path;
@@ -1503,6 +1503,8 @@ pub(crate) enum Type {
15031503

15041504
/// An `impl Trait`: `impl TraitA + TraitB + ...`
15051505
ImplTrait(Vec<GenericBound>),
1506+
1507+
UnsafeBinder(Box<UnsafeBinderTy>),
15061508
}
15071509

15081510
impl Type {
@@ -1695,7 +1697,7 @@ impl Type {
16951697
Type::Pat(..) => PrimitiveType::Pat,
16961698
RawPointer(..) => PrimitiveType::RawPointer,
16971699
QPath(box QPathData { ref self_type, .. }) => return self_type.def_id(cache),
1698-
Generic(_) | SelfTy | Infer | ImplTrait(_) => return None,
1700+
Generic(_) | SelfTy | Infer | ImplTrait(_) | UnsafeBinder(_) => return None,
16991701
};
17001702
Primitive(t).def_id(cache)
17011703
}
@@ -2335,6 +2337,12 @@ pub(crate) struct BareFunctionDecl {
23352337
pub(crate) abi: Abi,
23362338
}
23372339

2340+
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
2341+
pub(crate) struct UnsafeBinderTy {
2342+
pub(crate) generic_params: Vec<GenericParamDef>,
2343+
pub(crate) ty: Type,
2344+
}
2345+
23382346
#[derive(Clone, Debug)]
23392347
pub(crate) struct Static {
23402348
pub(crate) type_: Box<Type>,

src/librustdoc/html/format.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,11 @@ fn fmt_type(
10351035
}
10361036
decl.decl.print(cx).fmt(f)
10371037
}
1038+
clean::UnsafeBinder(ref binder) => {
1039+
// FIXME(unsafe_binders): This should print `unsafe<...>`
1040+
print_higher_ranked_params_with_space(&binder.generic_params, cx).fmt(f)?;
1041+
binder.ty.print(cx).fmt(f)
1042+
}
10381043
clean::Tuple(ref typs) => match &typs[..] {
10391044
&[] => primitive_link(f, PrimitiveType::Unit, format_args!("()"), cx),
10401045
[one] => {

src/librustdoc/html/render/search_index.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,8 @@ fn get_index_type_id(
822822
| clean::Generic(_)
823823
| clean::SelfTy
824824
| clean::ImplTrait(_)
825-
| clean::Infer => None,
825+
| clean::Infer
826+
| clean::UnsafeBinder(_) => None,
826827
}
827828
}
828829

src/librustdoc/json/conversions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl FromWithTcx<clean::Type> for Type {
576576
fn from_tcx(ty: clean::Type, tcx: TyCtxt<'_>) -> Self {
577577
use clean::Type::{
578578
Array, BareFunction, BorrowedRef, Generic, ImplTrait, Infer, Primitive, QPath,
579-
RawPointer, SelfTy, Slice, Tuple,
579+
RawPointer, SelfTy, Slice, Tuple, UnsafeBinder,
580580
};
581581

582582
match ty {
@@ -614,6 +614,8 @@ impl FromWithTcx<clean::Type> for Type {
614614
self_type: Box::new(self_type.into_tcx(tcx)),
615615
trait_: trait_.map(|trait_| trait_.into_tcx(tcx)),
616616
},
617+
// FIXME(unsafe_binder): Implement rustdoc-json.
618+
UnsafeBinder(_) => todo!(),
617619
}
618620
}
619621
}

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
506506
| ty::CoroutineClosure(..)
507507
| ty::Coroutine(..)
508508
| ty::CoroutineWitness(..)
509+
| ty::UnsafeBinder(..)
509510
| ty::Dynamic(..)
510511
| ty::Param(_)
511512
| ty::Bound(..)

src/tools/clippy/clippy_lints/src/dereference.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,8 @@ impl TyCoercionStability {
823823
| TyKind::Pat(..)
824824
| TyKind::Never
825825
| TyKind::Tup(_)
826-
| TyKind::Path(_) => Self::Deref,
826+
| TyKind::Path(_)
827+
| TyKind::UnsafeBinder(..) => Self::Deref,
827828
TyKind::OpaqueDef(..)
828829
| TyKind::Infer
829830
| TyKind::Typeof(..)
@@ -884,7 +885,8 @@ impl TyCoercionStability {
884885
| ty::CoroutineClosure(..)
885886
| ty::Never
886887
| ty::Tuple(_)
887-
| ty::Alias(ty::Projection, _) => Self::Deref,
888+
| ty::Alias(ty::Projection, _)
889+
| ty::UnsafeBinder(_) => Self::Deref,
888890
};
889891
}
890892
}

src/tools/clippy/clippy_lints/src/loops/never_loop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ fn never_loop_expr<'tcx>(
153153
ExprKind::Unary(_, e)
154154
| ExprKind::Cast(e, _)
155155
| ExprKind::Type(e, _)
156+
| ExprKind::UnsafeBinderCast(_, e, _)
156157
| ExprKind::Field(e, _)
157158
| ExprKind::AddrOf(_, _, e)
158159
| ExprKind::Repeat(e, _)

src/tools/clippy/clippy_lints/src/utils/author.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
626626
kind!("DropTemps({expr})");
627627
self.expr(expr);
628628
},
629+
ExprKind::UnsafeBinderCast(..) => {
630+
// FIXME(unsafe_binders): Implement this.
631+
todo!()
632+
}
629633
}
630634
}
631635

0 commit comments

Comments
 (0)