about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-11-01 22:37:24 +0000
committerbors <bors@rust-lang.org>2023-11-01 22:37:24 +0000
commit722b3eeb72b6bca6c38bbcbda57179f073f23431 (patch)
tree61b1842714ca01b32a7b51d531140980bbd10433
parent75b064d26970ca8e7a487072f51835ebb057d575 (diff)
parenteffc27dea4c5b2710bf8e49b8c4cbb641ee05e90 (diff)
downloadrust-722b3eeb72b6bca6c38bbcbda57179f073f23431.tar.gz
rust-722b3eeb72b6bca6c38bbcbda57179f073f23431.zip
Auto merge of #117498 - matthiaskrgr:rollup-z7mg4ck, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #117298 (Recover from missing param list in function definitions)
 - #117373 (Avoid the path trimming ICE lint in error reporting)
 - #117441 (Do not assert in op_to_const.)
 - #117488 (Update minifier-rs version to 0.3.0)

r? `@ghost`
`@rustbot` modify labels: rollup
-rw-r--r--Cargo.lock4
-rw-r--r--compiler/rustc_const_eval/src/const_eval/eval_queries.rs16
-rw-r--r--compiler/rustc_const_eval/src/const_eval/mod.rs4
-rw-r--r--compiler/rustc_const_eval/src/const_eval/valtrees.rs4
-rw-r--r--compiler/rustc_const_eval/src/interpret/cast.rs12
-rw-r--r--compiler/rustc_const_eval/src/lib.rs4
-rw-r--r--compiler/rustc_middle/src/hooks/mod.rs2
-rw-r--r--compiler/rustc_middle/src/mir/pretty.rs2
-rw-r--r--compiler/rustc_parse/messages.ftl3
-rw-r--r--compiler/rustc_parse/src/errors.rs8
-rw-r--r--compiler/rustc_parse/src/parser/item.rs10
-rw-r--r--src/librustdoc/Cargo.toml2
-rw-r--r--src/tools/clippy/clippy_utils/src/consts.rs2
-rw-r--r--tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff123
-rw-r--r--tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff92
-rw-r--r--tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff123
-rw-r--r--tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff92
-rw-r--r--tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs15
-rw-r--r--tests/ui/mismatched_types/recovered-block.rs6
-rw-r--r--tests/ui/mismatched_types/recovered-block.stderr8
-rw-r--r--tests/ui/parser/issues/issue-108109-fn-missing-params.fixed9
-rw-r--r--tests/ui/parser/issues/issue-108109-fn-missing-params.rs9
-rw-r--r--tests/ui/parser/issues/issue-108109-fn-missing-params.stderr14
-rw-r--r--tests/ui/parser/removed-syntax-fn-sigil.rs3
-rw-r--r--tests/ui/parser/removed-syntax-fn-sigil.stderr14
25 files changed, 540 insertions, 41 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a9090201710..93845578293 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2465,9 +2465,9 @@ dependencies = [
 
 [[package]]
 name = "minifier"
-version = "0.2.3"
+version = "0.3.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5394aa376422b4b2b6c02fd9cfcb657e4ec544ae98e43d7d5d785fd0d042fd6d"
+checksum = "95bbbf96b9ac3482c2a25450b67a15ed851319bc5fabf3b40742ea9066e84282"
 
 [[package]]
 name = "minimal-lexical"
diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs
index 669838308a5..7782cb8fd38 100644
--- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs
+++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs
@@ -106,10 +106,16 @@ pub(crate) fn mk_eval_cx<'mir, 'tcx>(
 }
 
 /// This function converts an interpreter value into a MIR constant.
+///
+/// The `for_diagnostics` flag turns the usual rules for returning `ConstValue::Scalar` into a
+/// best-effort attempt. This is not okay for use in const-eval sine it breaks invariants rustc
+/// relies on, but it is okay for diagnostics which will just give up gracefully when they
+/// encounter an `Indirect` they cannot handle.
 #[instrument(skip(ecx), level = "debug")]
 pub(super) fn op_to_const<'tcx>(
     ecx: &CompileTimeEvalContext<'_, 'tcx>,
     op: &OpTy<'tcx>,
+    for_diagnostics: bool,
 ) -> ConstValue<'tcx> {
     // Handle ZST consistently and early.
     if op.layout.is_zst() {
@@ -133,7 +139,13 @@ pub(super) fn op_to_const<'tcx>(
         _ => false,
     };
     let immediate = if force_as_immediate {
-        Right(ecx.read_immediate(op).expect("normalization works on validated constants"))
+        match ecx.read_immediate(op) {
+            Ok(imm) => Right(imm),
+            Err(err) if !for_diagnostics => {
+                panic!("normalization works on validated constants: {err:?}")
+            }
+            _ => op.as_mplace_or_imm(),
+        }
     } else {
         op.as_mplace_or_imm()
     };
