Repository: intellij-rust/intellij-rust
Issue: 'Un-elide lifetimes' intention should not be available when nothing to un-elide

<!--
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.
Feel free to remove all the irrelevant text to request a new feature.
-->

## Environment

* **IntelliJ Rust plugin version:** 0.4.184.5009-223-nightly
* **Rust toolchain version:** 1.65.0 (897e37553 2022-11-02) x86_64-apple-darwin
* **IDE name and version:** CLion 2022.3 EAP (CL-223.7571.12)
* **Operating system:** macOS 12.5.1
* **Macro expansion:** enabled
* **Additional experimental features:** org.rust.cargo.features.settings.gutter, org.rust.macros.proc.derive, org.rust.cargo.emulate.terminal, org.rust.macros.proc

## Problem description
```
Exceptions occurred on invoking the intention 'Un-elide lifetimes' on a copy of the file.

java.util.NoSuchElementException: List is empty.
	at kotlin.collections.CollectionsKt___CollectionsKt.first(_Collections.kt:214)
	at org.rust.ide.intentions.UnElideLifetimesIntention.invoke(UnElideLifetimesIntention.kt:62)
```


<details>

```
Exceptions occurred on invoking the intention 'Un-elide lifetimes' on a copy of the file.

java.util.NoSuchElementException: List is empty.
	at kotlin.collections.CollectionsKt___CollectionsKt.first(_Collections.kt:214)
	at org.rust.ide.intentions.UnElideLifetimesIntention.invoke(UnElideLifetimesIntention.kt:62)
	at org.rust.ide.intentions.UnElideLifetimesIntention.invoke(UnElideLifetimesIntention.kt:22)
	at org.rust.ide.intentions.RsElementBaseIntentionAction.invoke(RsElementBaseIntentionAction.kt:50)
	at com.intellij.codeInsight.intention.BaseElementAtCaretIntentionAction.invoke(BaseElementAtCaretIntentionAction.java:76)
	at com.intellij.codeInsight.intention.IntentionAction.generatePreview(IntentionAction.java:145)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.invokePreview$lambda-3$lambda-2(IntentionPreviewComputable.kt:146)
	at com.intellij.psi.impl.source.PostprocessReformattingAspect.lambda$postponeFormattingInside$2(PostprocessReformattingAspect.java:140)
	at com.intellij.psi.impl.source.PostprocessReformattingAspect.postponeFormattingInside(PostprocessReformattingAspect.java:148)
	at com.intellij.psi.impl.source.PostprocessReformattingAspect.postponeFormattingInside(PostprocessReformattingAspect.java:139)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.invokePreview$lambda-3(IntentionPreviewComputable.kt:146)
	at com.intellij.codeInsight.intention.preview.IntentionPreviewUtils.previewSession(IntentionPreviewUtils.java:94)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.invokePreview(IntentionPreviewComputable.kt:144)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.generatePreview(IntentionPreviewComputable.kt:103)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.tryCreateDiffContent$lambda-1(IntentionPreviewComputable.kt:61)
	at com.intellij.model.SideEffectGuard.computeWithAllowedSideEffects(SideEffectGuard.java:25)
	at com.intellij.model.SideEffectGuard.computeWithoutSideEffects(SideEffectGuard.java:18)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.tryCreateDiffContent(IntentionPreviewComputable.kt:61)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.call(IntentionPreviewComputable.kt:39)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.call(IntentionPreviewComputable.kt:34)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$OTelMonitor.callWrapped(NonBlockingReadActionImpl.java:746)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$OTelMonitor$MonitoredComputation.call(NonBlockingReadActionImpl.java:778)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.insideReadAction(NonBlockingReadActionImpl.java:573)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$attemptComputation$3(NonBlockingReadActionImpl.java:537)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1086)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runInReadActionWithWriteActionPriority$0(ProgressIndicatorUtils.java:71)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtilService.runActionAndCancelBeforeWrite(ProgressIndicatorUtilService.java:63)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:128)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runWithWriteActionPriority$1(ProgressIndicatorUtils.java:109)
	at com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:68)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:190)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:591)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:666)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:622)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:590)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:177)
	at com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:68)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runWithWriteActionPriority(ProgressIndicatorUtils.java:106)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(ProgressIndicatorUtils.java:71)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.attemptComputation(NonBlockingReadActionImpl.java:537)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$transferToBgThread$1(NonBlockingReadActionImpl.java:444)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
	at java.base/java.lang.Thread.run(Thread.java:833)

```

</details>

## Steps to reproduce
As usual I cannot reproduce it, but it happened after disabling `cargo check on the fly` in simple pro_macro_crate.

<!--
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/).
-->

Changed files:
src/test/kotlin/org/rust/ide/intentions/UnElideLifetimesIntentionTest.kt, src/main/kotlin/org/rust/ide/intentions/UnElideLifetimesIntention.kt

diff --git a/src/main/kotlin/org/rust/ide/intentions/UnElideLifetimesIntention.kt b/src/main/kotlin/org/rust/ide/intentions/UnElideLifetimesIntention.kt
index 7f95a9a70..9d597eb2e 100644
--- a/src/main/kotlin/org/rust/ide/intentions/UnElideLifetimesIntention.kt
+++ b/src/main/kotlin/org/rust/ide/intentions/UnElideLifetimesIntention.kt
@@ -33,8 +33,8 @@ class UnElideLifetimesIntention : RsElementBaseIntentionAction<LifetimeContext>(
             if (outputLifetimes.any { it != null } || outputLifetimes.size > 1) return null
         }
 
-        val refArgs = ctx.inputs + listOfNotNull(ctx.self)
-        if (refArgs.isEmpty() || refArgs.any { it.lifetimes.any { lifetime -> lifetime != null } }) return null
+        val inputLifetimes = ctx.inputs.flatMap { it.lifetimes } + ctx.self?.lifetimes.orEmpty()
+        if (inputLifetimes.isEmpty() || inputLifetimes.any { it != null }) return null
 
         return ctx
     }
diff --git a/src/test/kotlin/org/rust/ide/intentions/UnElideLifetimesIntentionTest.kt b/src/test/kotlin/org/rust/ide/intentions/UnElideLifetimesIntentionTest.kt
index fe268345b..4153ebecb 100644
--- a/src/test/kotlin/org/rust/ide/intentions/UnElideLifetimesIntentionTest.kt
+++ b/src/test/kotlin/org/rust/ide/intentions/UnElideLifetimesIntentionTest.kt
@@ -8,10 +8,15 @@ package org.rust.ide.intentions
 import org.rust.MockAdditionalCfgOptions
 
 class UnElideLifetimesIntentionTest : RsIntentionTestBase(UnElideLifetimesIntention::class) {
-    fun `test unavailable without references`() = doUnavailableTest("""
+    fun `test unavailable without references 1`() = doUnavailableTest("""
         fn bar/*caret*/(x: i32) -> i32 {}
     """)
 
+    fun `test unavailable without references 2`() = doUnavailableTest("""
+        fn bar/*caret*/(x: T) -> T {}
+        struct T;
+    """)
+
     fun `test unavailable in block body`() = doUnavailableTest("""
         fn bar(x: &i32) {/*caret*/}
     """)