1
Fork 0
rust/compiler
Matthias Krüger 4cadb5d513
Rollup merge of #135464 - lukas-code:project-infinite-to-error, r=FedericoBruzzone,oli-obk
fix ICE with references to infinite structs in consts

fixes https://github.com/rust-lang/rust/issues/114484

Normalizing `<Type as Pointee>::Metadata` may emit a (non-fatal) error during trait selection if finding the struct tail of `Type` hits the recursion limit. When this happens, prior this PR, we would treat the projection as rigid, i.e. don't normalize it further. This PR changes it so that we normalize to `ty::Error` instead.

This is important, because to compute the layout of `&Type` we need to compute the layout of `<Type as Pointee>::Metadata`

2ae9916816/compiler/rustc_ty_utils/src/layout.rs (L247-L273)

and computing the layout of a rigid alias will (correctly) fail and needs to report an error to the user. For example:

```rust
trait Project {
    type Assoc;
}

fn foo<T: Project>() {
    [(); {
        let _: Option<T::Assoc> = None;
                   // ^^^^^^^^ this projection is rigid, so we can't know it's layout
        0
    }];
}
```

```
error: constant expression depends on a generic parameter
  --> src/lib.rs:6:10
   |
6  |       [(); {
   |  __________^
7  | |         let _: Option<T::Assoc> = None;
8  | |                    // ^^^^^^^^ this projection is rigid, so we can't know it's layout
9  | |         0
10 | |     }];
   | |_____^
   |
   = note: this may fail depending on what value the parameter takes
```

For non-generic rigid projections we will currently ICE, because we incorrectly assume that `LayoutError::Unknown` means that a const must be generic (https://github.com/rust-lang/rust/issues/135138). This is being fixed and turned into a proper error in https://github.com/rust-lang/rust/pull/135158.

```rust
#![feature(trivial_bounds)]

trait Project {
    type Assoc;
}

fn foo()
where
    u8: Project,
{
    [(); {
        let _: Option<<u8 as Project>::Assoc> = None; // ICEs currently, but will be an error
        0
    }];
}
```

However, if we hit the recursion limit when normalizing `<Type as Pointee>::Metadata` we don't want to report a layout error, because we already emitted the recursion error. So by normalizing to `ty::Error` here, we get a `LayoutError::ReferencesError` instead of a `LayoutError::Unknown` and don't report the layout error to the user.
2025-01-14 07:56:24 +01:00
..
rustc switch jemalloc-sys back to tikv-jemalloc-sys, and update to 0.6.0 2024-12-03 08:56:33 +00:00
rustc_abi fix ZST handling for Windows ABIs on MSVC target 2025-01-10 12:16:49 +01:00
rustc_arena Add inherent versions of MaybeUninit methods for slices 2025-01-11 23:57:00 -05:00
rustc_ast Remove allocations from case-insensitive comparison to keywords 2025-01-11 12:39:44 -05:00
rustc_ast_ir
rustc_ast_lowering Rename PatKind::Lit to Expr 2025-01-08 07:34:59 +00:00
rustc_ast_passes update cfg(bootstrap) 2025-01-08 21:26:39 +01:00
rustc_ast_pretty Rename PatKind::Lit to Expr 2025-01-08 07:34:59 +00:00
rustc_attr_data_structures mir_transform: implement forced inlining 2025-01-10 18:37:54 +00:00
rustc_attr_parsing Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_baked_icu_data Delete the cfg(not(parallel)) serial compiler 2024-11-12 13:38:58 +00:00
rustc_borrowck Auto merge of #135465 - jhpratt:rollup-7p93bct, r=jhpratt 2025-01-14 03:08:59 +00:00
rustc_builtin_macros Rollup merge of #134877 - DavisRayM:129966-format-string-help-message, r=estebank 2025-01-01 16:35:30 +11:00
rustc_codegen_cranelift Merge commit 'e39eacd2d4' into sync_cg_clif-2025-01-10 2025-01-10 09:02:07 +00:00
rustc_codegen_gcc migrate rustc_codegen_gcc to the DenseBitSet name 2025-01-11 11:34:03 +00:00
rustc_codegen_llvm Rollup merge of #133752 - klensy:cp, r=davidtwco 2025-01-13 15:56:55 +01:00
rustc_codegen_ssa Fix emscripten-wasm-eh with unwind=abort 2025-01-13 23:34:06 +01:00
rustc_const_eval Assert that Instance::try_resolve is only used on body-like things 2025-01-13 02:20:08 +00:00
rustc_data_structures De-abstract tagged pointer abstraction 2025-01-12 14:56:10 +00:00
rustc_driver
rustc_driver_impl add deprecated and do nothing flag to options table 2025-01-06 15:38:02 +03:00
rustc_error_codes Rewrite the error-code docs for coverage attributes [E0788] 2024-12-25 19:23:48 +11:00
rustc_error_messages Convert some Into impls into From impls 2024-12-31 01:56:33 +00:00
rustc_errors Auto merge of #135402 - matthiaskrgr:rollup-cz7hs13, r=matthiaskrgr 2025-01-12 14:43:10 +00:00
rustc_expand Rollup merge of #135247 - tgross35:stdlib-sym-list, r=oli-obk 2025-01-09 09:05:09 +01:00
rustc_feature Rollup merge of #135245 - Enselic:no-set-env, r=davidtwco 2025-01-13 15:57:03 +01:00
rustc_fluent_macro
rustc_fs_util
rustc_graphviz
rustc_hir Auto merge of #135268 - pietroalbini:pa-bump-stage0, r=Mark-Simulacrum 2025-01-09 13:33:16 +00:00
rustc_hir_analysis rm unnecessary OpaqueTypeDecl wrapper 2025-01-13 14:33:18 +01:00
rustc_hir_pretty Rename PatKind::Lit to Expr 2025-01-08 07:34:59 +00:00
rustc_hir_typeck Rollup merge of #135440 - lcnr:yeeeeeeeeeeeeeeeeeeeeeeet, r=compiler-errors 2025-01-13 20:43:47 -05:00
rustc_incremental turn hir::ItemKind::Fn into a named-field variant 2025-01-04 11:35:31 +01:00
rustc_index document the use-cases of DenseBitSet a bit more 2025-01-11 11:34:03 +00:00
rustc_index_macros update rustc_index_macros feature handling 2024-12-19 20:32:12 +03:00
rustc_infer rm unnecessary OpaqueTypeDecl wrapper 2025-01-13 14:33:18 +01:00
rustc_interface Rollup merge of #134030 - folkertdev:min-fn-align, r=workingjubilee 2025-01-11 18:13:45 +01:00
rustc_lexer Add test to check unicode identifier version 2024-12-09 06:23:59 -08:00
rustc_lint Rollup merge of #135441 - compiler-errors:redundant-captures-lint, r=lqd 2025-01-13 20:43:48 -05:00
rustc_lint_defs remove test_unstable_lint feature 2025-01-13 00:14:24 +05:30
rustc_llvm llvm: Ignore error value that is always false 2025-01-07 01:02:22 +00:00
rustc_log Avoid naming variables str 2025-01-07 14:30:02 +02:00
rustc_macros Avoid naming variables str 2025-01-07 14:30:02 +02:00
rustc_metadata rename BitSet to DenseBitSet 2025-01-11 11:34:01 +00:00
rustc_middle Rollup merge of #135451 - mzacho:code-duplication, r=oli-obk 2025-01-14 07:56:24 +01:00
rustc_mir_build review comments 2025-01-11 01:23:37 +00:00
rustc_mir_dataflow rename BitSet to DenseBitSet 2025-01-11 11:34:01 +00:00
rustc_mir_transform Rollup merge of #135377 - compiler-errors:impossible-step, r=oli-obk 2025-01-12 12:07:58 +01:00
rustc_monomorphize Rollup merge of #135314 - compiler-errors:eagerly-mono-closures, r=wesleywiser 2025-01-11 18:13:47 +01:00
rustc_next_trait_solver Implement const Destruct in old solver 2025-01-08 18:14:58 +00:00
rustc_parse Remove allocations from case-insensitive comparison to keywords 2025-01-11 12:39:44 -05:00
rustc_parse_format add suggestion for wrongly ordered format parameters 2024-12-30 06:14:26 -08:00
rustc_passes On unused assign lint, detect mut arg: &Ty meant to be arg: &mut Ty 2025-01-11 01:34:23 +00:00
rustc_pattern_analysis rename BitSet to DenseBitSet 2025-01-11 11:34:01 +00:00
rustc_privacy turn hir::ItemKind::Fn into a named-field variant 2025-01-04 11:35:31 +01:00
rustc_query_impl don't return an Option from try_find_dep_kind 2025-01-07 21:57:00 +01:00
rustc_query_system remove code duplication when hashing query result and interning node 2025-01-13 20:25:46 +01:00
rustc_resolve Deny clippy:;four_forward_slashes and fix the only occurrence 2025-01-12 15:09:16 +02:00
rustc_sanitizers Eliminate an unnecessary Symbol::to_string; use as_str 2025-01-07 14:24:47 +02:00
rustc_serialize
rustc_session Rollup merge of #134030 - folkertdev:min-fn-align, r=workingjubilee 2025-01-11 18:13:45 +01:00
rustc_smir Auto merge of #134625 - compiler-errors:unsafe-binders-ty, r=oli-obk 2024-12-24 00:51:51 +00:00
rustc_span mir_transform: implement forced inlining 2025-01-10 18:37:54 +00:00
rustc_symbol_mangling Account for identity substituted items in symbol mangling 2025-01-09 13:55:40 +01:00
rustc_target on Windows, consistently pass ZST by-ref 2025-01-12 13:32:36 +01:00
rustc_trait_selection Rollup merge of #135464 - lukas-code:project-infinite-to-error, r=FedericoBruzzone,oli-obk 2025-01-14 07:56:24 +01:00
rustc_traits Delay a bug when encountering an impl with unconstrained generics in codegen_select 2024-11-23 05:27:45 +00:00
rustc_transmute add comment explaining why ty_and_layout_field is not used 2024-12-18 11:01:54 +01:00
rustc_ty_utils on Windows, consistently pass ZST by-ref 2025-01-12 13:32:36 +01:00
rustc_type_ir rename BitSet to DenseBitSet 2025-01-11 11:34:01 +00:00
rustc_type_ir_macros
stable_mir make no-variant types a dedicated Variants variant 2024-12-18 11:01:54 +01:00