Libs Meetings
Minutes
Meeting Link: https://meet.jit.si/rust-libs-meeting-crxoz2at8hiccp7b3ixf89qgxfymlbwr
Attendees: David, JoshT, Mara, TC
10 rust-lang/rust T-libs-api FCPs
box_into_inner
- (1 checkboxes left)PartialOrd
and Ord
for Discriminant
- (2 checkboxes left)non_null_from_ref
- (3 checkboxes left)cfg_match
- (4 checkboxes left)naked_functions
- (2 checkboxes left)replace
methods - (3 checkboxes left)os_string_pathbuf_leak
- (4 checkboxes left)concat_idents!
- (4 checkboxes left)tmandry (1), nikomatsakis (3), dtolnay (2), joshtriplett (5), Amanieu (6), BurntSushi (8), m-ou-se (2), scottmcm (3)
Discussed two weeks ago.
New suggestion by Chris: https://github.com/rust-lang/libs-team/issues/358#issuecomment-2683524977
Need to figure out what to do with the N==0
case.
JoshT: Make it a runtime error or compile error depending on if it is const eval'ed?
TC: That's just a regular assert!()
. In a const context, that will error. Here are the options. The analogy is that divide
is what we would do for array_chunks
. The divide_checked
function is the example of the problem that we're talking about (what people may or may not be able to write usefully).
Option 1: Use a constant assertion.
const fn divide<const D: u64>(n: u64) -> u64 {
const { assert!(D > 0) }; // <--- Post-mono assertion.
n / D
}
const fn divide_checked<const D: u64>(n: u64) -> Option<u64> {
match D {
0 => None,
1.. => Some(divide::<D>(n)),
}
}
fn main() {
dbg!({const { divide_checked::<1>(1) }});
dbg!({const { divide_checked::<0>(1) }}); // <--- Look here.
dbg!(divide_checked::<1>(1));
dbg!(divide_checked::<0>(1)); //~ ERROR
}
Playground link at: https://github.com/rust-lang/rust/issues/74985#issuecomment-2677242740.
Option 1b: Use a constant assertion and add a compiler feature to error on a generic being provided as a const generic argument to save space for changing the type of the const generic to const D: NonZero<u64>
.
const fn divide<#[require_concrete_val] const D: u64>(n: u64) -> u64 {
const { assert!(D > 0) }; // <--- Post-mono assertion.
n / D
}
const fn divide_checked<const D: u64>(n: u64) -> Option<u64> {
match D {
0 => None,
1.. => Some(divide::<D>(n)), //~ ERROR
}
}
fn main() {
dbg!({const { divide_checked::<1>(1) }}); //~ ERROR
dbg!({const { divide_checked::<0>(1) }}); //~ ERROR
dbg!(divide_checked::<1>(1)); //~ ERROR
dbg!(divide_checked::<0>(1)); //~ ERROR
}
Option 2: Use a runtime assertion.
const fn divide<const D: u64>(n: u64) -> u64 {
assert!(D > 0); // <--- Runtime assertion.
n / D
}
const fn divide_checked<const D: u64>(n: u64) -> Option<u64> {
match D {
0 => None,
1.. => Some(divide::<D>(n)),
}
}
fn main() {
dbg!({const { divide_checked::<1>(1) }});
dbg!({const { divide_checked::<0>(1) }});
dbg!(divide_checked::<1>(1));
dbg!(divide_checked::<0>(1));
}
Option 3 (with arbitrary time delay): Wait for a language feature like const match
before stabilizing anything.
const fn divide<const D: u64>(n: u64) -> u64 {
const { assert!(D > 0) }; // <--- Post-mono assertion.
n / D
}
const fn divide_checked<const D: u64>(n: u64) -> Option<u64> {
const match D { // <-- Doesn't exist yet.
0 => None,
1.. => Some(divide::<D>(n)),
}
}
fn main() {
dbg!({const { divide_checked::<1>(1) }});
dbg!({const { divide_checked::<0>(1) }});
dbg!(divide_checked::<1>(1));
dbg!(divide_checked::<0>(1));
}
David: We want this to be usable in an if-branch that's not taken at runtime.
JoshT: So const { divide::<0>(1) }
will error at compile time, and divide::<0>(1)
will panic and perhaps lint.
TC: divide_checked
is not divide
.
divide_checked
is the example that should still work.
The 8472: With option 1 a user can use https://github.com/rust-lang/rust/issues/122301 to avoid the post-mono error. But it's clunky and not forward-compatible.
Summary:
TC: Straw poll:
array_chunks::<3>(..)
. Offering this now would provide immediate value. Then the case of passing in a generic can be solved on the lang side later by making language progress.assert!
for better error outputcell_update
featurecfg_match!
to cfg_select!
josh: Would prefer not to rename. match
is a more familiar name to people and this does work like a match.
concat_idents!
Clone
implementation for ChunkBy
Display
and FromStr
, and their interactionsTEB
to get process information on Windowsiter::Peekable::next_unpeek
josh: Since File::append
has been approved, this becomes as simple as File::append("path")?.write_all("hello")?;
. Turning that into a single function doesn't seem worth it.
std::io::Seek
instance for std::io::Take<T>
when T: Seek
std::process::Output::exit_ok
Vec
Context
impl Display for CStr
uNN::checked_sub_nonzero
FromStr
NonNull::{from_ref, from_mut}
ExactSizeIterators
on 64-bit platformsFromByteStr
trait with blanket impl FromStr
Generated by fully-automatic-rust-libs-team-triage-meeting-agenda-generator