Skip to content
/ rust Public
forked from rust-lang/rust

Commit 0805fc2

Browse files
committed
Use infer tys for synthetic params when lowering const paths point to fns
1 parent 43a4909 commit 0805fc2

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,27 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
27692769
did,
27702770
path.segments.last().unwrap(),
27712771
);
2772-
ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, args))
2772+
2773+
if self.tcx().generics_of(did).own_synthetic_params_count() == 0 {
2774+
ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, args))
2775+
} else {
2776+
let tcx = self.tcx();
2777+
let generics = tcx.generics_of(did);
2778+
2779+
// Use infer tys for synthetic params; otherwise the impl header's trait ref may
2780+
// contain callee-owned synthetic params and fail when instantiated with impl args.
2781+
// See issue #155834
2782+
let args = args.iter().enumerate().map(|(index, arg)| {
2783+
let param = generics.param_at(index, tcx);
2784+
if param.kind.is_synthetic() {
2785+
self.ty_infer(Some(param), span).into()
2786+
} else {
2787+
arg
2788+
}
2789+
});
2790+
2791+
ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, args))
2792+
}
27732793
}
27742794

27752795
// Exhaustive match to be clear about what exactly we're considering to be
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Regression test for issue #155834
2+
3+
#![expect(incomplete_features)]
4+
#![feature(min_generic_const_args)]
5+
6+
trait Trait {}
7+
8+
impl<'t> Trait for [(); N] {}
9+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for implementations
10+
11+
fn N(arg: impl Trait) {}
12+
13+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations
2+
--> $DIR/bad-impl-trait-with-apit.rs:8:25
3+
|
4+
LL | impl<'t> Trait for [(); N] {}
5+
| ^ not allowed in type signatures
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)