fix lifetime error

This commit is contained in:
Ellis Hoag 2022-09-24 11:36:16 -07:00
parent 43b3206571
commit 0ae1e27b17
2 changed files with 3 additions and 29 deletions

View File

@ -18,7 +18,6 @@
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 @@ pub fn is_int_type_or_bool(&self, typ: Type<'gcc>) -> bool {
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 @@ fn handle_fn_abi_err(
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 } => {

View File

@ -225,14 +225,6 @@ pub(crate) struct InvalidMonomorphizationUnsupportedOperation<'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)]
#[diag(codegen_gcc::linkage_const_or_mut_type)]
pub(crate) struct LinkageConstOrMutType {