Skip to content

Commit

Permalink
Remove field attr
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaBluejay committed Aug 14, 2023
1 parent 08c4d34 commit f13572a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 84 deletions.
2 changes: 1 addition & 1 deletion impl/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn allowed_attr_params() -> AttrParams {
enum_: vec!["ignore", "forward"],
struct_: vec!["ignore", "forward"],
variant: vec!["ignore", "forward"],
field: vec!["ignore", "source", "backtrace", "forward"],
field: vec!["ignore", "source", "backtrace"],
}
}

Expand Down
30 changes: 0 additions & 30 deletions tests/error/derives_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,3 @@ fn variant_attr() {
assert!(err_b.source().is_some());
assert!(err_b.source().unwrap().is::<Inner>());
}

derive_display!(FieldAttr);
#[derive(Debug, Error)]
enum FieldAttr {
A {
#[error(forward, source)]
field: Inner,
},
B {
#[error(source)]
field: Inner,
},
}

#[test]
fn field_attr() {
let err_a = FieldAttr::A {
field: Inner { source: SimpleErr },
};

let err_b = FieldAttr::B {
field: Inner { source: SimpleErr },
};

assert!(err_a.source().is_some());
assert!(err_a.source().unwrap().is::<SimpleErr>());

assert!(err_b.source().is_some());
assert!(err_b.source().unwrap().is::<Inner>());
}
53 changes: 0 additions & 53 deletions tests/error/nightly/derives_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,56 +147,3 @@ fn variant_attr() {
assert_eq!(any::request_value::<i32>(&err_b), Some(42));
assert_bt!(==, err_b, .get_source_backtrace);
}

derive_display!(FieldAttr);
#[derive(Debug, Error)]
enum FieldAttr {
A {
#[error(forward, backtrace)]
source: Inner,
},
B {
#[error(backtrace)]
source: Inner,
},
}

impl FieldAttr {
fn get_source_backtrace(&self) -> &Backtrace {
any::request_ref(match self {
Self::A { source } => &source.source,
Self::B { source } => &source.source,
})
.unwrap()
}
}

#[test]
fn field_attr() {
let err_a = FieldAttr::A {
source: Inner {
source: BacktraceErr {
backtrace: Backtrace::force_capture(),
},
},
};
let err_b = FieldAttr::B {
source: Inner {
source: BacktraceErr {
backtrace: Backtrace::force_capture(),
},
},
};

assert!(err_a.source().is_some());
assert!(err_a.source().unwrap().is::<BacktraceErr>());
assert!(any::request_ref::<Backtrace>(&err_a).is_some());
assert_eq!(any::request_value::<i32>(&err_a), Some(42));
assert_bt!(==, err_a, .get_source_backtrace);

assert!(err_b.source().is_some());
assert!(err_b.source().unwrap().is::<Inner>());
assert!(any::request_ref::<Backtrace>(&err_b).is_some());
assert_eq!(any::request_value::<i32>(&err_b), Some(42));
assert_bt!(==, err_b, .get_source_backtrace);
}

0 comments on commit f13572a

Please sign in to comment.