Repository navigation
Open
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-coroutinesArea: CoroutinesArea: CoroutinesA-trait-systemArea: Trait systemArea: Trait systemAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.fixed-by-higher-ranked-assumptionsFixed by `-Zhigher-ranked-assumptions`Fixed by `-Zhigher-ranked-assumptions`
Description
use std::collections::{BTreeMap, HashMap};
use std::sync::Arc;
fn needs_send<T: Send>(_val: T) {}
async fn async_fn_a(_num: u32) {}
async fn async_fn_b(map: Arc<BTreeMap<u32, &'static u32>>) {
for (_i, v) in &*map {
async_fn_a(**v).await;
}
}
async fn async_fn_c(map: Arc<HashMap<u32, &'static u32>>) {
for (_i, v) in &*map {
async_fn_a(**v).await;
}
}
fn main() {
// this works...
let map: Arc<HashMap<u32, &'static u32>> = Arc::new(HashMap::new());
needs_send(async_fn_c(map.clone()));
// but this doesn't
let map: Arc<BTreeMap<u32, &'static u32>> = Arc::new(BTreeMap::new());
needs_send(async_fn_b(map.clone()));
}error: implementation of `std::marker::Send` is not general enough
--> src/main.rs:24:5
|
24 | needs_send(async_fn_b(map.clone()));
| ^^^^^^^^^^
|
= note: `std::marker::Send` would have to be implemented for the type `alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Immut<'0>, u32, &'1 u32, alloc::collections::btree::node::marker::Leaf>`, for any two lifetimes `'0` and `'1`
= note: but `std::marker::Send` is actually implemented for the type `alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Immut<'2>, u32, &u32, alloc::collections::btree::node::marker::Leaf>`, for some specific lifetime `'2`
Reacted by Adrodoc, Yifei, LIU JIE, Hans Christian Schmitz, Thomas de Zeeuw, maya_t, Nazar Mokrynskyi, Duncan, Richardn, Eric Zhang and 8 more
Reacted by Juan Campa, Harry Wu, Rogério da Silva Yokomizo, maya_t and William
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-coroutinesArea: CoroutinesArea: CoroutinesA-trait-systemArea: Trait systemArea: Trait systemAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.fixed-by-higher-ranked-assumptionsFixed by `-Zhigher-ranked-assumptions`Fixed by `-Zhigher-ranked-assumptions`
Type
Projects
- StatusShow more project fieldsOn deck
Activity
Aaron1011 commentedon Sep 18, 2019
Minimized:
It seems as though the manual
Sendimpl is confusing some async-related code. The code compiles if you removeunsafe impl<'a, T: 'a> Send for MyStruct<'a, T> {}, even though it's not actually adding any additional region constraints.Aaron1011 commentedon Sep 19, 2019
I think the bug occurs here:
rust/src/librustc_typeck/check/generator_interior.rs
Lines 124 to 144 in 9b9d2af
I believe that 'knowledge of the exact relationships between them isn't particularly important' is incorrect. If an auto trait impl imposes region constraints (as with
MyStruct), then the relationship between regions does matter.For this particular issue, leaving
'staticunmodified (i.e. not replacing it with a region variable) should be sufficient to allow the code to compile.In the general case, I think a full solution would require some notion of 'higher-ranked' region constraints. For example, consider the function:
The returned generator should implement
Send, becauseMyStruct<'a, &'b u8>implementsSend. However, proving this requires us to know that'b: 'aholds when we're inspecting the generator witness.[-]Strange error when iterating over BTreeMap in async fn[/-][+]Lifetime bounds in auto trait impls prevent trait from being implemented on generators[/+]Aaron1011 commentedon Sep 19, 2019
Concretely, I think we could implement this as follows:
List<RegionOutlivesPredicate>to GeneratorWitness. This would store a list of predicates involving any 'internal' regions variables. This list would be created here by recording all known relationships between interior region variables.GeneratorWitness, we extend theParamEnvfor the newly created sub-obligations with all of theRegionOutlivesPredicatefrom our generator witness. Effectively, aGeneratorWitnesscauses us to learn something new - however, this knowledge only applies to to the interior region variables.This should only affect auto-trait resolution for generators. Users cannot implement any traits on the underlying generator type (in fact, they cannot even name it). This should ensure that these
RegionOutlivesPredicatecannot affect any code external to the generator, except to the extent that they allow us to prove that an auto-trait impl applies. It should be impossible user code to observe these regions in any way, since the generator can only be interacted with viaGenerator::Resumeand the.awaitsyntax.cc @nikomatsakis @tmandry
51 remaining items
hcsch commentedon Jun 29, 2023
Make parser async & Replace references with Arc for Dlt parser
Make parser async & Use with Arc wit Dlt parser & Adjustments on plug…
Make parser async & Use with Arc wit Dlt parser & Adjustments on plug…
fix all async & clippy issues
Sendbound generatesthe parameter typeSmust be valid for any other region#71058 as a duplicate of this issuebrain(sessions): the listing reads the stamped turn count and fans it…