From ac3290e8d949448193014c85096f8772db331d46 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Sun, 17 Mar 2019 22:42:51 -0700 Subject: Add suggestion to use `&*var` when `&str: From` is expected --- src/libcore/convert.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/libcore') diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 774d648558b..cb574a53dbc 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -352,6 +352,12 @@ pub trait Into: Sized { /// [`from`]: trait.From.html#tymethod.from /// [book]: ../../book/ch09-00-error-handling.html #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_on_unimplemented( + on( + all(_Self="&str", T="std::string::String"), + note="you can coerce a `{T}` into a `{Self}` by writing `&*variable`" + ) +)] pub trait From: Sized { /// Performs the conversion. #[stable(feature = "rust1", since = "1.0.0")] -- cgit 1.4.1-3-g733a5 From e929d19edc99e5eb7af319709247470cff99719b Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Fri, 22 Mar 2019 20:38:09 -0700 Subject: review comments --- src/libcore/convert.rs | 2 +- src/test/ui/suggestions/into-str.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index cb574a53dbc..d36de3bbe86 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -355,7 +355,7 @@ pub trait Into: Sized { #[rustc_on_unimplemented( on( all(_Self="&str", T="std::string::String"), - note="you can coerce a `{T}` into a `{Self}` by writing `&*variable`" + note="to coerce a `{T}` into a `{Self}`, use `&*` as a prefix", ) )] pub trait From: Sized { diff --git a/src/test/ui/suggestions/into-str.stderr b/src/test/ui/suggestions/into-str.stderr index f341d363702..3e28700ce95 100644 --- a/src/test/ui/suggestions/into-str.stderr +++ b/src/test/ui/suggestions/into-str.stderr @@ -4,7 +4,7 @@ error[E0277]: the trait bound `&str: std::convert::From` is LL | foo(String::new()); | ^^^ the trait `std::convert::From` is not implemented for `&str` | - = note: you can coerce a `std::string::String` into a `&str` by writing `&*variable` + = note: to coerce a `std::string::String` into a `&str`, use `&*` as a prefix = note: required because of the requirements on the impl of `std::convert::Into<&str>` for `std::string::String` note: required by `foo` --> $DIR/into-str.rs:1:1 -- cgit 1.4.1-3-g733a5