Skip to content

Commit a7ff5a0

Browse files
authored
Rollup merge of #72450 - csmoe:issue-72442, r=oli-obk
Fix ice-#72442 Closes #72442 Closes #72426 r? @oli-obk
2 parents 0498845 + 16ba3e1 commit a7ff5a0

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

src/libcore/ops/try.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
)]
2727
#[doc(alias = "?")]
28+
#[cfg_attr(not(bootstrap), lang = "try")]
2829
pub trait Try {
2930
/// The type of this value when viewed as successful.
3031
#[unstable(feature = "try_trait", issue = "42327")]

src/librustc_hir/lang_items.rs

+2
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,6 @@ language_item_table! {
257257
AlignOffsetLangItem, "align_offset", align_offset_fn, Target::Fn;
258258

259259
TerminationTraitLangItem, "termination", termination, Target::Trait;
260+
261+
TryTraitLangItem, "try", try_trait, Target::Trait;
260262
}

src/librustc_trait_selection/traits/error_reporting/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
402402
self.suggest_remove_reference(&obligation, &mut err, &trait_ref);
403403
self.suggest_semicolon_removal(&obligation, &mut err, span, &trait_ref);
404404
self.note_version_mismatch(&mut err, &trait_ref);
405-
self.suggest_await_before_try(&mut err, &obligation, &trait_ref, span);
405+
406+
if Some(trait_ref.def_id()) == tcx.lang_items().try_trait() {
407+
self.suggest_await_before_try(&mut err, &obligation, &trait_ref, span);
408+
}
409+
406410
if self.suggest_impl_trait(&mut err, span, &obligation, &trait_ref) {
407411
err.emit();
408412
return;
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// edition:2018
2+
// compile-flags:-Cincremental=tmp/issue-72442
3+
4+
use std::fs::File;
5+
use std::future::Future;
6+
use std::io::prelude::*;
7+
8+
fn main() -> Result<(), Box<dyn std::error::Error>> {
9+
block_on(async {
10+
{
11+
let path = std::path::Path::new(".");
12+
let mut f = File::open(path.to_str())?;
13+
//~^ ERROR the trait bound
14+
let mut src = String::new();
15+
f.read_to_string(&mut src)?;
16+
Ok(())
17+
}
18+
})
19+
}
20+
21+
fn block_on<F>(f: F) -> F::Output
22+
where
23+
F: Future<Output = Result<(), Box<dyn std::error::Error>>>,
24+
{
25+
Ok(())
26+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: the trait bound `std::option::Option<&str>: std::convert::AsRef<std::path::Path>` is not satisfied
2+
--> $DIR/issue-72442.rs:12:36
3+
|
4+
LL | let mut f = File::open(path.to_str())?;
5+
| ^^^^^^^^^^^^^ the trait `std::convert::AsRef<std::path::Path>` is not implemented for `std::option::Option<&str>`
6+
|
7+
::: $SRC_DIR/libstd/fs.rs:LL:COL
8+
|
9+
LL | pub fn open<P: AsRef<Path>>(path: P) -> io::Result<File> {
10+
| ----------- required by this bound in `std::fs::File::open`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)