about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2017-11-19 11:25:35 -0800
committerZack M. Davis <code@zackmdavis.net>2018-01-06 17:15:59 -0800
commitaba56ddd05d821b6f0a3e5fc05bc47311e09051c (patch)
treec9c40e980387f5a32cc611e82e4da0df602d7ba7 /src/libstd
parent72176cf96cb79a0ebf62972b76dbe68c933bef4d (diff)
downloadrust-aba56ddd05d821b6f0a3e5fc05bc47311e09051c.tar.gz
rust-aba56ddd05d821b6f0a3e5fc05bc47311e09051c.zip
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 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.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/lib.rs2
-rw-r--r--src/libstd/path.rs1
2 files changed, 2 insertions, 1 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index 29ea87aaf78..0d4e310480d 100644
--- a/src/libstd/lib.rs
+++ b/src/libstd/lib.rs
@@ -229,7 +229,7 @@
 
 // Turn warnings into errors, but only after stage0, where it can be useful for
 // code to emit warnings during language transitions
-#![deny(warnings)]
+#![cfg_attr(not(stage0), deny(warnings))]
 
 // std may use features in a platform-specific way
 #![allow(unused_features)]
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index bed9efcb846..6328e4a8447 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -1702,6 +1702,7 @@ impl Path {
     /// let path_buf = Path::new("foo.txt").to_path_buf();
     /// assert_eq!(path_buf, std::path::PathBuf::from("foo.txt"));
     /// ```
+    #[rustc_conversion_suggestion]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn to_path_buf(&self) -> PathBuf {
         PathBuf::from(self.inner.to_os_string())