File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed
parse-display/tests/compile_fail/from_str Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -618,7 +618,7 @@ impl<'a> ParserBuilder<'a> {
618
618
} ,
619
619
) in self . with . iter ( ) . enumerate ( )
620
620
{
621
- with. push ( quote ! {
621
+ with. push ( quote_spanned ! { expr . span ( ) =>
622
622
( #capture, #helpers:: to_ast:: <#ty, _>( & #expr) )
623
623
} ) ;
624
624
let msg = format ! (
@@ -1699,14 +1699,23 @@ fn build_parse_capture_expr(
1699
1699
if let Some ( with) = & field. hattrs . with {
1700
1700
let ty = & field. source . ty ;
1701
1701
expr1 = quote ! {
1702
- #crate_path:: helpers:: parse_with:: <#ty, _ >( #with, #expr0)
1702
+ #crate_path:: helpers:: parse_with:: <#ty, _>( #with, #expr0)
1703
1703
} ;
1704
+ expr1 = set_span ( expr1, with. span ( ) ) ;
1704
1705
}
1705
1706
}
1706
1707
quote ! {
1707
1708
#expr1. map_err( |e| #crate_path:: ParseError :: with_message( #msg) ) ?
1708
1709
}
1709
1710
}
1711
+ fn set_span ( ts : TokenStream , span : Span ) -> TokenStream {
1712
+ ts. into_iter ( )
1713
+ . map ( |mut ts| {
1714
+ ts. set_span ( span) ;
1715
+ ts
1716
+ } )
1717
+ . collect ( )
1718
+ }
1710
1719
1711
1720
fn unref_ty ( ty : & Type ) -> Type {
1712
1721
if let Type :: Reference ( ty) = ty {
Original file line number Diff line number Diff line change
1
+ use parse_display:: FromStr ;
2
+
3
+ #[ derive( FromStr , Debug , PartialEq ) ]
4
+ struct X {
5
+ #[ from_str( with = "not impl FromStrFormat" ) ]
6
+ x : u8 ,
7
+ }
8
+
9
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0277]: the trait bound `&'static str: FromStrFormat<u8>` is not satisfied
2
+ --> tests/compile_fail/from_str/invalid_with.rs:5:23
3
+ |
4
+ 5 | #[from_str(with = "not impl FromStrFormat")]
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromStrFormat<u8>` is not implemented for `&'static str`
6
+ |
7
+ = note: required for the cast from `&&'static str` to `&dyn FromStrFormat<u8, Err = _>`
You can’t perform that action at this time.
0 commit comments