Skip to content

Commit 663bea5

Browse files
committed
Add better ICE messages for some undescriptive panics
1 parent 03515c6 commit 663bea5

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_ast::{self as ast, *};
99
use rustc_hir as hir;
1010
use rustc_hir::def::{DefKind, PartialRes, Res};
1111
use rustc_hir::GenericArg;
12+
use rustc_middle::span_bug;
1213
use rustc_span::symbol::{kw, sym, Ident};
1314
use rustc_span::{BytePos, Span, DUMMY_SP};
1415

@@ -285,7 +286,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
285286
let (start, end) = match self.resolver.get_lifetime_res(segment_id) {
286287
Some(LifetimeRes::ElidedAnchor { start, end }) => (start, end),
287288
None => return,
288-
Some(_) => panic!(),
289+
Some(res) => {
290+
span_bug!(path_span, "expected an elided lifetime to insert. found {res:?}")
291+
}
289292
};
290293
let expected_lifetimes = end.as_usize() - start.as_usize();
291294
debug!(expected_lifetimes);

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,9 @@ impl<'a> State<'a> {
15971597
}
15981598
match bound {
15991599
ast::GenericBound::Outlives(lt) => self.print_lifetime(*lt),
1600-
_ => panic!(),
1600+
_ => {
1601+
panic!("expected a lifetime bound, found a trait bound")
1602+
}
16011603
}
16021604
}
16031605
}

compiler/rustc_span/src/caching_source_map_view.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'sm> CachingSourceMapView<'sm> {
117117
self.time_stamp += 1;
118118

119119
// Check if lo and hi are in the cached lines.
120-
let lo_cache_idx = self.cache_entry_index(span_data.lo);
120+
let lo_cache_idx: isize = self.cache_entry_index(span_data.lo);
121121
let hi_cache_idx = self.cache_entry_index(span_data.hi);
122122

123123
if lo_cache_idx != -1 && hi_cache_idx != -1 {
@@ -205,7 +205,9 @@ impl<'sm> CachingSourceMapView<'sm> {
205205
(lo_cache_idx as usize, oldest)
206206
}
207207
_ => {
208-
panic!();
208+
panic!(
209+
"the case of neither value being equal to -1 was handled above and the function returns."
210+
);
209211
}
210212
};
211213

0 commit comments

Comments
 (0)