@@ -205,7 +217,7 @@ pub(crate) fn turn_into_const_value<'tcx>(
     );
 
     // Turn this into a proper constant.
-    op_to_const(&ecx, &mplace.into())
+    op_to_const(&ecx, &mplace.into(), /* for diagnostics */ false)
 }
 
 #[instrument(skip(tcx), level = "debug")]
diff --git a/compiler/rustc_const_eval/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs
index d6ee6975cdd..e53282ffaeb 100644
--- a/compiler/rustc_const_eval/src/const_eval/mod.rs
+++ b/compiler/rustc_const_eval/src/const_eval/mod.rs
@@ -72,7 +72,7 @@ pub(crate) fn eval_to_valtree<'tcx>(
 }
 
 #[instrument(skip(tcx), level = "debug")]
-pub(crate) fn try_destructure_mir_constant_for_diagnostics<'tcx>(
+pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>(
     tcx: TyCtxtAt<'tcx>,
     val: mir::ConstValue<'tcx>,
     ty: Ty<'tcx>,
@@ -99,7 +99,7 @@ pub(crate) fn try_destructure_mir_constant_for_diagnostics<'tcx>(
     let fields_iter = (0..field_count)
         .map(|i| {
             let field_op = ecx.project_field(&down, i).ok()?;
-            let val = op_to_const(&ecx, &field_op);
+            let val = op_to_const(&ecx, &field_op, /* for diagnostics */ true);
             Some((val, field_op.layout.ty))
         })
         .collect::<Option<Vec<_>>>()?;
diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs
index d6dc1a62f4d..3aaaf08c856 100644
--- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs
+++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs
@@ -232,7 +232,7 @@ pub fn valtree_to_const_value<'tcx>(
             let mut ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, CanAccessStatics::No);
             let imm = valtree_to_ref(&mut ecx, valtree, *inner_ty);
             let imm = ImmTy::from_immediate(imm, tcx.layout_of(param_env_ty).unwrap());
-            op_to_const(&ecx, &imm.into())
+            op_to_const(&ecx, &imm.into(), /* for diagnostics */ false)
         }
         ty::Tuple(_) | ty::Array(_, _) | ty::Adt(..) => {
             let layout = tcx.layout_of(param_env_ty).unwrap();
@@ -265,7 +265,7 @@ pub fn valtree_to_const_value<'tcx>(
             dump_place(&ecx, &place);
             intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &place).unwrap();
 
-            op_to_const(&ecx, &place.into())
+            op_to_const(&ecx, &place.into(), /* for diagnostics */ false)
         }
         ty::Never
         | ty::Error(_)
diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs
index 8fc0205d6c7..f4cb12c8d43 100644
--- a/compiler/rustc_const_eval/src/interpret/cast.rs
+++ b/compiler/rustc_const_eval/src/interpret/cast.rs
@@ -145,16 +145,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
                 assert!(dest.layout.is_sized());
                 assert_eq!(cast_ty, dest.layout.ty); // we otherwise ignore `cast_ty` enirely...
                 if src.layout.size != dest.layout.size {
-                    let src_bytes = src.layout.size.bytes();
-                    let dest_bytes = dest.layout.size.bytes();
-                    let src_ty = format!("{}", src.layout.ty);
-                    let dest_ty = format!("{}", dest.layout.ty);
                     throw_ub_custom!(
                         fluent::const_eval_invalid_transmute,
-                        src_bytes = src_bytes,
-                        dest_bytes = dest_bytes,
-                        src = src_ty,
-                        dest = dest_ty,
+                        src_bytes = src.layout.size.bytes(),
+                        dest_bytes = dest.layout.size.bytes(),
+                        src = src.layout.ty,
+                        dest = dest.layout.ty,
                     );
                 }
 
diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs
index 7d36e2eaefe..1e21c494070 100644
--- a/compiler/rustc_const_eval/src/lib.rs
+++ b/compiler/rustc_const_eval/src/lib.rs
@@ -54,8 +54,8 @@ pub fn provide(providers: &mut Providers) {
         let (param_env, raw) = param_env_and_value.into_parts();
         const_eval::eval_to_valtree(tcx, param_env, raw)
     };
-    providers.hooks.try_destructure_mir_constant_for_diagnostics =
-        const_eval::try_destructure_mir_constant_for_diagnostics;
+    providers.hooks.try_destructure_mir_constant_for_user_output =
+        const_eval::try_destructure_mir_constant_for_user_output;
     providers.valtree_to_const_val = |tcx, (ty, valtree)| {
         const_eval::valtree_to_const_value(tcx, ty::ParamEnv::empty().and(ty), valtree)
     };
diff --git a/compiler/rustc_middle/src/hooks/mod.rs b/compiler/rustc_middle/src/hooks/mod.rs
index 34838ca4302..8588ae20336 100644
--- a/compiler/rustc_middle/src/hooks/mod.rs
+++ b/compiler/rustc_middle/src/hooks/mod.rs
@@ -66,7 +66,7 @@ macro_rules! declare_hooks {
 declare_hooks! {
     /// Tries to destructure an `mir::Const` ADT or array into its variant index
     /// and its field values. This should only be used for pretty printing.
-    hook try_destructure_mir_constant_for_diagnostics(val: mir::ConstValue<'tcx>, ty: Ty<'tcx>) -> Option<mir::DestructuredConstant<'tcx>>;
+    hook try_destructure_mir_constant_for_user_output(val: mir::ConstValue<'tcx>, ty: Ty<'tcx>) -> Option<mir::DestructuredConstant<'tcx>>;
 
     /// Getting a &core::panic::Location referring to a span.
     hook const_caller_location(file: rustc_span::Symbol, line: u32, col: u32) -> mir::ConstValue<'tcx>;
diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs
index 5f4ff22bc49..debd85dad2e 100644
--- a/compiler/rustc_middle/src/mir/pretty.rs
+++ b/compiler/rustc_middle/src/mir/pretty.rs
@@ -1713,7 +1713,7 @@ fn pretty_print_const_value_tcx<'tcx>(
         (_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) if !ty.has_non_region_param() => {
             let ct = tcx.lift(ct).unwrap();
             let ty = tcx.lift(ty).unwrap();
-            if let Some(contents) = tcx.try_destructure_mir_constant_for_diagnostics(ct, ty) {
+            if let Some(contents) = tcx.try_destructure_mir_constant_for_user_output(ct, ty) {
                 let fields: Vec<(ConstValue<'_>, Ty<'_>)> = contents.fields.to_vec();
                 match *ty.kind() {
                     ty::Array(..) => {
diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl
index 9ba1f0a5df9..e51b672205c 100644
--- a/compiler/rustc_parse/messages.ftl
+++ b/compiler/rustc_parse/messages.ftl
@@ -526,6 +526,9 @@ parse_missing_fn_for_function_definition = missing `fn` for function definition
 parse_missing_fn_for_method_definition = missing `fn` for method definition
     .suggestion = add `fn` here to parse `{$ident}` as a public method
 
+parse_missing_fn_params = missing parameters for function definition
+    .suggestion = add a parameter list
+
 parse_missing_for_in_trait_impl = missing `for` in a trait impl
     .suggestion = add `for` here
 
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs
index e5cd91a32a7..20b4292701e 100644
--- a/compiler/rustc_parse/src/errors.rs
+++ b/compiler/rustc_parse/src/errors.rs
@@ -1552,6 +1552,14 @@ pub(crate) enum AmbiguousMissingKwForItemSub {
 }
 
 #[derive(Diagnostic)]
+#[diag(parse_missing_fn_params)]
+pub(crate) struct MissingFnParams {
+    #[primary_span]
+    #[suggestion(code = "()", applicability = "machine-applicable", style = "short")]
+    pub span: Span,
+}
+
+#[derive(Diagnostic)]
 #[diag(parse_missing_trait_in_trait_impl)]
 pub(crate) struct MissingTraitInTraitImpl {
     #[primary_span]
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index 55ad3f42938..f0cf6bb58ca 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -2499,6 +2499,16 @@ impl<'a> Parser<'a> {
     pub(super) fn parse_fn_params(&mut self, req_name: ReqName) -> PResult<'a, ThinVec<Param>> {
         let mut first_param = true;
         // Parse the arguments, starting out with `self` being allowed...
+        if self.token.kind != TokenKind::OpenDelim(Delimiter::Parenthesis)
+        // might be typo'd trait impl, handled elsewhere
+        && !self.token.is_keyword(kw::For)
+        {
+            // recover from missing argument list, e.g. `fn main -> () {}`
+            self.sess
+                .emit_err(errors::MissingFnParams { span: self.prev_token.span.shrink_to_hi() });
+            return Ok(ThinVec::new());
+        }
+
         let (mut params, _) = self.parse_paren_comma_seq(|p| {
             p.recover_diff_marker();
             let snapshot = p.create_snapshot_for_diagnostic();
diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml
index 0e01c100f9c..f3917b978df 100644
--- a/src/librustdoc/Cargo.toml
+++ b/src/librustdoc/Cargo.toml
@@ -11,7 +11,7 @@ arrayvec = { version = "0.7", default-features = false }
 askama = { version = "0.12", default-features = false, features = ["config"] }
 itertools = "0.10.1"
 indexmap = "2"
-minifier = "0.2.3"
+minifier = "0.3.0"
 once_cell = "1.10.0"
 regex = "1"
 rustdoc-json-types = { path = "../rustdoc-json-types" }
diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs
index 79c04c7c7f4..50a73745acb 100644
--- a/src/tools/clippy/clippy_utils/src/consts.rs
+++ b/src/tools/clippy/clippy_utils/src/consts.rs
@@ -710,7 +710,7 @@ fn field_of_struct<'tcx>(
     field: &Ident,
 ) -> Option<mir::Const<'tcx>> {
     if let mir::Const::Val(result, ty) = result
-        && let Some(dc) = lcx.tcx.try_destructure_mir_constant_for_diagnostics(result, ty)
+        && let Some(dc) = lcx.tcx.try_destructure_mir_constant_for_user_output(result, ty)
         && let Some(dc_variant) = dc.variant
         && let Some(variant) = adt_def.variants().get(dc_variant)
         && let Some(field_idx) = variant.fields.iter().position(|el| el.name == field.name)
diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff
new file mode 100644
index 00000000000..50189d192ce
--- /dev/null
+++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff
@@ -0,0 +1,123 @@
+- // MIR for `main` before GVN
++ // MIR for `main` after GVN
+  
+  fn main() -> () {
+      let mut _0: ();
+      let _1: std::alloc::Layout;
+      let mut _2: std::option::Option<std::alloc::Layout>;
+      let mut _3: *mut u8;
+      let mut _4: *mut [u8];
+      let mut _5: std::ptr::NonNull<[u8]>;
+      let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
+      let mut _7: &std::alloc::Global;
+      let mut _8: std::alloc::Layout;
+      scope 1 {
+          debug layout => _1;
+          let mut _9: &std::alloc::Global;
+          scope 2 {
+              debug ptr => _3;
+          }
+          scope 5 (inlined <std::alloc::Global as Allocator>::allocate) {
+              debug self => _9;
+              debug layout => _1;
+          }
+          scope 6 (inlined #[track_caller] Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap) {
+              debug self => _6;
+              let mut _12: isize;
+              let _13: std::alloc::AllocError;
+              let mut _14: !;
+              let _15: &str;
+              let mut _16: &dyn std::fmt::Debug;
+              let mut _17: &std::alloc::AllocError;
+              scope 7 {
+                  debug t => _5;
+              }
+              scope 8 {
+                  debug e => const std::alloc::AllocError;
+              }
+          }
+          scope 9 (inlined NonNull::<[u8]>::as_ptr) {
+              debug self => _5;
+              let mut _18: *const [u8];
+          }
+      }
+      scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) {
+          debug self => _2;
+          let mut _10: isize;
+          let mut _11: !;
+          scope 4 {
+              debug val => _1;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+-         _2 = Option::<Layout>::None;
++         _2 = const Option::<Layout>::None;
+          StorageLive(_10);
+          _10 = const 0_isize;
+          switchInt(const 0_isize) -> [0: bb1, 1: bb3, otherwise: bb2];
+      }
+  
+      bb1: {
+          _11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
+      }
+  
+      bb2: {
+          unreachable;
+      }
+  
+      bb3: {
+-         _1 = move ((_2 as Some).0: std::alloc::Layout);
++         _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }};
+          StorageDead(_10);
+          StorageDead(_2);
+          StorageLive(_3);
+          StorageLive(_4);
+          StorageLive(_5);
+          StorageLive(_6);
+          _9 = const _;
+-         _6 = std::alloc::Global::alloc_impl(_9, _1, const false) -> [return: bb4, unwind unreachable];
++         _6 = std::alloc::Global::alloc_impl(const {ALLOC1: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }}, const false) -> [return: bb4, unwind unreachable];
+      }
+  
+      bb4: {
+          StorageLive(_12);
+          StorageLive(_15);
+          _12 = discriminant(_6);
+          switchInt(move _12) -> [0: bb6, 1: bb5, otherwise: bb2];
+      }
+  
+      bb5: {
+          _15 = const "called `Result::unwrap()` on an `Err` value";
+          StorageLive(_16);
+          StorageLive(_17);
+          _17 = &_13;
+          _16 = move _17 as &dyn std::fmt::Debug (PointerCoercion(Unsize));
+          StorageDead(_17);
+          _14 = result::unwrap_failed(move _15, move _16) -> unwind unreachable;
+      }
+  
+      bb6: {
+          _5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
+          StorageDead(_15);
+          StorageDead(_12);
+          StorageDead(_6);
+          StorageLive(_18);
+          _18 = (_5.0: *const [u8]);
+          _4 = move _18 as *mut [u8] (PtrToPtr);
+          StorageDead(_18);
+          StorageDead(_5);
+          _3 = move _4 as *mut u8 (PtrToPtr);
+          StorageDead(_4);
+          StorageDead(_3);
+          return;
+      }
+  }
++ 
++ ALLOC0 (size: 8, align: 4) {
++     00 00 00 00 __ __ __ __                         │ ....░░░░
++ }
++ 
++ ALLOC1 (size: 0, align: 1) {}
+  
diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff
new file mode 100644
index 00000000000..6966762a1b8
--- /dev/null
+++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff
@@ -0,0 +1,92 @@
+- // MIR for `main` before GVN
++ // MIR for `main` after GVN
+  
+  fn main() -> () {
+      let mut _0: ();
+      let _1: std::alloc::Layout;
+      let mut _2: std::option::Option<std::alloc::Layout>;
+      let mut _3: *mut u8;
+      let mut _4: *mut [u8];
+      let mut _5: std::ptr::NonNull<[u8]>;
+      let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
+      let mut _7: &std::alloc::Global;
+      let mut _8: std::alloc::Layout;
+      scope 1 {
+          debug layout => _1;
+          let mut _9: &std::alloc::Global;
+          scope 2 {
+              debug ptr => _3;
+          }
+          scope 5 (inlined <std::alloc::Global as Allocator>::allocate) {
+              debug self => _9;
+              debug layout => _1;
+          }
+          scope 6 (inlined NonNull::<[u8]>::as_ptr) {
+              debug self => _5;
+              let mut _12: *const [u8];
+          }
+      }
+      scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) {
+          debug self => _2;
+          let mut _10: isize;
+          let mut _11: !;
+          scope 4 {
+              debug val => _1;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+-         _2 = Option::<Layout>::None;
++         _2 = const Option::<Layout>::None;
+          StorageLive(_10);
+          _10 = const 0_isize;
+          switchInt(const 0_isize) -> [0: bb2, 1: bb4, otherwise: bb3];
+      }
+  
+      bb1: {
+          StorageDead(_6);
+          StorageLive(_12);
+          _12 = (_5.0: *const [u8]);
+          _4 = move _12 as *mut [u8] (PtrToPtr);
+          StorageDead(_12);
+          StorageDead(_5);
+          _3 = move _4 as *mut u8 (PtrToPtr);
+          StorageDead(_4);
+          StorageDead(_3);
+          return;
+      }
+  
+      bb2: {
+          _11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
+      }
+  
+      bb3: {
+          unreachable;
+      }
+  
+      bb4: {
+-         _1 = move ((_2 as Some).0: std::alloc::Layout);
++         _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }};
+          StorageDead(_10);
+          StorageDead(_2);
+          StorageLive(_3);
+          StorageLive(_4);
+          StorageLive(_5);
+          StorageLive(_6);
+          _9 = const _;
+-         _6 = std::alloc::Global::alloc_impl(_9, _1, const false) -> [return: bb5, unwind continue];
++         _6 = std::alloc::Global::alloc_impl(const {ALLOC1: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }}, const false) -> [return: bb5, unwind continue];
+      }
+  
+      bb5: {
+          _5 = Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap(move _6) -> [return: bb1, unwind continue];
+      }
+  }
++ 
++ ALLOC0 (size: 8, align: 4) {
++     00 00 00 00 __ __ __ __                         │ ....░░░░
++ }
++ 
++ ALLOC1 (size: 0, align: 1) {}
+  
diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff
new file mode 100644
index 00000000000..08a185bad9c
--- /dev/null
+++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff
@@ -0,0 +1,123 @@
+- // MIR for `main` before GVN
++ // MIR for `main` after GVN
+  
+  fn main() -> () {
+      let mut _0: ();
+      let _1: std::alloc::Layout;
+      let mut _2: std::option::Option<std::alloc::Layout>;
+      let mut _3: *mut u8;
+      let mut _4: *mut [u8];
+      let mut _5: std::ptr::NonNull<[u8]>;
+      let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
+      let mut _7: &std::alloc::Global;
+      let mut _8: std::alloc::Layout;
+      scope 1 {
+          debug layout => _1;
+          let mut _9: &std::alloc::Global;
+          scope 2 {
+              debug ptr => _3;
+          }
+          scope 5 (inlined <std::alloc::Global as Allocator>::allocate) {
+              debug self => _9;
+              debug layout => _1;
+          }
+          scope 6 (inlined #[track_caller] Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap) {
+              debug self => _6;
+              let mut _12: isize;
+              let _13: std::alloc::AllocError;
+              let mut _14: !;
+              let _15: &str;
+              let mut _16: &dyn std::fmt::Debug;
+              let mut _17: &std::alloc::AllocError;
+              scope 7 {
+                  debug t => _5;
+              }
+              scope 8 {
+                  debug e => const std::alloc::AllocError;
+              }
+          }
+          scope 9 (inlined NonNull::<[u8]>::as_ptr) {
+              debug self => _5;
+              let mut _18: *const [u8];
+          }
+      }
+      scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) {
+          debug self => _2;
+          let mut _10: isize;
+          let mut _11: !;
+          scope 4 {
+              debug val => _1;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+-         _2 = Option::<Layout>::None;
++         _2 = const Option::<Layout>::None;
+          StorageLive(_10);
+          _10 = const 0_isize;
+          switchInt(const 0_isize) -> [0: bb1, 1: bb3, otherwise: bb2];
+      }
+  
+      bb1: {
+          _11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
+      }
+  
+      bb2: {
+          unreachable;
+      }
+  
+      bb3: {
+-         _1 = move ((_2 as Some).0: std::alloc::Layout);
++         _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): ptr::alignment::AlignmentEnum64) }};
+          StorageDead(_10);
+          StorageDead(_2);
+          StorageLive(_3);
+          StorageLive(_4);
+          StorageLive(_5);
+          StorageLive(_6);
+          _9 = const _;
+-         _6 = std::alloc::Global::alloc_impl(_9, _1, const false) -> [return: bb4, unwind unreachable];
++         _6 = std::alloc::Global::alloc_impl(const {ALLOC1: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): ptr::alignment::AlignmentEnum64) }}, const false) -> [return: bb4, unwind unreachable];
+      }
+  
+      bb4: {
+          StorageLive(_12);
+          StorageLive(_15);
+          _12 = discriminant(_6);
+          switchInt(move _12) -> [0: bb6, 1: bb5, otherwise: bb2];
+      }
+  
+      bb5: {
+          _15 = const "called `Result::unwrap()` on an `Err` value";
+          StorageLive(_16);
+          StorageLive(_17);
+          _17 = &_13;
+          _16 = move _17 as &dyn std::fmt::Debug (PointerCoercion(Unsize));
+          StorageDead(_17);
+          _14 = result::unwrap_failed(move _15, move _16) -> unwind unreachable;
+      }
+  
+      bb6: {
+          _5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
+          StorageDead(_15);
+          StorageDead(_12);
+          StorageDead(_6);
+          StorageLive(_18);
+          _18 = (_5.0: *const [u8]);
+          _4 = move _18 as *mut [u8] (PtrToPtr);
+          StorageDead(_18);
+          StorageDead(_5);
+          _3 = move _4 as *mut u8 (PtrToPtr);
+          StorageDead(_4);
+          StorageDead(_3);
+          return;
+      }
+  }
++ 
++ ALLOC0 (size: 16, align: 8) {
++     00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░
++ }
++ 
++ ALLOC1 (size: 0, align: 1) {}
+  
diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff
new file mode 100644
index 00000000000..6501cb85e8a
--- /dev/null
+++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff
@@ -0,0 +1,92 @@
+- // MIR for `main` before GVN
++ // MIR for `main` after GVN
+  
+  fn main() -> () {
+      let mut _0: ();
+      let _1: std::alloc::Layout;
+      let mut _2: std::option::Option<std::alloc::Layout>;
+      let mut _3: *mut u8;
+      let mut _4: *mut [u8];
+      let mut _5: std::ptr::NonNull<[u8]>;
+      let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
+      let mut _7: &std::alloc::Global;
+      let mut _8: std::alloc::Layout;
+      scope 1 {
+          debug layout => _1;
+          let mut _9: &std::alloc::Global;
+          scope 2 {
+              debug ptr => _3;
+          }
+          scope 5 (inlined <std::alloc::Global as Allocator>::allocate) {
+              debug self => _9;
+              debug layout => _1;
+          }
+          scope 6 (inlined NonNull::<[u8]>::as_ptr) {
+              debug self => _5;
+              let mut _12: *const [u8];
+          }
+      }
+      scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) {
+          debug self => _2;
+          let mut _10: isize;
+          let mut _11: !;
+          scope 4 {
+              debug val => _1;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+-         _2 = Option::<Layout>::None;
++         _2 = const Option::<Layout>::None;
+          StorageLive(_10);
+          _10 = const 0_isize;
+          switchInt(const 0_isize) -> [0: bb2, 1: bb4, otherwise: bb3];
+      }
+  
+      bb1: {
+          StorageDead(_6);
+          StorageLive(_12);
+          _12 = (_5.0: *const [u8]);
+          _4 = move _12 as *mut [u8] (PtrToPtr);
+          StorageDead(_12);
+          StorageDead(_5);
+          _3 = move _4 as *mut u8 (PtrToPtr);
+          StorageDead(_4);
+          StorageDead(_3);
+          return;
+      }
+  
+      bb2: {
+          _11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
+      }
+  
+      bb3: {
+          unreachable;
+      }
+  
+      bb4: {
+-         _1 = move ((_2 as Some).0: std::alloc::Layout);
++         _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): ptr::alignment::AlignmentEnum64) }};
+          StorageDead(_10);
+          StorageDead(_2);
+          StorageLive(_3);
+          StorageLive(_4);
+          StorageLive(_5);
+          StorageLive(_6);
+          _9 = const _;
+-         _6 = std::alloc::Global::alloc_impl(_9, _1, const false) -> [return: bb5, unwind continue];
++         _6 = std::alloc::Global::alloc_impl(const {ALLOC1: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): ptr::alignment::AlignmentEnum64) }}, const false) -> [return: bb5, unwind continue];
+      }
+  
+      bb5: {
+          _5 = Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap(move _6) -> [return: bb1, unwind continue];
+      }
+  }
++ 
++ ALLOC0 (size: 16, align: 8) {
++     00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░
++ }
++ 
++ ALLOC1 (size: 0, align: 1) {}
+  
diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs
new file mode 100644
index 00000000000..c92424f2983
--- /dev/null
+++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs
@@ -0,0 +1,15 @@
+// Verify that we do not ICE when printing an invalid constant.
+// EMIT_MIR_FOR_EACH_BIT_WIDTH
+// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
+
+#![feature(allocator_api)]
+
+use std::alloc::{Allocator, Global, Layout};
+
+// EMIT_MIR issue_117368_print_invalid_constant.main.GVN.diff
+fn main() {
+    // CHECK-LABEL: fn main(
+    // CHECK: debug layout => const Layout
+    let layout: Layout = None.unwrap();
+    let ptr: *mut u8 = Global.allocate(layout).unwrap().as_ptr() as _;
+}
diff --git a/tests/ui/mismatched_types/recovered-block.rs b/tests/ui/mismatched_types/recovered-block.rs
index b230b47d35d..a91bbe7083b 100644
--- a/tests/ui/mismatched_types/recovered-block.rs
+++ b/tests/ui/mismatched_types/recovered-block.rs
@@ -12,10 +12,4 @@ pub fn foo() -> Foo {
 }
 //~^^ ERROR missing `struct` for struct definition
 
