-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
associated constants should support references to outer type parameters #28809
Comments
Oh, I was interested in this some time ago, but mostly in |
sigh: my actual goal here was to be able to adjust I thought I could still achieve this by adding an And until recently, that worked. But now with #29085, adding the above check does not work, because we cannot call the non-const And we cannot make (I'm not 100% clear about the reasoning there, I have read the discussion in its alternatives section a couple times but still do not quite grok why it is hard to apply the same analysis we use for normal Update: okay, clearly even if we got the capability to declare trait methods as pub unsafe const fn new(inner: T) -> NonZero<T> {
debug_assert!(!inner.is_zero());
NonZero(inner)
} meh. |
I just encountered another case where this bug bit me: we have some places where we have a new-type wrapper around a
Anyway, I thought I might play with trying to make a trait to capture this pattern of new-typed wrapper around a simple trait Idx {
type Data;
const INVALID: Self;
fn idx(&self) -> usize;
} then I tried making this impl of the above trait: pub struct MovePathIndex(usize);
const INVALID_MOVE_PATH_INDEX: MovePathIndex = MovePathIndex(usize::MAX);
impl Idx for MovePathIndex {
type Data = MovePath;
const INVALID: Self = INVALID_MOVE_PATH_INDEX;
fn idx(&self) -> usize { self.0 }
} and Bam: I hit the bug:
(I suspect this is exactly the kind of case that @petrochenkov was talking about above.) |
(nominating so that the compiler team can decide what priority it is to fix this, assuming it should be fixed in the first place...) |
triage: P-medium |
Hit this just now. |
Similar thing you cannot do is
|
cc @eddyb |
The problem here is that we use a constant |
Support references to outer type params for assoc consts Fixes rust-lang#28809 r? @eddyb
Support references to outer type params for assoc consts Fixes rust-lang#28809 r? @eddyb
Support references to outer type params for assoc consts Fixes rust-lang#28809 r? @eddyb
associated constants should support references to outer type parameters
Here is an example, adapted from the
Zeroable
trait fromcore::non_zero
(playpen):An attempt to compile this yields the error:
The text was updated successfully, but these errors were encountered: