diff options
| author | bors <bors@rust-lang.org> | 2018-01-13 02:15:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-01-13 02:15:19 +0000 |
| commit | 6eff103aa1f93cbc07b1e5684e695635993c9752 (patch) | |
| tree | da7339b6774264455794dc563c202f45f7031479 /src/liballoc | |
| parent | 51b0b3734cbd0ca58c8be3512d53fce2d95f40dd (diff) | |
| parent | aba56ddd05d821b6f0a3e5fc05bc47311e09051c (diff) | |
| download | rust-6eff103aa1f93cbc07b1e5684e695635993c9752.tar.gz rust-6eff103aa1f93cbc07b1e5684e695635993c9752.zip | |
Auto merge of #46461 - zackmdavis:elemental_method_suggestion_jamboree, r=estebank
type error method suggestions use whitelisted identity-like conversions  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 pretty and good for RLS and friends. 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.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/slice.rs | 1 | ||||
| -rw-r--r-- | src/liballoc/string.rs | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 28caccbc87f..2c7bdc427ea 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -1624,6 +1624,7 @@ impl<T> [T] { /// let x = s.to_vec(); /// // Here, `s` and `x` can be modified independently. /// ``` + #[rustc_conversion_suggestion] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn to_vec(&self) -> Vec<T> diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index ca493ab27e3..8d99d0bc8f4 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2034,6 +2034,7 @@ pub trait ToString { /// /// assert_eq!(five, i.to_string()); /// ``` + #[rustc_conversion_suggestion] #[stable(feature = "rust1", since = "1.0.0")] fn to_string(&self) -> String; } |
