From 47cc221e9827ab1b92f20353f423916a3f14d182 Mon Sep 17 00:00:00 2001 From: csmoe Date: Fri, 22 May 2020 10:11:17 +0800 Subject: [PATCH 1/3] add mcve for issue 72442 --- src/test/ui/async-await/issue-72442.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/test/ui/async-await/issue-72442.rs diff --git a/src/test/ui/async-await/issue-72442.rs b/src/test/ui/async-await/issue-72442.rs new file mode 100644 index 0000000000000..cced1da48f693 --- /dev/null +++ b/src/test/ui/async-await/issue-72442.rs @@ -0,0 +1,25 @@ +// edition:2018 + +use std::fs::File; +use std::future::Future; +use std::io::prelude::*; + +fn main() -> Result<(), Box> { + block_on(async { + { + let path = std::path::Path::new("."); + let mut f = File::open(path.to_str())?; + //~^ ERROR the trait bound `std::option::Option<&str>: std::convert::AsRef` is not satisfied + let mut src = String::new(); + f.read_to_string(&mut src)?; + Ok(()) + } + }) +} + +fn block_on(f: F) -> F::Output +where + F: Future>>, +{ + Ok(()) +} From 7cdc8972342e8f4946b518ac4886079f604cf2c1 Mon Sep 17 00:00:00 2001 From: csmoe Date: Fri, 22 May 2020 10:11:52 +0800 Subject: [PATCH 2/3] only try to suggest for try trait_ref --- src/libcore/ops/try.rs | 1 + src/librustc_hir/lang_items.rs | 2 ++ src/librustc_trait_selection/traits/error_reporting/mod.rs | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libcore/ops/try.rs b/src/libcore/ops/try.rs index 996a01d413cbc..e15ea11569f34 100644 --- a/src/libcore/ops/try.rs +++ b/src/libcore/ops/try.rs @@ -25,6 +25,7 @@ ) )] #[doc(alias = "?")] +#[cfg_attr(not(bootstrap), lang = "try")] pub trait Try { /// The type of this value when viewed as successful. #[unstable(feature = "try_trait", issue = "42327")] diff --git a/src/librustc_hir/lang_items.rs b/src/librustc_hir/lang_items.rs index 53f72804a848d..8921cc0c99dca 100644 --- a/src/librustc_hir/lang_items.rs +++ b/src/librustc_hir/lang_items.rs @@ -256,4 +256,6 @@ language_item_table! { AlignOffsetLangItem, "align_offset", align_offset_fn, Target::Fn; TerminationTraitLangItem, "termination", termination, Target::Trait; + + TryTraitLangItem, "try", try_trait, Target::Trait; } diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index 139b860072224..f18a417cccd05 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -402,7 +402,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { self.suggest_remove_reference(&obligation, &mut err, &trait_ref); self.suggest_semicolon_removal(&obligation, &mut err, span, &trait_ref); self.note_version_mismatch(&mut err, &trait_ref); - self.suggest_await_before_try(&mut err, &obligation, &trait_ref, span); + + if Some(trait_ref.def_id()) == tcx.lang_items().try_trait() { + self.suggest_await_before_try(&mut err, &obligation, &trait_ref, span); + } + if self.suggest_impl_trait(&mut err, span, &obligation, &trait_ref) { err.emit(); return; From 16ba3e129d5d37c63b7000fcd4b52261e7f1c4f1 Mon Sep 17 00:00:00 2001 From: csmoe Date: Fri, 22 May 2020 10:12:03 +0800 Subject: [PATCH 3/3] bless issue-72442 --- src/test/ui/async-await/issue-72442.rs | 3 ++- src/test/ui/async-await/issue-72442.stderr | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/async-await/issue-72442.stderr diff --git a/src/test/ui/async-await/issue-72442.rs b/src/test/ui/async-await/issue-72442.rs index cced1da48f693..61c8c8c1594d3 100644 --- a/src/test/ui/async-await/issue-72442.rs +++ b/src/test/ui/async-await/issue-72442.rs @@ -1,4 +1,5 @@ // edition:2018 +// compile-flags:-Cincremental=tmp/issue-72442 use std::fs::File; use std::future::Future; @@ -9,7 +10,7 @@ fn main() -> Result<(), Box> { { let path = std::path::Path::new("."); let mut f = File::open(path.to_str())?; - //~^ ERROR the trait bound `std::option::Option<&str>: std::convert::AsRef` is not satisfied + //~^ ERROR the trait bound let mut src = String::new(); f.read_to_string(&mut src)?; Ok(()) diff --git a/src/test/ui/async-await/issue-72442.stderr b/src/test/ui/async-await/issue-72442.stderr new file mode 100644 index 0000000000000..5685433357871 --- /dev/null +++ b/src/test/ui/async-await/issue-72442.stderr @@ -0,0 +1,14 @@ +error[E0277]: the trait bound `std::option::Option<&str>: std::convert::AsRef` is not satisfied + --> $DIR/issue-72442.rs:12:36 + | +LL | let mut f = File::open(path.to_str())?; + | ^^^^^^^^^^^^^ the trait `std::convert::AsRef` is not implemented for `std::option::Option<&str>` + | + ::: $SRC_DIR/libstd/fs.rs:LL:COL + | +LL | pub fn open>(path: P) -> io::Result { + | ----------- required by this bound in `std::fs::File::open` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`.