Open jamesmunns opened 3 weeks ago
diagnostic::on_unimplemented
does not current work for borrow checker errors, for the record. Just trait errors. Borrowck happens after trait selection, where we currently lack the necessary information to currently issue on-unimplemented errors.
@Dirbaio suggested this might just be a limitation of the trait solver:
when checking
&'a Example: SecretStatic
, the trait solver goes "okay there's an applicable impl,impl<T: 'static> SecretStatic for T
, i'm going to use that one", and emits a lifetime constraint'a: 'static
that gets checked and fails later
Would it make sense to track where the lifetime constraint "comes from" so that borrowck can emit the diagnostic if it came from that impl? (Or maybe it should be new kind of custom diagnostic `#[on_lifetime_error]
, because I imagine this can apply to more situations than trait impls)
Would it make sense to track where the lifetime constraint "comes from" so that borrowck can emit the diagnostic if it came from that impl?
I fear this would be quite difficult to do given how we track lifetime constraints, particularly due to NLL.
Or maybe it should be new kind of custom diagnostic
`#[on_lifetime_error]
, because I imagine this can apply to more situations than trait impls
Yeah, I think so. This isn't really an "unimplemented trait" per se, because lifetimes don't affect trait selection (mostly lol).
Code
Current output
Desired output
Rationale and extra context
We want to use a marker trait in macro expanded code for the embassy executor so that all arguments to tasks are 'static. This is a limitation of the executor, and is a common stumbling block for users.
We wanted to use diagnostics for this to reduce the amount of work required in a proc macro to get good spans and errors, but noticed that diagnostics did not fire at all. They DO fire when we manually add impls for the type instead of using a blanket impl (this is not practical to support for arbitrary user types
Other cases
No response
Rust Version
Tested with 1.81.0 stable and 1.82.0-beta.6, same output
Anything else?
No response