forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#97450 - c410-f3r:assert-compiler, r=oli-obk
[RFC 2011] Basic compiler infrastructure Splitting rust-lang#96496 into smaller pieces as was done in rust-lang#97233. Hope review will be easier. This PR practically contains no logic and only serves as a building ground for the actual code that will be placed in a posterior step. * Adds `context.rs` to place the new `assert!` logic. Has a lot of unused elements but all of them are used by the implementation. * Creates an unstable flag because the feature is not yet complete and also to allow external feedback. * Creates the necessary `sym` identifiers that are mostly based on the library elements -> https://github.com/rust-lang/rust/blob/master/library/core/src/asserting.rs * Modifies `assert.rs` to branch to `context.rs` if the unstable flag is enabled. * Adds a test to satisfy tidy but the test does nothing in reality.
- Loading branch information
Showing
7 changed files
with
129 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use rustc_ast::{ptr::P, Expr, Path}; | ||
use rustc_expand::base::ExtCtxt; | ||
use rustc_span::Span; | ||
|
||
pub(super) struct Context<'cx, 'a> { | ||
cx: &'cx ExtCtxt<'a>, | ||
span: Span, | ||
} | ||
|
||
impl<'cx, 'a> Context<'cx, 'a> { | ||
pub(super) fn new(cx: &'cx ExtCtxt<'a>, span: Span) -> Self { | ||
Self { cx, span } | ||
} | ||
|
||
/// Builds the whole `assert!` expression. | ||
/// | ||
/// { | ||
/// use ::core::asserting::{ ... }; | ||
/// | ||
/// let mut __capture0 = Capture::new(); | ||
/// ... | ||
/// ... | ||
/// ... | ||
/// | ||
/// if !{ | ||
/// ... | ||
/// ... | ||
/// ... | ||
/// } { | ||
/// panic!( | ||
/// "Assertion failed: ... \n With expansion: ...", | ||
/// __capture0, | ||
/// ... | ||
/// ... | ||
/// ... | ||
/// ); | ||
/// } | ||
/// } | ||
pub(super) fn build(self, _cond_expr: P<Expr>, _panic_path: Path) -> P<Expr> { | ||
let Self { cx, span, .. } = self; | ||
let stmts = Vec::new(); | ||
cx.expr_block(cx.block(span, stmts)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/ui/rfc-2011-nicer-assert-messages/feature-gate-generic_assert.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// compile-flags: --test | ||
// run-pass | ||
|
||
// `generic_assert` is completely unimplemented and doesn't generate any logic, thus the | ||
// reason why this test currently passes | ||
#![feature(core_intrinsics, generic_assert, generic_assert_internals)] | ||
|
||
use std::fmt::{Debug, Formatter}; | ||
|
||
#[derive(Clone, Copy, PartialEq)] | ||
struct CopyDebug(i32); | ||
|
||
impl Debug for CopyDebug { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { | ||
f.write_str("With great power comes great electricity bills") | ||
} | ||
} | ||
|
||
#[test] | ||
fn test() { | ||
let _copy_debug = CopyDebug(1); | ||
assert!(_copy_debug == CopyDebug(3)); | ||
} | ||
|
||
fn main() { | ||
} |