Skip to content

Commit fab3984

Browse files
Fix tools
1 parent a7379f7 commit fab3984

File tree

15 files changed

+62
-9
lines changed

15 files changed

+62
-9
lines changed

compiler/rustc_codegen_cranelift/src/base.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,9 @@ pub(crate) fn codegen_place<'tcx>(
983983
cplace = cplace.place_deref(fx);
984984
}
985985
PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"),
986-
PlaceElem::Subtype(ty) => cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty)),
986+
PlaceElem::Subtype(ty) | PlaceElem::UnsafeBinderCast(_, ty) => {
987+
cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty));
988+
}
987989
PlaceElem::Field(field, _ty) => {
988990
cplace = cplace.place_field(fx, field);
989991
}

src/librustdoc/clean/mod.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18401840
}
18411841
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
18421842
TyKind::UnsafeBinder(..) => {
1843-
unimplemented!("unsafe binders are not supported yet")
1843+
UnsafeBinder(Box::new(clean_unsafe_binder_ty(unsafe_binder_ty, cx)))
18441844
}
18451845
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
18461846
TyKind::Infer
@@ -2070,6 +2070,11 @@ pub(crate) fn clean_middle_ty<'tcx>(
20702070
abi: sig.abi(),
20712071
}))
20722072
}
2073+
ty::UnsafeBinder(inner) => {
2074+
let generic_params = clean_bound_vars(inner.bound_vars());
2075+
let ty = clean_middle_ty(inner.into(), cx, None, None);
2076+
UnsafeBinder(Box::new(UnsafeBinderTy { generic_params, ty }))
2077+
}
20732078
ty::Adt(def, args) => {
20742079
let did = def.did();
20752080
let kind = match def.adt_kind() {
@@ -2557,6 +2562,21 @@ fn clean_bare_fn_ty<'tcx>(
25572562
BareFunctionDecl { safety: bare_fn.safety, abi: bare_fn.abi, decl, generic_params }
25582563
}
25592564

2565+
fn clean_unsafe_binder_ty<'tcx>(
2566+
unsafe_binder_ty: &hir::UnsafeBinderTy<'tcx>,
2567+
cx: &mut DocContext<'tcx>,
2568+
) -> UnsafeBinderTy {
2569+
// NOTE: generics must be cleaned before args
2570+
let generic_params = unsafe_binder_ty
2571+
.generic_params
2572+
.iter()
2573+
.filter(|p| !is_elided_lifetime(p))
2574+
.map(|x| clean_generic_param(cx, None, x))
2575+
.collect();
2576+
let ty = clean_ty(unsafe_binder_ty.inner_ty, cx);
2577+
UnsafeBinderTy { generic_params, ty }
2578+
}
2579+
25602580
pub(crate) fn reexport_chain(
25612581
tcx: TyCtxt<'_>,
25622582
import_def_id: LocalDefId,

src/librustdoc/clean/types.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use {rustc_ast as ast, rustc_hir as hir};
3434
pub(crate) use self::ItemKind::*;
3535
pub(crate) use self::Type::{
3636
Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive, QPath,
37-
RawPointer, SelfTy, Slice, Tuple,
37+
RawPointer, SelfTy, Slice, Tuple, UnsafeBinder,
3838
};
3939
use crate::clean::cfg::Cfg;
4040
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: ExternAbi,
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

+5
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,11 @@ fn fmt_type(
10371037
}
10381038
decl.decl.print(cx).fmt(f)
10391039
}
1040+
clean::UnsafeBinder(ref binder) => {
1041+
// FIXME(unsafe_binders): This should print `unsafe<...>`
1042+
print_higher_ranked_params_with_space(&binder.generic_params, cx).fmt(f)?;
1043+
binder.ty.print(cx).fmt(f)
1044+
}
10401045
clean::Tuple(ref typs) => match &typs[..] {
10411046
&[] => primitive_link(f, PrimitiveType::Unit, format_args!("()"), cx),
10421047
[one] => {

src/librustdoc/html/render/search_index.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,8 @@ fn get_index_type_id(
900900
| clean::Generic(_)
901901
| clean::SelfTy
902902
| clean::ImplTrait(_)
903-
| clean::Infer => None,
903+
| clean::Infer
904+
| clean::UnsafeBinder(_) => None,
904905
}
905906
}
906907

src/librustdoc/json/conversions.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ impl FromClean<clean::Type> for Type {
571571
fn from_clean(ty: clean::Type, renderer: &JsonRenderer<'_>) -> Self {
572572
use clean::Type::{
573573
Array, BareFunction, BorrowedRef, Generic, ImplTrait, Infer, Primitive, QPath,
574-
RawPointer, SelfTy, Slice, Tuple,
574+
RawPointer, SelfTy, Slice, Tuple, UnsafeBinder,
575575
};
576576

577577
match ty {
@@ -611,6 +611,8 @@ impl FromClean<clean::Type> for Type {
611611
self_type: Box::new(self_type.into_json(renderer)),
612612
trait_: trait_.map(|trait_| trait_.into_json(renderer)),
613613
},
614+
// FIXME(unsafe_binder): Implement rustdoc-json.
615+
UnsafeBinder(_) => todo!(),
614616
}
615617
}
616618
}

src/librustdoc/passes/collect_intra_doc_links.rs

+1
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ impl<'tcx> LinkCollector<'_, 'tcx> {
558558
| ty::CoroutineClosure(..)
559559
| ty::Coroutine(..)
560560
| ty::CoroutineWitness(..)
561+
| ty::UnsafeBinder(..)
561562
| ty::Dynamic(..)
562563
| ty::Param(_)
563564
| ty::Bound(..)

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,8 @@ impl TyCoercionStability {
812812
| TyKind::Pat(..)
813813
| TyKind::Never
814814
| TyKind::Tup(_)
815-
| TyKind::Path(_) => Self::Deref,
815+
| TyKind::Path(_)
816+
| TyKind::UnsafeBinder(..) => Self::Deref,
816817
TyKind::OpaqueDef(..)
817818
| TyKind::TraitAscription(..)
818819
| TyKind::Infer
@@ -877,7 +878,8 @@ impl TyCoercionStability {
877878
| ty::CoroutineClosure(..)
878879
| ty::Never
879880
| ty::Tuple(_)
880-
| ty::Alias(ty::Projection, _) => Self::Deref,
881+
| ty::Alias(ty::Projection, _)
882+
| ty::UnsafeBinder(_) => Self::Deref,
881883
};
882884
}
883885
}

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

