Skip to content

Commit 3e857f5

Browse files
committed
Improve impl trait disallowed context error text
1 parent e0745e8 commit 3e857f5

10 files changed

+100
-100
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14661466
t.span,
14671467
E0562,
14681468
"`impl Trait` not allowed outside of {}",
1469-
"function and inherent method return types",
1469+
"function and method return types",
14701470
);
14711471
err.emit();
14721472
hir::TyKind::Err

src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ fn _rpit_dyn() -> Box<dyn Tr1<As1: Copy>> { Box::new(S1) }
5757

5858
const _cdef: impl Tr1<As1: Copy> = S1;
5959
//~^ ERROR associated type bounds are unstable
60-
//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562]
60+
//~| ERROR `impl Trait` not allowed outside of function and method return types [E0562]
6161
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
6262
// const _cdef_dyn: &dyn Tr1<As1: Copy> = &S1;
6363

6464
static _sdef: impl Tr1<As1: Copy> = S1;
6565
//~^ ERROR associated type bounds are unstable
66-
//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562]
66+
//~| ERROR `impl Trait` not allowed outside of function and method return types [E0562]
6767
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
6868
// static _sdef_dyn: &dyn Tr1<As1: Copy> = &S1;
6969

7070
fn main() {
7171
let _: impl Tr1<As1: Copy> = S1;
7272
//~^ ERROR associated type bounds are unstable
73-
//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562]
73+
//~| ERROR `impl Trait` not allowed outside of function and method return types [E0562]
7474
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
7575
// let _: &dyn Tr1<As1: Copy> = &S1;
7676
}

src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ LL | let _: impl Tr1<As1: Copy> = S1;
115115
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
116116
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
117117

118-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
118+
error[E0562]: `impl Trait` not allowed outside of function and method return types
119119
--> $DIR/feature-gate-associated_type_bounds.rs:58:14
120120
|
121121
LL | const _cdef: impl Tr1<As1: Copy> = S1;
122122
| ^^^^^^^^^^^^^^^^^^^
123123

124-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
124+
error[E0562]: `impl Trait` not allowed outside of function and method return types
125125
--> $DIR/feature-gate-associated_type_bounds.rs:64:15
126126
|
127127
LL | static _sdef: impl Tr1<As1: Copy> = S1;
128128
| ^^^^^^^^^^^^^^^^^^^
129129

130-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
130+
error[E0562]: `impl Trait` not allowed outside of function and method return types
131131
--> $DIR/feature-gate-associated_type_bounds.rs:71:12
132132
|
133133
LL | let _: impl Tr1<As1: Copy> = S1;

src/test/ui/feature-gates/feature-gate-min_type_alias_impl_trait.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ LL | type Baa = (Vec<impl Debug>, impl Debug, impl Iterator<Item = impl Debu
106106
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
107107
= help: add `#![feature(min_type_alias_impl_trait)]` to the crate attributes to enable
108108

109-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
109+
error[E0562]: `impl Trait` not allowed outside of function and method return types
110110
--> $DIR/feature-gate-min_type_alias_impl_trait.rs:23:18
111111
|
112112
LL | type Assoc = impl Debug;

src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
struct Foo<T = impl Copy>(T);
2-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
2+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
33

44
type Result<T, E = impl std::error::Error> = std::result::Result<T, E>;
5-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
5+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
66

77
// should not cause ICE
88
fn x() -> Foo {

src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
22
--> $DIR/issue-83929-impl-trait-in-generic-default.rs:1:16
33
|
44
LL | struct Foo<T = impl Copy>(T);
55
| ^^^^^^^^^
66

7-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
7+
error[E0562]: `impl Trait` not allowed outside of function and method return types
88
--> $DIR/issue-83929-impl-trait-in-generic-default.rs:4:20
99
|
1010
LL | type Result<T, E = impl std::error::Error> = std::result::Result<T, E>;

src/test/ui/impl-trait/nested_impl_trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
3434
| | nested `impl Trait` here
3535
| outer `impl Trait`
3636

37-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
37+
error[E0562]: `impl Trait` not allowed outside of function and method return types
3838
--> $DIR/nested_impl_trait.rs:8:32
3939
|
4040
LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
4141
| ^^^^^^^^^^^^^^^^^^^^^
4242

43-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
43+
error[E0562]: `impl Trait` not allowed outside of function and method return types
4444
--> $DIR/nested_impl_trait.rs:25:42
4545
|
4646
LL | fn allowed_in_ret_type() -> impl Fn() -> impl Into<u32> {

src/test/ui/impl-trait/where-allowed.rs

+41-41
Original file line numberDiff line numberDiff line change
@@ -13,61 +13,61 @@ fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() }
1313

1414
// Disallowed
1515
fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
16-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
16+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
1717

1818
// Disallowed
1919
fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
20-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
20+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
2121

2222
// Disallowed
2323
fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() }
24-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
24+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
2525

2626
// Disallowed
2727
fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
28-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
28+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
2929

3030
// Disallowed
3131
fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
32-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
32+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
3333

3434
// Disallowed
3535
fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
36-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
36+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
3737

3838
// Disallowed
3939
fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
40-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
40+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
4141

4242
// Disallowed
4343
fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() }
44-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
44+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
4545

