about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDrMeepster <19316085+DrMeepster@users.noreply.github.com>2023-04-21 01:44:17 -0700
committerDrMeepster <19316085+DrMeepster@users.noreply.github.com>2023-04-21 02:14:04 -0700
commit3206960ec660f45169c03afb789f0e4ef4e4f193 (patch)
treebb881e95440ce04b8cccc428cfdb76c619d847ca
parentf92294f76b130f44659a2e8a1fc4b3bd16c5b20b (diff)
downloadrust-3206960ec660f45169c03afb789f0e4ef4e4f193.tar.gz
rust-3206960ec660f45169c03afb789f0e4ef4e4f193.zip
minor tweaks
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state/expr.rs13
-rw-r--r--compiler/rustc_const_eval/src/interpret/step.rs2
-rw-r--r--compiler/rustc_hir_pretty/src/lib.rs13
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs1
-rw-r--r--compiler/rustc_mir_build/src/build/expr/category.rs4
-rw-r--r--compiler/rustc_mir_build/src/thir/print.rs2
-rw-r--r--library/core/src/mem/mod.rs2
-rw-r--r--src/tools/rustfmt/src/expr.rs3
8 files changed, 19 insertions, 21 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
index d31332b3b91..aeb0c762020 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
@@ -558,14 +558,13 @@ impl<'a> State<'a> {
                 self.word(",");
                 self.space();
 
-                let (&first, rest) =
-                    fields.split_first().expect("offset_of! should have at least 1 field");
+                if let Some((&first, rest)) = fields.split_first() {
+                    self.print_ident(first);
 
-                self.print_ident(first);
-
-                for &field in rest {
-                    self.word(".");
-                    self.print_ident(field);
+                    for &field in rest {
+                        self.word(".");
+                        self.print_ident(field);
+                    }
                 }
 
                 self.end();
diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs
index 4ed83f1db0e..4d3a1193508 100644
--- a/compiler/rustc_const_eval/src/interpret/step.rs
+++ b/compiler/rustc_const_eval/src/interpret/step.rs
@@ -287,7 +287,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
                     // FIXME: This should be a span_bug (#80742)
                     self.tcx.sess.delay_span_bug(
                         self.frame().current_span(),
-                        &format!("Nullary MIR operator called for unsized type {}", ty),
+                        &format!("{null_op:?} MIR operator called for unsized type {ty}"),
                     );
                     throw_inval!(SizeOfUnsizedType(ty));
                 }
diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs
index 1e05003c19c..2db4f1e50d4 100644
--- a/compiler/rustc_hir_pretty/src/lib.rs
+++ b/compiler/rustc_hir_pretty/src/lib.rs
@@ -1557,14 +1557,13 @@ impl<'a> State<'a> {
                 self.word(",");
                 self.space();
 
-                let (&first, rest) =
-                    fields.split_first().expect("offset_of! should have at least 1 field");
+                if let Some((&first, rest)) = fields.split_first() {
+                    self.print_ident(first);
 
-                self.print_ident(first);
-
-                for &field in rest {
-                    self.word(".");
-                    self.print_ident(field);
+                    for &field in rest {
+                        self.word(".");
+                        self.print_ident(field);
+                    }
                 }
 
                 self.word(")");
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 653f2f2886f..3ffc583d43f 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -3084,6 +3084,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     {
                         let field_ty = self.field_ty(expr.span, field, substs);
 
+                        // FIXME: DSTs with static alignment should be allowed
                         self.require_type_is_sized(field_ty, expr.span, traits::MiscObligation);
 
                         if field.vis.is_accessible_from(def_scope, self.tcx) {
diff --git a/compiler/rustc_mir_build/src/build/expr/category.rs b/compiler/rustc_mir_build/src/build/expr/category.rs
index 3cc104ad96a..d9aa461c19d 100644
--- a/compiler/rustc_mir_build/src/build/expr/category.rs
+++ b/compiler/rustc_mir_build/src/build/expr/category.rs
@@ -53,7 +53,8 @@ impl Category {
             | ExprKind::Borrow { .. }
             | ExprKind::AddressOf { .. }
             | ExprKind::Yield { .. }
-            | ExprKind::Call { .. } => Some(Category::Rvalue(RvalueFunc::Into)),
+            | ExprKind::Call { .. }
+            | ExprKind::InlineAsm { .. } => Some(Category::Rvalue(RvalueFunc::Into)),
 
             ExprKind::Array { .. }
             | ExprKind::Tuple { .. }
@@ -67,7 +68,6 @@ impl Category {
             | ExprKind::Assign { .. }
             | ExprKind::AssignOp { .. }
             | ExprKind::ThreadLocalRef(_)
-            | ExprKind::InlineAsm { .. }
             | ExprKind::OffsetOf { .. } => Some(Category::Rvalue(RvalueFunc::AsRvalue)),
 
             ExprKind::ConstBlock { .. }
diff --git a/compiler/rustc_mir_build/src/thir/print.rs b/compiler/rustc_mir_build/src/thir/print.rs
index 86d20327f60..9fec3ce16ee 100644
--- a/compiler/rustc_mir_build/src/thir/print.rs
+++ b/compiler/rustc_mir_build/src/thir/print.rs
@@ -520,7 +520,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
                 print_indented!(self, "}", depth_lvl);
             }
             OffsetOf { container, fields } => {
-                print_indented!(self, "InlineAsm {", depth_lvl);
+                print_indented!(self, "OffsetOf {", depth_lvl);
                 print_indented!(self, format!("container: {:?}", container), depth_lvl + 1);
                 print_indented!(self, "fields: [", depth_lvl + 1);
 
diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs
index 85745334e9f..7d2f2971523 100644
--- a/library/core/src/mem/mod.rs
+++ b/library/core/src/mem/mod.rs
@@ -1319,5 +1319,5 @@ impl<T> SizedTypeProperties for T {}
 #[rustc_builtin_macro]
 #[cfg(not(bootstrap))]
 pub macro offset_of($Container:ty, $($fields:tt).+ $(,)?) {
-    // ...implementation defined...
+    /* compiler built-in */
 }
diff --git a/src/tools/rustfmt/src/expr.rs b/src/tools/rustfmt/src/expr.rs
index b76e3a2a87c..a0882eff707 100644
--- a/src/tools/rustfmt/src/expr.rs
+++ b/src/tools/rustfmt/src/expr.rs
@@ -345,7 +345,6 @@ pub(crate) fn format_expr(
         // Style Guide RFC for InlineAsm variant pending
         // https://github.com/rust-dev-tools/fmt-rfcs/issues/152
         ast::ExprKind::InlineAsm(..) => Some(context.snippet(expr.span).to_owned()),
-        ast::ExprKind::OffsetOf(..) => Some(context.snippet(expr.span).to_owned()),
         ast::ExprKind::TryBlock(ref block) => {
             if let rw @ Some(_) =
                 rewrite_single_line_block(context, "try ", block, Some(&expr.attrs), None, shape)
@@ -400,7 +399,7 @@ pub(crate) fn format_expr(
             }
         }
         ast::ExprKind::Underscore => Some("_".to_owned()),
-        ast::ExprKind::FormatArgs(..) | ast::ExprKind::IncludedBytes(..) => {
+        ast::ExprKind::FormatArgs(..) | ast::ExprKind::IncludedBytes(..) | ast::ExprKind::OffsetOf(..) => {
             // These do not occur in the AST because macros aren't expanded.
             unreachable!()
         }