Skip to content

Commit 0fc289a

Browse files
committed
Replace trait_is_async_fn with async_fn_trait_kind_from_def_id
1 parent 67d42b5 commit 0fc289a

File tree

5 files changed

+14
-35
lines changed

5 files changed

+14
-35
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
560560
self.trait_is_alias(trait_def_id)
561561
}
562562

563-
fn trait_is_async_fn(self, trait_def_id: DefId) -> bool {
564-
self.trait_is_async_fn(trait_def_id)
565-
}
566-
567563
fn trait_is_dyn_compatible(self, trait_def_id: DefId) -> bool {
568564
self.is_dyn_compatible(trait_def_id)
569565
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,17 +1830,6 @@ impl<'tcx> TyCtxt<'tcx> {
18301830
self.trait_def(trait_def_id).has_auto_impl
18311831
}
18321832

1833-
/// Returns `true` if this is an `AsyncFn`, `AsyncFnMut`, or `AsyncFnOnce` trait.
1834-
pub fn trait_is_async_fn(self, trait_def_id: DefId) -> bool {
1835-
let lang_items = self.lang_items();
1836-
[
1837-
lang_items.async_fn_trait(),
1838-
lang_items.async_fn_mut_trait(),
1839-
lang_items.async_fn_once_trait(),
1840-
]
1841-
.contains(&Some(trait_def_id))
1842-
}
1843-
18441833
/// Returns `true` if this is coinductive, either because it is
18451834
/// an auto trait or because it has the `#[rustc_coinductive]` attribute.
18461835
pub fn trait_is_coinductive(self, trait_def_id: DefId) -> bool {

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_infer::traits::{
1717
};
1818
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
1919
use rustc_middle::ty::{self, Ty, TyCtxt};
20-
use rustc_span::{ErrorGuaranteed, ExpnKind, Span, Symbol};
20+
use rustc_span::{ErrorGuaranteed, ExpnKind, Span};
2121
use tracing::{info, instrument};
2222

2323
pub use self::overflow::*;
@@ -431,35 +431,31 @@ pub fn report_dyn_incompatibility<'tcx>(
431431

432432
// Avoid errors diving into the details of the `AsyncFn` traits if this is
433433
// a straightforward "`AsyncFn` is not yet dyn compatible" error.
434-
if tcx.trait_is_async_fn(trait_def_id) {
435-
let fn_trait: Symbol = violations
436-
.iter()
437-
.find_map(|violation| {
438-
// Try to find the original trait that caused the violation.
439-
match *violation {
440-
DynCompatibilityViolation::AsyncFnTrait { fn_trait } => Some(fn_trait),
441-
_ => None,
442-
}
443-
})
444-
.expect("AsyncFn traits should report a corresponding DynCompatibilityViolation");
434+
if let Some(async_fn_trait_kind) = tcx.async_fn_trait_kind_from_def_id(trait_def_id) {
435+
let async_fn_trait_name = match async_fn_trait_kind {
436+
ty::ClosureKind::Fn => "AsyncFn",
437+
ty::ClosureKind::FnMut => "AsyncFnMut",
438+
ty::ClosureKind::FnOnce => "AsyncFnOnce",
439+
};
440+
445441
let mut err = struct_span_code_err!(
446442
tcx.dcx(),
447443
span,
448444
E0802,
449445
"the trait `{}` is not yet dyn compatible",
450-
fn_trait
446+
async_fn_trait_name
451447
);
452448
// Note: this check is quite imprecise.
453449
// Comparing the DefIds or similar would be better, but we can't store
454450
// DefIds in `DynCompatibilityViolation`.
455-
if fn_trait.as_str() == trait_str {
456-
err.span_label(span, format!("`{fn_trait}` is not yet dyn compatible"));
451+
if async_fn_trait_name == trait_str {
452+
err.span_label(span, format!("`{async_fn_trait_name}` is not yet dyn compatible"));
457453
} else {
458454
let trait_str = tcx.def_path_str(trait_def_id);
459455
err.span_label(
460456
span,
461457
format!(
462-
"`{trait_str}` inherits from `{fn_trait}` which is not yet dyn compatible'"
458+
"`{trait_str}` inherits from `{async_fn_trait_name}` which is not yet dyn compatible'"
463459
),
464460
);
465461
}

compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn hir_ty_lowering_dyn_compatibility_violations(
4343
// Check for `AsyncFn` traits first to avoid reporting various other
4444
// errors about the details of why these traits aren't object-safe.
4545
for supertrait in tcx.supertrait_def_ids(trait_def_id) {
46-
if tcx.trait_is_async_fn(supertrait) {
46+
if tcx.async_fn_trait_kind_from_def_id(supertrait).is_some() {
4747
let fn_trait = tcx.item_name(supertrait);
4848
return vec![DynCompatibilityViolation::AsyncFnTrait { fn_trait }];
4949
}
@@ -66,7 +66,7 @@ fn dyn_compatibility_violations(
6666
// Check for `AsyncFn` traits first to avoid reporting various other
6767
// errors about the details of why these traits aren't object-safe.
6868
for supertrait in tcx.supertrait_def_ids(trait_def_id) {
69-
if tcx.trait_is_async_fn(supertrait) {
69+
if tcx.async_fn_trait_kind_from_def_id(supertrait).is_some() {
7070
let fn_trait = tcx.item_name(supertrait);
7171
return core::slice::from_ref(
7272
tcx.arena.alloc(DynCompatibilityViolation::AsyncFnTrait { fn_trait }),

compiler/rustc_type_ir/src/interner.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ pub trait Interner:
262262

263263
fn trait_is_alias(self, trait_def_id: Self::DefId) -> bool;
264264

265-
fn trait_is_async_fn(self, trait_def_id: Self::DefId) -> bool;
266-
267265
fn trait_is_dyn_compatible(self, trait_def_id: Self::DefId) -> bool;
268266

269267
fn trait_is_fundamental(self, def_id: Self::DefId) -> bool;

0 commit comments

Comments
 (0)