You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
occurs, a new item `m` is made available in the function namespace of the current module. Any attempts to call this item are treated calling the trait method explicitly qualified. As always, the `as` qualifier is optional, in which case the name of the new item is identical with the name of the method in the trait. In other words, the example:
119
+
occurs, we first find the supertrait in which `method` occurs.
120
+
A new item `m` is made available in the function namespace of the current module. Any attempts to call this item are treated calling the (super-)trait method explicitly qualified. As always, the `as` qualifier is optional, in which case the name of the new item is identical with the name of the method in the trait. In other words, the example:
120
121
121
122
```rust
122
123
useDefault::default;
@@ -166,7 +167,26 @@ is sugar for
166
167
usesome_module::Trait;
167
168
```
168
169
169
-
The restriction on importing parent trait methods is a consequence of this desugaring, see https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=51bef9ba69ce1fc20248e987bf106bd4 for examples of the errors you get when you try to call parent trait methods through a child trait. We will likely want better error messages than this if a user tries to import a parent method.
170
+
Finally, given traits
171
+
```rust
172
+
traitSuper {
173
+
fnf();
174
+
}
175
+
176
+
traitSub:Super {
177
+
}
178
+
```
179
+
the usage
180
+
```rust
181
+
usemodule::Sub::f;
182
+
f();
183
+
```
184
+
desugars to
185
+
```rust
186
+
usemodule::Sub::f;
187
+
Super::f();
188
+
```
189
+
**not**`Sub::f();` as that desugaring will cause compiler errors, see https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=51bef9ba69ce1fc20248e987bf106bd4.
170
190
171
191
# Drawbacks
172
192
[drawbacks]: #drawbacks
@@ -190,6 +210,8 @@ In [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Wr
190
210
191
211
Option 1 is what is proposed here. It has the simplest semantics, and I believe it best matches the user intent when they import a trait method; the desire is to make that method available as-if it were a regular function. Furthermore, it is more minimalist than the other two options in the sense that you can get to option 2 simply by importing the trait also. Option 3 seems like extra complexity for almost no added value.
192
212
213
+
An earlier version of this RFC proposed not allowing `use Trait::super_trait_method`. This was changed because comments indicated this usecase would be common.
214
+
193
215
## What is the impact of not doing this?
194
216
195
217
Users of the language continue to create helper methods to access trait methods with infix syntax.
0 commit comments