Skip to content

Commit 69930d3

Browse files
committed
fix unused closure lint
1 parent 8de9341 commit 69930d3

File tree

3 files changed

+13
-12
lines changed
  • compiler
    • rustc_const_eval/src/transform/check_consts
    • rustc_lint/src
    • rustc_trait_selection/src/traits/select

3 files changed

+13
-12
lines changed

compiler/rustc_const_eval/src/transform/check_consts/check.rs

-9
Original file line numberDiff line numberDiff line change
@@ -888,15 +888,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
888888
return;
889889
}
890890

891-
// FIXME(swatinem): figure out how to handle async blocks not going through `from_generator`
892-
// `async` blocks get lowered to `std::future::from_generator(/* a closure */)`.
893-
let is_async_block = Some(callee) == tcx.lang_items().from_generator_fn();
894-
if is_async_block {
895-
let kind = hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block);
896-
self.check_op(ops::Generator(kind));
897-
return;
898-
}
899-
900891
if !tcx.is_const_fn_raw(callee) {
901892
if !tcx.is_const_default_method(callee) {
902893
// To get to here we must have already found a const impl for the

compiler/rustc_lint/src/unused.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,16 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
284284
);
285285
true
286286
}
287-
ty::Generator(..) => {
287+
ty::Generator(def_id, ..) => {
288+
// async fn should be treated as "implementor of `Future`"
289+
if matches!(cx.tcx.generator_kind(def_id), Some(hir::GeneratorKind::Async(..)))
290+
{
291+
let def_id = cx.tcx.lang_items().future_trait().unwrap();
292+
let descr_pre = &format!("{}implementer{} of ", descr_pre, plural_suffix,);
293+
if check_must_use_def(cx, def_id, span, descr_pre, descr_post) {
294+
return true;
295+
}
296+
}
288297
cx.struct_span_lint(
289298
UNUSED_MUST_USE,
290299
span,

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1150,9 +1150,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11501150
ProjectionCandidate(_, ty::BoundConstness::ConstIfConst) => {}
11511151
// auto trait impl
11521152
AutoImplCandidate => {}
1153-
// generator, this will raise error in other places
1153+
// generator / future, this will raise error in other places
11541154
// or ignore error with const_async_blocks feature
1155-
GeneratorCandidate { .. } => {}
1155+
GeneratorCandidate => {}
1156+
FutureCandidate => {}
11561157
// FnDef where the function is const
11571158
FnPointerCandidate { is_const: true } => {}
11581159
ConstDestructCandidate(_) => {}

0 commit comments

Comments
 (0)