-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Make impl blocks only give rise to direct trait implementation #20847
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
Changes from 4 commits
089bfff
ec74be6
e0d0f03
e29ca72
4e918f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,16 +72,24 @@ module FunctionPositionMatchingInput { | |
| } | ||
|
|
||
| private newtype TAssocFunctionType = | ||
| /** An associated function `f` that should be specialized for `i` at `pos`. */ | ||
| MkAssocFunctionType(Function f, ImplOrTraitItemNode i, FunctionPosition pos) { | ||
| f = i.getASuccessor(_) and exists(pos.getTypeMention(f)) | ||
| /** An associated function `f` in `parent` should be specialized for `i` at `pos`. */ | ||
| MkAssocFunctionType( | ||
| ImplOrTraitItemNode parent, Function f, ImplOrTraitItemNode i, FunctionPosition pos | ||
| ) { | ||
| parent.getAnAssocItem() = f and | ||
| i.getASuccessor(_) = f and | ||
| // When `f` is not directly in `i`, the `parent` should be satisfiable | ||
| // through `i`. This ensures that `parent` is either a supertrait of `i` or | ||
| // `i` in an `impl` block implementing `parent`. | ||
| (parent = i or BaseTypes::rootTypesSatisfaction(_, TTrait(parent), i, _, _)) and | ||
| exists(pos.getTypeMention(f)) | ||
| } | ||
|
|
||
| bindingset[condition, constraint, tp] | ||
| bindingset[abs, constraint, tp] | ||
| private Type getTraitConstraintTypeAt( | ||
| TypeMention condition, TypeMention constraint, TypeParameter tp, TypePath path | ||
| TypeAbstraction abs, TypeMention constraint, TypeParameter tp, TypePath path | ||
| ) { | ||
| BaseTypes::conditionSatisfiesConstraintTypeAt(_, condition, constraint, | ||
| BaseTypes::conditionSatisfiesConstraintTypeAt(abs, _, constraint, | ||
|
Comment on lines
+88
to
+92
|
||
| TypePath::singleton(tp).appendInverse(path), result) | ||
| } | ||
|
|
||
|
|
@@ -91,28 +99,19 @@ private Type getTraitConstraintTypeAt( | |
| */ | ||
| pragma[nomagic] | ||
| Type getAssocFunctionTypeAt(Function f, ImplOrTraitItemNode i, FunctionPosition pos, TypePath path) { | ||
| exists(MkAssocFunctionType(f, i, pos)) and | ||
| ( | ||
| exists(ImplOrTraitItemNode parent | exists(MkAssocFunctionType(parent, f, i, pos)) | | ||
| // No specialization needed when the function is directly in the trait or | ||
| // impl block or the declared type is not a type parameter | ||
| (i.getAnAssocItem() = f or not result instanceof TypeParameter) and | ||
| (parent = i or not result instanceof TypeParameter) and | ||
| result = pos.getTypeMention(f).resolveTypeAt(path) | ||
| or | ||
| not i.getAnAssocItem() = f and | ||
| exists(TypePath prefix, TypePath suffix, TypeParameter tp | | ||
| exists(TypePath prefix, TypePath suffix, TypeParameter tp, TypeMention constraint | | ||
| BaseTypes::rootTypesSatisfaction(_, TTrait(parent), i, _, constraint) and | ||
| path = prefix.append(suffix) and | ||
| tp = pos.getTypeMention(f).resolveTypeAt(prefix) | ||
| | | ||
| tp = pos.getTypeMention(f).resolveTypeAt(prefix) and | ||
| if tp = TSelfTypeParameter(_) | ||
| then result = resolveImplOrTraitType(i, suffix) | ||
| else | ||
| exists(TraitItemNode trait, TypeMention condition, TypeMention constraint | | ||
| trait.getAnAssocItem() = f and | ||
| BaseTypes::rootTypesSatisfaction(_, TTrait(trait), _, condition, constraint) and | ||
| result = getTraitConstraintTypeAt(condition, constraint, tp, suffix) | ||
| | | ||
| condition = i.(Trait) or condition = i.(Impl).getSelfTy() | ||
| ) | ||
| else result = getTraitConstraintTypeAt(i, constraint, tp, suffix) | ||
| ) | ||
| ) | ||
| } | ||
|
|
@@ -125,40 +124,42 @@ Type getAssocFunctionTypeAt(Function f, ImplOrTraitItemNode i, FunctionPosition | |
| * | ||
| * ```rust | ||
| * trait T1 { | ||
| * fn m1(self); // self1 | ||
| * fn m1(self); // T1::m1 | ||
| * | ||
| * fn m2(self) { ... } // self2 | ||
| * fn m2(self) { ... } // T1::m2 | ||
| * } | ||
| * | ||
| * trait T2 : T1 { | ||
| * fn m3(self); // self3 | ||
| * fn m3(self); // T2::m3 | ||
| * } | ||
| * | ||
| * impl T2 for X { | ||
| * fn m1(self) { ... } // self4 | ||
| * impl T1 for X { | ||
| * fn m1(self) { ... } // X::m1 | ||
| * } | ||
| * | ||
| * fn m3(self) { ... } // self5 | ||
| * impl T2 for X { | ||
| * fn m3(self) { ... } // X::m3 | ||
| * } | ||
| * ``` | ||
| * | ||
| * param | `impl` or trait | type | ||
| * ------- | --------------- | ---- | ||
| * `self1` | `trait T1` | `T1` | ||
| * `self1` | `trait T2` | `T2` | ||
| * `self2` | `trait T1` | `T1` | ||
| * `self2` | `trait T2` | `T2` | ||
| * `self2` | `impl T2 for X` | `X` | ||
| * `self3` | `trait T2` | `T2` | ||
| * `self4` | `impl T2 for X` | `X` | ||
| * `self5` | `impl T2 for X` | `X` | ||
| * f | `impl` or trait | pos | type | ||
| * -------- | --------------- | ------ | ---- | ||
| * `T1::m1` | `trait T1` | `self` | `T1` | ||
| * `T1::m1` | `trait T2` | `self` | `T2` | ||
| * `T1::m2` | `trait T1` | `self` | `T1` | ||
| * `T1::m2` | `trait T2` | `self` | `T2` | ||
| * `T1::m2` | `impl T1 for X` | `self` | `X` | ||
| * `T2::m3` | `trait T2` | `self` | `T2` | ||
| * `X::m1` | `impl T1 for X` | `self` | `X` | ||
| * `X::m3` | `impl T2 for X` | `self` | `X` | ||
| */ | ||
| class AssocFunctionType extends MkAssocFunctionType { | ||
| /** | ||
| * Holds if this function type applies to the function `f` at position `pos`, | ||
| * when viewed as a member of the `impl` or trait item `i`. | ||
| */ | ||
| predicate appliesTo(Function f, ImplOrTraitItemNode i, FunctionPosition pos) { | ||
| this = MkAssocFunctionType(f, i, pos) | ||
| this = MkAssocFunctionType(_, f, i, pos) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.