rust/compiler/rustc_mir_transform/src
bors ed49386d3a Auto merge of #136539 - matthewjasper:late-normalize-errors, r=compiler-errors
Emit dropck normalization errors in borrowck

Borrowck generally assumes that any queries it runs for type checking will succeed, thinking that HIR typeck will have errored first if there was a problem. However as of #98641, dropck isn't run on HIR, so there's no direct guarantee that it doesn't error. While a type being well-formed might be expected to ensure that its fields are well-formed, this is not the case for types containing a type projection:

```rust
pub trait AuthUser {
    type Id;
}

pub trait AuthnBackend {
    type User: AuthUser;
}

pub struct AuthSession<Backend: AuthnBackend> {
    data: Option<<<Backend as AuthnBackend>::User as AuthUser>::Id>,
}

pub trait Authz: Sized {
    type AuthnBackend: AuthnBackend<User = Self>;
}

pub fn run_query<User: Authz>(auth: AuthSession<User::AuthnBackend>) {}
// ^ No User: AuthUser bound is required or inferred.
```

While improvements to trait solving might fix this in the future, for now we go for a pragmatic solution of emitting an error from borrowck (by rerunning dropck outside of a query) and making drop elaboration check if an error has been emitted previously before panicking for a failed normalization.

Closes #103899
Closes #135039

r? `@compiler-errors` (feel free to re-assign)
2025-02-19 07:49:08 +00:00
..
coroutine Rustfmt 2025-02-08 22:12:13 +00:00
coverage Overhaul the intravisit::Map trait. 2025-02-17 13:21:35 +11:00
inline use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00
shim Rustfmt 2025-02-08 22:12:13 +00:00
abort_unwinding_calls.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
add_call_guards.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
add_moves_for_packed_drops.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
add_retag.rs Rustfmt 2025-02-08 22:12:13 +00:00
add_subtyping_projections.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
check_alignment.rs Detect (non-raw) borrows of null ZST pointers in CheckNull 2025-02-08 21:38:16 +00:00
check_call_recursion.rs Rustfmt 2025-02-08 22:12:13 +00:00
check_const_item_mutation.rs Move find_self_call. 2025-01-31 16:04:13 +11:00
check_inline.rs Move methods from Map to TyCtxt, part 2. 2025-02-18 10:17:44 +11:00
check_null.rs Detect (non-raw) borrows of null ZST pointers in CheckNull 2025-02-08 21:38:16 +00:00
check_packed_ref.rs use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00
check_pointers.rs Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptr 2025-02-10 12:49:18 +00:00
check_undefined_transmutes.rs Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptr 2025-02-10 12:49:18 +00:00
cleanup_post_borrowck.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
copy_prop.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
coroutine.rs Inline and remove BasicBlockData::retain_statements. 2025-02-18 13:31:08 +11:00
cost_checker.rs use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00
cross_crate_inline.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
ctfe_limit.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
dataflow_const_prop.rs Implement MIR, CTFE, and codegen for unsafe binders 2025-01-31 17:19:53 +00:00
dead_store_elimination.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
deduce_param_attrs.rs rename BitSet to DenseBitSet 2025-01-11 11:34:01 +00:00
deref_separator.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
dest_prop.rs Implement MIR, CTFE, and codegen for unsafe binders 2025-01-31 17:19:53 +00:00
dump_mir.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
early_otherwise_branch.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
elaborate_box_derefs.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
elaborate_drop.rs Auto merge of #136539 - matthewjasper:late-normalize-errors, r=compiler-errors 2025-02-19 07:49:08 +00:00
elaborate_drops.rs Improve MirPatch documentation and naming. 2025-02-18 13:12:50 +11:00
errors.rs Remove redundant to_ident_string calls 2025-01-27 01:23:34 +00:00
ffi_unwind_calls.rs Move methods from Map to TyCtxt, part 2. 2025-02-18 10:17:44 +11:00
function_item_references.rs compiler: replace ExternAbi::name calls with formatters 2025-02-11 19:42:47 -08:00
gvn.rs Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptr 2025-02-10 12:49:18 +00:00
impossible_predicates.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
inline.rs Move methods from Map to TyCtxt, part 2. 2025-02-18 10:17:44 +11:00
instsimplify.rs Move methods from Map to TyCtxt, part 2. 2025-02-18 10:17:44 +11:00
jump_threading.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
known_panics_lint.rs Rustfmt 2025-02-08 22:12:13 +00:00
large_enums.rs Use MirPatch in EnumSizeOpt. 2025-02-18 12:52:56 +11:00
lib.rs Move methods from Map to TyCtxt, part 2. 2025-02-18 10:17:44 +11:00
lint.rs rename BitSet to DenseBitSet 2025-01-11 11:34:01 +00:00
lint_tail_expr_drop_order.rs remove more redundant into() conversions 2025-01-10 07:08:28 +01:00
lower_intrinsics.rs Contracts core intrinsics. 2025-02-03 12:53:57 -08:00
lower_slice_len.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
match_branches.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
mentioned_items.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
multiple_return_terminators.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
nrvo.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
pass_manager.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
patch.rs Improve MirPatch documentation and naming. 2025-02-18 13:12:50 +11:00
post_analysis_normalize.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
post_drop_elaboration.rs Make check_live_drops into a MirLint. 2024-09-10 09:11:17 +10:00
prettify.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
promote_consts.rs Rustfmt 2025-02-08 22:12:13 +00:00
ref_prop.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
remove_noop_landing_pads.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
remove_place_mention.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
remove_storage_markers.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
remove_uninit_drops.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
remove_unneeded_drops.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
remove_zsts.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
required_consts.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
sanity_check.rs Move MirPass to rustc_mir_transform. 2024-09-03 16:03:46 +10:00
shim.rs Don't project into NonNull when dropping a Box 2025-02-15 23:20:52 -08:00
simplify.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
simplify_branches.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
simplify_comparison_integral.rs Rustfmt 2025-02-08 22:12:13 +00:00
single_use_consts.rs Inline and replace Statement::replace_nop. 2025-02-18 13:43:43 +11:00
sroa.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
ssa.rs Rustfmt 2025-02-08 22:12:13 +00:00
strip_debuginfo.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
unreachable_enum_branching.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
unreachable_prop.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
validate.rs MIR validation: add comment explaining the limitations of CfgChecker 2025-02-06 11:36:58 +01:00