Fix index out of bounds in suggest_trait_fn_ty_for_impl_fn_infer
This commit is contained in:
parent
c90eb4825a
commit
60da5de1c6
3 changed files with 30 additions and 3 deletions
|
@ -3317,10 +3317,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
tcx,
|
tcx,
|
||||||
trait_ref.substs.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)),
|
trait_ref.substs.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)),
|
||||||
);
|
);
|
||||||
|
let fn_sig = tcx.liberate_late_bound_regions(fn_hir_id.expect_owner().to_def_id(), fn_sig);
|
||||||
|
|
||||||
let ty = if let Some(arg_idx) = arg_idx { fn_sig.input(arg_idx) } else { fn_sig.output() };
|
Some(if let Some(arg_idx) = arg_idx {
|
||||||
|
*fn_sig.inputs().get(arg_idx)?
|
||||||
Some(tcx.liberate_late_bound_regions(fn_hir_id.expect_owner().to_def_id(), ty))
|
} else {
|
||||||
|
fn_sig.output()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self, generate_err))]
|
#[instrument(level = "trace", skip(self, generate_err))]
|
||||||
|
|
10
tests/ui/suggestions/bad-infer-in-trait-impl.rs
Normal file
10
tests/ui/suggestions/bad-infer-in-trait-impl.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
trait Foo {
|
||||||
|
fn bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Foo for () {
|
||||||
|
fn bar(s: _) {}
|
||||||
|
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
14
tests/ui/suggestions/bad-infer-in-trait-impl.stderr
Normal file
14
tests/ui/suggestions/bad-infer-in-trait-impl.stderr
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
|
||||||
|
--> $DIR/bad-infer-in-trait-impl.rs:6:15
|
||||||
|
|
|
||||||
|
LL | fn bar(s: _) {}
|
||||||
|
| ^ not allowed in type signatures
|
||||||
|
|
|
||||||
|
help: use type parameters instead
|
||||||
|
|
|
||||||
|
LL | fn bar<T>(s: T) {}
|
||||||
|
| +++ ~
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0121`.
|
Loading…
Add table
Add a link
Reference in a new issue