Stream: t-compiler/help

Topic: finding impl's for better suggestions

Samrat Man Singh (Apr 29 2020 at 17:46, on Zulip):

Hi, I'm working on issue #71580 to suggest into() instead of try_into() if possible. In the thread there Jonas suggested looking for the impl(eg. impl Into<isize> from i16) as a way to have a more robust mechanism to do this.

I'm a bit stumped on how I can go about finding the impl. From Jonas's comment it seems I can achieve this by using rustc_trait_selection::traits::SelectionContext::select, however I'm not entirely sure how I can construct an Obligation to pass.

I'd appreaciate any advice on how I can proceed with SelectionContext, or alternative ways

eddyb (May 01 2020 at 04:58, on Zulip):

@Samrat Man Singh that is the (only) way, and the obligation is just a predicate (which will be your X: Into<Y>) and a "cause" - if you're not going to report an error from this lookup (which diagnostics wouldn't), you can use a dummy cause

eddyb (May 01 2020 at 05:01, on Zulip):

@Samrat Man Singh there's also the predicate_for_trait_def helper function but idk how often it's used

eddyb (May 01 2020 at 05:01, on Zulip):

/me is looking at

Philipp Hansch (May 01 2020 at 06:41, on Zulip):

In Clippy we have a small helper using predicate_for_trait_def:

Philipp Hansch (May 01 2020 at 06:42, on Zulip):

ah this is about finding impls, not traits

Last update: Sep 28 2020 at 16:45UTC