rust: Don't produce apex variants if apex_exclude

The apex variants of apex_exclude modules were leading to a mixing of
apex and non-apex dependencies in their dependency trees, causing
StableId collisions when an -L path for both variants was emitted
to the rustc command.

Since we already exclude these variants from apexes (they are
effectively serving as a stop-gap for stub support), don't produce apex
variants if apex_exclude is true.

Bug: 203478530
Test: m
Change-Id: I1448ce1aad989b8a97fd31552a00afa7e6b78829
diff --git a/rust/rust.go b/rust/rust.go
index 5602edc..a044a99 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -1756,6 +1756,16 @@
 
 var _ android.ApexModule = (*Module)(nil)
 
+// If a module is marked for exclusion from apexes, don't provide apex variants.
+// TODO(b/362509506): remove this once stubs are properly supported by rust_ffi targets.
+func (m *Module) CanHaveApexVariants() bool {
+	if m.ApexExclude() {
+		return false
+	} else {
+		return m.ApexModuleBase.CanHaveApexVariants()
+	}
+}
+
 func (mod *Module) MinSdkVersion() string {
 	return String(mod.Properties.Min_sdk_version)
 }