Repository navigation
Tracking issue for RFC 2011: Generic assert #44838
Copy link
Copy link
Open
Labels
A-error-handlingArea: Error handlingArea: Error handlingA-fmtArea: `core::fmt`Area: `core::fmt`B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-generic_assert`#![feature(generic_assert)]``#![feature(generic_assert)]`I-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.PG-error-handlingProject group: Error handling (https://github.com/rust-lang/project-error-handling)Project group: Error handling (https://github.com/rust-lang/project-error-handling)S-tracking-impl-incompleteStatus: The implementation is incomplete.Status: The implementation is incomplete.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
This is a tracking issue for rust-lang/rfcs#2011.
The feature gate for the issue is #![feature(generic_assert)].
Sub tracking-issue: #96949.
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
- Implementation (see section Implementation history)
- Final comment period (FCP)1
- Stabilization PR
Blockers
Implementation history
- [RFC 2011] Library code #97233
- [RFC 2011] Basic compiler infrastructure #97450
- [RFC 2011] Minimal initial implementation #97665
- [RFC 2011] Expand expressions where possible #98148
- [RFC 2011] Optimize non-consuming operators #98337
- [RFC-2011] Expand more expressions #111928
- [generic_assert] Constify methods used by the formatting system #135139
- [generic_assert] "Constify" the
Debugtrait #135712
Footnotes
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-error-handlingArea: Error handlingArea: Error handlingA-fmtArea: `core::fmt`Area: `core::fmt`B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-generic_assert`#![feature(generic_assert)]``#![feature(generic_assert)]`I-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.PG-error-handlingProject group: Error handling (https://github.com/rust-lang/project-error-handling)Project group: Error handling (https://github.com/rust-lang/project-error-handling)S-tracking-impl-incompleteStatus: The implementation is incomplete.Status: The implementation is incomplete.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Activity
bstrie commentedon Sep 27, 2017
durka commentedon Sep 27, 2017
bstrie commentedon Sep 27, 2017
emilio commentedon Feb 7, 2018
Quick question, is it expected for this to have some sort of switch to less-nice error messages? Sometimes people care about code size, and including a bunch of debug formatters on release builds may not be acceptable.
ishitatsuyuki commentedon Feb 7, 2018
This was one of the concerns in the RFC, and following are some points:
sinkuu commentedon Mar 8, 2018
I am trying to implement this, but have not been successful so far. The problem is that we don't know if a operand is
Copyduring macro expansion.Status quo(sinkuu@ba00a0e):
expands to
But this moves non-
Copyoperands intoassert, and causes use-after-move afterward.@ishitatsuyuki Do you have concrete implementation strategies in mind?
ishitatsuyuki commentedon Mar 8, 2018
@sinkuu Nice work! However,
PartialEqtakes self by reference, which means you don't have to copy/clone it. In this case, we may have to call the trait methods directly instead of the operators.In the case of moving Ops like
Add, your approach is good and should just work.Another thing is that we should use our own enum instead of
Optionhere, as we need to handle the case of non-Copy type and the case of short-circuit differently.shepmaster commentedon Mar 8, 2018
You might be able to use the tricks that
assert_eq!uses to take references to the arguments as well.gilescope commentedon Mar 21, 2018
I’m probably not meant to comment now given the RFC has been merged, but spare a thought for if it’s possible to line up both sides of an == vertically above and below one another as that can make things much easier to spot the difference. Really love this rfc btw, looking forward to it.
ishitatsuyuki commentedon Mar 21, 2018
@gilescope You're welcome to comment on how we should form the message. The RFC is just meant to be a brief proposal, and there are libraries in other languages that has much more helpful expansion outputs. (Example: https://github.com/power-assert-js/power-assert)
35 remaining items
Auto merge of rust-lang#111928 - c410-f3r:dqewdas, r=eholk
[-]Tracking issue for RFC 2011: nicer assert messages[/-][+]Tracking issue for RFC 2011: Generic assert[/+]Auto merge of rust-lang#134126 - c410-f3r:hocus-pocus, r=<try>
Auto merge of rust-lang#134126 - c410-f3r:hocus-pocus, r=<try>
Rollup merge of rust-lang#135139 - c410-f3r:8-years-rfc, r=jhpratt
Rollup merge of rust-lang#135139 - c410-f3r:8-years-rfc, r=jhpratt
Unrolled build for rust-lang#135139
Sky9x commentedon Feb 23, 2025
@c410-f3r IIUC the most straightforward implementation (where you write
constand~constin a few places and rustc does the rest) requires dynamic dispatch in CTFE, which in turn requiresconst fn()function pointers. This is becauseFormatterinternally holds and writes to adyn fmt::Write.Here's a little const formatting demo i threw together a couple months ago: https://gist.github.com/Sky9x/e11cb7ba0772289c05172ebda7dcaeda
the code is pretty crap but it all leads to this line:
where
MEOWis a&'static strand after const evaluation it has the content"meow :3 -59999 true x3".I couldn't be bothered to implement template parsing so instead it just formats and concatenates everything into one big buffer, then returns it as a
&'static str. The macro will also panic if called at runtime.However, that API is not suitable for use in
stdbecause it makesFormatterandDisplay::fmtgeneric over the writer type, which is a breaking change.c410-f3r commentedon Feb 24, 2025
The intention is to "constify" all methods and related traits of https://github.com/rust-lang/rust/blob/master/library/core/src/asserting.rs, which is on the library side.
If additional support is necessary on the compiler side beyond the ongoing
#[const_trait]effort, then it is probably wise to just skipgeneric_assertin constant environments.Rollup merge of rust-lang#135139 - c410-f3r:8-years-rfc, r=jhpratt