Skip to content

Commit e125c71

Browse files
committed
Revert "Altered RFC to allow super-trait imports."
This reverts commit 98834a4.
1 parent d40c696 commit e125c71

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

text/0000-import-trait-methods.md

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Importing a method from a trait does not import the trait. If you want to call `
5353

5454
```rust
5555
mod a {
56-
pub trait A {
56+
trait A {
5757
fn new() -> Self;
5858
fn do_something(&self);
5959
}
@@ -97,10 +97,10 @@ impl S {
9797
}
9898
```
9999

100-
You can also import a parent trait method from a sub-trait:
100+
You cannot import a parent trait method from a sub-trait:
101101

102102
```rust
103-
use num_traits::float::Float::zero;
103+
use num_traits::float::Float::zero; // Error: try `use num_traits::identities::Zero::zero` instead.
104104

105105
fn main() {
106106
let x : f64 = zero();
@@ -116,10 +116,7 @@ When
116116
```rust
117117
use Trait::method as m;
118118
```
119-
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:
123120

124121
```rust
125122
use Default::default;
@@ -169,26 +166,7 @@ is sugar for
169166
use some_module::Trait;
170167
```
171168

172-
Finally, given traits
173-
```rust
174-
trait Super {
175-
fn f();
176-
}
177-
178-
trait Sub : Super {
179-
}
180-
```
181-
the usage
182-
```rust
183-
use module::Sub::f;
184-
f();
185-
```
186-
desugars to
187-
```rust
188-
use module::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.
192170

193171
# Drawbacks
194172
[drawbacks]: #drawbacks
@@ -219,8 +197,6 @@ In [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Wr
219197

220198
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.
221199

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-
224200
## What is the impact of not doing this?
225201

226202
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

Comments
 (0)