Skip to content

Commit b8c5a0f

Browse files
Fix tools
1 parent c5d0223 commit b8c5a0f

File tree

14 files changed

+80
-6
lines changed

14 files changed

+80
-6
lines changed

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2893,7 +2893,7 @@ pub enum TyKind<'hir> {
28932893
Ref(&'hir Lifetime, MutTy<'hir>),
28942894
/// A bare function (e.g., `fn(usize) -> bool`).
28952895
BareFn(&'hir BareFnTy<'hir>),
2896-
/// Uwu
2896+
/// An unsafe binder type (e.g. `unsafe<'a> Foo<'a>`).
28972897
UnsafeBinder(&'hir UnsafeBinderTy<'hir>),
28982898
/// The never type (`!`).
28992899
Never,

src/librustdoc/clean/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,9 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18411841
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
18421842
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
18431843
TyKind::Infer | TyKind::Err(_) | TyKind::Typeof(..) | TyKind::InferDelegation(..) => Infer,
1844+
TyKind::UnsafeBinder(..) => {
1845+
unimplemented!("unsafe binders are not supported yet")
1846+
}
18441847
}
18451848
}
18461849

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

+1
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ impl TyCoercionStability {
819819
| TyKind::TraitObject(..)
820820
| TyKind::InferDelegation(..)
821821
| TyKind::Err(_) => Self::Reborrow,
822+
TyKind::UnsafeBinder(..) => Self::None,
822823
};
823824
}
824825
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ fn never_loop_expr<'tcx>(
156156
| ExprKind::Field(e, _)
157157
| ExprKind::AddrOf(_, _, e)
158158
| ExprKind::Repeat(e, _)
159-
| ExprKind::DropTemps(e) => never_loop_expr(cx, e, local_labels, main_loop_id),
159+
| ExprKind::DropTemps(e)
160+
| ExprKind::UnsafeBinderCast(_, e, _) => never_loop_expr(cx, e, local_labels, main_loop_id),
160161
ExprKind::Let(let_expr) => never_loop_expr(cx, let_expr.init, local_labels, main_loop_id),
161162
ExprKind::Array(es) | ExprKind::Tup(es) => never_loop_expr_all(cx, es.iter(), local_labels, main_loop_id),
162163
ExprKind::MethodCall(_, receiver, es, _) => {

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

+3
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
623623
kind!("DropTemps({expr})");
624624
self.expr(expr);
625625
},
626+
ExprKind::UnsafeBinderCast(..) => {
627+
unimplemented!("unsafe binders are not implemented yet");
628+
}
626629
}
627630
}
628631

src/tools/clippy/clippy_utils/src/eager_or_lazy.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
303303
| ExprKind::AddrOf(..)
304304
| ExprKind::Repeat(..)
305305
| ExprKind::Block(Block { stmts: [], .. }, _)
306-
| ExprKind::OffsetOf(..) => (),
306+
| ExprKind::OffsetOf(..)
307+
| ExprKind::UnsafeBinderCast(..) => (),
307308

308309
// Assignment might be to a local defined earlier, so don't eagerly evaluate.
309310
// Blocks with multiple statements might be expensive, so don't eagerly evaluate.

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

+15
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ impl HirEqInterExpr<'_, '_, '_> {
370370
&& self.eq_expr(l_receiver, r_receiver)
371371
&& self.eq_exprs(l_args, r_args)
372372
},
373+
(&ExprKind::UnsafeBinderCast(lkind, le, None), &ExprKind::UnsafeBinderCast(rkind, re, None)) =>
374+
lkind == rkind && self.eq_expr(le, re),
375+
(&ExprKind::UnsafeBinderCast(lkind, le, Some(lt)), &ExprKind::UnsafeBinderCast(rkind, re, Some(rt))) =>
376+
lkind == rkind && self.eq_expr(le, re) && self.eq_ty(lt, rt),
373377
(&ExprKind::OffsetOf(l_container, l_fields), &ExprKind::OffsetOf(r_container, r_fields)) => {
374378
self.eq_ty(l_container, r_container) && over(l_fields, r_fields, |l, r| l.name == r.name)
375379
},
@@ -424,6 +428,7 @@ impl HirEqInterExpr<'_, '_, '_> {
424428
| &ExprKind::Type(..)
425429
| &ExprKind::Unary(..)
426430
| &ExprKind::Yield(..)
431+
| &ExprKind::UnsafeBinderCast(..)
427432

428433
// --- Special cases that do not have a positive branch.
429434

