diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-07-25 16:48:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-25 16:48:21 +0200 |
| commit | 5a853d02f1b2f07d6600a5d193712e7d86274f35 (patch) | |
| tree | 127e279a399173548498f7a91e85db1fc1b05f14 /compiler | |
| parent | 606c9fcb4d0306341a8427ca2d0c93faea2f8f73 (diff) | |
| parent | 40d132f0f826b0f0ae203219ab30d23da8f55573 (diff) | |
| download | rust-5a853d02f1b2f07d6600a5d193712e7d86274f35.tar.gz rust-5a853d02f1b2f07d6600a5d193712e7d86274f35.zip | |
Rollup merge of #128171 - compiler-errors:arg-compat, r=oli-obk
Make sure that args are compatible in `resolve_associated_item` Implements a similar check to the one that we have in projection for GATs (#102488, #123240), where we check that the args of an impl item are compatible before returning it. This is done in `resolve_assoc_item`, which is backing `Instance::resolve`, so this is conceptually generalizing the check from GATs to methods/assoc consts. This is important to make sure that the inliner will only visit and substitute MIR bodies that are compatible w/ their trait definitions. This shouldn't happen in codegen, but there are a few ways to get the inliner to be invoked (via calls to `optimized_mir`) before codegen, namely polymorphization and CTFE. Fixes #121957 Fixes #120792 Fixes #120793 Fixes #121063
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ty_utils/src/instance.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 7b6d86d22a5..a2bed61a7ae 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -191,11 +191,22 @@ fn resolve_associated_item<'tcx>( // Any final impl is required to define all associated items. if !leaf_def.item.defaultness(tcx).has_value() { - let guard = tcx.dcx().span_delayed_bug( + let guar = tcx.dcx().span_delayed_bug( tcx.def_span(leaf_def.item.def_id), "missing value for assoc item in impl", ); - return Err(guard); + return Err(guar); + } + + // Make sure that we're projecting to an item that has compatible args. + // This may happen if we are resolving an instance before codegen, such + // as during inlining. This check is also done in projection. + if !tcx.check_args_compatible(leaf_def.item.def_id, args) { + let guar = tcx.dcx().span_delayed_bug( + tcx.def_span(leaf_def.item.def_id), + "missing value for assoc item in impl", + ); + return Err(guar); } let args = tcx.erase_regions(args); |
