diff options
| author | Boxy <rust@boxyuwu.dev> | 2024-11-12 21:35:38 +0000 |
|---|---|---|
| committer | Boxy <rust@boxyuwu.dev> | 2024-11-12 21:36:42 +0000 |
| commit | 6dad0749075b77b08788f530dca5a3af0a26b6d7 (patch) | |
| tree | 84aff3a3336dfccacbfab727f0fe976a24394b28 /compiler/rustc_trait_selection/src/traits/mod.rs | |
| parent | 6503543d11583d1686d4989847b2afbec8d9fdba (diff) | |
| download | rust-6dad0749075b77b08788f530dca5a3af0a26b6d7.tar.gz rust-6dad0749075b77b08788f530dca5a3af0a26b6d7.zip | |
Handle infer vars in anon consts on stable
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits/mod.rs')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/mod.rs | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 17636d432ae..fe90066b4e7 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -578,16 +578,28 @@ pub fn try_evaluate_const<'tcx>( (args, param_env) } } - } else { - // FIXME: We don't check anything on stable as the only way we can wind up with - // an unevaluated constant containing generic parameters is through array repeat - // expression counts which have a future compat lint for usage of generic parameters - // instead of a hard error. + } else if tcx.def_kind(uv.def) == DefKind::AnonConst && uv.has_non_region_infer() { + // FIXME: remove this when `const_evaluatable_unchecked` is a hard error. + // + // Diagnostics will sometimes replace the identity args of anon consts in + // array repeat expr counts with inference variables so we have to handle this + // even though it is not something we should ever actually encounter. // - // This codepath is however also reachable by `generic_const_exprs` and some other - // feature gates which allow constants in the type system to use generic parameters. - // In theory we should be checking for generic parameters here and returning an error - // in such cases. + // Array repeat expr counts are allowed to syntactically use generic parameters + // but must not actually depend on them in order to evalaute succesfully. This means + // that it is actually fine to evalaute them in their own environment rather than with + // the actually provided generic arguments. + tcx.dcx().delayed_bug( + "Encountered anon const with inference variable args but no error reported", + ); + + let args = GenericArgs::identity_for_item(tcx, uv.def); + let param_env = tcx.param_env(uv.def); + (args, param_env) + } else { + // FIXME: This codepath is reachable under `associated_const_equality` and in the + // future will be reachable by `min_generic_const_args`. We should handle inference + // variables and generic parameters properly instead of doing nothing. (uv.args, param_env) }; let uv = ty::UnevaluatedConst::new(uv.def, args); |
