Skip to content

Commit 01bff9e

Browse files
author
yimiliya
committed
Handle non-type args in TraitRefPrintSugared
The issue was that `TraitRefPrintSugared` called `type_at(1)` which panics when the argument is not a type (e.g., an inference variable). This can happen when there are prior errors in user code, such as incorrect trait parameters with paren sugar syntax. The fix uses `get(1).and_then(|arg| arg.as_type())` to safely check if the argument is a type before accessing it, falling back to the default printing path if not.
1 parent 0d1ac13 commit 01bff9e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3313,7 +3313,8 @@ define_print_and_forward_display! {
33133313
TraitRefPrintSugared<'tcx> {
33143314
if !with_reduced_queries()
33153315
&& p.tcx().trait_def(self.0.def_id).paren_sugar
3316-
&& let ty::Tuple(args) = self.0.args.type_at(1).kind()
3316+
&& let Some(ty) = self.0.args.get(1).and_then(|arg| arg.as_type())
3317+
&& let ty::Tuple(args) = ty.kind()
33173318
{
33183319
write!(p, "{}(", p.tcx().item_name(self.0.def_id))?;
33193320
for (i, arg) in args.iter().enumerate() {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Test for issue #153853: ICE when using paren sugar with inferred types
2+
#![feature(unboxed_closures)]
3+
#[rustc_paren_sugar]
4+
trait Tr<'a, 'b, T> {
5+
fn method() {}
6+
}
7+
8+
fn main() {
9+
<u8 as Tr(&u8)>::method;
10+
}

0 commit comments

Comments
 (0)