Skip to content

Commit 3206960

Browse files
committed
minor tweaks
1 parent f92294f commit 3206960

File tree

8 files changed

+19
-21
lines changed

8 files changed

+19
-21
lines changed

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,13 @@ impl<'a> State<'a> {
558558
self.word(",");
559559
self.space();
560560

561-
let (&first, rest) =
562-
fields.split_first().expect("offset_of! should have at least 1 field");
561+
if let Some((&first, rest)) = fields.split_first() {
562+
self.print_ident(first);
563563

564-
self.print_ident(first);
565-
566-
for &field in rest {
567-
self.word(".");
568-
self.print_ident(field);
564+
for &field in rest {
565+
self.word(".");
566+
self.print_ident(field);
567+
}
569568
}
570569

571570
self.end();

compiler/rustc_const_eval/src/interpret/step.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
287287
// FIXME: This should be a span_bug (#80742)
288288
self.tcx.sess.delay_span_bug(
289289
self.frame().current_span(),
290-
&format!("Nullary MIR operator called for unsized type {}", ty),
290+
&format!("{null_op:?} MIR operator called for unsized type {ty}"),
291291
);
292292
throw_inval!(SizeOfUnsizedType(ty));
293293
}

compiler/rustc_hir_pretty/src/lib.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1557,14 +1557,13 @@ impl<'a> State<'a> {
15571557
self.word(",");
15581558
self.space();
15591559

1560-
let (&first, rest) =
1561-
fields.split_first().expect("offset_of! should have at least 1 field");
1560+
if let Some((&first, rest)) = fields.split_first() {
1561+
self.print_ident(first);
15621562

1563-
self.print_ident(first);
1564-
1565-
for &field in rest {
1566-
self.word(".");
1567-
self.print_ident(field);
1563+
for &field in rest {
1564+
self.word(".");
1565+
self.print_ident(field);
1566+
}
15681567
}
15691568

15701569
self.word(")");

compiler/rustc_hir_typeck/src/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3084,6 +3084,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30843084
{
30853085
let field_ty = self.field_ty(expr.span, field, substs);
30863086

3087+
// FIXME: DSTs with static alignment should be allowed
30873088
self.require_type_is_sized(field_ty, expr.span, traits::MiscObligation);
30883089

30893090
if field.vis.is_accessible_from(def_scope, self.tcx) {

compiler/rustc_mir_build/src/build/expr/category.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ impl Category {
5353
| ExprKind::Borrow { .. }
5454
| ExprKind::AddressOf { .. }
5555
| ExprKind::Yield { .. }
56-
| ExprKind::Call { .. } => Some(Category::Rvalue(RvalueFunc::Into)),
56+
| ExprKind::Call { .. }
57+
| ExprKind::InlineAsm { .. } => Some(Category::Rvalue(RvalueFunc::Into)),
5758

5859
ExprKind::Array { .. }
5960
| ExprKind::Tuple { .. }
@@ -67,7 +68,6 @@ impl Category {
6768
| ExprKind::Assign { .. }
6869
| ExprKind::AssignOp { .. }
6970
| ExprKind::ThreadLocalRef(_)
70-
| ExprKind::InlineAsm { .. }
7171
| ExprKind::OffsetOf { .. } => Some(Category::Rvalue(RvalueFunc::AsRvalue)),
7272

7373
ExprKind::ConstBlock { .. }

compiler/rustc_mir_build/src/thir/print.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
520520
print_indented!(self, "}", depth_lvl);
521521
}
522522
OffsetOf { container, fields } => {
523-
print_indented!(self, "InlineAsm {", depth_lvl);
523+
print_indented!(self, "OffsetOf {", depth_lvl);
524524
print_indented!(self, format!("container: {:?}", container), depth_lvl + 1);
525525
print_indented!(self, "fields: [", depth_lvl + 1);
526526

library/core/src/mem/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1319,5 +1319,5 @@ impl<T> SizedTypeProperties for T {}
13191319
#[rustc_builtin_macro]
13201320
#[cfg(not(bootstrap))]
13211321
pub macro offset_of($Container:ty, $($fields:tt).+ $(,)?) {
1322-
// ...implementation defined...
1322+
/* compiler built-in */
13231323
}

src/tools/rustfmt/src/expr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ pub(crate) fn format_expr(
345345
// Style Guide RFC for InlineAsm variant pending
346346
// https://github.com/rust-dev-tools/fmt-rfcs/issues/152
347347
ast::ExprKind::InlineAsm(..) => Some(context.snippet(expr.span).to_owned()),
348-
ast::ExprKind::OffsetOf(..) => Some(context.snippet(expr.span).to_owned()),
349348
ast::ExprKind::TryBlock(ref block) => {
350349
if let rw @ Some(_) =
351350
rewrite_single_line_block(context, "try ", block, Some(&expr.attrs), None, shape)
@@ -400,7 +399,7 @@ pub(crate) fn format_expr(
400399
}
401400
}
402401
ast::ExprKind::Underscore => Some("_".to_owned()),
403-
ast::ExprKind::FormatArgs(..) | ast::ExprKind::IncludedBytes(..) => {
402+
ast::ExprKind::FormatArgs(..) | ast::ExprKind::IncludedBytes(..) | ast::ExprKind::OffsetOf(..) => {
404403
// These do not occur in the AST because macros aren't expanded.
405404
unreachable!()
406405
}

0 commit comments

Comments
 (0)