Skip to content

Commit

Permalink
ANN: Fix E0562 inspection for nested functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mchernyavsky committed Aug 12, 2019
1 parent f0374a6 commit 79e6ac7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
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 @@ -2342,6 +2342,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

0 comments on commit 79e6ac7

Please sign in to comment.