Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libcore/ops/try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_hir/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 5 additions & 1 deletion src/librustc_trait_selection/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/async-await/issue-72442.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
14 changes: 14 additions & 0 deletions src/test/ui/async-await/issue-72442.stderr
Original file line number Diff line number Diff line change
@@ -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`.