2024-10-04 09:10:28 -05:00
error[E0782]: expected a type, found a trait
2021-03-16 15:47:06 -05:00
--> $DIR/dyn-2021-edition-error.rs:3:17
|
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
2021-03-19 04:18:22 -05:00
| ^^^^^^^^^
|
2024-07-13 10:49:14 -05:00
help: use a new generic type parameter, constrained by `SomeTrait`
|
LL | fn function<T: SomeTrait>(x: &T, y: Box<SomeTrait>) {
| ++++++++++++++ ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
|
LL | fn function(x: &impl SomeTrait, y: Box<SomeTrait>) {
| ++++
help: alternatively, use a trait object to accept any type that implements `SomeTrait`, accessing its methods at runtime using dynamic dispatch
2021-03-19 04:18:22 -05:00
|
2022-09-11 14:19:07 -05:00
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
| +++
2021-03-16 15:47:06 -05:00
2024-10-04 09:10:28 -05:00
error[E0782]: expected a type, found a trait
2021-03-16 15:47:06 -05:00
--> $DIR/dyn-2021-edition-error.rs:3:35
|
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
2021-03-19 04:18:22 -05:00
| ^^^^^^^^^
|
2024-10-04 09:10:28 -05:00
help: you can add the `dyn` keyword if you want a trait object
2021-03-19 04:18:22 -05:00
|
2022-09-11 14:19:07 -05:00
LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
| +++
2021-03-16 15:47:06 -05:00
2024-10-04 09:10:28 -05:00
error[E0782]: expected a type, found a trait
2023-10-31 08:45:26 -05:00
--> $DIR/dyn-2021-edition-error.rs:6:14
|
LL | let _x: &SomeTrait = todo!();
| ^^^^^^^^^
|
2024-10-04 09:10:28 -05:00
help: you can add the `dyn` keyword if you want a trait object
2023-10-31 08:45:26 -05:00
|
LL | let _x: &dyn SomeTrait = todo!();
| +++
error: aborting due to 3 previous errors
2021-03-16 15:47:06 -05:00
For more information about this error, try `rustc --explain E0782`.