rust/compiler
Michael Goulet cf09718876
Rollup merge of #133367 - compiler-errors:array-len-mismatch, r=BoxyUwU
Simplify array length mismatch error reporting (to not try to turn consts into target usizes)

This changes `TypeError::FixedArrayLen` to use `ExpectedFound<ty::Const<'tcx>>` (instead of `ExpectedFound<u64>`), and renames it to `TypeError::ArrayLen`. This allows us to avoid a `try_to_target_usize` call in the type relation, which ICEs when we have a scalar of the wrong bit length (i.e. u8).

This also makes `structurally_relate_tys` to always use this type error kind any time we have a const mismatch resulting from relating the array-len part of `[T; N]`.

This has the effect of changing the error message we issue for array length mismatches involving non-valtree consts. I actually quite like the change, though, since before:

```
LL | fn test<const N: usize, const M: usize>() -> [u8; M] {
   |                                              ------- expected `[u8; M]` because of return type
LL |     [0; N]
   |     ^^^^^^ expected `M`, found `N`
   |
   = note: expected array `[u8; M]`
              found array `[u8; N]`
```

and after, which I think is far less verbose:

```
LL | fn test<const N: usize, const M: usize>() -> [u8; M] {
   |                                              ------- expected `[u8; M]` because of return type
LL |     [0; N]
   |     ^^^^^^ expected an array with a size of M, found one with a size of N
```

The only questions I have are:
1. Should we do something about backticks here? Right now we don't backtick either fully evaluated consts like `2`, or rigid consts like `Foo::BAR`.... but maybe we should? It seems kinda verbose to do for numbers -- maybe we could intercept those specifically.
2. I guess we may still run the risk of leaking unevaluated consts into error reporting like `2 + 1`...?

r? ``@BoxyUwU``

