Skip to content

Commit a1104b4

Browse files
committed
bless ui tests
1 parent c7e64f5 commit a1104b4

File tree

6 files changed

+41
-10
lines changed

6 files changed

+41
-10
lines changed

src/librustc_hir/lang_items.rs

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ language_item_table! {
194194
ShrAssignTraitLangItem, "shr_assign", shr_assign_trait, Target::Trait;
195195
IndexTraitLangItem, "index", index_trait, Target::Trait;
196196
IndexMutTraitLangItem, "index_mut", index_mut_trait, Target::Trait;
197+
197198
UnsafeCellTypeLangItem, "unsafe_cell", unsafe_cell_type, Target::Struct;
198199
VaListTypeLangItem, "va_list", va_list, Target::Struct;
199200

src/librustc_middle/hir/map/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,7 @@ impl<'hir> Map<'hir> {
390390
/// Given a `HirId`, returns the `BodyId` associated with it,
391391
/// if the node is a body owner, otherwise returns `None`.
392392
pub fn maybe_body_owned_by(&self, hir_id: HirId) -> Option<BodyId> {
393-
if let Some(node) = self.find(hir_id) {
394-
associated_body(node)
395-
} else {
396-
bug!("no entry for id `{}`", hir_id)
397-
}
393+
if let Some(node) = self.find(hir_id) { associated_body(node) } else { None }
398394
}
399395

400396
/// Given a body owner's id, returns the `BodyId` associated with it.

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,19 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
17911791
let body_hir_id = obligation.cause.body_id;
17921792
let item_id = self.tcx.hir().get_parent_node(body_hir_id);
17931793

1794+
let mut is_future = false;
1795+
if let ty::Opaque(def_id, substs) = trait_ref.self_ty().kind {
1796+
let preds = self.tcx.predicates_of(def_id).instantiate(self.tcx, substs);
1797+
for p in preds.predicates {
1798+
if let Some(trait_ref) = p.to_opt_poly_trait_ref() {
1799+
if Some(trait_ref.def_id()) == self.tcx.lang_items().future_trait() {
1800+
is_future = true;
1801+
break;
1802+
}
1803+
}
1804+
}
1805+
}
1806+
17941807
if let Some(body_id) = self.tcx.hir().maybe_body_owned_by(item_id) {
17951808
let body = self.tcx.hir().body(body_id);
17961809
if let Some(hir::GeneratorKind::Async(_)) = body.generator_kind {
@@ -1802,6 +1815,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
18021815
.next()
18031816
.unwrap()
18041817
.def_id;
1818+
debug!("trait_ref_self_ty: {:?}", trait_ref.self_ty());
18051819
// `<T as Future>::Output`
18061820
let projection_ty = ty::ProjectionTy {
18071821
// `T`
@@ -1813,7 +1827,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
18131827
item_def_id,
18141828
};
18151829

1816-
//let cause = ObligationCause::misc(span, body_hir_id);
18171830
let mut selcx = SelectionContext::new(self);
18181831

18191832
let mut obligations = vec![];
@@ -1826,15 +1839,18 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
18261839
&mut obligations,
18271840
);
18281841

1829-
debug!("suggest_await_befor_try: normalized_projection_type {:?}", normalized_ty);
1842+
debug!(
1843+
"suggest_await_befor_try: normalized_projection_type {:?}",
1844+
self.resolve_vars_if_possible(&normalized_ty)
1845+
);
18301846
let try_obligation = self.mk_obligation_for_def_id(
18311847
trait_ref.def_id(),
18321848
normalized_ty,
18331849
obligation.cause.clone(),
18341850
obligation.param_env,
18351851
);
18361852
debug!("suggest_await_befor_try: try_trait_obligation {:?}", try_obligation);
1837-
if self.predicate_may_hold(&try_obligation) {
1853+
if self.predicate_may_hold(&try_obligation) && is_future {
18381854
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
18391855
if snippet.ends_with('?') {
18401856
err.span_suggestion(

src/test/ui/async-await/await-keyword/incorrect-syntax-suggestions.stderr

+4-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ error[E0277]: the `?` operator can only be applied to values that implement `std
237237
--> $DIR/incorrect-syntax-suggestions.rs:16:19
238238
|
239239
LL | let _ = await bar()?;
240-
| ^^^^^^ the `?` operator cannot be applied to type `impl std::future::Future`
240+
| ^^^^^^
241+
| |
242+
| the `?` operator cannot be applied to type `impl std::future::Future`
243+
| help: consider using `.await` here: `bar().await?`
241244
|
242245
= help: the trait `std::ops::Try` is not implemented for `impl std::future::Future`
243246
= note: required by `std::ops::Try::into_result`

src/test/ui/async-await/issue-61076.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ async fn foo() -> Result<(), ()> {
55
}
66

77
async fn bar() -> Result<(), ()> {
8-
foo()?;
8+
foo()?; //~ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
99
Ok(())
1010
}
1111

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
2+
--> $DIR/issue-61076.rs:8:5
3+
|
4+
LL | foo()?;
5+
| ^^^^^^
6+
| |
7+
| the `?` operator cannot be applied to type `impl std::future::Future`
8+
| help: consider using `.await` here: `foo().await?`
9+
|
10+
= help: the trait `std::ops::Try` is not implemented for `impl std::future::Future`
11+
= note: required by `std::ops::Try::into_result`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)