Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANN: Fix E0562 inspection for nested functions #4239

Merged
merged 1 commit into from Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/main/kotlin/org/rust/ide/annotator/RsErrorAnnotator.kt
Expand Up @@ -27,12 +27,8 @@ import org.rust.lang.core.resolve.Namespace
import org.rust.lang.core.resolve.knownItems
import org.rust.lang.core.resolve.namespaces
import org.rust.lang.core.resolve.ref.deepResolve
import org.rust.lang.core.types.TraitRef
import org.rust.lang.core.types.implLookup
import org.rust.lang.core.types.asTy
import org.rust.lang.core.types.inference
import org.rust.lang.core.types.*
import org.rust.lang.core.types.ty.*
import org.rust.lang.core.types.type
import org.rust.lang.utils.RsDiagnostic
import org.rust.lang.utils.RsErrorCode
import org.rust.lang.utils.addToHolder
Expand Down Expand Up @@ -104,7 +100,7 @@ class RsErrorAnnotator : RsAnnotatorBase(), HighlightRangeExtension {
it is RsTypeParameterList ||
it is RsFieldsOwner ||
it is RsForeignModItem ||
it is RsRetType && it.ancestorStrict<RsTraitOrImpl>()?.implementedTrait != null
it is RsRetType && it.parent.ancestorStrict<RsTraitOrImpl>(RsAbstractable::class.java)?.implementedTrait != null
// type alias and let expr are not included because
// they are planned to be allowed soon
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/org/rust/lang/core/psi/ext/PsiElement.kt
Expand Up @@ -70,6 +70,9 @@ val PsiElement.elementType: IElementType
inline fun <reified T : PsiElement> PsiElement.ancestorStrict(): T? =
PsiTreeUtil.getParentOfType(this, T::class.java, /* strict */ true)

inline fun <reified T : PsiElement> PsiElement.ancestorStrict(stopAt: Class<out PsiElement>): T? =
PsiTreeUtil.getParentOfType(this, T::class.java, /* strict */ true, stopAt)

inline fun <reified T : PsiElement> PsiElement.ancestorOrSelf(): T? =
PsiTreeUtil.getParentOfType(this, T::class.java, /* strict */ false)

Expand Down
Expand Up @@ -2332,6 +2332,7 @@ class RsErrorAnnotatorTest : RsAnnotatorTestBase(RsErrorAnnotator::class.java) {
// type Out;
fn in_trait_impl_parameter(_: impl Debug);
fn in_trait_impl_return() -> Self::Out;
fn wrapper();
}
impl DummyTrait for () {
// type Out = impl Debug;
Expand All @@ -2342,6 +2343,11 @@ class RsErrorAnnotatorTest : RsAnnotatorTestBase(RsErrorAnnotator::class.java) {

fn in_trait_impl_return() -> <error descr="`impl Trait` not allowed outside of function and inherent method return types [E0562]">impl Debug</error> { () }
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types

fn wrapper() {
fn in_nested_impl_return() -> impl Debug { () }
// Allowed
}
}

// Allowed
Expand Down