Only reachable traits · rust-lang/rust@90dfa24 (original) (raw)

File tree

2 files changed

lines changed

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -93,10 +93,16 @@ impl<'tcx> LateLintPass<'tcx> for AsyncFnInTrait {
93 93 if let hir::TraitItemKind::Fn(sig, body) = item.kind
94 94 && let hir::IsAsync::Async(async_span) = sig.header.asyncness
95 95 {
96 +// RTN can be used to bound `async fn` in traits in a better way than "always"
96 97 if cx.tcx.features().return_type_notation {
97 98 return;
98 99 }
99 100
101 +// Only need to think about library implications of reachable traits
102 +if !cx.tcx.effective_visibilities(()).is_reachable(item.owner_id.def_id) {
103 +return;
104 +}
105 +
100 106 let hir::FnRetTy::Return(hir::Ty { kind: hir::TyKind::OpaqueDef(def, ..), .. }) =
101 107 sig.decl.output
102 108 else {
Original file line number Diff line number Diff line change
@@ -3,9 +3,21 @@
3 3 #![feature(async_fn_in_trait)]
4 4 #![deny(async_fn_in_trait)]
5 5
6 -trait Foo {
6 +pub trait Foo {
7 7 async fn not_send();
8 -//~^ ERROR
8 +//~^ ERROR use of `async fn` in public traits is discouraged
9 +}
10 +
11 +mod private {
12 +pub trait FooUnreachable {
13 +async fn not_send();
14 +// No warning
15 +}
16 +}
17 +
18 +pub(crate) trait FooCrate {
19 +async fn not_send();
20 +// No warning
9 21 }
10 22
11 23 fn main() {}