Skip to content

Commit 9ce2645

Browse files
authored
Rollup merge of rust-lang#134140 - compiler-errors:unsafe-binders-ast, r=oli-obk
Add AST support for unsafe binders I'm splitting up rust-lang#130514 into pieces. It's impossible for me to keep up with a huge PR like that. I'll land type system support for this next, probably w/o MIR lowering, which will come later. r? `@oli-obk` cc `@BoxyUwU` and `@lcnr` who also may want to look at this, though this PR doesn't do too much yet
2 parents e2a0e38 + 87af9d0 commit 9ce2645

File tree

7 files changed

+28
-4
lines changed

7 files changed

+28
-4
lines changed

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
}

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, _) => {

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

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.

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

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)),

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(())

0 commit comments

Comments
 (0)