Skip to content

Commit d1508f4

Browse files
committed
Fix specifying target expression for static method
1 parent 5c0eee7 commit d1508f4

2 files changed

Lines changed: 35 additions & 85 deletions

File tree

tests/ui/delegation/newtypes.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ mod more_than_one_field {
6363
reuse Trait::method { self.0 }
6464
//~^ ERROR: mismatched types
6565

66-
reuse Trait::r#static { self.0 }
67-
//~^ ERROR: delegation's target expression is specified for function with no params
68-
//~| ERROR: method `static` has an incompatible type for trait
69-
//~| ERROR: this function takes 0 arguments but 1 argument was supplied
70-
//~| ERROR: the trait bound `(): more_than_one_field::Trait` is not satisfied
66+
reuse Trait::r#static;
67+
//~^ WARN: function cannot return without recursing
7168

7269
reuse Trait::raw_S { self.0 }
7370
}
Lines changed: 33 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
error: delegation's target expression is specified for function with no params
2-
--> $DIR/newtypes.rs:66:31
3-
|
4-
LL | reuse Trait::r#static { self.0 }
5-
| ^^^^^^^^^^
6-
7-
error[E0053]: method `static` has an incompatible type for trait
8-
--> $DIR/newtypes.rs:66:22
9-
|
10-
LL | reuse Trait::r#static { self.0 }
11-
| ^^^^^^^^ expected `more_than_one_field::W`, found `()`
12-
|
13-
note: type in trait
14-
--> $DIR/newtypes.rs:51:26
15-
|
16-
LL | fn r#static() -> Self;
17-
| ^^^^
18-
= note: expected signature `fn() -> more_than_one_field::W`
19-
found signature `fn() -> ()`
20-
help: change the output type to match the trait
21-
|
22-
LL - reuse Trait::r#static { self.0 }
23-
LL + reuse Trait:: -> more_than_one_field::W { self.0 }
24-
|
25-
261
error[E0308]: mismatched types
272
--> $DIR/newtypes.rs:63:31
283
|
@@ -40,42 +15,8 @@ note: method defined here
4015
LL | fn method(&self) -> Self;
4116
| ^^^^^^ ----
4217

