Skip to content

Commit 2255723

Browse files
authored
[Rust] Fixed generic interface implementation types (#3787)
1 parent edbd77c commit 2255723

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/Fable.Cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
* [JS/TS] Fixed `DateTime.Add` for `DateTimeKind.Unspecified` (by @ncave)
1313
* [Rust] Fixed deprecated `NaiveDateTime` usage in `DateTime` (by @ncave)
14+
* [Rust] Fixed generic interface implementation types (by @ncave)
1415

1516
### Added
1617

src/Fable.Transforms/Rust/Fable2Rust.fs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4459,16 +4459,14 @@ module Util =
44594459

44604460
[ ctorItem ]
44614461

4462-
let makeInterfaceTraitImpls (com: IRustCompiler) ctx entName genArgs ifcEntRef memberItems =
4462+
let makeInterfaceTraitImpls (com: IRustCompiler) ctx entName genArgs (ifc: Fable.DeclaredType) memberItems =
44634463
let genArgsOpt = transformGenArgs com ctx genArgs
44644464
let traitBound = mkTypeTraitGenericBound [ entName ] genArgsOpt
44654465
let ty = mkTraitTy [ traitBound ]
44664466
let generics = makeGenerics com ctx genArgs
44674467

4468-
let ifcEnt = com.GetEntity(ifcEntRef)
4469-
let ifcFullName = getInterfaceImportName com ctx ifcEntRef
4470-
let ifcGenArgs = FSharp2Fable.Util.getEntityGenArgs ifcEnt
4471-
let ifcGenArgsOpt = transformGenArgs com ctx ifcGenArgs
4468+
let ifcFullName = ifc.Entity |> getInterfaceImportName com ctx
4469+
let ifcGenArgsOpt = ifc.GenericArgs |> transformGenArgs com ctx
44724470

44734471
let path = makeFullNamePath ifcFullName ifcGenArgsOpt
44744472
let ofTrait = mkTraitRef path |> Some
@@ -4549,16 +4547,17 @@ module Util =
45494547

45504548
let interfaces =
45514549
ent.AllInterfaces
4552-
|> Seq.map (fun ifc -> ifc.Entity, ifc.Entity |> getInterfaceMemberNames com)
4553-
|> Seq.filter (fun (ifcEntRef, _) ->
4550+
|> Seq.filter (fun ifc ->
45544551
// throws out anything on the ignored interfaces list
4555-
not (Set.contains ifcEntRef.FullName ignoredInterfaceNames)
4552+
not (Set.contains ifc.Entity.FullName ignoredInterfaceNames)
45564553
)
45574554
|> Seq.toList
45584555

45594556
let interfaceTraitImpls =
45604557
interfaces
4561-
|> List.collect (fun (ifcEntRef, ifcMemberNames) ->
4558+
|> List.collect (fun ifc ->
4559+
let ifcMemberNames = ifc.Entity |> getInterfaceMemberNames com
4560+
45624561
let memberItems =
45634562
interfaceMembers
45644563
|> List.filter (fun (d, m) ->
@@ -4570,7 +4569,7 @@ module Util =
45704569
if List.isEmpty memberItems then
45714570
[]
45724571
else
4573-
makeInterfaceTraitImpls com ctx entName genArgs ifcEntRef memberItems
4572+
makeInterfaceTraitImpls com ctx entName genArgs ifc memberItems
45744573
)
45754574

45764575
nonInterfaceImpls @ displayTraitImpls @ operatorTraitImpls @ interfaceTraitImpls

0 commit comments

Comments
 (0)