about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEllis Hoag <ellis.sparky.hoag@gmail.com>2022-09-24 11:36:16 -0700
committerEllis Hoag <ellis.sparky.hoag@gmail.com>2022-09-24 11:36:16 -0700
commitac97487645fdf018724f17ed1e764f2dbb4b04ba (patch)
tree70259f51b76123daff85d282c66b192069c625db
parent5c7e629b6378a25d3575c56a803fa1de0b2641e5 (diff)
downloadrust-ac97487645fdf018724f17ed1e764f2dbb4b04ba.tar.gz
rust-ac97487645fdf018724f17ed1e764f2dbb4b04ba.zip
fix lifetime error
-rw-r--r--compiler/rustc_codegen_gcc/src/context.rs24
-rw-r--r--compiler/rustc_codegen_gcc/src/errors.rs8
-rw-r--r--compiler/rustc_middle/src/ty/layout.rs10
3 files changed, 11 insertions, 31 deletions
diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs
index 14de0cee28e..46ade33eb01 100644
--- a/compiler/rustc_codegen_gcc/src/context.rs
+++ b/compiler/rustc_codegen_gcc/src/context.rs
@@ -18,7 +18,6 @@ use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDat
 use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
 
 use crate::callee::get_fn;
-use crate::errors::LayoutSizeOverflow;
 
 #[derive(Clone)]
 pub struct FuncSig<'gcc> {
@@ -294,7 +293,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
         self.is_native_int_type(typ) || self.is_non_native_int_type(typ) || typ.is_compatible_with(self.bool_type)
     }
 
-    pub fn sess(&self) -> &Session {
+    pub fn sess(&self) -> &'tcx Session {
         &self.tcx.sess
     }
 
@@ -478,24 +477,7 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
     #[inline]
     fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
         if let LayoutError::SizeOverflow(_) = err {
-            let _ = respan(span, err);
-            //             error: lifetime may not live long enough
-            //    --> src/context.rs:483:13
-            //     |
-            // 475 | impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
-            //     |      ----  ---- lifetime `'tcx` defined here
-            //     |      |
-            //     |      lifetime `'gcc` defined here
-            // ...
-            // 483 |             self.sess().emit_fatal(respan(span, err))
-            //     |             ^^^^^^^^^^^ argument requires that `'gcc` must outlive `'tcx`
-            //     |
-            //     = help: consider adding the following bound: `'gcc: 'tcx`
-            //     = note: requirement occurs because of the type `CodegenCx<'_, '_>`, which makes the generic argument `'_` invariant
-            //     = note: the struct `CodegenCx<'gcc, 'tcx>` is invariant over the parameter `'gcc`
-            //     = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
-            // self.sess().emit_fatal(respan(span, err))
-            self.sess().emit_fatal(LayoutSizeOverflow { span, error: err.to_string() })
+            self.sess().emit_fatal(respan(span, err))
         } else {
             span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
         }
@@ -513,7 +495,7 @@ impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
         fn_abi_request: FnAbiRequest<'tcx>,
     ) -> ! {
         if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
-            self.sess().emit_fatal(LayoutSizeOverflow { span, error: err.to_string() })
+            self.sess().emit_fatal(respan(span, err))
         } else {
             match fn_abi_request {
                 FnAbiRequest::OfFnPtr { sig, extra_args } => {
diff --git a/compiler/rustc_codegen_gcc/src/errors.rs b/compiler/rustc_codegen_gcc/src/errors.rs
index a1c95e7a7f4..eb8528104fa 100644
--- a/compiler/rustc_codegen_gcc/src/errors.rs
+++ b/compiler/rustc_codegen_gcc/src/errors.rs
@@ -226,14 +226,6 @@ pub(crate) struct InvalidMonomorphizationUnsupportedOperation<'a> {
 }
 
 #[derive(Diagnostic)]
-#[diag(codegen_gcc::layout_size_overflow)]
-pub(crate) struct LayoutSizeOverflow {
-    #[primary_span]
-    pub span: Span,
-    pub error: String,
-}
-
-#[derive(Diagnostic)]
 #[diag(codegen_gcc::linkage_const_or_mut_type)]
 pub(crate) struct LinkageConstOrMutType {
     #[primary_span]
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs
index a0b7cf1feb5..3c523659df7 100644
--- a/compiler/rustc_middle/src/ty/layout.rs
+++ b/compiler/rustc_middle/src/ty/layout.rs
@@ -7,7 +7,7 @@ use crate::ty::{
 };
 use rustc_ast as ast;
 use rustc_attr as attr;
-use rustc_errors::{Handler, IntoDiagnostic};
+use rustc_errors::{DiagnosticBuilder, Handler, IntoDiagnostic};
 use rustc_hir as hir;
 use rustc_hir::def_id::DefId;
 use rustc_hir::lang_items::LangItem;
@@ -208,7 +208,7 @@ pub enum LayoutError<'tcx> {
 }
 
 impl<'a> IntoDiagnostic<'a, !> for LayoutError<'a> {
-    fn into_diagnostic(self, handler: &'a Handler) -> rustc_errors::DiagnosticBuilder<'a, !> {
+    fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, !> {
         handler.struct_fatal(self.to_string())
     }
 }
@@ -3072,6 +3072,12 @@ impl<'tcx> fmt::Display for FnAbiError<'tcx> {
     }
 }
 
+impl<'tcx> IntoDiagnostic<'tcx, !> for FnAbiError<'tcx> {
+    fn into_diagnostic(self, handler: &'tcx Handler) -> DiagnosticBuilder<'tcx, !> {
+        handler.struct_fatal(self.to_string())
+    }
+}
+
 // FIXME(eddyb) maybe use something like this for an unified `fn_abi_of`, not
 // just for error handling.
 #[derive(Debug)]