diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-19 06:57:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-19 06:57:28 +0100 |
| commit | ffb3c2cb3d2081d295dab9ca38f3a5e1e13c863d (patch) | |
| tree | e57d5f5db40badac99123f9f3bff6fde2115c436 /src/librustc/ty | |
| parent | fddbee64ac6d5ba461c8bdfdf72757dda1d35d8f (diff) | |
| parent | bc8ff3fe8e8cebc9e4855aaf44c19c887f8f4be4 (diff) | |
| download | rust-ffb3c2cb3d2081d295dab9ca38f3a5e1e13c863d.tar.gz rust-ffb3c2cb3d2081d295dab9ca38f3a5e1e13c863d.zip | |
Rollup merge of #69036 - eddyb:monoshim, r=nikomatsakis
rustc: don't resolve Instances which would produce malformed shims. There are some `InstanceDef` variants (shims and drop "glue") which contain a `Ty`, and that `Ty` is used in generating the shim MIR. But if that `Ty` mentions any generic parameters, the generated shim would refer to them (but they won't match the `Substs` of the `Instance`), or worse, generating the shim would fail because not enough of the type is known. Ideally we would always produce a "skeleton" of the type, e.g. `(_, _)` for dropping any tuples with two elements, or `Vec<_>` for dropping any `Vec` value, but that's a lot of work, and they would still not match the `Substs` of the `Instance` as it exists today, so `Instance` would probably need to change. By making `Instance::resolve` return `None` in the still-generic cases, we get behavior similar to specialization, where a default can only be used if there are no more generic parameters which would allow a more specialized `impl` to match. <hr/> This was found while testing the MIR inliner with #68965, because it was trying to inline shims. cc @rust-lang/wg-mir-opt
Diffstat (limited to 'src/librustc/ty')
| -rw-r--r-- | src/librustc/ty/instance.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 445df76cd32..c9ad8707a74 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -39,6 +39,10 @@ pub enum InstanceDef<'tcx> { /// `<fn() as FnTrait>::call_*` /// `DefId` is `FnTrait::call_*`. + /// + /// NB: the (`fn` pointer) type must currently be monomorphic to avoid double substitution + /// problems with the MIR shim bodies. `Instance::resolve` enforces this. + // FIXME(#69925) support polymorphic MIR shim bodies properly instead. FnPtrShim(DefId, Ty<'tcx>), /// `<dyn Trait as Trait>::fn`, "direct calls" of which are implicitly @@ -57,9 +61,17 @@ pub enum InstanceDef<'tcx> { /// The `DefId` is for `core::ptr::drop_in_place`. /// The `Option<Ty<'tcx>>` is either `Some(T)`, or `None` for empty drop /// glue. + /// + /// NB: the type must currently be monomorphic to avoid double substitution + /// problems with the MIR shim bodies. `Instance::resolve` enforces this. + // FIXME(#69925) support polymorphic MIR shim bodies properly instead. DropGlue(DefId, Option<Ty<'tcx>>), ///`<T as Clone>::clone` shim. + /// + /// NB: the type must currently be monomorphic to avoid double substitution + /// problems with the MIR shim bodies. `Instance::resolve` enforces this. + // FIXME(#69925) support polymorphic MIR shim bodies properly instead. CloneShim(DefId, Ty<'tcx>), } |
