2019-01-08 21:14:04 +00:00
error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
Support HIR wf checking for function signatures
During function type-checking, we normalize any associated types in
the function signature (argument types + return type), and then
create WF obligations for each of the normalized types. The HIR wf code
does not currently support this case, so any errors that we get have
imprecise spans.
This commit extends `ObligationCauseCode::WellFormed` to support
recording a function parameter, allowing us to get the corresponding
HIR type if an error occurs. Function typechecking is modified to
pass this information during signature normalization and WF checking.
The resulting code is fairly verbose, due to the fact that we can
no longer normalize the entire signature with a single function call.
As part of the refactoring, we now perform HIR-based WF checking
for several other 'typed items' (statics, consts, and inherent impls).
As a result, WF and projection errors in a function signature now
have a precise span, which points directly at the responsible type.
If a function signature is constructed via a macro, this will allow
the error message to point at the code 'most responsible' for the error
(e.g. a user-supplied macro argument).
2021-07-18 16:33:49 +00:00
--> $DIR/feature-gate-object_safe_for_dispatch.rs:18:39
2019-01-08 21:14:04 +00:00
|
2020-10-16 00:23:45 +00:00
LL | fn takes_non_object_safe_ref<T>(obj: &dyn NonObjectSafe1) {
Support HIR wf checking for function signatures
During function type-checking, we normalize any associated types in
the function signature (argument types + return type), and then
create WF obligations for each of the normalized types. The HIR wf code
does not currently support this case, so any errors that we get have
imprecise spans.
This commit extends `ObligationCauseCode::WellFormed` to support
recording a function parameter, allowing us to get the corresponding
HIR type if an error occurs. Function typechecking is modified to
pass this information during signature normalization and WF checking.
The resulting code is fairly verbose, due to the fact that we can
no longer normalize the entire signature with a single function call.
As part of the refactoring, we now perform HIR-based WF checking
for several other 'typed items' (statics, consts, and inherent impls).
As a result, WF and projection errors in a function signature now
have a precise span, which points directly at the responsible type.
If a function signature is constructed via a macro, this will allow
the error message to point at the code 'most responsible' for the error
(e.g. a user-supplied macro argument).
2021-07-18 16:33:49 +00:00
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe1` cannot be made into an object
2020-10-16 00:23:45 +00:00
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-object_safe_for_dispatch.rs:4:23
|
2020-01-19 22:53:37 +00:00
LL | trait NonObjectSafe1: Sized {}
2020-10-16 00:23:45 +00:00
| -------------- ^^^^^ ...because it requires `Self: Sized`
2020-02-01 00:47:00 +00:00
| |
| this trait cannot be made into an object...
2019-01-08 21:14:04 +00:00
error[E0038]: the trait `NonObjectSafe2` cannot be made into an object
2022-08-30 06:19:48 +00:00
--> $DIR/feature-gate-object_safe_for_dispatch.rs:22:45
2019-01-08 21:14:04 +00:00
|
2020-10-16 00:23:45 +00:00
LL | fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 {
2022-08-30 06:19:48 +00:00
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe2` cannot be made into an object
2020-10-16 00:23:45 +00:00
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-object_safe_for_dispatch.rs:7:8
|
2020-02-01 00:47:00 +00:00
LL | trait NonObjectSafe2 {
| -------------- this trait cannot be made into an object...
2019-01-08 21:14:04 +00:00
LL | fn static_fn() {}
2020-10-16 00:23:45 +00:00
| ^^^^^^^^^ ...because associated function `static_fn` has no `self` parameter
help: consider turning `static_fn` into a method by giving it a `&self` argument
2020-02-01 00:47:00 +00:00
|
2020-10-16 00:23:45 +00:00
LL | fn static_fn(&self) {}
2021-06-22 02:07:19 +00:00
| +++++
2020-10-16 00:23:45 +00:00
help: alternatively, consider constraining `static_fn` so it does not apply to trait objects
2020-02-01 02:48:35 +00:00
|
LL | fn static_fn() where Self: Sized {}
2021-06-22 02:07:19 +00:00
| +++++++++++++++++
2019-01-08 21:14:04 +00:00
error[E0038]: the trait `NonObjectSafe3` cannot be made into an object
Support HIR wf checking for function signatures
During function type-checking, we normalize any associated types in
the function signature (argument types + return type), and then
create WF obligations for each of the normalized types. The HIR wf code
does not currently support this case, so any errors that we get have
imprecise spans.
This commit extends `ObligationCauseCode::WellFormed` to support
recording a function parameter, allowing us to get the corresponding
HIR type if an error occurs. Function typechecking is modified to
pass this information during signature normalization and WF checking.
The resulting code is fairly verbose, due to the fact that we can
no longer normalize the entire signature with a single function call.
As part of the refactoring, we now perform HIR-based WF checking
for several other 'typed items' (statics, consts, and inherent impls).
As a result, WF and projection errors in a function signature now
have a precise span, which points directly at the responsible type.
If a function signature is constructed via a macro, this will allow
the error message to point at the code 'most responsible' for the error
(e.g. a user-supplied macro argument).
2021-07-18 16:33:49 +00:00
--> $DIR/feature-gate-object_safe_for_dispatch.rs:27:39
2019-01-08 21:14:04 +00:00
|
LL | fn takes_non_object_safe_box(obj: Box<dyn NonObjectSafe3>) {
Support HIR wf checking for function signatures
During function type-checking, we normalize any associated types in
the function signature (argument types + return type), and then
create WF obligations for each of the normalized types. The HIR wf code
does not currently support this case, so any errors that we get have
imprecise spans.
This commit extends `ObligationCauseCode::WellFormed` to support
recording a function parameter, allowing us to get the corresponding
HIR type if an error occurs. Function typechecking is modified to
pass this information during signature normalization and WF checking.
The resulting code is fairly verbose, due to the fact that we can
no longer normalize the entire signature with a single function call.
As part of the refactoring, we now perform HIR-based WF checking
for several other 'typed items' (statics, consts, and inherent impls).
As a result, WF and projection errors in a function signature now
have a precise span, which points directly at the responsible type.
If a function signature is constructed via a macro, this will allow
the error message to point at the code 'most responsible' for the error
(e.g. a user-supplied macro argument).
2021-07-18 16:33:49 +00:00
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe3` cannot be made into an object
2020-02-01 00:47:00 +00:00
|
2020-10-16 00:23:45 +00:00
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-object_safe_for_dispatch.rs:11:8
|
LL | trait NonObjectSafe3 {
| -------------- this trait cannot be made into an object...
LL | fn foo<T>(&self);
| ^^^ ...because method `foo` has generic type parameters
2021-09-12 18:49:56 +00:00
= help: consider moving `foo` to another trait
2019-01-08 21:14:04 +00:00
error[E0038]: the trait `NonObjectSafe4` cannot be made into an object
2022-08-30 06:19:48 +00:00
--> $DIR/feature-gate-object_safe_for_dispatch.rs:31:47
2019-01-08 21:14:04 +00:00
|
LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn NonObjectSafe4> {
2022-08-30 06:19:48 +00:00
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe4` cannot be made into an object
2020-02-01 00:47:00 +00:00
|
2020-10-16 00:23:45 +00:00
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
2021-03-08 23:43:18 +00:00
--> $DIR/feature-gate-object_safe_for_dispatch.rs:15:22
2020-10-16 00:23:45 +00:00
|
LL | trait NonObjectSafe4 {
| -------------- this trait cannot be made into an object...
2021-03-08 23:43:18 +00:00
LL | fn foo(&self, s: &Self);
| ^^^^^ ...because method `foo` references the `Self` type in this parameter
2021-09-12 18:49:56 +00:00
= help: consider moving `foo` to another trait
2019-01-08 21:14:04 +00:00
error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
2020-07-25 06:05:19 +00:00
--> $DIR/feature-gate-object_safe_for_dispatch.rs:38:16
2019-01-08 21:14:04 +00:00
|
2020-10-16 00:23:45 +00:00
LL | impl Trait for dyn NonObjectSafe1 {}
2020-10-20 00:57:18 +00:00
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe1` cannot be made into an object
2020-10-16 00:23:45 +00:00
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-object_safe_for_dispatch.rs:4:23
|
2020-01-19 22:53:37 +00:00
LL | trait NonObjectSafe1: Sized {}
2020-10-16 00:23:45 +00:00
| -------------- ^^^^^ ...because it requires `Self: Sized`
2020-02-01 00:47:00 +00:00
| |
| this trait cannot be made into an object...
2019-01-08 21:14:04 +00:00
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0038`.