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:
commit
a7ff5a0077
@ -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")]
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
26
src/test/ui/async-await/issue-72442.rs
Normal file
26
src/test/ui/async-await/issue-72442.rs
Normal 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(())
|
||||
}
|
14
src/test/ui/async-await/issue-72442.stderr
Normal file
14
src/test/ui/async-await/issue-72442.stderr
Normal 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`.
|
Loading…
x
Reference in New Issue
Block a user