Skip to content

Commit 60da5de

Browse files
Fix index out of bounds in suggest_trait_fn_ty_for_impl_fn_infer
1 parent c90eb48 commit 60da5de

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -3317,10 +3317,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
33173317
tcx,
33183318
trait_ref.substs.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)),
33193319
);
3320+
let fn_sig = tcx.liberate_late_bound_regions(fn_hir_id.expect_owner().to_def_id(), fn_sig);
33203321

3321-
let ty = if let Some(arg_idx) = arg_idx { fn_sig.input(arg_idx) } else { fn_sig.output() };
3322-
3323-
Some(tcx.liberate_late_bound_regions(fn_hir_id.expect_owner().to_def_id(), ty))
3322+
Some(if let Some(arg_idx) = arg_idx {
3323+
*fn_sig.inputs().get(arg_idx)?
3324+
} else {
3325+
fn_sig.output()
3326+
})
33243327
}
33253328

33263329
#[instrument(level = "trace", skip(self, generate_err))]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
trait Foo {
2+
fn bar();
3+
}
4+
5+
impl Foo for () {
6+
fn bar(s: _) {}
7+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
2+
--> $DIR/bad-infer-in-trait-impl.rs:6:15
3+
|
4+
LL | fn bar(s: _) {}
5+
| ^ not allowed in type signatures
6+
|
7+
help: use type parameters instead
8+
|
9+
LL | fn bar<T>(s: T) {}
10+
| +++ ~
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)