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.
- 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() { | ||
} |