+1
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_utils/src/eager_or_lazy.rs

+1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
294294
| ExprKind::Lit(_)
295295
| ExprKind::Cast(..)
296296
| ExprKind::Type(..)
297+
| ExprKind::UnsafeBinderCast(..)
297298
| ExprKind::DropTemps(_)
298299
| ExprKind::Let(..)
299300
| ExprKind::If(..)

src/tools/clippy/clippy_utils/src/hir_utils.rs

+4
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ impl HirEqInterExpr<'_, '_, '_> {
394394
},
395395
(&ExprKind::Tup(l_tup), &ExprKind::Tup(r_tup)) => self.eq_exprs(l_tup, r_tup),
396396
(&ExprKind::Type(le, lt), &ExprKind::Type(re, rt)) => self.eq_expr(le, re) && self.eq_ty(lt, rt),
397+
(&ExprKind::UnsafeBinderCast(lkind, le, None), &ExprKind::UnsafeBinderCast(rkind, re, None)) =>
398+
lkind == rkind && self.eq_expr(le, re),
399+
(&ExprKind::UnsafeBinderCast(lkind, le, Some(lt)), &ExprKind::UnsafeBinderCast(rkind, re, Some(rt))) =>
400+
lkind == rkind && self.eq_expr(le, re) && self.eq_ty(lt, rt),
397401
(&ExprKind::Unary(l_op, le), &ExprKind::Unary(r_op, re)) => l_op == r_op && self.eq_expr(le, re),
398402
(&ExprKind::Yield(le, _), &ExprKind::Yield(re, _)) => return self.eq_expr(le, re),
399403
(

src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &B
288288
| ProjectionElem::Downcast(..)
289289
| ProjectionElem::Subslice { .. }
290290
| ProjectionElem::Subtype(_)
291-
| ProjectionElem::Index(_) => {},
291+
| ProjectionElem::Index(_)
292+
| ProjectionElem::UnsafeBinderCast(..) => {},
292293
}
293294
}
294295

src/tools/clippy/clippy_utils/src/sugg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ impl<'a> Sugg<'a> {
226226
| ast::ExprKind::Array(..)
227227
| ast::ExprKind::While(..)
228228
| ast::ExprKind::Await(..)
229+
| ast::ExprKind::UnsafeBinderCast(..)
229230
| ast::ExprKind::Err(_)
230231
| ast::ExprKind::Dummy
231232
| ast::ExprKind::UnsafeBinderCast(..) => Sugg::NonParen(snippet(expr.span)),

src/tools/clippy/clippy_utils/src/visitors.rs

+3
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,9 @@ pub fn for_each_unconsumed_temporary<'tcx, B>(
677677
ExprKind::Type(e, _) => {
678678
helper(typeck, consume, e, f)?;
679679
},
680+
ExprKind::UnsafeBinderCast(_, e, _) => {
681+
helper(typeck, consume, e, f)?;
682+
},
680683

681684
// Either drops temporaries, jumps out of the current expression, or has no sub expression.
682685
ExprKind::DropTemps(_)

src/tools/rustfmt/src/utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
497497
| ast::ExprKind::Await(..)
498498
| ast::ExprKind::Break(..)
499499
| ast::ExprKind::Cast(..)
500+
| ast::ExprKind::UnsafeBinderCast(..)
500501
| ast::ExprKind::Continue(..)
501502
| ast::ExprKind::Dummy
502503
| ast::ExprKind::Err(_)

0 commit comments

Comments
 (0)