-pub fn bar() -> Foo {
-    fn
-    Foo { text: "".to_string() }
-}
-//~^^ ERROR expected one of `(` or `<`, found `{`
-
 fn main() {}
diff --git a/tests/ui/mismatched_types/recovered-block.stderr b/tests/ui/mismatched_types/recovered-block.stderr
index f275321abe5..88d62545656 100644
--- a/tests/ui/mismatched_types/recovered-block.stderr
+++ b/tests/ui/mismatched_types/recovered-block.stderr
@@ -9,11 +9,5 @@ help: add `struct` here to parse `Foo` as a public struct
 LL |     pub struct Foo { text }
    |         ++++++
 
-error: expected one of `(` or `<`, found `{`
-  --> $DIR/recovered-block.rs:17:9
-   |
-LL |     Foo { text: "".to_string() }
-   |         ^ expected one of `(` or `<`
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
diff --git a/tests/ui/parser/issues/issue-108109-fn-missing-params.fixed b/tests/ui/parser/issues/issue-108109-fn-missing-params.fixed
new file mode 100644
index 00000000000..b819aa810cb
--- /dev/null
+++ b/tests/ui/parser/issues/issue-108109-fn-missing-params.fixed
@@ -0,0 +1,9 @@
+// run-rustfix
+
+pub fn missing() -> () {}
+//~^ ERROR missing parameters for function definition
+
+pub fn missing2() {}
+//~^ ERROR missing parameters for function definition
+
+fn main() {}
diff --git a/tests/ui/parser/issues/issue-108109-fn-missing-params.rs b/tests/ui/parser/issues/issue-108109-fn-missing-params.rs
new file mode 100644
index 00000000000..01efe728081
--- /dev/null
+++ b/tests/ui/parser/issues/issue-108109-fn-missing-params.rs
@@ -0,0 +1,9 @@
+// run-rustfix
+
+pub fn missing -> () {}
+//~^ ERROR missing parameters for function definition
+
+pub fn missing2 {}
+//~^ ERROR missing parameters for function definition
+
+fn main() {}
diff --git a/tests/ui/parser/issues/issue-108109-fn-missing-params.stderr b/tests/ui/parser/issues/issue-108109-fn-missing-params.stderr
new file mode 100644
index 00000000000..86d3449cc33
--- /dev/null
+++ b/tests/ui/parser/issues/issue-108109-fn-missing-params.stderr
@@ -0,0 +1,14 @@
+error: missing parameters for function definition
+  --> $DIR/issue-108109-fn-missing-params.rs:3:15
+   |
+LL | pub fn missing -> () {}
+   |               ^ help: add a parameter list
+
+error: missing parameters for function definition
+  --> $DIR/issue-108109-fn-missing-params.rs:6:16
+   |
+LL | pub fn missing2 {}
+   |                ^ help: add a parameter list
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/parser/removed-syntax-fn-sigil.rs b/tests/ui/parser/removed-syntax-fn-sigil.rs
index 725843429c0..d55a032d1f2 100644
--- a/tests/ui/parser/removed-syntax-fn-sigil.rs
+++ b/tests/ui/parser/removed-syntax-fn-sigil.rs
@@ -1,3 +1,4 @@
 fn main() {
-    let x: fn~() = || (); //~ ERROR expected `(`, found `~`
+    let x: fn~() = || (); //~ ERROR missing parameters for function definition
+    //~| ERROR expected one of `->`, `;`, or `=`, found `~`
 }
diff --git a/tests/ui/parser/removed-syntax-fn-sigil.stderr b/tests/ui/parser/removed-syntax-fn-sigil.stderr
index 196a5af4729..0d377416700 100644
--- a/tests/ui/parser/removed-syntax-fn-sigil.stderr
+++ b/tests/ui/parser/removed-syntax-fn-sigil.stderr
@@ -1,10 +1,14 @@
-error: expected `(`, found `~`
+error: missing parameters for function definition
   --> $DIR/removed-syntax-fn-sigil.rs:2:14
    |
 LL |     let x: fn~() = || ();
-   |         -    ^ expected `(`
-   |         |
-   |         while parsing the type for `x`
+   |              ^ help: add a parameter list
 
-error: aborting due to previous error
+error: expected one of `->`, `;`, or `=`, found `~`
+  --> $DIR/removed-syntax-fn-sigil.rs:2:14
+   |
+LL |     let x: fn~() = || ();
+   |              ^ expected one of `->`, `;`, or `=`
+
+error: aborting due to 2 previous errors