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, we first find the supertrait in which `method` occurs. If it occurs in multiple supertraits, or in the trait and in a supertrait, then error.
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.
121
-
122
-
In other words, the example:
119
+
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:
123
120
124
121
```rust
125
122
useDefault::default;
@@ -169,26 +166,7 @@ is sugar for
169
166
usesome_module::Trait;
170
167
```
171
168
172
-
Finally, given traits
173
-
```rust
174
-
traitSuper {
175
-
fnf();
176
-
}
177
-
178
-
traitSub:Super {
179
-
}
180
-
```
181
-
the usage
182
-
```rust
183
-
usemodule::Sub::f;
184
-
f();
185
-
```
186
-
desugars to
187
-
```rust
188
-
usemodule::Sub::f;
189
-
Super::f();
190
-
```
191
-
**not**`Sub::f();` as that desugaring will cause compiler errors, see https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=51bef9ba69ce1fc20248e987bf106bd4.
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.
192
170
193
171
# Drawbacks
194
172
[drawbacks]: #drawbacks
@@ -219,8 +197,6 @@ In [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Wr
219
197
220
198
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.
221
199
222
-
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.
223
-
224
200
## What is the impact of not doing this?
225
201
226
202
Users of the language continue to create helper methods to access trait methods with regular function syntax. More specifically, each such instance requires a minimum of three lines when using normal rust formatting, corresponding to the following example:
0 commit comments