Skip to content

Commit 2e46dc2

Browse files
ellishgantoyo
authored andcommitted
impl SessionDiagnostic for LayoutError and Spanned<T>
1 parent ef3aaa1 commit 2e46dc2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/context.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::mir::mono::CodegenUnit;
1414
use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
1515
use rustc_middle::ty::layout::{FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, TyAndLayout, LayoutOfHelpers};
1616
use rustc_session::Session;
17-
use rustc_span::Span;
17+
use rustc_span::{Span, source_map::respan};
1818
use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx};
1919
use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
2020

@@ -493,6 +493,23 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
493493
#[inline]
494494
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
495495
if let LayoutError::SizeOverflow(_) = err {
496+
let _ = respan(span, err);
497+
// error: lifetime may not live long enough
498+
// --> src/context.rs:483:13
499+
// |
500+
// 475 | impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
501+
// | ---- ---- lifetime `'tcx` defined here
502+
// | |
503+
// | lifetime `'gcc` defined here
504+
// ...
505+
// 483 | self.sess().emit_fatal(respan(span, err))
506+
// | ^^^^^^^^^^^ argument requires that `'gcc` must outlive `'tcx`
507+
// |
508+
// = help: consider adding the following bound: `'gcc: 'tcx`
509+
// = note: requirement occurs because of the type `CodegenCx<'_, '_>`, which makes the generic argument `'_` invariant
510+
// = note: the struct `CodegenCx<'gcc, 'tcx>` is invariant over the parameter `'gcc`
511+
// = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
512+
// self.sess().emit_fatal(respan(span, err))
496513
self.sess().emit_fatal(LayoutSizeOverflow { span, error: err.to_string() })
497514
} else {
498515
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)

0 commit comments

Comments
 (0)