Skip to content

Commit ac97487

Browse files
committed
fix lifetime error
1 parent 5c7e629 commit ac97487

File tree

3 files changed

+11
-31
lines changed

3 files changed

+11
-31
lines changed

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDat
1818
use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
1919

2020
use crate::callee::get_fn;
21-
use crate::errors::LayoutSizeOverflow;
2221

2322
#[derive(Clone)]
2423
pub struct FuncSig<'gcc> {
@@ -294,7 +293,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
294293
self.is_native_int_type(typ) || self.is_non_native_int_type(typ) || typ.is_compatible_with(self.bool_type)
295294
}
296295

297-
pub fn sess(&self) -> &Session {
296+
pub fn sess(&self) -> &'tcx Session {
298297
&self.tcx.sess
299298
}
300299

@@ -478,24 +477,7 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
478477
#[inline]
479478
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
480479
if let LayoutError::SizeOverflow(_) = err {
481-
let _ = respan(span, err);
482-
// error: lifetime may not live long enough
483-
// --> src/context.rs:483:13
484-
// |
485-
// 475 | impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
486-
// | ---- ---- lifetime `'tcx` defined here
487-
// | |
488-
// | lifetime `'gcc` defined here
489-
// ...
490-
// 483 | self.sess().emit_fatal(respan(span, err))
491-
// | ^^^^^^^^^^^ argument requires that `'gcc` must outlive `'tcx`
492-
// |
493-
// = help: consider adding the following bound: `'gcc: 'tcx`
494-
// = note: requirement occurs because of the type `CodegenCx<'_, '_>`, which makes the generic argument `'_` invariant
495-
// = note: the struct `CodegenCx<'gcc, 'tcx>` is invariant over the parameter `'gcc`
496-
// = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
497-
// self.sess().emit_fatal(respan(span, err))
498-
self.sess().emit_fatal(LayoutSizeOverflow { span, error: err.to_string() })
480+
self.sess().emit_fatal(respan(span, err))
499481
} else {
500482
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
501483
}
@@ -513,7 +495,7 @@ impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
513495
fn_abi_request: FnAbiRequest<'tcx>,
514496
) -> ! {
515497
if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
516-
self.sess().emit_fatal(LayoutSizeOverflow { span, error: err.to_string() })
498+
self.sess().emit_fatal(respan(span, err))
517499
} else {
518500
match fn_abi_request {
519501
FnAbiRequest::OfFnPtr { sig, extra_args } => {

compiler/rustc_codegen_gcc/src/errors.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,6 @@ pub(crate) struct InvalidMonomorphizationUnsupportedOperation<'a> {
225225
pub in_elem: Ty<'a>,
226226
}
227227

228-
#[derive(Diagnostic)]
229-
#[diag(codegen_gcc::layout_size_overflow)]
230-
pub(crate) struct LayoutSizeOverflow {
231-
#[primary_span]
232-
pub span: Span,
233-
pub error: String,
234-
}
235-
236228
#[derive(Diagnostic)]
237229
#[diag(codegen_gcc::linkage_const_or_mut_type)]
238230
pub(crate) struct LinkageConstOrMutType {

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::ty::{
77
};
88
use rustc_ast as ast;
99
use rustc_attr as attr;
10-
use rustc_errors::{Handler, IntoDiagnostic};
10+
use rustc_errors::{DiagnosticBuilder, Handler, IntoDiagnostic};
1111
use rustc_hir as hir;
1212
use rustc_hir::def_id::DefId;
1313
use rustc_hir::lang_items::LangItem;
@@ -208,7 +208,7 @@ pub enum LayoutError<'tcx> {
208208
}
209209

210210
impl<'a> IntoDiagnostic<'a, !> for LayoutError<'a> {
211-
fn into_diagnostic(self, handler: &'a Handler) -> rustc_errors::DiagnosticBuilder<'a, !> {
211+
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, !> {
212212
handler.struct_fatal(self.to_string())
213213
}
214214
}
@@ -3072,6 +3072,12 @@ impl<'tcx> fmt::Display for FnAbiError<'tcx> {
30723072
}
30733073
}
30743074

3075+
impl<'tcx> IntoDiagnostic<'tcx, !> for FnAbiError<'tcx> {
3076+
fn into_diagnostic(self, handler: &'tcx Handler) -> DiagnosticBuilder<'tcx, !> {
3077+
handler.struct_fatal(self.to_string())
3078+
}
3079+
}
3080+
30753081
// FIXME(eddyb) maybe use something like this for an unified `fn_abi_of`, not
30763082
// just for error handling.
30773083
#[derive(Debug)]

0 commit comments

Comments
 (0)