os-rust/compiler
bors 32a3ed229c Auto merge of #125671 - BoxyUwU:remove_const_ty_eq, r=compiler-errors
Do not equate `Const`'s ty in `super_combine_const`

Fixes #114456

In #125451 we started relating the `Const`'s tys outside of a probe so it was no longer simply an assertion to catch bugs.

This was done so that when we _do_ provide a wrongly typed const argument to an item if we wind up relating it with some other instantiation we'll have a `TypeError` we can bubble up and taint the resulting mir allowing const eval to skip evaluation.

In this PR I instead change `ConstArgHasType` to correctly handle checking the types of const inference variables. Previously if we had something like `impl<const N: u32> Trait for [(); N]`, when using the impl we would instantiate it with infer vars and then check that `?x: u32` is of type `u32` and succeed. Then later we would infer `?x` to some `Const` of type `usize`.

We now stall on `?x` in `ConstArgHasType` until it has a concrete value that we can determine the type of. This allows us to fail using the erroneous implementation of `Trait` which allows us to taint the mir.

Long term we intend to remove the `ty` field on `Const` so we would have no way of accessing the `ty` of a const inference variable anyway and would have to do this. I did not fully update `ConstArgHasType` to avoid using the `ty` field as it's not entirely possible right now- we would need to lookup `ConstArgHasType` candidates in the env.

---

As for _why_ I think we should do this, relating the types of const's is not necessary for soundness of the type system. Originally this check started off as a plain `==` in `super_relate_consts` and gradually has been growing in complexity as we support more complicated types. It was never actually required to ensure that const arguments are correctly typed for their parameters however.

The way we currently check that a const argument has the correct type is a little convoluted and confusing (and will hopefully be less weird as time goes on). Every const argument has an anon const with its return type set to type of the const parameter it is an argument to. When type checking the anon const regular type checking rules require that the expression is the same type as the return type. This effectively ensure that no matter what every const argument _always_ has the correct type.

An extra bit of complexity is that during `hir_ty_lowering` we do not represent everything as a `ConstKind::Unevaluated` corresponding to the anon const. For generic parameters i.e. `[(); N]` we simply represent them as `ConstKind::Param` as we do not want `ConstKind::Unevaluated` with generic substs on stable under min const generics. The anon const still gets type checked resulting in errors about type mismatches.

Eventually we intend to not create anon consts for all const arguments (for example for `ConstKind::Param`) and instead check that the argument type is correct via `ConstArgHasType` obligations (these effectively also act as a check that the anon consts have the correctly set return type).

What this all means is that the the only time we should ever have mismatched types when relating two `Const`s is if we have messed up our logic for ensuring that const arguments are of the correct type. Having this not be an assert is:
- Confusing as it may incorrectly lead people to believe this is an important check that is actually required
- Opens the possibility for bugs or behaviour reliant on this (unnecessary) check existing

---

This PR makes two tests go from pass->ICE (`generic_const_exprs/ice-125520-layout-mismatch-mulwithoverflow.rs` and `tests/crashes/121858.rs`). This is caused by the fact that we evaluate anon consts even if their where clauses do not hold and is a pre-existing issue and only affects `generic_const_exprs`. I am comfortable exposing the brokenness of `generic_const_exprs` more with this PR

This PR makes a test go from ICE->pass (`const-generics/issues/issue-105821.rs`). I have no idea why this PR affects that but I believe that ICE is an unrelated issue to do with the fact that under `generic_const_exprs`/`adt_const_params` we do not handle lifetimes in const parameter types correctly. This PR is likely just masking this bug.

Note: this PR doesn't re-introduce the assertion that the two consts' tys are equal. I'm not really sure how I feel about this but tbh it has caused more ICEs than its found lately so 🤷‍♀️

r? `@oli-obk` `@compiler-errors`
2024-05-30 05:50:44 +00:00
..
rustc Change SIGPIPE ui from #[unix_sigpipe = "..."] to -Zon-broken-pipe=... 2024-05-02 19:48:29 +02:00
rustc_abi don't inhibit random field reordering on repr(packed(1)) 2024-05-21 19:22:04 +02:00
rustc_arena rename ptr::invalid -> ptr::without_provenance 2024-02-21 20:15:52 +01:00
rustc_ast ast: Revert a breaking attribute visiting order change 2024-05-29 21:55:24 +03:00
rustc_ast_ir Remove extern crate rustc_macros from numerous crates. 2024-04-29 10:21:54 +10:00
rustc_ast_lowering Cache whether a body has inline consts 2024-05-28 13:38:43 +00:00
rustc_ast_passes Rollup merge of #124048 - veera-sivarajan:bugfix-123773-c23-variadics, r=compiler-errors 2024-05-26 15:28:26 -07:00
rustc_ast_pretty Create const block DefIds in typeck instead of ast lowering 2024-05-28 13:38:43 +00:00
rustc_attr Rename buffer_lint_with_diagnostic to buffer_lint 2024-05-21 20:16:39 +00:00
rustc_baked_icu_data Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_borrowck Remove DefId from EarlyParamRegion (tedium/diagnostics) 2024-05-24 18:06:53 +01:00
rustc_builtin_macros Rollup merge of #125316 - nnethercote:tweak-Spacing, r=petrochenkov 2024-05-23 07:41:18 +02:00
rustc_codegen_cranelift Rollup merge of #124251 - scottmcm:unop-ptr-metadata, r=oli-obk 2024-05-29 03:25:07 +01:00
rustc_codegen_gcc Rollup merge of #125345 - durin42:thin-link-bitcode, r=bjorn3 2024-05-23 23:39:26 +02:00
rustc_codegen_llvm Rollup merge of #124655 - Darksonn:fixed-x18, r=lqd,estebank 2024-05-29 20:12:32 +02:00
rustc_codegen_ssa Rollup merge of #124251 - scottmcm:unop-ptr-metadata, r=oli-obk 2024-05-29 03:25:07 +01:00
rustc_const_eval Rollup merge of #125633 - RalfJung:miri-no-copy, r=saethlin 2024-05-29 03:25:09 +01:00
rustc_data_structures Rollup merge of #124818 - compiler-errors:ena, r=Mark-Simulacrum 2024-05-11 08:00:15 +02:00
rustc_driver Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_driver_impl Rollup merge of #124320 - Urgau:print-check-cfg, r=petrochenkov 2024-05-29 03:25:07 +01:00
rustc_error_codes Remove a stray backtick in an error explanation. 2024-05-13 07:53:38 +10:00
rustc_error_messages Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercote 2024-05-27 08:44:12 +00:00
rustc_errors Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercote 2024-05-27 08:44:12 +00:00
rustc_expand Rollup merge of #125530 - SparrowLii:expand2, r=petrochenkov 2024-05-27 13:10:35 +02:00
rustc_feature Auto merge of #125326 - weiznich:move/do_not_recommend_to_diganostic_namespace, r=compiler-errors 2024-05-22 04:14:08 +00:00
rustc_fluent_macro Rename SubdiagnosticMessage as SubdiagMessage. 2024-03-05 12:14:49 +11:00
rustc_fs_util Stabilize std::path::absolute 2024-04-24 14:35:02 +00:00
rustc_graphviz Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_hir Add lang item for AsyncFnKindHelper::Upvars 2024-05-29 14:28:53 -04:00
rustc_hir_analysis Add lang item for Future::Output 2024-05-29 14:22:56 -04:00
rustc_hir_pretty Create const block DefIds in typeck instead of ast lowering 2024-05-28 13:38:43 +00:00
rustc_hir_typeck Rollup merge of #125664 - compiler-errors:trace-tweaks, r=lcnr 2024-05-29 03:25:11 +01:00
rustc_incremental Run rustfmt on files that need it. 2024-05-24 15:17:21 +10:00
rustc_index Simplify static_assert_sizes. 2024-04-18 15:36:25 +10:00
rustc_index_macros rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
rustc_infer Auto merge of #125671 - BoxyUwU:remove_const_ty_eq, r=compiler-errors 2024-05-30 05:50:44 +00:00
rustc_interface Rollup merge of #124655 - Darksonn:fixed-x18, r=lqd,estebank 2024-05-29 20:12:32 +02:00
rustc_lexer Improved the compiler code with clippy 2024-04-24 09:41:44 +02:00
rustc_lint Change lint_dropping_copy_types to use UseLetUnderscoreIgnoreSuggestion as suggestion. 2024-05-29 18:09:20 +08:00
rustc_lint_defs Rollup merge of #125522 - spastorino:fix-lint-docs-edition-handling, r=Urgau,michaelwoerister 2024-05-27 13:10:34 +02:00
rustc_llvm thinlto: only build summary file if needed 2024-05-23 14:58:30 -04:00
rustc_log Use Backtrace::force_capture instead of Backtrace::capture in rustc_log 2024-05-21 10:54:36 +02:00
rustc_macros Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercote 2024-05-27 08:44:12 +00:00
rustc_metadata Give EarlyBinder a tcx parameter 2024-05-26 20:04:05 -04:00
rustc_middle Rollup merge of #125633 - RalfJung:miri-no-copy, r=saethlin 2024-05-29 03:25:09 +01:00
rustc_mir_build Rollup merge of #125700 - Zalathar:limit-overflow, r=nnethercote 2024-05-29 20:12:33 +02:00
rustc_mir_dataflow Remove #[macro_use] extern crate tracing from rustc_mir_dataflow. 2024-05-23 18:02:40 +10:00
rustc_mir_transform Rollup merge of #124251 - scottmcm:unop-ptr-metadata, r=oli-obk 2024-05-29 03:25:07 +01:00
rustc_monomorphize Don't eagerly monomorphize drop for types that are impossible to instantiate 2024-05-24 21:53:39 -04:00
rustc_next_trait_solver Uplift binder 2024-05-21 17:00:45 -04:00
rustc_parse Create const block DefIds in typeck instead of ast lowering 2024-05-28 13:38:43 +00:00
rustc_parse_format Simplify static_assert_sizes. 2024-04-18 15:36:25 +10:00
rustc_passes Create const block DefIds in typeck instead of ast lowering 2024-05-28 13:38:43 +00:00
rustc_pattern_analysis Remove LintDiagnostic::msg 2024-05-23 04:08:35 +02:00
rustc_privacy split out AliasTy -> AliasTerm 2024-05-13 11:59:42 -04:00
rustc_query_impl Remove extern crate rustc_middle from rustc_query_impl. 2024-05-13 08:20:18 +10:00
rustc_query_system Add a footer in FileEncoder and check for it in MemDecoder 2024-05-21 20:12:29 -04:00
rustc_resolve Rollup merge of #125705 - oli-obk:const_block_ice, r=compiler-errors 2024-05-29 20:12:34 +02:00
rustc_sanitizers Fix typos (taking into account review comments) 2024-05-18 18:12:18 +02:00
rustc_serialize PR feedback 2024-05-21 20:12:30 -04:00
rustc_session Rollup merge of #124655 - Darksonn:fixed-x18, r=lqd,estebank 2024-05-29 20:12:32 +02:00
rustc_smir Add an intrinsic for ptr::metadata 2024-05-28 09:28:51 -07:00
rustc_span Add lang item for AsyncFnKindHelper::Upvars 2024-05-29 14:28:53 -04:00
rustc_symbol_mangling Rename Unsafe to Safety 2024-05-17 18:33:37 -03:00
rustc_target Rollup merge of #117671 - kjetilkjeka:nvptx_c_abi_avoid_direct, r=davidtwco 2024-05-28 18:04:31 +02:00
rustc_trait_selection Auto merge of #125671 - BoxyUwU:remove_const_ty_eq, r=compiler-errors 2024-05-30 05:50:44 +00:00
rustc_traits split out AliasTy -> AliasTerm 2024-05-13 11:59:42 -04:00
rustc_transmute Align: add bytes_usize and bits_usize 2024-05-01 15:57:33 +02:00
rustc_ty_utils Auto merge of #125695 - RalfJung:fn_arg_sanity_check, r=jieyouxu 2024-05-29 09:49:23 +00:00
rustc_type_ir Make ProofTreeBuilder actually generic over interner 2024-05-28 11:10:11 -04:00
rustc_type_ir_macros Uplift TraitPredicate 2024-05-11 18:20:00 -04:00
stable_mir Add an intrinsic for ptr::metadata 2024-05-28 09:28:51 -07:00