Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upassociated constants should support references to outer type parameters #28809
Comments
This comment has been minimized.
This comment has been minimized.
|
Oh, I was interested in this some time ago, but mostly in |
steveklabnik
added
the
A-associated-items
label
Oct 4, 2015
This comment has been minimized.
This comment has been minimized.
|
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. |
pnkfelix
referenced this issue
Jan 26, 2016
Closed
NonZero constructor in debug-builds should assert input is actually nonzero. #31217
This comment has been minimized.
This comment has been minimized.
|
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.) |
pnkfelix
added
T-compiler
I-nominated
labels
Jan 29, 2016
This comment has been minimized.
This comment has been minimized.
|
(nominating so that the compiler team can decide what priority it is to fix this, assuming it should be fixed in the first place...) |
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium |
rust-highfive
added
P-medium
and removed
I-nominated
labels
Feb 4, 2016
petrochenkov
referenced this issue
Mar 14, 2016
Closed
Default Associated Consts cannot use `Self::` #32241
alexcrichton
added
the
A-resolve
label
Mar 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Hit this just now. |
This comment has been minimized.
This comment has been minimized.
|
Similar thing you cannot do is
|
This comment has been minimized.
This comment has been minimized.
|
cc @eddyb |
This comment has been minimized.
This comment has been minimized.
|
The problem here is that we use a constant |
pnkfelix commentedOct 2, 2015
associated constants should support references to outer type parameters
Here is an example, adapted from the
Zeroabletrait fromcore::non_zero(playpen):An attempt to compile this yields the error: