mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
Skip single use lifetime lint for generated opaque types
As reported in issue #77175, the opaque type generated by the desugaring process of an async function uses the lifetimes defined by the originating function. The definition ID for the lifetimes in the opaque method is different from the one in the originating async function and it could therefore be considered a single use of the lifetimne, this causes the single_use_lifetimes lint to fail compilation if explicitly denied. This fix skips the lint for lifetimes used only once in generated opaque types for an async function that are declared in the parent async function definition.
This commit is contained in:
parent
226e181b80
commit
82f1f50335
@ -2024,7 +2024,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
// ensure that we issue lints in a repeatable order
|
||||
def_ids.sort_by_cached_key(|&def_id| self.tcx.def_path_hash(def_id));
|
||||
|
||||
for def_id in def_ids {
|
||||
'lifetimes: for def_id in def_ids {
|
||||
debug!("check_uses_for_lifetimes_defined_by_scope: def_id = {:?}", def_id);
|
||||
|
||||
let lifetimeuseset = self.lifetime_uses.remove(&def_id);
|
||||
@ -2067,6 +2067,27 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// opaque types generated when desugaring an async function can have a single
|
||||
// use lifetime even if it is explicitly denied (Issue #77175)
|
||||
if let hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::OpaqueTy(ref opaque),
|
||||
..
|
||||
}) = self.tcx.hir().get(parent_hir_id)
|
||||
{
|
||||
if opaque.origin != hir::OpaqueTyOrigin::AsyncFn {
|
||||
continue 'lifetimes;
|
||||
}
|
||||
// We want to do this only if the liftime identifier is already defined
|
||||
// in the async function that generated this. Otherwise it could be
|
||||
// an opaque type defined by the developer and we still want this
|
||||
// lint to fail compilation
|
||||
for p in opaque.generics.params {
|
||||
if defined_by.contains_key(&p.name) {
|
||||
continue 'lifetimes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user