diff options
| author | Arpad Borsos <swatinem@swatinem.de> | 2022-11-18 22:56:22 +0100 |
|---|---|---|
| committer | Arpad Borsos <swatinem@swatinem.de> | 2022-11-24 10:04:27 +0100 |
| commit | 9f36f988ad873f5d34cd9c08e4903c597ffc9532 (patch) | |
| tree | 48825cd5da62cbc7f585c6c991a3b8e25d01dd20 /compiler/rustc_lint | |
| parent | fd815a5091eb4d49cd317f8ad272f17b7a5f550d (diff) | |
| download | rust-9f36f988ad873f5d34cd9c08e4903c597ffc9532.tar.gz rust-9f36f988ad873f5d34cd9c08e4903c597ffc9532.zip | |
Avoid `GenFuture` shim when compiling async constructs
Previously, async constructs would be lowered to "normal" generators, with an additional `from_generator` / `GenFuture` shim in between to convert from `Generator` to `Future`. The compiler will now special-case these generators internally so that async constructs will *directly* implement `Future` without the need to go through the `from_generator` / `GenFuture` shim. The primary motivation for this change was hiding this implementation detail in stack traces and debuginfo, but it can in theory also help the optimizer as there is less abstractions to see through.
Diffstat (limited to 'compiler/rustc_lint')
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 0471890230a..d6a01b42548 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -319,7 +319,20 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { .map(|inner| MustUsePath::Array(Box::new(inner), len)), }, ty::Closure(..) => Some(MustUsePath::Closure(span)), - ty::Generator(..) => Some(MustUsePath::Generator(span)), + ty::Generator(def_id, ..) => { + // async fn should be treated as "implementor of `Future`" + let must_use = if matches!( + cx.tcx.generator_kind(def_id), + Some(hir::GeneratorKind::Async(..)) + ) { + let def_id = cx.tcx.lang_items().future_trait().unwrap(); + is_def_must_use(cx, def_id, span) + .map(|inner| MustUsePath::Opaque(Box::new(inner))) + } else { + None + }; + must_use.or(Some(MustUsePath::Generator(span))) + } _ => None, } } |
