forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
result_tracing
: error return tracing in core
#1
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
Open
BGR360
wants to merge
3
commits into
const-trait-specialize
Choose a base branch
from
result-tracing
base: const-trait-specialize
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -1132,6 +1132,7 @@ symbols! { | |
repr_transparent, | ||
residual, | ||
result, | ||
result_tracing, | ||
rhs, | ||
rintf32, | ||
rintf64, | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -425,3 +425,74 @@ fn result_try_trait_v2_branch() { | |
assert_eq!(Ok::<NonZeroU32, ()>(one).branch(), Continue(one)); | ||
assert_eq!(Err::<NonZeroU32, ()>(()).branch(), Break(Err(()))); | ||
} | ||
|
||
mod result_tracing { | ||
use core::panic; | ||
use core::result::Trace; | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
struct TracedError(pub u32); | ||
|
||
impl From<u32> for TracedError { | ||
fn from(i: u32) -> Self { | ||
Self(i) | ||
} | ||
} | ||
|
||
impl Trace for TracedError { | ||
// Increment by 1 on every `?` invocation. | ||
fn trace(&mut self, _location: &'static panic::Location<'static>) { | ||
self.0 += 1; | ||
} | ||
} | ||
|
||
#[test] | ||
fn try_operator_calls_trace() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: add const equivalent of this test |
||
fn foo() -> Result<(), TracedError> { | ||
Err(TracedError(0)) | ||
} | ||
|
||
fn bar() -> Result<(), TracedError> { | ||
Ok(foo()?) | ||
} | ||
|
||
fn baz() -> Result<(), TracedError> { | ||
Ok(bar()?) | ||
} | ||
|
||
let result = baz(); | ||
assert_eq!(result, Err(TracedError(2))); | ||
} | ||
|
||
#[test] | ||
fn try_operator_converts_into_traced_type_and_calls_trace() { | ||
fn foo() -> Result<(), TracedError> { | ||
Err(0)? | ||
} | ||
|
||
let result = foo(); | ||
assert_eq!(result, Err(TracedError(1))); | ||
} | ||
|
||
#[test] | ||
fn try_operator_provides_correct_location() { | ||
#[derive(Default)] | ||
struct TheLocation(pub Option<&'static panic::Location<'static>>); | ||
|
||
impl Trace for TheLocation { | ||
fn trace(&mut self, location: &'static panic::Location<'static>) { | ||
self.0 = Some(location); | ||
} | ||
} | ||
|
||
let two_lines_before = panic::Location::caller(); | ||
fn foo() -> Result<(), TheLocation> { | ||
Err(TheLocation::default())? | ||
} | ||
|
||
let result = foo(); | ||
let location = result.unwrap_err().0.unwrap(); | ||
assert_eq!(location.file(), two_lines_before.file()); | ||
assert_eq!(location.line(), two_lines_before.line() + 2); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/ui/rfc-2632-const-trait-impl/specialization/const-default-const-specialized.rs
This file contains hidden or 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,38 @@ | ||
// Tests that a const default trait impl can be specialized by another const | ||
// trait impl and that the specializing impl will be used during const-eval. | ||
|
||
// run-pass | ||
|
||
#![feature(const_trait_impl)] | ||
#![feature(min_specialization)] | ||
|
||
trait Value { | ||
fn value() -> u32; | ||
} | ||
|
||
const fn get_value<T: ~const Value>() -> u32 { | ||
T::value() | ||
} | ||
|
||
impl<T> const Value for T { | ||
default fn value() -> u32 { | ||
0 | ||
} | ||
} | ||
|
||
struct FortyTwo; | ||
|
||
impl const Value for FortyTwo { | ||
fn value() -> u32 { | ||
42 | ||
} | ||
} | ||
|
||
const ZERO: u32 = get_value::<()>(); | ||
|
||
const FORTY_TWO: u32 = get_value::<FortyTwo>(); | ||
|
||
fn main() { | ||
assert_eq!(ZERO, 0); | ||
assert_eq!(FORTY_TWO, 42); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/ui/rfc-2632-const-trait-impl/specialization/const-default-non-const-specialized.rs
This file contains hidden or 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,37 @@ | ||
// Tests that a const default trait impl can be specialized by a non-const trait | ||
// impl, but that the specializing impl cannot be used in a const context. | ||
|
||
#![feature(const_trait_impl)] | ||
#![feature(min_specialization)] | ||
|
||
trait Value { | ||
fn value() -> u32; | ||
} | ||
|
||
const fn get_value<T: ~const Value>() -> u32 { | ||
// Ideally this error would show up at the call to `get_value`, not here. | ||
T::value() | ||
//~^ ERROR any use of this value will cause an error | ||
//~| WARNING this was previously accepted | ||
} | ||
|
||
impl<T> const Value for T { | ||
default fn value() -> u32 { | ||
0 | ||
} | ||
} | ||
|
||
struct FortyTwo; | ||
|
||
impl Value for FortyTwo { | ||
fn value() -> u32 { | ||
println!("You can't do that (constly)"); | ||
42 | ||
} | ||
} | ||
|
||
const ZERO: u32 = get_value::<()>(); | ||
|
||
const FORTY_TWO: u32 = get_value::<FortyTwo>(); | ||
|
||
fn main() {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think you did it right. The release team has a whole process for how they remove cfg(bootstrap) directives
https://forge.rust-lang.org/release/process.html?highlight=bootstrap#master-bootstrap-update-t-2-day-tuesday
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.
ok dope