File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -119,13 +119,29 @@ impl From<String> for Box<Error + Send + Sync> {
119119 }
120120}
121121
122+ #[ stable( feature = "string_box_error" , since = "1.7.0" ) ]
123+ impl From < String > for Box < Error > {
124+ fn from ( str_err : String ) -> Box < Error > {
125+ let err1: Box < Error + Send + Sync > = From :: from ( str_err) ;
126+ let err2: Box < Error > = err1;
127+ err2
128+ }
129+ }
130+
122131#[ stable( feature = "rust1" , since = "1.0.0" ) ]
123132impl < ' a , ' b > From < & ' b str > for Box < Error + Send + Sync + ' a > {
124133 fn from ( err : & ' b str ) -> Box < Error + Send + Sync + ' a > {
125134 From :: from ( String :: from ( err) )
126135 }
127136}
128137
138+ #[ stable( feature = "string_box_error" , since = "1.7.0" ) ]
139+ impl < ' a > From < & ' a str > for Box < Error > {
140+ fn from ( err : & ' a str ) -> Box < Error > {
141+ From :: from ( String :: from ( err) )
142+ }
143+ }
144+
129145#[ stable( feature = "rust1" , since = "1.0.0" ) ]
130146impl Error for str:: ParseBoolError {
131147 fn description ( & self ) -> & str { "failed to parse bool" }
Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ // Ensure that both `Box<Error + Send + Sync>` and `Box<Error>` can be obtained from `String`.
12+
13+ use std:: error:: Error ;
14+
15+ fn main ( ) {
16+ let _err1: Box < Error + Send + Sync > = From :: from ( "test" . to_string ( ) ) ;
17+ let _err2: Box < Error > = From :: from ( "test" . to_string ( ) ) ;
18+ let _err3: Box < Error + Send + Sync + ' static > = From :: from ( "test" ) ;
19+ let _err4: Box < Error > = From :: from ( "test" ) ;
20+ }
You can’t perform that action at this time.
0 commit comments