@@ -1032,6 +1037,13 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
10321037
std::mem::discriminant(&lop).hash(&mut self.s);
10331038
self.hash_expr(le);
10341039
},
1040+
ExprKind::UnsafeBinderCast(kind, expr, ty) => {
1041+
std::mem::discriminant(&kind).hash(&mut self.s);
1042+
self.hash_expr(expr);
1043+
if let Some(ty) = ty {
1044+
self.hash_ty(ty);
1045+
}
1046+
}
10351047
ExprKind::Err(_) => {},
10361048
}
10371049
}
@@ -1241,6 +1253,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
12411253
TyKind::Typeof(anon_const) => {
12421254
self.hash_body(anon_const.body);
12431255
},
1256+
TyKind::UnsafeBinder(binder) => {
1257+
self.hash_ty(binder.inner_ty);
1258+
}
12441259
TyKind::Err(_)
12451260
| TyKind::Infer
12461261
| TyKind::Never

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ impl<'a> Sugg<'a> {
151151
| ExprKind::Become(..)
152152
| ExprKind::Struct(..)
153153
| ExprKind::Tup(..)
154-
| ExprKind::Err(_) => Sugg::NonParen(get_snippet(expr.span)),
154+
| ExprKind::Err(_)
155+
| ExprKind::UnsafeBinderCast(..) => Sugg::NonParen(get_snippet(expr.span)),
155156
ExprKind::DropTemps(inner) => Self::hir_from_snippet(inner, get_snippet),
156157
ExprKind::Assign(lhs, rhs, _) => {
157158
Sugg::BinOp(AssocOp::Assign, get_snippet(lhs.span), get_snippet(rhs.span))
@@ -226,7 +227,8 @@ impl<'a> Sugg<'a> {
226227
| ast::ExprKind::While(..)
227228
| ast::ExprKind::Await(..)
228229
| ast::ExprKind::Err(_)
229-
| ast::ExprKind::Dummy => Sugg::NonParen(snippet(expr.span)),
230+
| ast::ExprKind::Dummy
231+
| ast::ExprKind::UnsafeBinderCast(..) => Sugg::NonParen(snippet(expr.span)),
230232
ast::ExprKind::Range(ref lhs, ref rhs, RangeLimits::HalfOpen) => Sugg::BinOp(
231233
AssocOp::DotDot,
232234
lhs.as_ref().map_or("".into(), |lhs| snippet(lhs.span)),

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

+1
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>(
694694
| ExprKind::Continue(_)
695695
| ExprKind::InlineAsm(_)
696696
| ExprKind::OffsetOf(..)
697+
| ExprKind::UnsafeBinderCast(..)
697698
| ExprKind::Err(_) => (),
698699
}
699700
ControlFlow::Continue(())

src/tools/rustfmt/src/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ pub(crate) fn format_expr(
413413
ast::ExprKind::FormatArgs(..)
414414
| ast::ExprKind::Type(..)
415415
| ast::ExprKind::IncludedBytes(..)
416-
| ast::ExprKind::OffsetOf(..) => {
416+
| ast::ExprKind::OffsetOf(..)
417+
| ast::ExprKind::UnsafeBinderCast(..) => {
417418
// These don't normally occur in the AST because macros aren't expanded. However,
418419
// rustfmt tries to parse macro arguments when formatting macros, so it's not totally
419420
// impossible for rustfmt to come across one of these nodes when formatting a file.

src/tools/rustfmt/src/types.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,31 @@ impl Rewrite for ast::Ty {
10161016
let pat = pat.rewrite_result(context, shape)?;
10171017
Ok(format!("{ty} is {pat}"))
10181018
}
1019+
ast::TyKind::UnsafeBinder(ref binder) => {
1020+
let mut result = String::new();
1021+
if let Some(ref lifetime_str) =
1022+
rewrite_bound_params(context, shape, &binder.generic_params)
1023+
{
1024+
result.push_str("unsafe<");
1025+
result.push_str(lifetime_str);
1026+
result.push_str("> ");
1027+
}
1028+
1029+
let inner_ty_shape = if context.use_block_indent() {
1030+
shape
1031+
.offset_left(result.len())
1032+
.max_width_error(shape.width, self.span())?
1033+
} else {
1034+
shape
1035+
.visual_indent(result.len())
1036+
.sub_width(result.len())
1037+
.max_width_error(shape.width, self.span())?
1038+
};
1039+
1040+
let rewrite = binder.inner_ty.rewrite_result(context, inner_ty_shape)?;
1041+
result.push_str(&rewrite);
1042+
Ok(result)
1043+
}
10191044
}
10201045
}
10211046
}

src/tools/rustfmt/src/utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
504504
| ast::ExprKind::IncludedBytes(..)
505505
| ast::ExprKind::InlineAsm(..)
506506
| ast::ExprKind::OffsetOf(..)
507+
| ast::ExprKind::UnsafeBinderCast(..)
507508
| ast::ExprKind::Let(..)
508509
| ast::ExprKind::Path(..)
509510
| ast::ExprKind::Range(..)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn foo() -> unsafe<'a>
2+
&'a () {}
3+
4+
struct Foo {
5+
x: unsafe<'a>
6+
&'a (),
7+
}
8+
9+
struct Bar(unsafe<'a> &'a ());
10+
11+
impl Trait for unsafe<'a> &'a () {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn foo() -> unsafe<'a> &'a () {}
2+
3+
struct Foo {
4+
x: unsafe<'a> &'a (),
5+
}
6+
7+
struct Bar(unsafe<'a> &'a ());
8+
9+
impl Trait for unsafe<'a> &'a () {}

0 commit comments

Comments
 (0)