43-
error[E0061]: this function takes 0 arguments but 1 argument was supplied
44-
--> $DIR/newtypes.rs:66:22
45-
|
46-
LL | reuse Trait::r#static { self.0 }
47-
| ^^^^^^^^ ---------- unexpected argument
48-
| |
49-
| this implicit `()` return type influences the call expression's return type
50-
|
51-
note: associated function defined here
52-
--> $DIR/newtypes.rs:51:12
53-
|
54-
LL | fn r#static() -> Self;
55-
| ^^^^^^^^
56-
help: remove the extra argument
57-
|
58-
LL - reuse Trait::r#static { self.0 }
59-
LL + reuse Trait::r#stati{ self.0 }
60-
|
61-
62-
error[E0277]: the trait bound `(): more_than_one_field::Trait` is not satisfied
63-
--> $DIR/newtypes.rs:66:22
64-
|
65-
LL | reuse Trait::r#static { self.0 }
66-
| ^^^^^^^^ the trait `more_than_one_field::Trait` is not implemented for `()`
67-
|
68-
help: the following other types implement trait `more_than_one_field::Trait`
69-
--> $DIR/newtypes.rs:56:5
70-
|
71-
LL | impl Trait for S {
72-
| ^^^^^^^^^^^^^^^^ `more_than_one_field::S`
73-
...
74-
LL | impl Trait for W {
75-
| ^^^^^^^^^^^^^^^^ `more_than_one_field::W`
76-
7718
error[E0308]: mismatched types
78-
--> $DIR/newtypes.rs:101:25
19+
--> $DIR/newtypes.rs:98:25
7920
|
8021
LL | pub fn method(_: impl super::Trait) -> impl super::Trait {
8122
| ----------------- the found opaque type
@@ -90,7 +31,7 @@ LL | reuse to_reuse::method { self.0 }
9031
found opaque type `impl non_trait_path_reuse::Trait`
9132

9233
error[E0308]: mismatched types
93-
--> $DIR/newtypes.rs:103:25
34+
--> $DIR/newtypes.rs:100:25
9435
|
9536
LL | pub fn r#static() -> impl super::Trait {
9637
| ----------------- the found opaque type
@@ -105,7 +46,7 @@ LL | reuse to_reuse::r#static;
10546
found opaque type `impl non_trait_path_reuse::Trait`
10647

10748
error[E0308]: mismatched types
108-
--> $DIR/newtypes.rs:124:31
49+
--> $DIR/newtypes.rs:121:31
10950
|
11051
LL | reuse Trait::method { self.0 }
11152
| ------ ^^^^^^ expected `&_`, found `()`
@@ -115,7 +56,7 @@ LL | reuse Trait::method { self.0 }
11556
= note: expected reference `&_`
11657
found unit type `()`
11758
note: method defined here
118-
--> $DIR/newtypes.rs:110:12
59+
--> $DIR/newtypes.rs:107:12
11960
|
12061
LL | fn method(&self) -> ();
12162
| ^^^^^^ ----
@@ -125,14 +66,14 @@ LL | reuse Trait::method { &self.0 }
12566
| +
12667

12768
error[E0283]: type annotations needed
128-
--> $DIR/newtypes.rs:127:22
69+
--> $DIR/newtypes.rs:124:22
12970
|
13071
LL | reuse Trait::r#static;
13172
| ^^^^^^^^ cannot infer type
13273
|
13374
= note: the type must implement `non_Self_return_type::Trait`
13475
help: the following types implement trait `non_Self_return_type::Trait`
135-
--> $DIR/newtypes.rs:116:5
76+
--> $DIR/newtypes.rs:113:5
13677
|
13778
LL | impl Trait for S {
13879
| ^^^^^^^^^^^^^^^^ `non_Self_return_type::S`
@@ -141,7 +82,7 @@ LL | impl Trait for W {
14182
| ^^^^^^^^^^^^^^^^ `non_Self_return_type::W`
14283

14384
error[E0308]: mismatched types
144-
--> $DIR/newtypes.rs:130:30
85+
--> $DIR/newtypes.rs:127:30
14586
|
14687
LL | reuse Trait::raw_S { self.0 }
14788
| ----- ^^^^^^ expected `&_`, found `()`
@@ -151,7 +92,7 @@ LL | reuse Trait::raw_S { self.0 }
15192
= note: expected reference `&_`
15293
found unit type `()`
15394
note: method defined here
154-
--> $DIR/newtypes.rs:112:12
95+
--> $DIR/newtypes.rs:109:12
15596
|
15697
LL | fn raw_S(&self) -> S { S }
15798
| ^^^^^ -----
@@ -161,7 +102,7 @@ LL | reuse Trait::raw_S { &self.0 }
161102
| +
162103

163104
error[E0308]: mismatched types
164-
--> $DIR/newtypes.rs:156:38
105+
--> $DIR/newtypes.rs:153:38
165106
|
166107
LL | reuse <F as Trait>::method { self.0 }
167108
| ------ ^^^^^^ expected `&F`, found `&S`
@@ -172,13 +113,13 @@ LL | reuse <F as Trait>::method { self.0 }
172113
= note: expected reference `&wrong_return_type::F`
173114
found reference `&wrong_return_type::S`
174115
note: method defined here
175-
--> $DIR/newtypes.rs:137:12
116+
--> $DIR/newtypes.rs:134:12
176117
|
177118
LL | fn method(&self) -> Self;
178119
| ^^^^^^ ----
179120

180121
error[E0308]: mismatched types
181-
--> $DIR/newtypes.rs:156:29
122+
--> $DIR/newtypes.rs:153:29
182123
|
183124
LL | reuse <F as Trait>::method { self.0 }
184125
| ^^^^^^
@@ -187,13 +128,13 @@ LL | reuse <F as Trait>::method { self.0 }
187128
| arguments to this function are incorrect
188129
|
189130
note: tuple struct defined here
190-
--> $DIR/newtypes.rs:154:12
131+
--> $DIR/newtypes.rs:151:12
191132
|
192133
LL | struct W(S);
193134
| ^
194135

195136
error[E0308]: mismatched types
196-
--> $DIR/newtypes.rs:160:29
137+
--> $DIR/newtypes.rs:157:29
197138
|
198139
LL | reuse <F as Trait>::r#static;
199140
| ^^^^^^^^
@@ -202,13 +143,13 @@ LL | reuse <F as Trait>::r#static;
202143
| arguments to this function are incorrect
203144
|
204145
note: tuple struct defined here
205-
--> $DIR/newtypes.rs:154:12
146+
--> $DIR/newtypes.rs:151:12
206147
|
207148
LL | struct W(S);
208149
| ^
209150

210151
error[E0308]: mismatched types
211-
--> $DIR/newtypes.rs:163:37
152+
--> $DIR/newtypes.rs:160:37
212153
|
213154
LL | reuse <F as Trait>::raw_S { self.0 }
214155
| ----- ^^^^^^ expected `&F`, found `&S`
@@ -218,13 +159,13 @@ LL | reuse <F as Trait>::raw_S { self.0 }
218159
= note: expected reference `&wrong_return_type::F`
219160
found reference `&wrong_return_type::S`
220161
note: method defined here
221-
--> $DIR/newtypes.rs:139:12
162+
--> $DIR/newtypes.rs:136:12
222163
|
223164
LL | fn raw_S(&self) -> S { S }
224165
| ^^^^^ -----
225166

226167
error[E0308]: mismatched types
227-
--> $DIR/newtypes.rs:189:31
168+
--> $DIR/newtypes.rs:186:31
228169
|
229170
LL | reuse Trait::method { F }
230171
| ------ ^ expected `&S`, found `&F`
@@ -235,12 +176,24 @@ LL | reuse Trait::method { F }
235176
= note: expected reference `&wrong_target_expression::S`
236177
found reference `&wrong_target_expression::F`
237178
note: method defined here
238-
--> $DIR/newtypes.rs:170:12
179+
--> $DIR/newtypes.rs:167:12
239180
|
240181
LL | fn method(&self) -> Self;
241182
| ^^^^^^ ----
242183

243-
error: aborting due to 15 previous errors
184+
warning: function cannot return without recursing
185+
--> $DIR/newtypes.rs:66:22
186+
|
187+
LL | reuse Trait::r#static;
188+
| ^^^^^^^^
189+
| |
190+
| cannot return without recursing
191+
| recursive call site
192+
|
193+
= help: a `loop` may express intention better if this is on purpose
194+
= note: `#[warn(unconditional_recursion)]` on by default
195+
196+
error: aborting due to 11 previous errors; 1 warning emitted
244197

245-
Some errors have detailed explanations: E0053, E0061, E0277, E0283, E0308.
246-
For more information about an error, try `rustc --explain E0053`.
198+
Some errors have detailed explanations: E0283, E0308.
199+
For more information about an error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)