4646
// Disallowed
4747
fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
48-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
48+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
4949
//~^^ ERROR nested `impl Trait` is not allowed
5050

5151
// Disallowed
5252
fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
53-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
53+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
5454

5555
// Disallowed
5656
fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
57-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
57+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
5858
//~| ERROR nested `impl Trait` is not allowed
5959

6060
// Disallowed
6161
fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() }
62-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
62+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
6363

6464
// Disallowed
6565
fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
66-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
66+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
6767

6868
// Disallowed
6969
fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() }
70-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
70+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
7171

7272

7373
// Allowed
@@ -80,22 +80,22 @@ fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> {
8080

8181
// Disallowed
8282
struct InBraceStructField { x: impl Debug }
83-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
83+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
8484

8585
// Disallowed
8686
struct InAdtInBraceStructField { x: Vec<impl Debug> }
87-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
87+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
8888

8989
// Disallowed
9090
struct InTupleStructField(impl Debug);
91-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
91+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
9292

9393
// Disallowed
9494
enum InEnum {
9595
InBraceVariant { x: impl Debug },
96-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
96+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
9797
InTupleVariant(impl Debug),
98-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
98+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
9999
}
100100

101101
// Allowed
@@ -106,7 +106,7 @@ trait InTraitDefnParameters {
106106
// Disallowed
107107
trait InTraitDefnReturn {
108108
fn in_return() -> impl Debug;
109-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
109+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
110110
}
111111

112112
// Allowed and disallowed in trait impls
@@ -123,7 +123,7 @@ impl DummyTrait for () {
123123
// Allowed
124124

125125
fn in_trait_impl_return() -> impl Debug { () }
126-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
126+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
127127
}
128128

129129
// Allowed
@@ -136,10 +136,10 @@ impl DummyType {
136136
// Disallowed
137137
extern "C" {
138138
fn in_foreign_parameters(_: impl Debug);
139-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
139+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
140140

141141
fn in_foreign_return() -> impl Debug;
142-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
142+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
143143
}
144144

145145
// Allowed
@@ -155,96 +155,96 @@ type InTypeAlias<R> = impl Debug;
155155
//~^ ERROR `impl Trait` in type aliases is unstable
156156

157157
type InReturnInTypeAlias<R> = fn() -> impl Debug;
158-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
158+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
159159
//~| ERROR `impl Trait` in type aliases is unstable
160160

161161
// Disallowed in impl headers
162162
impl PartialEq<impl Debug> for () {
163-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
163+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
164164
}
165165

166166
// Disallowed in impl headers
167167
impl PartialEq<()> for impl Debug {
168-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
168+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
169169
}
170170

171171
// Disallowed in inherent impls
172172
impl impl Debug {
173-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
173+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
174174
}
175175

176176
// Disallowed in inherent impls
177177
struct InInherentImplAdt<T> { t: T }
178178
impl InInherentImplAdt<impl Debug> {
179-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
179+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
180180
}
181181

182182
// Disallowed in where clauses
183183
fn in_fn_where_clause()
184184
where impl Debug: Debug
185-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
185+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
186186
{
187187
}
188188

189189
// Disallowed in where clauses
190190
fn in_adt_in_fn_where_clause()
191191
where Vec<impl Debug>: Debug
192-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
192+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
193193
{
194194
}
195195

196196
// Disallowed
197197
fn in_trait_parameter_in_fn_where_clause<T>()
198198
where T: PartialEq<impl Debug>
199-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
199+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
200200
{
201201
}
202202

203203
// Disallowed
204204
fn in_Fn_parameter_in_fn_where_clause<T>()
205205
where T: Fn(impl Debug)
206-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
206+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
207207
{
208208
}
209209

210210
// Disallowed
211211
fn in_Fn_return_in_fn_where_clause<T>()
212212
where T: Fn() -> impl Debug
213-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
213+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
214214
{
215215
}
216216

217217
// Disallowed
218218
struct InStructGenericParamDefault<T = impl Debug>(T);
219-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
219+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
220220

221221
// Disallowed
222222
enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) }
223-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
223+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
224224

225225
// Disallowed
226226
trait InTraitGenericParamDefault<T = impl Debug> {}
227-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
227+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
228228

229229
// Disallowed
230230
type InTypeAliasGenericParamDefault<T = impl Debug> = T;
231-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
231+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
232232

233233
// Disallowed
234234
impl <T = impl Debug> T {}
235235
//~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
236236
//~| WARNING this was previously accepted by the compiler but is being phased out
237-
//~| ERROR `impl Trait` not allowed outside of function and inherent method return types
237+
//~| ERROR `impl Trait` not allowed outside of function and method return types
238238

239239
// Disallowed
240240
fn in_method_generic_param_default<T = impl Debug>(_: T) {}
241241
//~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
242242
//~| WARNING this was previously accepted by the compiler but is being phased out
243-
//~| ERROR `impl Trait` not allowed outside of function and inherent method return types
243+
//~| ERROR `impl Trait` not allowed outside of function and method return types
244244

245245
fn main() {
246246
let _in_local_variable: impl Fn() = || {};
247-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
247+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
248248
let _in_return_in_local_variable = || -> impl Fn() { || {} };
249-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
249+
//~^ ERROR `impl Trait` not allowed outside of function and method return types
250250
}

0 commit comments

Comments
 (0)