Skip to content

Commit a43409f

Browse files
committed
Panic when creating a HirDisplayWrapper with DisplayTarget::SourceCode
1 parent ffdb2da commit a43409f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

crates/hir_ty/src/display.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ pub trait HirDisplay {
5151
where
5252
Self: Sized,
5353
{
54+
assert!(
55+
!matches!(display_target, DisplayTarget::SourceCode { .. }),
56+
"HirDisplayWrapper cannot fail with DisplaySourceCodeError, use HirDisplay::hir_fmt directly instead"
57+
);
5458
HirDisplayWrapper { db, t: self, max_size, omit_verbose_types, display_target }
5559
}
5660

@@ -235,7 +239,7 @@ where
235239
Err(HirDisplayError::FmtError) => Err(fmt::Error),
236240
Err(HirDisplayError::DisplaySourceCodeError(_)) => {
237241
// This should never happen
238-
panic!("HirDisplay failed when calling Display::fmt!")
242+
panic!("HirDisplay::hir_fmt failed with DisplaySourceCodeError when calling Display::fmt!")
239243
}
240244
}
241245
}

0 commit comments

Comments
 (0)