Fixed ICE when using a function with anonymous type parameters as a const generic argument#158329
Fixed ICE when using a function with anonymous type parameters as a const generic argument#158329kytoaa wants to merge 1 commit into
Conversation
|
HIR ty lowering was modified cc @fmease |
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @nnethercote (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
| if let Some(param_id) = inferred_synth_arg { | ||
| let fn_name = path.segments.last().unwrap().ident; | ||
| let anon_param = tcx.def_path_str(param_id); | ||
| let fn_span = tcx.hir_span_if_local(did); | ||
|
|
||
| let e = tcx | ||
| .dcx() | ||
| .create_err(ConstParamCannotInferAnonTypeParam { | ||
| span, | ||
| fn_name, | ||
| anon_param, | ||
| fn_span, | ||
| }) | ||
| .emit(); | ||
|
|
||
| ty::Const::new_error(tcx, e) |
There was a problem hiding this comment.
This is a hyper specific band-aid solution to a lowering step that's simply incorrect (introduced in #155096) and only happens to work for delegation because of the way it gets lowered.
This function should not need to know which APITs were inferred uprooted.
Copy/pasting https://github.com/rust-lang/rust/pull/155096/changes#r3462851183:
+ } else if synthetic { + Ty::new_param(tcx, param.index, param.name).into()This is not correct. It's injecting type parameters into a whole different context, it's uprooting a parameter from the def site and planting it at the use site (semi related: things like
EarlyBindersolely exist to force people to think about this context change..).I guess it only happens to work for delegation specifically because the generated delegate either reuses or has a copy of the generic parameters of the delegated function.
It's basically doing this:
fn f() { g(); // ==> g::<T>(); // but `T` is not in scope! } fn g<T>() {}
|
Reminder, once the PR becomes ready for a review, use |
Detects anonymous type parameters in functions being used as const generic arguments, and returns the
DefIdof the parameter for emitting an error.I don't love the solution of adding an
Option<DefId>to the tuple returned bylower_generic_args_of_path, and it might be nicer to wrap it in some kind of larger result type with theGenericArgCountResult, but changes like that would probably be more suitable for a larger refactor that takes into account delegation's requirements forlower_generic_args_of_path.Fixes #158152
Added a test with a more minimal example