Rollup merge of #72450 - csmoe:issue-72442, r=oli-obk

Fix ice-#72442

Closes #72442
Closes #72426
r? @oli-obk
This commit is contained in:
Dylan DPC 2020-05-25 23:58:56 +02:00 committed by GitHub
commit a7ff5a0077
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 1 deletions

View file

@ -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")]

View file

@ -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;
}

View file

@ -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;

View file

@ -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(())
}

View file

@ -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`.