Skip to content

Commit 55d5cd5

Browse files
authored
Rollup merge of #109200 - compiler-errors:issue-109191, r=WaffleLapkin
Fix index out of bounds in `suggest_trait_fn_ty_for_impl_fn_infer` Fixes #109191
2 parents 0ee7539 + 60da5de commit 55d5cd5

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
@@ -3328,10 +3328,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
33283328
tcx,
33293329
trait_ref.substs.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)),
33303330
);
3331+
let fn_sig = tcx.liberate_late_bound_regions(fn_hir_id.expect_owner().to_def_id(), fn_sig);
33313332

3332-
let ty = if let Some(arg_idx) = arg_idx { fn_sig.input(arg_idx) } else { fn_sig.output() };
3333-
3334-
Some(tcx.liberate_late_bound_regions(fn_hir_id.expect_owner().to_def_id(), ty))
3333+
Some(if let Some(arg_idx) = arg_idx {
3334+
*fn_sig.inputs().get(arg_idx)?
3335+
} else {
3336+
fn_sig.output()
3337+
})
33353338
}
33363339

33373340
#[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)