Repository: intellij-rust/intellij-rust (language: rust)

Issue:
copy type report error: Use of moved value 
<!--
Hello and thank you for the issue!
If you would like to report a bug, we have added some points below that you can fill out.
Consider using "Help | Create New Issue" action that fills out all necessary information automatically.
Feel free to remove all the irrelevant text to request a new feature.
-->

## Environment

* **IntelliJ Rust plugin version:** 0.4.195.5369-231-nightly
* **Rust toolchain version:** rustc 1.71.0-nightly (a368898de 2023-05-02)
* **IDE name and version:** Clion 2023.1.2
* **Operating system:** Archlinux

## Problem description
![image](https://user-images.githubusercontent.com/10096425/236003647-db31a17e-4d8b-407e-9d67-5fa05798b688.png)

the `fwmark` is u32, so it won't have a **Use of moved value** problem

I already run `cargo clean` and clean the ide cache but it doesn't work

## Steps to reproduce

<!--
Please include as much of your codebase as needed to reproduce the error.
If the relevant files are large, please provide a link to a public repository or a [Gist](https://gist.github.com/).

If you provide a screenshot of some code, please also copy-paste the corresponding code snippet here.
-->



Discussion / hints:
Can confirm the same behavior on:

IntelliJ Rust plugin version: 0.4.195.5369-231-nightly
Rust toolchain version: rustc 1.71.0-nightly (a368898de 2023-05-02)
IDE name and version: Intellij Ultimate 2023.1.1
Operating system: PopOS

Hi! Thank you for the report!
The issue is 100% reproducible on the latest Rust nightly toolchain, but not on the stable toolchain.
I investigated that the Rust plugin can't expand an stdlib macro that implements `Copy` for primitive types (because of the latest changes in the stdlib) and hence the plugin doesn't know that primitive types implement `Copy`.
I'll investigate it further and try to fix it. As a workaround, you can try to use less recent Rust nightly version
A good workaround is to (erroneously) manually implement `Copy` for the types you want:
```rs
impl Copy for usize {}
impl Copy for f32 {}
```
And then disabling this when you're actually compiling. I tend to write large chunks of code and don't compile very often, so this works for me, but if you find it cumbersome to do so, then write a feature that you never actually use and tell ij-rs to enable that feature when doing code analysis (by ticking the box in the `Cargo.toml`), but then don't compile your code with the feature. Place the `impl`s in a module only enabled by said feature.
For reference, the latest nightly that doesn't exhibit this false positive is the one released on `2023-05-01`, which can be installed with `rustup toolchain install nightly-2023-05-01`.

Fix patch:
diff --git a/src/main/kotlin/org/rust/lang/core/psi/ext/RsMacro2.kt b/src/main/kotlin/org/rust/lang/core/psi/ext/RsMacro2.kt
index 4dfb8da5cc0..e73b1ff25f2 100644
--- a/src/main/kotlin/org/rust/lang/core/psi/ext/RsMacro2.kt
+++ b/src/main/kotlin/org/rust/lang/core/psi/ext/RsMacro2.kt
@@ -77,6 +77,6 @@ fun RsMacro2.prepareMacroBody(): String {
     return if (macroPatternContents != null && macroExpansionContents != null) {
         "{(${macroPatternContents.text}) => {${macroExpansionContents.text}}}"
     } else {
-        macroCaseList.joinToString(prefix = "{", postfix = "}") { it.text }
+        macroCaseList.joinToString(prefix = "{", postfix = "}", separator = "") { it.text }
     }
 }
diff --git a/src/main/kotlin/org/rust/lang/core/stubs/StubImplementations.kt b/src/main/kotlin/org/rust/lang/core/stubs/StubImplementations.kt
index 1766e02ed45..6f05c912146 100644
--- a/src/main/kotlin/org/rust/lang/core/stubs/StubImplementations.kt
+++ b/src/main/kotlin/org/rust/lang/core/stubs/StubImplementations.kt
@@ -86,7 +86,7 @@ class RsFileStub(
 
     object Type : IStubFileElementType<RsFileStub>(RsLanguage) {
         // Bump this number if Stub structure changes
-        private const val STUB_VERSION = 232
+        private const val STUB_VERSION = 233
 
         override fun getStubVersion(): Int =
             RustParserDefinition.PARSER_VERSION + RS_BUILTIN_ATTRIBUTES_VERSION + STUB_VERSION


Test patch:
diff --git a/src/test/kotlin/org/rust/lang/core/macros/decl/RsMacroExpansionTest.kt b/src/test/kotlin/org/rust/lang/core/macros/decl/RsMacroExpansionTest.kt
index 0a7fb72638b..6991df7d1be 100644
--- a/src/test/kotlin/org/rust/lang/core/macros/decl/RsMacroExpansionTest.kt
+++ b/src/test/kotlin/org/rust/lang/core/macros/decl/RsMacroExpansionTest.kt
@@ -1335,6 +1335,70 @@ class RsMacroExpansionTest : RsMacroExpansionTestBase() {
         "bar"
     """)
 
+    fun `test marker_impls using macro 2`() = doTest("""
+        macro marker_impls {
+            ( $(#[$($ meta:tt)*])* $ Trait:ident for $({$($ bounds:tt)*})? $ T:ty $(, $($ rest:tt)*)? ) => {
+                    $(#[$($ meta)*])* impl< $($($ bounds)*)? > $ Trait for $ T {}
+                    marker_impls! { $(#[$($ meta)*])* $ Trait for $($($ rest)*)? }
+                },
+            ( $(#[$($ meta:tt)*])* $ Trait:ident for ) => {},
+
+            ( $(#[$($ meta:tt)*])* unsafe $ Trait:ident for $({$($ bounds:tt)*})? $ T:ty $(, $($ rest:tt)*)? ) => {
+                    $(#[$($ meta)*])* unsafe impl< $($($ bounds)*)? > $ Trait for $ T {}
+                    marker_impls! { $(#[$($ meta)*])* unsafe $ Trait for $($($ rest)*)? }
+                },
+            ( $(#[$($ meta:tt)*])* unsafe $ Trait:ident for ) => {},
+        }
+        marker_impls! {
+            #[stable(feature = "rust1", since = "1.0.0")]
+            Copy for
+                usize, u8, u16, u32, u64, u128,
+                isize, i8, i16, i32, i64, i128,
+                f32, f64,
+                bool, char,
+                {T: ?Sized} *const T,
+                {T: ?Sized} *mut T,
+
+        }
+    """, """
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for usize {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for u8 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for u16 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for u32 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for u64 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for u128 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for isize {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for i8 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for i16 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for i32 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for i64 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for i128 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for f32 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for f64 {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for bool {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<> Copy for char {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<T: ?Sized> Copy for *const T {}
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl<T: ?Sized> Copy for *mut T {}
+    """)
+
     companion object {
         // BACKCOMPAT: Rust 1.62
         private val RUST_1_63 = "1.63.0".parseSemVer()