Skip to content

Commit c2383b5

Browse files
committed
Don't propagate synthetic params, remove lifetime hacks
1 parent 8a70352 commit c2383b5

5 files changed

Lines changed: 66 additions & 23 deletions

File tree

compiler/rustc_ast_lowering/src/delegation/generics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
337337
// HACK: for now we generate predicates such that all lifetimes are early bound,
338338
// we can not not generate early-bound lifetimes, but we can't know which of them
339339
// are late-bound at this level of compilation.
340-
// FIXME(fn_delegation): proper support for late bound lifetimes.
341340
let predicates =
342341
self.arena.alloc_from_iter(params.iter().filter_map(|p| {
343342
p.is_lifetime().then(|| self.generate_lifetime_predicate(p, span))
@@ -391,7 +390,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
391390
self.arena.alloc(hir::GenericArgs {
392391
args: self.arena.alloc_from_iter(params.iter().filter_map(|p| {
393392
// Skip self generic arg, we do not need to propagate it.
394-
if p.name.ident().name == kw::SelfUpper {
393+
if p.name.ident().name == kw::SelfUpper || p.is_impl_trait() {
395394
return None;
396395
}
397396

compiler/rustc_hir_analysis/src/delegation.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ fn create_mapping<'tcx>(
138138
tcx: TyCtxt<'tcx>,
139139
sig_id: DefId,
140140
def_id: LocalDefId,
141-
args: &[ty::GenericArg<'tcx>],
142141
) -> FxHashMap<u32, u32> {
143142
let mut mapping: FxHashMap<u32, u32> = Default::default();
144143

@@ -176,13 +175,6 @@ fn create_mapping<'tcx>(
176175
}
177176
}
178177

179-
// If there are still unmapped lifetimes left and we are to map types and maybe self
180-
// then skip them, now it is the case when we generated more lifetimes then needed.
181-
// FIXME(fn_delegation): proper support for late bound lifetimes.
182-
while args_index < args.len() && args[args_index].as_region().is_some() {
183-
args_index += 1;
184-
}
185-
186178
// If self after lifetimes insert mapping, relying that self is at 0 in sig parent.
187179
if matches!(self_pos_kind, SelfPositionKind::AfterLifetimes) {
188180
mapping.insert(0, args_index as u32);
@@ -511,7 +503,7 @@ fn create_folder_and_args<'tcx>(
511503
child_args: &'tcx [ty::GenericArg<'tcx>],
512504
) -> (ParamIndexRemapper<'tcx>, Vec<ty::GenericArg<'tcx>>) {
513505
let args = create_generic_args(tcx, sig_id, def_id, parent_args, child_args);
514-
let remap_table = create_mapping(tcx, sig_id, def_id, &args);
506+
let remap_table = create_mapping(tcx, sig_id, def_id);
515507

516508
(ParamIndexRemapper { tcx, remap_table }, args)
517509
}

tests/ui/delegation/generics/mapping/free-to-free-pass.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,16 @@ mod test_6 {
7878
}
7979
}
8080

81-
// FIXME(fn_delegation): Uncomment this test when impl Traits in function params are supported
82-
83-
// mod test_7 {
84-
// fn foo<T, U>(t: T, u: U, f: impl FnOnce(T, U) -> U) -> U {
85-
// f(t, u)
86-
// }
81+
mod test_7 {
82+
fn foo<T, U>(t: T, u: U, f: impl FnOnce(T, U) -> U) -> U {
83+
f(t, u)
84+
}
8785

88-
// pub fn check() {
89-
// reuse foo as bar;
90-
// assert_eq!(bar::<i32, i32>(1, 2, |x, y| y), 2);
91-
// }
92-
// }
86+
pub fn check() {
87+
reuse foo as bar;
88+
assert_eq!(bar::<i32, i32>(1, 2, |_, y| y), 2);
89+
}
90+
}
9391

9492
// Testing reuse of local fn with delegation parent generic params specified,
9593
// late-bound lifetimes + types + consts, reusing with user args,
@@ -126,7 +124,7 @@ pub fn main() {
126124
test_4::check::<i32, String>();
127125
test_5::check::<i32, String>();
128126
test_6::check::<i32, String>();
129-
// test_7::check();
127+
test_7::check();
130128
test_8::check::<i32, String>();
131129
test_9::check::<String, i32>();
132130
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//@ compile-flags: -Z deduplicate-diagnostics=yes
2+
//@ edition:2024
3+
4+
#![feature(fn_delegation)]
5+
#![feature(iter_advance_by)]
6+
#![feature(iter_array_chunks)]
7+
#![feature(iterator_try_collect)]
8+
#![feature(iterator_try_reduce)]
9+
#![feature(iter_collect_into)]
10+
#![feature(iter_intersperse)]
11+
#![feature(iter_is_partitioned)]
12+
#![feature(iter_map_windows)]
13+
#![feature(iter_next_chunk)]
14+
#![feature(iter_order_by)]
15+
#![feature(iter_partition_in_place)]
16+
#![feature(trusted_random_access)]
17+
#![feature(try_find)]
18+
#![allow(incomplete_features)]
19+
20+
impl X {
21+
//~^ ERROR: cannot find type `X` in this scope
22+
reuse< std::fmt::Debug as Iterator >::*;
23+
//~^ ERROR: expected method or associated constant, found associated type `Iterator::Item`
24+
//~| ERROR: expected a type, found a trait
25+
}
26+
27+
pub fn main() {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0425]: cannot find type `X` in this scope
2+
--> $DIR/synth-params-ice-143498.rs:20:6
3+
|
4+
LL | impl X {
5+
| ^ not found in this scope
6+
7+
error[E0575]: expected method or associated constant, found associated type `Iterator::Item`
8+
--> $DIR/synth-params-ice-143498.rs:22:10
9+
|
10+
LL | reuse< std::fmt::Debug as Iterator >::*;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a method or associated constant
12+
13+
error[E0782]: expected a type, found a trait
14+
--> $DIR/synth-params-ice-143498.rs:22:12
15+
|
16+
LL | reuse< std::fmt::Debug as Iterator >::*;
17+
| ^^^^^^^^^^^^^^^
18+
|
19+
help: you can add the `dyn` keyword if you want a trait object
20+
|
21+
LL | reuse< dyn std::fmt::Debug as Iterator >::*;
22+
| +++
23+
24+
error: aborting due to 3 previous errors
25+
26+
Some errors have detailed explanations: E0425, E0575, E0782.
27+
For more information about an error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)