Closed
Description
We want to allow rustc_on_unimplemented
to check arbitrary type conditions to make the error message depend on the input types. The sanest way to do that is to allow conditioning on traits. For example, for #42526 we want something like:
trait IsNoneError {}
impl IsNoneError for NoneError {}
#[rustc_on_unimplemented(
on(all(from_method="from",
from_desugaring="?",
matches("IsNoneError", Self="T")),
message="can't use Try on Option in a function returning Result")
)]
trait From<T> {
// ...
}
The syntax I prefer is matches("TRAIT_NAME", Self="SELF_NAME", "PARAM_1_NAME", ..)
where TRAIT_NAME
and SELF_NAME
are mandatory, but probably any syntax can work (this is all feature gated under the rustc_on_unimplemented
attribute, so we can experiment).
At least for now, we can limit the parameters to be type parameters from our generics - the on_unimplemented
code already knows how to look these up. You can use these to implement anything you like with the proper trait bound.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsCategory: An issue proposing an enhancement or a PR with one.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Relevant to the compiler team, which will review and decide on the PR/issue.Working group: Diagnostics