-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: Make impl blocks only give rise to direct trait implementation #20723
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -586,10 +586,10 @@ mod impl_overlap { | |
| println!("{:?}", w.m(x)); // $ target=S3<T>::m | ||
| println!("{:?}", S3::m(&w, x)); // $ target=S3<T>::m | ||
|
|
||
| S4.m(); // $ target=<S4_as_MyTrait1>::m $ SPURIOUS: target=MyTrait1::m | ||
| S4.m(); // $ target=<S4_as_MyTrait1>::m | ||
| S4::m(&S4); // $ target=<S4_as_MyTrait1>::m $ SPURIOUS: target=MyTrait1::m | ||
| S5(0i32).m(); // $ target=<S5<i32>_as_MyTrait1>::m $ SPURIOUS: target=MyTrait1::m | ||
| S5::m(&S5(0i32)); // $ target=<S5<i32>_as_MyTrait1>::m $ SPURIOUS: target=MyTrait1::m | ||
| S5(0i32).m(); // $ target=<S5<i32>_as_MyTrait1>::m | ||
| S5::m(&S5(0i32)); // $ target=<S5<i32>_as_MyTrait1>::m | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why the second test did not get fixed, especially since it looks a lot like the fourth test. I'm guessing something more might be needed here, as the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I have something to address this follow-up. |
||
| S5(true).m(); // $ target=MyTrait1::m | ||
| S5::m(&S5(true)); // $ target=MyTrait1::m | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -449,7 +449,9 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |
| * - `abs` is a type abstraction that introduces type variables that are | ||
| * free in `condition` and `constraint`, | ||
| * - and for every instantiation of the type parameters from `abs` the | ||
| * resulting `condition` satisifies the constraint given by `constraint`. | ||
| * resulting `condition` satisfies the constraint given by `constraint`. | ||
| * - `transitive` corresponds to whether any further constraints satisfied | ||
| * through `constraint` also applies to `condition`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: apply |
||
| * | ||
| * Example in C#: | ||
| * ```csharp | ||
|
|
@@ -487,7 +489,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |
| * should be empty. | ||
| */ | ||
| predicate conditionSatisfiesConstraint( | ||
| TypeAbstraction abs, TypeMention condition, TypeMention constraint | ||
| TypeAbstraction abs, TypeMention condition, TypeMention constraint, boolean transitive | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -754,13 +756,13 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |
| private predicate typeCondition( | ||
| Type type, TypeAbstraction abs, TypeMentionTypeTree condition | ||
| ) { | ||
| conditionSatisfiesConstraint(abs, condition, _) and | ||
| conditionSatisfiesConstraint(abs, condition, _, _) and | ||
| type = resolveTypeMentionRoot(condition) | ||
| } | ||
|
|
||
| pragma[nomagic] | ||
| private predicate typeConstraint(Type type, TypeMentionTypeTree constraint) { | ||
| conditionSatisfiesConstraint(_, _, constraint) and | ||
| conditionSatisfiesConstraint(_, _, constraint, _) and | ||
| type = resolveTypeMentionRoot(constraint) | ||
| } | ||
|
|
||
|
|
@@ -781,12 +783,12 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> { | |
| TypeAbstraction abs, TypeMention condition, TypeMention constraint, TypePath path, Type t | ||
| ) { | ||
| // base case | ||
| conditionSatisfiesConstraint(abs, condition, constraint) and | ||
| conditionSatisfiesConstraint(abs, condition, constraint, _) and | ||
| constraint.resolveTypeAt(path) = t | ||
| or | ||
| // recursive case | ||
| exists(TypeAbstraction midAbs, TypeMention midConstraint, TypeMention midCondition | | ||
| conditionSatisfiesConstraint(abs, condition, midConstraint) and | ||
| conditionSatisfiesConstraint(abs, condition, midConstraint, true) and | ||
| // NOTE: `midAbs` describe the free type variables in `midCondition`, hence | ||
| // we use that for instantiation check. | ||
| IsInstantiationOf<TypeMentionTypeTree, TypeMentionTypeTree, IsInstantiationOfInput>::isInstantiationOf(midConstraint, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though this calls the version of
minimpl MyTrait1 for S4, if that did not overridemI believe Rust would in fact fall back to the implementation inMyTrait1. It's also possible that a function in a directImpl S4could be called here. I'm seeking reassurance that we will get the right call targets in expanded cases such as these: