diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-05-25 23:58:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-25 23:58:56 +0200 |
| commit | a7ff5a00775ca8db59077307b0b9eb706f907941 (patch) | |
| tree | f1f780332b987c63d59211028b717b6f3162a086 | |
| parent | 0498845e54baf8f3bf493de39009d2d175dbd374 (diff) | |
| parent | 16ba3e129d5d37c63b7000fcd4b52261e7f1c4f1 (diff) | |
| download | rust-a7ff5a00775ca8db59077307b0b9eb706f907941.tar.gz rust-a7ff5a00775ca8db59077307b0b9eb706f907941.zip | |
Rollup merge of #72450 - csmoe:issue-72442, r=oli-obk
Fix ice-#72442 Closes #72442 Closes #72426 r? @oli-obk
| -rw-r--r-- | src/libcore/ops/try.rs | 1 | ||||
| -rw-r--r-- | src/librustc_hir/lang_items.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trait_selection/traits/error_reporting/mod.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/async-await/issue-72442.rs | 26 | ||||
| -rw-r--r-- | src/test/ui/async-await/issue-72442.stderr | 14 |
5 files changed, 48 insertions, 1 deletions
diff --git a/src/libcore/ops/try.rs b/src/libcore/ops/try.rs index 996a01d413c..e15ea11569f 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 04fe3b60b6a..83bada40419 100644 --- a/src/librustc_hir/lang_items.rs +++ b/src/librustc_hir/lang_items.rs @@ -257,4 +257,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 b1c6815c741..50af3c12c6f 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; 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 00000000000..61c8c8c1594 --- /dev/null +++ b/src/test/ui/async-await/issue-72442.rs @@ -0,0 +1,26 @@ +// edition:2018 +// compile-flags:-Cincremental=tmp/issue-72442 + +use std::fs::File; +use std::future::Future; +use std::io::prelude::*; + +fn main() -> Result<(), Box<dyn std::error::Error>> { + block_on(async { + { + let path = std::path::Path::new("."); + let mut f = File::open(path.to_str())?; + //~^ ERROR the trait bound + let mut src = String::new(); + f.read_to_string(&mut src)?; + Ok(()) + } + }) +} + +fn block_on<F>(f: F) -> F::Output +where + F: Future<Output = Result<(), Box<dyn std::error::Error>>>, +{ + 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 00000000000..56854333578 --- /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<std::path::Path>` is not satisfied + --> $DIR/issue-72442.rs:12:36 + | +LL | let mut f = File::open(path.to_str())?; + | ^^^^^^^^^^^^^ the trait `std::convert::AsRef<std::path::Path>` is not implemented for `std::option::Option<&str>` + | + ::: $SRC_DIR/libstd/fs.rs:LL:COL + | +LL | pub fn open<P: AsRef<Path>>(path: P) -> io::Result<File> { + | ----------- 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`. |
