Check Rust dep is a Module before checking target.

The Target checks against the os type and arch type occur before we
determine a dependency is a rust.Module / cc.Module. This meant
rust_defaults would fail this check, preventing them from being used.

Bug: 140963307
Test: make a rust_binary_host using rust_defaults.
Change-Id: Ibf43635f14ad367b4ce8016a2196f8c645b36bfe
diff --git a/rust/rust.go b/rust/rust.go
index 62ccfc7..7cc0b2c 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -334,17 +334,19 @@
 	ctx.VisitDirectDeps(func(dep android.Module) {
 		depName := ctx.OtherModuleName(dep)
 		depTag := ctx.OtherModuleDependencyTag(dep)
-		if dep.Target().Os != ctx.Os() {
-			ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
-			return
-		}
-		if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
-			ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
-			return
-		}
 
 		if rustDep, ok := dep.(*Module); ok {
 			//Handle Rust Modules
+
+			if rustDep.Target().Os != ctx.Os() {
+				ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
+				return
+			}
+			if rustDep.Target().Arch.ArchType != ctx.Arch().ArchType {
+				ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
+				return
+			}
+
 			linkFile := rustDep.outputFile
 			if !linkFile.Valid() {
 				ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
@@ -393,8 +395,17 @@
 			}
 
 		} else if ccDep, ok := dep.(*cc.Module); ok {
-
 			//Handle C dependencies
+
+			if ccDep.Target().Os != ctx.Os() {
+				ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
+				return
+			}
+			if ccDep.Target().Arch.ArchType != ctx.Arch().ArchType {
+				ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
+				return
+			}
+
 			linkFile := ccDep.OutputFile()
 			linkPath := linkPathFromFilePath(linkFile.Path())
 			libName := libNameFromFilePath(linkFile.Path())