Skip to content

Commit 8af1a6a

Browse files
committedJan 7, 2024
Make ImplTraitPosition display more descriptive
1 parent fde0e98 commit 8af1a6a

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed
 

‎compiler/rustc_ast_lowering/src/lib.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -329,24 +329,24 @@ impl std::fmt::Display for ImplTraitPosition {
329329
ImplTraitPosition::AsyncBlock => "async blocks",
330330
ImplTraitPosition::Bound => "bounds",
331331
ImplTraitPosition::Generic => "generics",
332-
ImplTraitPosition::ExternFnParam => "`extern fn` params",
333-
ImplTraitPosition::ClosureParam => "closure params",
334-
ImplTraitPosition::PointerParam => "`fn` pointer params",
335-
ImplTraitPosition::FnTraitParam => "`Fn` trait params",
336-
ImplTraitPosition::TraitParam => "trait method params",
337-
ImplTraitPosition::ImplParam => "`impl` method params",
332+
ImplTraitPosition::ExternFnParam => "`extern fn` parameters",
333+
ImplTraitPosition::ClosureParam => "closure parameters",
334+
ImplTraitPosition::PointerParam => "`fn` pointer parameters",
335+
ImplTraitPosition::FnTraitParam => "the parameters of `Fn` trait bounds",
336+
ImplTraitPosition::TraitParam => "trait method parameters",
337+
ImplTraitPosition::ImplParam => "`impl` method parameters",
338338
ImplTraitPosition::ExternFnReturn => "`extern fn` return types",
339339
ImplTraitPosition::ClosureReturn => "closure return types",
340340
ImplTraitPosition::PointerReturn => "`fn` pointer return types",
341-
ImplTraitPosition::FnTraitReturn => "`Fn` trait return types",
341+
ImplTraitPosition::FnTraitReturn => "the return types of `Fn` trait bounds",
342342
ImplTraitPosition::GenericDefault => "generic parameter defaults",
343343
ImplTraitPosition::ConstTy => "const types",
344344
ImplTraitPosition::StaticTy => "static types",
345345
ImplTraitPosition::AssocTy => "associated types",
346346
ImplTraitPosition::FieldTy => "field types",
347-
ImplTraitPosition::Cast => "cast types",
347+
ImplTraitPosition::Cast => "cast expression types",
348348
ImplTraitPosition::ImplSelf => "impl headers",
349-
ImplTraitPosition::OffsetOf => "`offset_of!` params",
349+
ImplTraitPosition::OffsetOf => "`offset_of!` parameters",
350350
};
351351

352352
write!(f, "{name}")
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn f() -> impl Fn() -> impl Sized { || () }
2-
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return
2+
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
33
fn g() -> &'static dyn Fn() -> impl Sized { &|| () }
4-
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return
4+
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
55

66
fn main() {}

‎tests/ui/feature-gates/feature-gate-impl_trait_in_fn_trait_return.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
1+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
22
--> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:1:24
33
|
44
LL | fn f() -> impl Fn() -> impl Sized { || () }
@@ -7,7 +7,7 @@ LL | fn f() -> impl Fn() -> impl Sized { || () }
77
= note: see issue #99697 <https://github.com/rust-lang/rust/issues/99697> for more information
88
= help: add `#![feature(impl_trait_in_fn_trait_return)]` to the crate attributes to enable
99

10-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
10+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
1111
--> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:3:32
1212
|
1313
LL | fn g() -> &'static dyn Fn() -> impl Sized { &|| () }

‎tests/ui/impl-trait/where-allowed.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ LL | type InReturnInTypeAlias<R> = fn() -> impl Debug;
4343
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
4444
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
4545

46-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer params
46+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer parameters
4747
--> $DIR/where-allowed.rs:18:40
4848
|
4949
LL | fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
@@ -55,7 +55,7 @@ error[E0562]: `impl Trait` only allowed in function and inherent method argument
5555
LL | fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
5656
| ^^^^^^^^^^
5757

58-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer params
58+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer parameters
5959
--> $DIR/where-allowed.rs:26:38
6060
|
6161
LL | fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() }
@@ -67,49 +67,49 @@ error[E0562]: `impl Trait` only allowed in function and inherent method argument
6767
LL | fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
6868
| ^^^^^^^^^^
6969

70-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
70+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
7171
--> $DIR/where-allowed.rs:34:49
7272
|
7373
LL | fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
7474
| ^^^^^^^^^^
7575

76-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
76+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
7777
--> $DIR/where-allowed.rs:38:51
7878
|
7979
LL | fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
8080
| ^^^^^^^^^^
8181

82-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
82+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
8383
--> $DIR/where-allowed.rs:42:55
8484
|
8585
LL | fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
8686
| ^^^^^^^^^^
8787

88-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
88+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
8989
--> $DIR/where-allowed.rs:49:51
9090
|
9191
LL | fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
9292
| ^^^^^^^^^^
9393

94-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
94+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
9595
--> $DIR/where-allowed.rs:54:53
9696
|
9797
LL | fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
9898
| ^^^^^^^^^^
9999

100-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
100+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
101101
--> $DIR/where-allowed.rs:58:57
102102
|
103103
LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
104104
| ^^^^^^^^^^
105105

106-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
106+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
107107
--> $DIR/where-allowed.rs:66:38
108108
|
109109
LL | fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
110110
| ^^^^^^^^^^
111111

112-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
112+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
113113
--> $DIR/where-allowed.rs:70:40
114114
|
115115
LL | fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() }
@@ -145,7 +145,7 @@ error[E0562]: `impl Trait` only allowed in function and inherent method argument
145145
LL | InTupleVariant(impl Debug),
146146
| ^^^^^^^^^^
147147

148-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `extern fn` params
148+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `extern fn` parameters
149149
--> $DIR/where-allowed.rs:138:33
150150
|
151151
LL | fn in_foreign_parameters(_: impl Debug);
@@ -205,13 +205,13 @@ error[E0562]: `impl Trait` only allowed in function and inherent method argument
205205
LL | where T: PartialEq<impl Debug>
206206
| ^^^^^^^^^^
207207

208-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
208+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
209209
--> $DIR/where-allowed.rs:205:17
210210
|
211211
LL | where T: Fn(impl Debug)
212212
| ^^^^^^^^^^
213213

214-
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
214+
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
215215
--> $DIR/where-allowed.rs:212:22
216216
|
217217
LL | where T: Fn() -> impl Debug

0 commit comments

Comments
 (0)