1
Fork 0

fix lifetime error

This commit is contained in:
Ellis Hoag 2022-09-24 11:36:16 -07:00
parent 5c7e629b63
commit ac97487645
3 changed files with 11 additions and 31 deletions

View file

@ -18,7 +18,6 @@ use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDat
use rustc_target::spec::{HasTargetSpec, Target, TlsModel}; use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
use crate::callee::get_fn; use crate::callee::get_fn;
use crate::errors::LayoutSizeOverflow;
#[derive(Clone)] #[derive(Clone)]
pub struct FuncSig<'gcc> { 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) 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 &self.tcx.sess
} }
@ -478,24 +477,7 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
#[inline] #[inline]
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! { fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
if let LayoutError::SizeOverflow(_) = err { if let LayoutError::SizeOverflow(_) = err {
let _ = respan(span, err); self.sess().emit_fatal(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() })
} else { } else {
span_bug!(span, "failed to get layout for `{}`: {}", ty, err) 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>, fn_abi_request: FnAbiRequest<'tcx>,
) -> ! { ) -> ! {
if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err { 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 { } else {
match fn_abi_request { match fn_abi_request {
FnAbiRequest::OfFnPtr { sig, extra_args } => { FnAbiRequest::OfFnPtr { sig, extra_args } => {

View file

@ -225,14 +225,6 @@ pub(crate) struct InvalidMonomorphizationUnsupportedOperation<'a> {
pub in_elem: Ty<'a>, pub in_elem: Ty<'a>,
} }
#[derive(Diagnostic)]
#[diag(codegen_gcc::layout_size_overflow)]
pub(crate) struct LayoutSizeOverflow {
#[primary_span]
pub span: Span,
pub error: String,
}
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(codegen_gcc::linkage_const_or_mut_type)] #[diag(codegen_gcc::linkage_const_or_mut_type)]
pub(crate) struct LinkageConstOrMutType { pub(crate) struct LinkageConstOrMutType {

View file

@ -7,7 +7,7 @@ use crate::ty::{
}; };
use rustc_ast as ast; use rustc_ast as ast;
use rustc_attr as attr; use rustc_attr as attr;
use rustc_errors::{Handler, IntoDiagnostic}; use rustc_errors::{DiagnosticBuilder, Handler, IntoDiagnostic};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
@ -208,7 +208,7 @@ pub enum LayoutError<'tcx> {
} }
impl<'a> IntoDiagnostic<'a, !> for LayoutError<'a> { 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()) 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 // FIXME(eddyb) maybe use something like this for an unified `fn_abi_of`, not
// just for error handling. // just for error handling.
#[derive(Debug)] #[derive(Debug)]