Skip to content

Commit 5c839d9

Browse files
committed
impl SessionDiagnostic for LayoutError and Spanned<T>
1 parent 059326c commit 5c839d9

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
@@ -13,7 +13,7 @@ use rustc_middle::mir::mono::CodegenUnit;
1313
use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
1414
use rustc_middle::ty::layout::{FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, TyAndLayout, LayoutOfHelpers};
1515
use rustc_session::Session;
16-
use rustc_span::Span;
16+
use rustc_span::{Span, source_map::respan};
1717
use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx};
1818
use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
1919

@@ -478,6 +478,23 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
478478
#[inline]
479479
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
480480
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))
481498
self.sess().emit_fatal(LayoutSizeOverflow { span, error: err.to_string() })
482499
} else {
483500
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)

0 commit comments

Comments
 (0)