mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Rollup merge of #111491 - compiler-errors:nested-fut-must-use, r=wesleywiser
Dont check `must_use` on nested `impl Future` from fn Fixes (but does not close, per beta policy) #111484 Also fixes a `FIXME` left in the code about (presumably) false-positives on non-async `#[must_use] fn() -> impl Future` cases, though if that's not desirable to include in the beta backport then I can certainly revert it. Beta nominating as it fixes a beta ICE.
This commit is contained in:
commit
2294d81fb3
@ -103,8 +103,10 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
||||
&& let ty = cx.typeck_results().expr_ty(&await_expr)
|
||||
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id: future_def_id, .. }) = ty.kind()
|
||||
&& cx.tcx.ty_is_opaque_future(ty)
|
||||
// FIXME: This also includes non-async fns that return `impl Future`.
|
||||
&& let async_fn_def_id = cx.tcx.parent(*future_def_id)
|
||||
&& matches!(cx.tcx.def_kind(async_fn_def_id), DefKind::Fn | DefKind::AssocFn)
|
||||
// Check that this `impl Future` actually comes from an `async fn`
|
||||
&& cx.tcx.asyncness(async_fn_def_id).is_async()
|
||||
&& check_must_use_def(
|
||||
cx,
|
||||
async_fn_def_id,
|
||||
|
12
tests/ui/lint/unused/auxiliary/must-use-foreign.rs
Normal file
12
tests/ui/lint/unused/auxiliary/must-use-foreign.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// edition:2021
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
pub struct Manager;
|
||||
|
||||
impl Manager {
|
||||
#[must_use]
|
||||
pub async fn new() -> (Self, impl Future<Output = ()>) {
|
||||
(Manager, async {})
|
||||
}
|
||||
}
|
15
tests/ui/lint/unused/must-use-foreign.rs
Normal file
15
tests/ui/lint/unused/must-use-foreign.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// edition:2021
|
||||
// aux-build:must-use-foreign.rs
|
||||
// check-pass
|
||||
|
||||
extern crate must_use_foreign;
|
||||
|
||||
use must_use_foreign::Manager;
|
||||
|
||||
async fn async_main() {
|
||||
Manager::new().await.1.await;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = async_main();
|
||||
}
|
@ -33,7 +33,7 @@ async fn test() {
|
||||
foo().await; //~ ERROR unused output of future returned by `foo` that must be used
|
||||
bar(); //~ ERROR unused return value of `bar` that must be used
|
||||
//~^ ERROR unused implementer of `Future` that must be used
|
||||
bar().await; //~ ERROR unused output of future returned by `bar` that must be used
|
||||
bar().await; // ok, it's not an async fn
|
||||
baz(); //~ ERROR unused implementer of `Future` that must be used
|
||||
baz().await; // ok
|
||||
}
|
||||
|
@ -52,17 +52,6 @@ help: use `let _ = ...` to ignore the resulting value
|
||||
LL | let _ = bar();
|
||||
| +++++++
|
||||
|
||||
error: unused output of future returned by `bar` that must be used
|
||||
--> $DIR/unused-async.rs:36:5
|
||||
|
|
||||
LL | bar().await;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: use `let _ = ...` to ignore the resulting value
|
||||
|
|
||||
LL | let _ = bar().await;
|
||||
| +++++++
|
||||
|
||||
error: unused implementer of `Future` that must be used
|
||||
--> $DIR/unused-async.rs:37:5
|
||||
|
|
||||
@ -71,5 +60,5 @@ LL | baz();
|
||||
|
|
||||
= note: futures do nothing unless you `.await` or poll them
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user