Only reachable traits
This commit is contained in:
parent
afea0b4eab
commit
90dfa24415
2 changed files with 20 additions and 2 deletions
|
@ -93,10 +93,16 @@ impl<'tcx> LateLintPass<'tcx> for AsyncFnInTrait {
|
|||
if let hir::TraitItemKind::Fn(sig, body) = item.kind
|
||||
&& let hir::IsAsync::Async(async_span) = sig.header.asyncness
|
||||
{
|
||||
// RTN can be used to bound `async fn` in traits in a better way than "always"
|
||||
if cx.tcx.features().return_type_notation {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only need to think about library implications of reachable traits
|
||||
if !cx.tcx.effective_visibilities(()).is_reachable(item.owner_id.def_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
let hir::FnRetTy::Return(hir::Ty { kind: hir::TyKind::OpaqueDef(def, ..), .. }) =
|
||||
sig.decl.output
|
||||
else {
|
||||
|
|
|
@ -3,9 +3,21 @@
|
|||
#![feature(async_fn_in_trait)]
|
||||
#![deny(async_fn_in_trait)]
|
||||
|
||||
trait Foo {
|
||||
pub trait Foo {
|
||||
async fn not_send();
|
||||
//~^ ERROR
|
||||
//~^ ERROR use of `async fn` in public traits is discouraged
|
||||
}
|
||||
|
||||
mod private {
|
||||
pub trait FooUnreachable {
|
||||
async fn not_send();
|
||||
// No warning
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait FooCrate {
|
||||
async fn not_send();
|
||||
// No warning
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue