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

Commit 0254fba

Browse files
Record asyncness span in HIR
1 parent ae9465f commit 0254fba

File tree

17 files changed

+48
-29
lines changed

17 files changed

+48
-29
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13081308

13091309
fn lower_asyncness(&mut self, a: Async) -> hir::IsAsync {
13101310
match a {
1311-
Async::Yes { .. } => hir::IsAsync::Async,
1311+
Async::Yes { span, .. } => hir::IsAsync::Async(span),
13121312
Async::No => hir::IsAsync::NotAsync,
13131313
}
13141314
}

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
302302
if free_region.bound_region.is_named() {
303303
// A named region that is actually named.
304304
Some(RegionName { name, source: RegionNameSource::NamedFreeRegion(span) })
305-
} else if let hir::IsAsync::Async = tcx.asyncness(self.mir_hir_id().owner) {
305+
} else if tcx.asyncness(self.mir_hir_id().owner).is_async() {
306306
// If we spuriously thought that the region is named, we should let the
307307
// system generate a true name for error messages. Currently this can
308308
// happen if we have an elided name in an async fn for example: the

compiler/rustc_hir/src/hir.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,13 +2853,13 @@ impl ImplicitSelfKind {
28532853
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)]
28542854
#[derive(HashStable_Generic)]
28552855
pub enum IsAsync {
2856-
Async,
2856+
Async(Span),
28572857
NotAsync,
28582858
}
28592859

28602860
impl IsAsync {
28612861
pub fn is_async(self) -> bool {
2862-
self == IsAsync::Async
2862+
matches!(self, IsAsync::Async(_))
28632863
}
28642864
}
28652865

@@ -3296,7 +3296,7 @@ pub struct FnHeader {
32963296

32973297
impl FnHeader {
32983298
pub fn is_async(&self) -> bool {
3299-
matches!(&self.asyncness, IsAsync::Async)
3299+
matches!(&self.asyncness, IsAsync::Async(_))
33003300
}
33013301

33023302
pub fn is_const(&self) -> bool {
@@ -4091,10 +4091,10 @@ mod size_asserts {
40914091
static_assert_size!(GenericBound<'_>, 48);
40924092
static_assert_size!(Generics<'_>, 56);
40934093
static_assert_size!(Impl<'_>, 80);
4094-
static_assert_size!(ImplItem<'_>, 80);
4095-
static_assert_size!(ImplItemKind<'_>, 32);
4096-
static_assert_size!(Item<'_>, 80);
4097-
static_assert_size!(ItemKind<'_>, 48);
4094+
static_assert_size!(ImplItem<'_>, 88);
4095+
static_assert_size!(ImplItemKind<'_>, 40);
4096+
static_assert_size!(Item<'_>, 88);
4097+
static_assert_size!(ItemKind<'_>, 56);
40984098
static_assert_size!(Local<'_>, 64);
40994099
static_assert_size!(Param<'_>, 32);
41004100
static_assert_size!(Pat<'_>, 72);
@@ -4105,8 +4105,8 @@ mod size_asserts {
41054105
static_assert_size!(Res, 12);
41064106
static_assert_size!(Stmt<'_>, 32);
41074107
static_assert_size!(StmtKind<'_>, 16);
4108-
static_assert_size!(TraitItem<'_>, 80);
4109-
static_assert_size!(TraitItemKind<'_>, 40);
4108+
static_assert_size!(TraitItem<'_>, 88);
4109+
static_assert_size!(TraitItemKind<'_>, 48);
41104110
static_assert_size!(Ty<'_>, 48);
41114111
static_assert_size!(TyKind<'_>, 32);
41124112
// tidy-alphabetical-end

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ fn compare_asyncness<'tcx>(
595595
trait_m: ty::AssocItem,
596596
delay: bool,
597597
) -> Result<(), ErrorGuaranteed> {
598-
if tcx.asyncness(trait_m.def_id) == hir::IsAsync::Async {
598+
if tcx.asyncness(trait_m.def_id).is_async() {
599599
match tcx.fn_sig(impl_m.def_id).skip_binder().skip_binder().output().kind() {
600600
ty::Alias(ty::Opaque, ..) => {
601601
// allow both `async fn foo()` and `fn foo() -> impl Future`

compiler/rustc_hir_analysis/src/check/entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
112112
}
113113

114114
let main_asyncness = tcx.asyncness(main_def_id);
115-
if let hir::IsAsync::Async = main_asyncness {
115+
if main_asyncness.is_async() {
116116
let asyncness_span = main_fn_asyncness_span(tcx, main_def_id);
117117
tcx.sess.emit_err(errors::MainFunctionAsync { span: main_span, asyncness: asyncness_span });
118118
error = true;
@@ -212,7 +212,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
212212
});
213213
error = true;
214214
}
215-
if let hir::IsAsync::Async = sig.header.asyncness {
215+
if sig.header.asyncness.is_async() {
216216
let span = tcx.def_span(it.owner_id);
217217
tcx.sess.emit_err(errors::StartAsync { span: span });
218218
error = true;

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
12061206
&& let Some(generics) = self.tcx.hir().get_generics(self.tcx.local_parent(param_id))
12071207
&& let Some(param) = generics.params.iter().find(|p| p.def_id == param_id)
12081208
&& param.is_elided_lifetime()
1209-
&& let hir::IsAsync::NotAsync = self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id)
1209+
&& !self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id).is_async()
12101210
&& !self.tcx.features().anonymous_lifetime_in_impl_trait
12111211
{
12121212
let mut diag = rustc_session::parse::feature_err(

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ impl<'a> State<'a> {
23042304

23052305
match header.asyncness {
23062306
hir::IsAsync::NotAsync => {}
2307-
hir::IsAsync::Async => self.word_nbsp("async"),
2307+
hir::IsAsync::Async(_) => self.word_nbsp("async"),
23082308
}
23092309

23102310
self.print_unsafety(header.unsafety);

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,10 +987,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
987987
let bound_vars = self.tcx.late_bound_vars(fn_id);
988988
let ty = self.tcx.erase_late_bound_regions(Binder::bind_with_vars(ty, bound_vars));
989989
let ty = match self.tcx.asyncness(fn_id.owner) {
990-
hir::IsAsync::Async => self.get_impl_future_output_ty(ty).unwrap_or_else(|| {
990+
ty::Asyncness::Yes => self.get_impl_future_output_ty(ty).unwrap_or_else(|| {
991991
span_bug!(fn_decl.output.span(), "failed to get output type of async function")
992992
}),
993-
hir::IsAsync::NotAsync => ty,
993+
ty::Asyncness::No => ty,
994994
};
995995
let ty = self.normalize(expr.span, ty);
996996
if self.can_coerce(found, ty) {

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use crate::{
4141
},
4242
EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext,
4343
};
44-
use hir::IsAsync;
4544
use rustc_ast::attr;
4645
use rustc_ast::tokenstream::{TokenStream, TokenTree};
4746
use rustc_ast::visit::{FnCtxt, FnKind};
@@ -1294,7 +1293,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
12941293
span: Span,
12951294
def_id: LocalDefId,
12961295
) {
1297-
if fn_kind.asyncness() == IsAsync::Async
1296+
if fn_kind.asyncness().is_async()
12981297
&& !cx.tcx.features().async_fn_track_caller
12991298
// Now, check if the function has the `#[track_caller]` attribute
13001299
&& let Some(attr) = cx.tcx.get_attr(def_id, sym::track_caller)

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ define_tables! {
439439
coerce_unsized_info: Table<DefIndex, LazyValue<ty::adjustment::CoerceUnsizedInfo>>,
440440
mir_const_qualif: Table<DefIndex, LazyValue<mir::ConstQualifs>>,
441441
rendered_const: Table<DefIndex, LazyValue<String>>,
442-
asyncness: Table<DefIndex, hir::IsAsync>,
442+
asyncness: Table<DefIndex, ty::Asyncness>,
443443
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
444444
generator_kind: Table<DefIndex, LazyValue<hir::GeneratorKind>>,
445445
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ fixed_size_enum! {
206206
}
207207

208208
fixed_size_enum! {
209-
hir::IsAsync {
210-
( NotAsync )
211-
( Async )
209+
ty::Asyncness {
210+
( Yes )
211+
( No )
212212
}
213213
}
214214

compiler/rustc_middle/src/query/erase.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ trivial! {
270270
rustc_middle::ty::adjustment::CoerceUnsizedInfo,
271271
rustc_middle::ty::AssocItem,
272272
rustc_middle::ty::AssocItemContainer,
273+
rustc_middle::ty::Asyncness,
273274
rustc_middle::ty::BoundVariableKind,
274275
rustc_middle::ty::DeducedParamAttrs,
275276
rustc_middle::ty::Destructor,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ rustc_queries! {
731731
separate_provide_extern
732732
}
733733

734-
query asyncness(key: DefId) -> hir::IsAsync {
734+
query asyncness(key: DefId) -> ty::Asyncness {
735735
desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
736736
separate_provide_extern
737737
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,19 @@ impl fmt::Display for ImplPolarity {
280280
}
281281
}
282282

283+
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable, Debug)]
284+
#[derive(TypeFoldable, TypeVisitable)]
285+
pub enum Asyncness {
286+
Yes,
287+
No,
288+
}
289+
290+
impl Asyncness {
291+
pub fn is_async(self) -> bool {
292+
matches!(self, Asyncness::Yes)
293+
}
294+
}
295+
283296
#[derive(Clone, Debug, PartialEq, Eq, Copy, Hash, Encodable, Decodable, HashStable)]
284297
pub enum Visibility<Id = LocalDefId> {
285298
/// Visible everywhere (including in other crates).

compiler/rustc_middle/src/ty/parameterized.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ trivially_parameterized_over_tcx! {
6262
crate::middle::resolve_bound_vars::ObjectLifetimeDefault,
6363
crate::mir::ConstQualifs,
6464
ty::AssocItemContainer,
65+
ty::Asyncness,
6566
ty::DeducedParamAttrs,
6667
ty::Generics,
6768
ty::ImplPolarity,

compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
103103
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. }) => {
104104
self.describe_generator(*body_id).or_else(|| {
105105
Some(match sig.header {
106-
hir::FnHeader { asyncness: hir::IsAsync::Async, .. } => "an async function",
106+
hir::FnHeader { asyncness: hir::IsAsync::Async(_), .. } => {
107+
"an async function"
108+
}
107109
_ => "a function",
108110
})
109111
})
@@ -117,7 +119,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
117119
..
118120
}) => self.describe_generator(*body_id).or_else(|| {
119121
Some(match sig.header {
120-
hir::FnHeader { asyncness: hir::IsAsync::Async, .. } => "an async method",
122+
hir::FnHeader { asyncness: hir::IsAsync::Async(_), .. } => "an async method",
121123
_ => "a method",
122124
})
123125
}),

compiler/rustc_ty_utils/src/ty.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,12 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<EarlyBinder<Ty<'
299299
}
300300

301301
/// Check if a function is async.
302-
fn asyncness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::IsAsync {
302+
fn asyncness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Asyncness {
303303
let node = tcx.hir().get_by_def_id(def_id);
304-
node.fn_sig().map_or(hir::IsAsync::NotAsync, |sig| sig.header.asyncness)
304+
node.fn_sig().map_or(ty::Asyncness::No, |sig| match sig.header.asyncness {
305+
hir::IsAsync::Async(_) => ty::Asyncness::Yes,
306+
hir::IsAsync::NotAsync => ty::Asyncness::No,
307+
})
305308
}
306309

307310
fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32> {

0 commit comments

Comments
 (0)