From aba56ddd05d821b6f0a3e5fc05bc47311e09051c Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sun, 19 Nov 2017 11:25:35 -0800 Subject: type error method suggestions use whitelisted identity-like conversions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, on a type mismatch (and if this wasn't preƫmpted by a higher-priority suggestion), we would look for argumentless methods returning the expected type, and list them in a `help` note. This had two major shortcomings. Firstly, a lot of the suggestions didn't really make sense (if you used a &str where a String was expected, `.to_ascii_uppercase()` is probably not the solution you were hoping for). Secondly, we weren't generating suggestions from the most useful traits! We address the first problem with an internal `#[rustc_conversion_suggestion]` attribute meant to mark methods that keep the "same value" in the relevant sense, just converting the type. We address the second problem by making `FnCtxt.probe_for_return_type` pass the `ProbeScope::AllTraits` to `probe_op`: this would seem to be safe because grep reveals no other callers of `probe_for_return_type`. Also, structured suggestions are preferred (because they're pretty, but also for RLS and friends). Also also, we make the E0055 autoderef recursion limit error use the one-time-diagnostics set, because we can potentially hit the limit a lot during probing. (Without this, test/ui/did_you_mean/recursion_limit_deref.rs would report "aborting due to 51 errors"). Unfortunately, the trait probing is still not all one would hope for: at a minimum, we don't know how to rule out `into()` in cases where it wouldn't actually work, and we don't know how to rule in `.to_owned()` where it would. Issues #46459 and #46460 have been filed and are ref'd in a FIXME. This is hoped to resolve #42929, #44672, and #45777. --- src/test/ui/span/coerce-suggestions.stderr | 8 ++++---- src/test/ui/span/issue-34264.stderr | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/test/ui/span') diff --git a/src/test/ui/span/coerce-suggestions.stderr b/src/test/ui/span/coerce-suggestions.stderr index 07852619765..06f0e6ec228 100644 --- a/src/test/ui/span/coerce-suggestions.stderr +++ b/src/test/ui/span/coerce-suggestions.stderr @@ -6,9 +6,6 @@ error[E0308]: mismatched types | = note: expected type `usize` found type `std::string::String` - = help: here are some functions which might fulfill your needs: - - .capacity() - - .len() error[E0308]: mismatched types --> $DIR/coerce-suggestions.rs:19:19 @@ -44,7 +41,10 @@ error[E0308]: mismatched types --> $DIR/coerce-suggestions.rs:27:9 | 27 | f = box f; - | ^^^^^ cyclic type of infinite size + | ^^^^^ + | | + | cyclic type of infinite size + | help: try using a conversion method: `box f.to_string()` error[E0308]: mismatched types --> $DIR/coerce-suggestions.rs:31:9 diff --git a/src/test/ui/span/issue-34264.stderr b/src/test/ui/span/issue-34264.stderr index 3794d6ba2de..18860a7456e 100644 --- a/src/test/ui/span/issue-34264.stderr +++ b/src/test/ui/span/issue-34264.stderr @@ -33,8 +33,6 @@ error[E0308]: mismatched types | = note: expected type `usize` found type `&'static str` - = help: here are some functions which might fulfill your needs: - - .len() error[E0061]: this function takes 2 parameters but 3 parameters were supplied --> $DIR/issue-34264.rs:20:5 -- cgit 1.4.1-3-g733a5