Skip to content

Commit f61bcd7

Browse files
committed
gccrs: Fix ICE accessing empty vector without check
Fixes #2747 gcc/rust/ChangeLog: * typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args): fix gcc/testsuite/ChangeLog: * rust/compile/issue-2747.rs: New test.
1 parent d6e10d2 commit f61bcd7

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

gcc/rust/typecheck/rust-tyty-subst.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@ SubstitutionRef::get_mappings_from_generic_args (HIR::GenericArgs &args)
617617
if (args.get_type_args ().size () + offs > substitutions.size ())
618618
{
619619
rich_location r (line_table, args.get_locus ());
620-
r.add_range (substitutions.front ().get_param_locus ());
620+
if (!substitutions.empty ())
621+
r.add_range (substitutions.front ().get_param_locus ());
621622

622623
rust_error_at (
623624
r,
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#[lang = "sized"]
2+
pub trait Sized {}
3+
4+
#[lang = "fn_once"]
5+
pub trait FnOnce<Args> {
6+
#[lang = "fn_once_output"]
7+
type Output;
8+
9+
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
10+
}
11+
12+
struct Foo<'a, 'b: 'a> {
13+
x: &'a i32,
14+
y: &'a i32,
15+
a: &'b i32,
16+
q: &'a [&'b i32],
17+
}
18+
19+
pub fn test<'x, 'y>(f: Foo<'x, 'y, ()>) {
20+
// { dg-error "generic item takes at most 0 type arguments but 1 were supplied" "" { target *-*-* } .-1 }
21+
let x = 5;
22+
let y = 6;
23+
let z = 7;
24+
type F<'a, 'b> = fn(&'a i32, &'b i32) -> i32;
25+
let f = Foo {
26+
x: &x,
27+
y: &y,
28+
a: &z,
29+
q: &[&x, &y],
30+
};
31+
}

0 commit comments

Comments
 (0)