Fix tools
This commit is contained in:
parent
c5d02237d3
commit
b8c5a0f0eb
14 changed files with 80 additions and 6 deletions
|
@ -2893,7 +2893,7 @@ pub enum TyKind<'hir> {
|
||||||
Ref(&'hir Lifetime, MutTy<'hir>),
|
Ref(&'hir Lifetime, MutTy<'hir>),
|
||||||
/// A bare function (e.g., `fn(usize) -> bool`).
|
/// A bare function (e.g., `fn(usize) -> bool`).
|
||||||
BareFn(&'hir BareFnTy<'hir>),
|
BareFn(&'hir BareFnTy<'hir>),
|
||||||
/// Uwu
|
/// An unsafe binder type (e.g. `unsafe<'a> Foo<'a>`).
|
||||||
UnsafeBinder(&'hir UnsafeBinderTy<'hir>),
|
UnsafeBinder(&'hir UnsafeBinderTy<'hir>),
|
||||||
/// The never type (`!`).
|
/// The never type (`!`).
|
||||||
Never,
|
Never,
|
||||||
|
|
|
@ -1841,6 +1841,9 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
||||||
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
|
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
|
||||||
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
|
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
|
||||||
TyKind::Infer | TyKind::Err(_) | TyKind::Typeof(..) | TyKind::InferDelegation(..) => Infer,
|
TyKind::Infer | TyKind::Err(_) | TyKind::Typeof(..) | TyKind::InferDelegation(..) => Infer,
|
||||||
|
TyKind::UnsafeBinder(..) => {
|
||||||
|
unimplemented!("unsafe binders are not supported yet")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -819,6 +819,7 @@ impl TyCoercionStability {
|
||||||
| TyKind::TraitObject(..)
|
| TyKind::TraitObject(..)
|
||||||
| TyKind::InferDelegation(..)
|
| TyKind::InferDelegation(..)
|
||||||
| TyKind::Err(_) => Self::Reborrow,
|
| TyKind::Err(_) => Self::Reborrow,
|
||||||
|
TyKind::UnsafeBinder(..) => Self::None,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,8 @@ fn never_loop_expr<'tcx>(
|
||||||
| ExprKind::Field(e, _)
|
| ExprKind::Field(e, _)
|
||||||
| ExprKind::AddrOf(_, _, e)
|
| ExprKind::AddrOf(_, _, e)
|
||||||
| ExprKind::Repeat(e, _)
|
| ExprKind::Repeat(e, _)
|
||||||
| ExprKind::DropTemps(e) => never_loop_expr(cx, e, local_labels, main_loop_id),
|
| ExprKind::DropTemps(e)
|
||||||
|
| ExprKind::UnsafeBinderCast(_, e, _) => never_loop_expr(cx, e, local_labels, main_loop_id),
|
||||||
ExprKind::Let(let_expr) => never_loop_expr(cx, let_expr.init, local_labels, main_loop_id),
|
ExprKind::Let(let_expr) => never_loop_expr(cx, let_expr.init, local_labels, main_loop_id),
|
||||||
ExprKind::Array(es) | ExprKind::Tup(es) => never_loop_expr_all(cx, es.iter(), local_labels, main_loop_id),
|
ExprKind::Array(es) | ExprKind::Tup(es) => never_loop_expr_all(cx, es.iter(), local_labels, main_loop_id),
|
||||||
ExprKind::MethodCall(_, receiver, es, _) => {
|
ExprKind::MethodCall(_, receiver, es, _) => {
|
||||||
|
|
|
@ -623,6 +623,9 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
|
||||||
kind!("DropTemps({expr})");
|
kind!("DropTemps({expr})");
|
||||||
self.expr(expr);
|
self.expr(expr);
|
||||||
},
|
},
|
||||||
|
ExprKind::UnsafeBinderCast(..) => {
|
||||||
|
unimplemented!("unsafe binders are not implemented yet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -303,7 +303,8 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
|
||||||
| ExprKind::AddrOf(..)
|
| ExprKind::AddrOf(..)
|
||||||
| ExprKind::Repeat(..)
|
| ExprKind::Repeat(..)
|
||||||
| ExprKind::Block(Block { stmts: [], .. }, _)
|
| ExprKind::Block(Block { stmts: [], .. }, _)
|
||||||
| ExprKind::OffsetOf(..) => (),
|
| ExprKind::OffsetOf(..)
|
||||||
|
| ExprKind::UnsafeBinderCast(..) => (),
|
||||||
|
|
||||||
// Assignment might be to a local defined earlier, so don't eagerly evaluate.
|
// Assignment might be to a local defined earlier, so don't eagerly evaluate.
|
||||||
// Blocks with multiple statements might be expensive, so don't eagerly evaluate.
|
// Blocks with multiple statements might be expensive, so don't eagerly evaluate.
|
||||||
|
|
|
@ -370,6 +370,10 @@ impl HirEqInterExpr<'_, '_, '_> {
|
||||||
&& self.eq_expr(l_receiver, r_receiver)
|
&& self.eq_expr(l_receiver, r_receiver)
|
||||||
&& self.eq_exprs(l_args, r_args)
|
&& self.eq_exprs(l_args, r_args)
|
||||||
},
|
},
|
||||||
|
(&ExprKind::UnsafeBinderCast(lkind, le, None), &ExprKind::UnsafeBinderCast(rkind, re, None)) =>
|
||||||
|
lkind == rkind && self.eq_expr(le, re),
|
||||||
|
(&ExprKind::UnsafeBinderCast(lkind, le, Some(lt)), &ExprKind::UnsafeBinderCast(rkind, re, Some(rt))) =>
|
||||||
|
lkind == rkind && self.eq_expr(le, re) && self.eq_ty(lt, rt),
|
||||||
(&ExprKind::OffsetOf(l_container, l_fields), &ExprKind::OffsetOf(r_container, r_fields)) => {
|
(&ExprKind::OffsetOf(l_container, l_fields), &ExprKind::OffsetOf(r_container, r_fields)) => {
|
||||||
self.eq_ty(l_container, r_container) && over(l_fields, r_fields, |l, r| l.name == r.name)
|
self.eq_ty(l_container, r_container) && over(l_fields, r_fields, |l, r| l.name == r.name)
|
||||||
},
|
},
|
||||||
|
@ -424,6 +428,7 @@ impl HirEqInterExpr<'_, '_, '_> {
|
||||||
| &ExprKind::Type(..)
|
| &ExprKind::Type(..)
|
||||||
| &ExprKind::Unary(..)
|
| &ExprKind::Unary(..)
|
||||||
| &ExprKind::Yield(..)
|
| &ExprKind::Yield(..)
|
||||||
|
| &ExprKind::UnsafeBinderCast(..)
|
||||||
|
|
||||||
// --- Special cases that do not have a positive branch.
|
// --- Special cases that do not have a positive branch.
|
||||||
|
|
||||||
|
@ -1032,6 +1037,13 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||||
std::mem::discriminant(&lop).hash(&mut self.s);
|
std::mem::discriminant(&lop).hash(&mut self.s);
|
||||||
self.hash_expr(le);
|
self.hash_expr(le);
|
||||||
},
|
},
|
||||||
|
ExprKind::UnsafeBinderCast(kind, expr, ty) => {
|
||||||
|
std::mem::discriminant(&kind).hash(&mut self.s);
|
||||||
|
self.hash_expr(expr);
|
||||||
|
if let Some(ty) = ty {
|
||||||
|
self.hash_ty(ty);
|
||||||
|
}
|
||||||
|
}
|
||||||
ExprKind::Err(_) => {},
|
ExprKind::Err(_) => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1241,6 +1253,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||||
TyKind::Typeof(anon_const) => {
|
TyKind::Typeof(anon_const) => {
|
||||||
self.hash_body(anon_const.body);
|
self.hash_body(anon_const.body);
|
||||||
},
|
},
|
||||||
|
TyKind::UnsafeBinder(binder) => {
|
||||||
|
self.hash_ty(binder.inner_ty);
|
||||||
|
}
|
||||||
TyKind::Err(_)
|
TyKind::Err(_)
|
||||||
| TyKind::Infer
|
| TyKind::Infer
|
||||||
| TyKind::Never
|
| TyKind::Never
|
||||||
|
|
|
@ -151,7 +151,8 @@ impl<'a> Sugg<'a> {
|
||||||
| ExprKind::Become(..)
|
| ExprKind::Become(..)
|
||||||
| ExprKind::Struct(..)
|
| ExprKind::Struct(..)
|
||||||
| ExprKind::Tup(..)
|
| ExprKind::Tup(..)
|
||||||
| ExprKind::Err(_) => Sugg::NonParen(get_snippet(expr.span)),
|
| ExprKind::Err(_)
|
||||||
|
| ExprKind::UnsafeBinderCast(..) => Sugg::NonParen(get_snippet(expr.span)),
|
||||||
ExprKind::DropTemps(inner) => Self::hir_from_snippet(inner, get_snippet),
|
ExprKind::DropTemps(inner) => Self::hir_from_snippet(inner, get_snippet),
|
||||||
ExprKind::Assign(lhs, rhs, _) => {
|
ExprKind::Assign(lhs, rhs, _) => {
|
||||||
Sugg::BinOp(AssocOp::Assign, get_snippet(lhs.span), get_snippet(rhs.span))
|
Sugg::BinOp(AssocOp::Assign, get_snippet(lhs.span), get_snippet(rhs.span))
|
||||||
|
@ -226,7 +227,8 @@ impl<'a> Sugg<'a> {
|
||||||
| ast::ExprKind::While(..)
|
| ast::ExprKind::While(..)
|
||||||
| ast::ExprKind::Await(..)
|
| ast::ExprKind::Await(..)
|
||||||
| ast::ExprKind::Err(_)
|
| ast::ExprKind::Err(_)
|
||||||
| ast::ExprKind::Dummy => Sugg::NonParen(snippet(expr.span)),
|
| ast::ExprKind::Dummy
|
||||||
|
| ast::ExprKind::UnsafeBinderCast(..) => Sugg::NonParen(snippet(expr.span)),
|
||||||
ast::ExprKind::Range(ref lhs, ref rhs, RangeLimits::HalfOpen) => Sugg::BinOp(
|
ast::ExprKind::Range(ref lhs, ref rhs, RangeLimits::HalfOpen) => Sugg::BinOp(
|
||||||
AssocOp::DotDot,
|
AssocOp::DotDot,
|
||||||
lhs.as_ref().map_or("".into(), |lhs| snippet(lhs.span)),
|
lhs.as_ref().map_or("".into(), |lhs| snippet(lhs.span)),
|
||||||
|
|
|
@ -694,6 +694,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>(
|
||||||
| ExprKind::Continue(_)
|
| ExprKind::Continue(_)
|
||||||
| ExprKind::InlineAsm(_)
|
| ExprKind::InlineAsm(_)
|
||||||
| ExprKind::OffsetOf(..)
|
| ExprKind::OffsetOf(..)
|
||||||
|
| ExprKind::UnsafeBinderCast(..)
|
||||||
| ExprKind::Err(_) => (),
|
| ExprKind::Err(_) => (),
|
||||||
}
|
}
|
||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
|
|
|
@ -413,7 +413,8 @@ pub(crate) fn format_expr(
|
||||||
ast::ExprKind::FormatArgs(..)
|
ast::ExprKind::FormatArgs(..)
|
||||||
| ast::ExprKind::Type(..)
|
| ast::ExprKind::Type(..)
|
||||||
| ast::ExprKind::IncludedBytes(..)
|
| ast::ExprKind::IncludedBytes(..)
|
||||||
| ast::ExprKind::OffsetOf(..) => {
|
| ast::ExprKind::OffsetOf(..)
|
||||||
|
| ast::ExprKind::UnsafeBinderCast(..) => {
|
||||||
// These don't normally occur in the AST because macros aren't expanded. However,
|
// These don't normally occur in the AST because macros aren't expanded. However,
|
||||||
// rustfmt tries to parse macro arguments when formatting macros, so it's not totally
|
// rustfmt tries to parse macro arguments when formatting macros, so it's not totally
|
||||||
// impossible for rustfmt to come across one of these nodes when formatting a file.
|
// impossible for rustfmt to come across one of these nodes when formatting a file.
|
||||||
|
|
|
@ -1016,6 +1016,31 @@ impl Rewrite for ast::Ty {
|
||||||
let pat = pat.rewrite_result(context, shape)?;
|
let pat = pat.rewrite_result(context, shape)?;
|
||||||
Ok(format!("{ty} is {pat}"))
|
Ok(format!("{ty} is {pat}"))
|
||||||
}
|
}
|
||||||
|
ast::TyKind::UnsafeBinder(ref binder) => {
|
||||||
|
let mut result = String::new();
|
||||||
|
if let Some(ref lifetime_str) =
|
||||||
|
rewrite_bound_params(context, shape, &binder.generic_params)
|
||||||
|
{
|
||||||
|
result.push_str("unsafe<");
|
||||||
|
result.push_str(lifetime_str);
|
||||||
|
result.push_str("> ");
|
||||||
|
}
|
||||||
|
|
||||||
|
let inner_ty_shape = if context.use_block_indent() {
|
||||||
|
shape
|
||||||
|
.offset_left(result.len())
|
||||||
|
.max_width_error(shape.width, self.span())?
|
||||||
|
} else {
|
||||||
|
shape
|
||||||
|
.visual_indent(result.len())
|
||||||
|
.sub_width(result.len())
|
||||||
|
.max_width_error(shape.width, self.span())?
|
||||||
|
};
|
||||||
|
|
||||||
|
let rewrite = binder.inner_ty.rewrite_result(context, inner_ty_shape)?;
|
||||||
|
result.push_str(&rewrite);
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -504,6 +504,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
|
||||||
| ast::ExprKind::IncludedBytes(..)
|
| ast::ExprKind::IncludedBytes(..)
|
||||||
| ast::ExprKind::InlineAsm(..)
|
| ast::ExprKind::InlineAsm(..)
|
||||||
| ast::ExprKind::OffsetOf(..)
|
| ast::ExprKind::OffsetOf(..)
|
||||||
|
| ast::ExprKind::UnsafeBinderCast(..)
|
||||||
| ast::ExprKind::Let(..)
|
| ast::ExprKind::Let(..)
|
||||||
| ast::ExprKind::Path(..)
|
| ast::ExprKind::Path(..)
|
||||||
| ast::ExprKind::Range(..)
|
| ast::ExprKind::Range(..)
|
||||||
|
|
11
src/tools/rustfmt/tests/source/unsafe-binders.rs
Normal file
11
src/tools/rustfmt/tests/source/unsafe-binders.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fn foo() -> unsafe<'a>
|
||||||
|
&'a () {}
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
x: unsafe<'a>
|
||||||
|
&'a (),
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar(unsafe<'a> &'a ());
|
||||||
|
|
||||||
|
impl Trait for unsafe<'a> &'a () {}
|
9
src/tools/rustfmt/tests/target/unsafe-binders.rs
Normal file
9
src/tools/rustfmt/tests/target/unsafe-binders.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
fn foo() -> unsafe<'a> &'a () {}
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
x: unsafe<'a> &'a (),
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar(unsafe<'a> &'a ());
|
||||||
|
|
||||||
|
impl Trait for unsafe<'a> &'a () {}
|
Loading…
Add table
Add a link
Reference in a new issue