Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2e2aac4

Browse files
committed
add try trait as lang item
1 parent 32a46e9 commit 2e2aac4

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

src/libcore/ops/try.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
)]
2727
#[doc(alias = "?")]
28+
#[cfg_attr(not(bootstrap), lang = "try_trait")]
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

Lines changed: 1 addition & 0 deletions
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+
TryTraitLangItem, "try_trait", try_trait, Target::Trait;
197198

198199
UnsafeCellTypeLangItem, "unsafe_cell", unsafe_cell_type, Target::Struct;
199200
VaListTypeLangItem, "va_list", va_list, Target::Struct;

src/librustc_typeck/check/mod.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5289,6 +5289,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
52895289
expected: Ty<'tcx>,
52905290
found: Ty<'tcx>,
52915291
) {
5292+
debug!("suggest_missing_await: expr={:?} expected={:?}, found={:?}", expr, expected, found);
52925293
// `.await` is not permitted outside of `async` bodies, so don't bother to suggest if the
52935294
// body isn't `async`.
52945295
let item_id = self.tcx().hir().get_parent_node(self.body_id);
@@ -5306,22 +5307,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
53065307
.next()
53075308
.unwrap()
53085309
.def_id;
5310+
// `<T as Future>::Output`
5311+
let projection_ty = ty::ProjectionTy {
5312+
// `T`
5313+
substs: self
5314+
.tcx
5315+
.mk_substs_trait(found, self.fresh_substs_for_item(sp, item_def_id)),
5316+
// `Future::Output`
5317+
item_def_id,
5318+
};
5319+
53095320
let predicate =
53105321
ty::Predicate::Projection(ty::Binder::bind(ty::ProjectionPredicate {
5311-
// `<T as Future>::Output`
5312-
projection_ty: ty::ProjectionTy {
5313-
// `T`
5314-
substs: self.tcx.mk_substs_trait(
5315-
found,
5316-
self.fresh_substs_for_item(sp, item_def_id),
5317-
),
5318-
// `Future::Output`
5319-
item_def_id,
5320-
},
5322+
projection_ty,
53215323
ty: expected,
53225324
}));
53235325
let obligation = traits::Obligation::new(self.misc(sp), self.param_env, predicate);
53245326
debug!("suggest_missing_await: trying obligation {:?}", obligation);
5327+
5328+
//let try_trait_def_id = self.tcx.require_lang_item(lang_items::TryTraitLangItem, None);
5329+
//let try_trait_ref = ty::TraitRef {
5330+
// def_id: try_trait_def_id,
5331+
// substs: self.tcx.mk_substs_trait(self.tcx.type_of(item_def_id), &[]),
5332+
//};
5333+
//let try_obligation = traits::Obligation::new(self.misc(sp), self.param_env, try_trait_ref.without_const().to_predicate());
5334+
//let try_trait_is_implemented = self.predicate_must_hold_modulo_regions(&try_obligation);
5335+
//debug!("suggest_missing_await: try trait is implemented {}", try_trait_is_implemented);
5336+
53255337
if self.infcx.predicate_may_hold(&obligation) {
53265338
debug!("suggest_missing_await: obligation held: {:?}", obligation);
53275339
if let Ok(code) = self.sess().source_map().span_to_snippet(sp) {

0 commit comments

Comments
 (0)