-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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.
Description
I tried this code: (try it in a playground)
use std::hash::BuildHasher;
use std::collections::HashMap;
trait H: Send + Sync + Clone + BuildHasher { }
struct I<'i, RS: H> {
h: &'i HashMap<i32, i32, RS>,
s: VeryVeryLongTypeName
}
impl<'i, RS: H> I<'i, RS> {
const CHUNK_SIZE: usize = VeryVeryLongTypeName::CHUNK_SIZE;
fn go(&mut self) {
self.s.chunks.push(Box::new([0; Self::CHUNK_SIZE])); // ERROR
}
}
struct VeryVeryLongTypeName {
chunks: Vec<Box<[u8; Self::CHUNK_SIZE]>>
}
impl VeryVeryLongTypeName {
const CHUNK_SIZE: usize = 69;
}
I expect this code to either compile fine or provide a warning similar to #76200.
However, I see an error:
11 | impl<'i, RS: H> I<'i, RS> {
| --- help: consider adding an explicit lifetime bound...: `RS: 'i +`
...
15 | self.s.chunks.push(Box::new([0; Self::CHUNK_SIZE]));
| ^^^^ ...so that the type `RS` will meet its required lifetime bounds
I don't understand why RS: 'i
is needed for accessing a constant off of Self
. As one might expect, replacing Self::CHUNK_SIZE
with VeryVeryLongTypeName::CHUNK_SIZE
works around the issue.
Tested with stable 1.55.0
and 1.57.0-nightly (2021-09-23 2b862bed9889808b6962)
.
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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.