Skip to content

Commit

Permalink
fix unused closure lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Nov 13, 2022
1 parent 8de9341 commit 69930d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
9 changes: 0 additions & 9 deletions compiler/rustc_const_eval/src/transform/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,15 +888,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
return;
}

// FIXME(swatinem): figure out how to handle async blocks not going through `from_generator`
// `async` blocks get lowered to `std::future::from_generator(/* a closure */)`.
let is_async_block = Some(callee) == tcx.lang_items().from_generator_fn();
if is_async_block {
let kind = hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block);
self.check_op(ops::Generator(kind));
return;
}

if !tcx.is_const_fn_raw(callee) {
if !tcx.is_const_default_method(callee) {
// To get to here we must have already found a const impl for the
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,16 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
);
true
}
ty::Generator(..) => {
ty::Generator(def_id, ..) => {
// async fn should be treated as "implementor of `Future`"
if matches!(cx.tcx.generator_kind(def_id), Some(hir::GeneratorKind::Async(..)))
{
let def_id = cx.tcx.lang_items().future_trait().unwrap();
let descr_pre = &format!("{}implementer{} of ", descr_pre, plural_suffix,);
if check_must_use_def(cx, def_id, span, descr_pre, descr_post) {
return true;
}
}
cx.struct_span_lint(
UNUSED_MUST_USE,
span,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,9 +1150,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ProjectionCandidate(_, ty::BoundConstness::ConstIfConst) => {}
// auto trait impl
AutoImplCandidate => {}
// generator, this will raise error in other places
// generator / future, this will raise error in other places
// or ignore error with const_async_blocks feature
GeneratorCandidate { .. } => {}
GeneratorCandidate => {}
FutureCandidate => {}
// FnDef where the function is const
FnPointerCandidate { is_const: true } => {}
ConstDestructCandidate(_) => {}
Expand Down

0 comments on commit 69930d3

Please sign in to comment.