diff options
| author | bors <bors@rust-lang.org> | 2025-08-25 22:56:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-08-25 22:56:37 +0000 |
| commit | d327d651e2583eb601978179f2ca9808f5e243bb (patch) | |
| tree | 227e23c440f2b35e073db48fc71278ce55ded2e7 /compiler/rustc_borrowck | |
| parent | 54c581243c977c7662c949b5795c31147f8a60ed (diff) | |
| parent | d6a18e18676f355e9f5350a9204f81c4dd2bc0f3 (diff) | |
| download | rust-d327d651e2583eb601978179f2ca9808f5e243bb.tar.gz rust-d327d651e2583eb601978179f2ca9808f5e243bb.zip | |
Auto merge of #145711 - lcnr:non-defining-uses-hir-typeck, r=BoxyUwU
Support non-defining uses in HIR typeck This changes the impl of `NormalizesTo` for opaque types to be structural during HIR typeck. The previous impl equated region variables of the opaque type key with existing entries which can result in spurious leak check errors and also results in mismatches with MIR borrowck, theoretically causing ICE. The approach is very similar to rust-lang/rust#145244 in MIR typeck: - we collect all uses of opaque types during HIR typeck - before writeback, we search for *defining uses* - the opaque type key has fully universal generic args modulo regions - the hidden type has no infer vars - we use these defining uses to compute the concrete type for the opaque and map it to the definition site - we use this concrete type to check the type of all uses of opaques during HIR typeck. This also constrains infer vars in non-defining uses Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/135, fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/49. r? `@BoxyUwU`
Diffstat (limited to 'compiler/rustc_borrowck')
| -rw-r--r-- | compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs index 33c4879af98..bee82e17835 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs @@ -17,7 +17,7 @@ use rustc_middle::ty::{ use rustc_mir_dataflow::points::DenseLocationMap; use rustc_span::Span; use rustc_trait_selection::opaque_types::{ - InvalidOpaqueTypeArgs, check_opaque_type_parameter_valid, + NonDefiningUseReason, opaque_type_has_defining_use_args, }; use rustc_trait_selection::solve::NoSolution; use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp; @@ -42,7 +42,7 @@ use region_ctxt::RegionCtxt; /// if there are no `RegionErrors`. If there are region errors, it's likely /// that errors here are caused by them and don't need to be handled separately. pub(crate) enum DeferredOpaqueTypeError<'tcx> { - InvalidOpaqueTypeArgs(InvalidOpaqueTypeArgs<'tcx>), + InvalidOpaqueTypeArgs(NonDefiningUseReason<'tcx>), LifetimeMismatchOpaqueParam(LifetimeMismatchOpaqueParam<'tcx>), UnexpectedHiddenRegion { /// The opaque type. @@ -238,7 +238,7 @@ fn collect_defining_uses<'tcx>( let non_nll_opaque_type_key = opaque_type_key.fold_captured_lifetime_args(infcx.tcx, |r| { nll_var_to_universal_region(&rcx, r.as_var()).unwrap_or(r) }); - if let Err(err) = check_opaque_type_parameter_valid( + if let Err(err) = opaque_type_has_defining_use_args( infcx, non_nll_opaque_type_key, hidden_type.span, @@ -248,11 +248,10 @@ fn collect_defining_uses<'tcx>( // with `TypingMode::Borrowck`. if infcx.tcx.use_typing_mode_borrowck() { match err { - InvalidOpaqueTypeArgs::AlreadyReported(guar) => root_cx - .add_concrete_opaque_type( - opaque_type_key.def_id, - OpaqueHiddenType::new_error(infcx.tcx, guar), - ), + NonDefiningUseReason::Tainted(guar) => root_cx.add_concrete_opaque_type( + opaque_type_key.def_id, + OpaqueHiddenType::new_error(infcx.tcx, guar), + ), _ => debug!(?non_nll_opaque_type_key, ?err, "ignoring non-defining use"), } } else { @@ -676,8 +675,8 @@ impl<'tcx> InferCtxt<'tcx> { &self, opaque_type_key: OpaqueTypeKey<'tcx>, instantiated_ty: OpaqueHiddenType<'tcx>, - ) -> Result<Ty<'tcx>, InvalidOpaqueTypeArgs<'tcx>> { - check_opaque_type_parameter_valid( + ) -> Result<Ty<'tcx>, NonDefiningUseReason<'tcx>> { + opaque_type_has_defining_use_args( self, opaque_type_key, instantiated_ty.span, |
