Make ImplTraitPosition display more descriptive

This commit is contained in:
Michael Goulet 2024-01-07 02:41:28 +00:00
parent fde0e98247
commit 8af1a6a1e5
4 changed files with 26 additions and 26 deletions

View File

@ -329,24 +329,24 @@ impl std::fmt::Display for ImplTraitPosition {
ImplTraitPosition::AsyncBlock => "async blocks",
ImplTraitPosition::Bound => "bounds",
ImplTraitPosition::Generic => "generics",
ImplTraitPosition::ExternFnParam => "`extern fn` params",
ImplTraitPosition::ClosureParam => "closure params",
ImplTraitPosition::PointerParam => "`fn` pointer params",
ImplTraitPosition::FnTraitParam => "`Fn` trait params",
ImplTraitPosition::TraitParam => "trait method params",
ImplTraitPosition::ImplParam => "`impl` method params",
ImplTraitPosition::ExternFnParam => "`extern fn` parameters",
ImplTraitPosition::ClosureParam => "closure parameters",
ImplTraitPosition::PointerParam => "`fn` pointer parameters",
ImplTraitPosition::FnTraitParam => "the parameters of `Fn` trait bounds",
ImplTraitPosition::TraitParam => "trait method parameters",
ImplTraitPosition::ImplParam => "`impl` method parameters",
ImplTraitPosition::ExternFnReturn => "`extern fn` return types",
ImplTraitPosition::ClosureReturn => "closure return types",
ImplTraitPosition::PointerReturn => "`fn` pointer return types",
ImplTraitPosition::FnTraitReturn => "`Fn` trait return types",
ImplTraitPosition::FnTraitReturn => "the return types of `Fn` trait bounds",
ImplTraitPosition::GenericDefault => "generic parameter defaults",
ImplTraitPosition::ConstTy => "const types",
ImplTraitPosition::StaticTy => "static types",
ImplTraitPosition::AssocTy => "associated types",
ImplTraitPosition::FieldTy => "field types",
ImplTraitPosition::Cast => "cast types",
ImplTraitPosition::Cast => "cast expression types",
ImplTraitPosition::ImplSelf => "impl headers",
ImplTraitPosition::OffsetOf => "`offset_of!` params",
ImplTraitPosition::OffsetOf => "`offset_of!` parameters",
};
write!(f, "{name}")

View File

@ -1,6 +1,6 @@
fn f() -> impl Fn() -> impl Sized { || () }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
fn g() -> &'static dyn Fn() -> impl Sized { &|| () }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
fn main() {}

View File

@ -1,4 +1,4 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
--> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:1:24
|
LL | fn f() -> impl Fn() -> impl Sized { || () }
@ -7,7 +7,7 @@ LL | fn f() -> impl Fn() -> impl Sized { || () }
= note: see issue #99697 <https://github.com/rust-lang/rust/issues/99697> for more information
= help: add `#![feature(impl_trait_in_fn_trait_return)]` to the crate attributes to enable
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
--> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:3:32
|
LL | fn g() -> &'static dyn Fn() -> impl Sized { &|| () }

View File

@ -43,7 +43,7 @@ LL | type InReturnInTypeAlias<R> = fn() -> impl Debug;
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer params
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer parameters
--> $DIR/where-allowed.rs:18:40
|
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
LL | fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer params
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer parameters
--> $DIR/where-allowed.rs:26:38
|
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
LL | fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:34:49
|
LL | fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
--> $DIR/where-allowed.rs:38:51
|
LL | fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:42:55
|
LL | fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:49:51
|
LL | fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
--> $DIR/where-allowed.rs:54:53
|
LL | fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:58:57
|
LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:66:38
|
LL | fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
--> $DIR/where-allowed.rs:70:40
|
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
LL | InTupleVariant(impl Debug),
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `extern fn` params
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `extern fn` parameters
--> $DIR/where-allowed.rs:138:33
|
LL | fn in_foreign_parameters(_: impl Debug);
@ -205,13 +205,13 @@ error[E0562]: `impl Trait` only allowed in function and inherent method argument
LL | where T: PartialEq<impl Debug>
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:205:17
|
LL | where T: Fn(impl Debug)
| ^^^^^^^^^^
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait return types
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds
--> $DIR/where-allowed.rs:212:22
|
LL | where T: Fn() -> impl Debug