Fixes #126359
Fixes #131101
2024-11-26 12:03:44 -05:00
..
rustc Auto merge of #132282 - Noratrieb:it-is-the-end-of-serial, r=cjgillot 2024-11-12 15:14:56 +00:00
rustc_abi Auto merge of #130867 - michirakara:steps_between, r=dtolnay 2024-11-22 10:54:22 +00:00
rustc_arena move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
rustc_ast Rollup merge of #133140 - dtolnay:precedence, r=fmease 2024-11-26 12:03:41 -05:00
rustc_ast_ir Add sugar for &pin (const|mut) types 2024-10-07 11:15:04 -07:00
rustc_ast_lowering Auto merge of #132894 - frank-king:feature/where-refactor, r=cjgillot 2024-11-26 04:12:33 +00:00
rustc_ast_passes Refactor where predicates, and reserve for attributes support 2024-11-25 16:38:35 +08:00
rustc_ast_pretty Rollup merge of #133140 - dtolnay:precedence, r=fmease 2024-11-26 12:03:41 -05:00
rustc_attr ensure that all publicly reachable const fn have const stability info 2024-11-10 10:16:26 +01:00
rustc_baked_icu_data Delete the cfg(not(parallel)) serial compiler 2024-11-12 13:38:58 +00:00
rustc_borrowck Refactor where predicates, and reserve for attributes support 2024-11-25 16:38:35 +08:00
rustc_builtin_macros Auto merge of #132894 - frank-king:feature/where-refactor, r=cjgillot 2024-11-26 04:12:33 +00:00
rustc_codegen_cranelift Rollup merge of #131664 - taiki-e:s390x-asm-vreg-inout, r=Amanieu 2024-11-25 07:01:37 +01:00
rustc_codegen_gcc Make s390x non-clobber-only vector register support unstable 2024-11-24 21:42:22 +09:00
rustc_codegen_llvm Rollup merge of #131664 - taiki-e:s390x-asm-vreg-inout, r=Amanieu 2024-11-25 07:01:37 +01:00
rustc_codegen_ssa Rollup merge of #133384 - RalfJung:vector-abi-check-tests, r=jieyouxu 2024-11-25 00:39:06 +08:00
rustc_const_eval remove is_trivially_const_drop 2024-11-23 08:41:06 +01:00
rustc_data_structures Add UnordMap::clear method 2024-11-20 18:11:37 +01:00
rustc_driver
rustc_driver_impl Rollup merge of #130236 - yaahc:unstable-feature-usage, r=estebank 2024-11-21 11:58:36 +01:00
rustc_error_codes remove support for rustc_safe_intrinsic attribute; use rustc_intrinsic functions instead 2024-11-08 09:16:00 +01:00
rustc_error_messages Delete the cfg(not(parallel)) serial compiler 2024-11-12 13:38:58 +00:00
rustc_errors Auto merge of #132954 - matthiaskrgr:rollup-x3rww9h, r=matthiaskrgr 2024-11-12 18:04:27 +00:00
rustc_expand Implement the unsafe-fields RFC. 2024-11-21 19:32:07 +01:00
rustc_feature Rollup merge of #131664 - taiki-e:s390x-asm-vreg-inout, r=Amanieu 2024-11-25 07:01:37 +01:00
rustc_fluent_macro use tracked_path in rustc_fluent_macro 2024-10-19 22:32:38 +08:00
rustc_fs_util Couple of changes to make it easier to compile rustc for wasm 2024-09-26 19:51:14 +00:00
rustc_graphviz Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_hir Rollup merge of #133140 - dtolnay:precedence, r=fmease 2024-11-26 12:03:41 -05:00
rustc_hir_analysis Auto merge of #132894 - frank-king:feature/where-refactor, r=cjgillot 2024-11-26 04:12:33 +00:00
rustc_hir_pretty Rollup merge of #133140 - dtolnay:precedence, r=fmease 2024-11-26 12:03:41 -05:00
rustc_hir_typeck Rollup merge of #133140 - dtolnay:precedence, r=fmease 2024-11-26 12:03:41 -05:00
rustc_incremental replace manual time convertions with std ones 2024-11-03 15:51:39 +03:00
rustc_index reduce false positives of tail-expr-drop-order from consumed values 2024-11-20 20:53:11 +08:00
rustc_index_macros Auto merge of #130867 - michirakara:steps_between, r=dtolnay 2024-11-22 10:54:22 +00:00
rustc_infer Auto merge of #133242 - lcnr:questionable-uwu, r=compiler-errors,BoxyUwU 2024-11-23 18:01:21 +00:00
rustc_interface Rollup merge of #133023 - samestep:hir-stats-total-count, r=nnethercote 2024-11-19 09:19:20 +01:00
rustc_lexer Clean up c_or_byte_string. 2024-11-25 16:10:55 +11:00
rustc_lint Refactor where predicates, and reserve for attributes support 2024-11-25 16:38:35 +08:00
rustc_lint_defs show abi_unsupported_vector_types lint in future breakage reports 2024-11-23 09:15:25 +01:00
rustc_llvm Rollup merge of #127483 - BertalanD:no_sanitize-global-var, r=rcvalle 2024-11-23 20:19:51 +08:00
rustc_log Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_macros give a better error for tuple structs in derive(Diagnostic) 2024-10-27 21:23:28 -04:00
rustc_metadata Rollup merge of #133300 - Enselic:build-std-instrument-coverage, r=jieyouxu 2024-11-24 11:08:18 +01:00
rustc_middle Rollup merge of #133367 - compiler-errors:array-len-mismatch, r=BoxyUwU 2024-11-26 12:03:44 -05:00
rustc_mir_build Auto merge of #131859 - chriskrycho:update-trpl, r=onur-ozkan 2024-11-23 23:26:19 +00:00
rustc_mir_dataflow Rollup merge of #133326 - nnethercote:rm-DefinitelyInitializedPlaces, r=cjgillot 2024-11-26 12:03:42 -05:00
rustc_mir_transform Make it possible for ResultsCursor to borrow a Results. 2024-11-26 11:23:40 +11:00
rustc_monomorphize remove remaining references to Reveal 2024-11-23 13:52:56 +01:00
rustc_next_trait_solver remove remaining references to Reveal 2024-11-23 13:52:56 +01:00
rustc_parse Rollup merge of #133140 - dtolnay:precedence, r=fmease 2024-11-26 12:03:41 -05:00
rustc_parse_format Remove 'apostrophes' from rustc_parse_format 2024-10-14 23:22:51 +02:00
rustc_passes Refactor where predicates, and reserve for attributes support 2024-11-25 16:38:35 +08:00
rustc_pattern_analysis no more Reveal :( 2024-11-23 13:52:54 +01:00
rustc_privacy Simplify some places that deal with generic parameter defaults 2024-11-11 21:29:18 +01:00
rustc_query_impl Delete the cfg(not(parallel)) serial compiler 2024-11-12 13:38:58 +00:00
rustc_query_system Auto merge of #124780 - Mark-Simulacrum:lockless-cache, r=lcnr 2024-11-19 02:07:48 +00:00
rustc_resolve Refactor where predicates, and reserve for attributes support 2024-11-25 16:38:35 +08:00
rustc_sanitizers use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00
rustc_serialize Fix explicit_iter_loop in rustc_serialize 2024-10-16 15:44:16 +02:00
rustc_session Rollup merge of #133159 - Zalathar:unstable-options-no-value, r=jieyouxu 2024-11-22 21:07:40 -05:00
rustc_smir reduce false positives of tail-expr-drop-order from consumed values 2024-11-20 20:53:11 +08:00
rustc_span Rollup merge of #133326 - nnethercote:rm-DefinitelyInitializedPlaces, r=cjgillot 2024-11-26 12:03:42 -05:00
rustc_symbol_mangling additional TypingEnv cleanups 2024-11-19 21:36:23 +01:00
rustc_target Rollup merge of #131664 - taiki-e:s390x-asm-vreg-inout, r=Amanieu 2024-11-25 07:01:37 +01:00
rustc_trait_selection Rollup merge of #133367 - compiler-errors:array-len-mismatch, r=BoxyUwU 2024-11-26 12:03:44 -05:00
rustc_traits use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00
rustc_transmute use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00
rustc_ty_utils rebase 2024-11-23 13:52:57 +01:00
rustc_type_ir Simplify array length mismatch error reporting 2024-11-24 03:32:11 +00:00
rustc_type_ir_macros do not relate Abi and Safety 2024-10-22 23:13:04 +02:00
stable_mir Rollup merge of #132161 - celinval:smir-fix-indent, r=compiler-errors 2024-11-08 18:51:28 +11:00