-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Constify conversion traits (part 1) #145279
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
base: master
Are you sure you want to change the base?
Conversation
#![feature(const_default)] | ||
#![feature(const_eval_select)] | ||
#![feature(const_heap)] | ||
#![feature(const_trait_impl)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was listed under library features, and is actually a language feature. Since the diff doesn't make that clear.
// FIXME(const-hack): this should use map_err instead | ||
match u8::try_from(u32::from(c)) { | ||
Ok(b) => Ok(b), | ||
Err(_) => Err(TryFromCharError(())), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned not wanting to add any more const-hacks, but I figured this one (+ for u16
below) was okay because we're already going to have to fix a lot of const code once things are stable, and I think that simple char <-> integer conversions are useful enough to get on nightly sooner. Especially since const closures seem pretty far off at the moment.
☔ The latest upstream changes (presumably #145334) made this pull request unmergeable. Please resolve the merge conflicts. |
365fcde
to
97c330f
Compare
This is the first part of #144289 being split into smaller pieces. It adds/moves constness of several traits under the
const_convert
feature:From
Into
TryFrom
TryInto
FromStr
AsRef
AsMut
Borrow
BorrowMut
Deref
DerefMut
There are a few methods that are intrinsically tied to these traits which I've included in the feature. Particularly, those which are wrappers over
AsRef
:ByteStr::new
(unstable underbstr
feature)OsStr::new
Path::new
Those which directly use
Into
:Result::into_ok
Result::into_err
And those which use
Deref
andDerefMut
:Pin::as_ref
Pin::as_mut
Pin::as_deref_mut
The parts which are missing from this PR are:
OsStr
orPath
(note: this mostly makes these methods useless sincestr
doesn't implementAsRef<OsStr>
yet, but it's better to track the method for now and add impls later, IMHO)r? @tgross35 (who mostly already reviewed this)