File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,11 +4,17 @@ use std::env;
44
55fn main ( ) {
66 let ac = autocfg:: new ( ) ;
7+
78 if ac. probe_type ( "i128" ) {
89 println ! ( "cargo:rustc-cfg=has_i128" ) ;
910 } else if env:: var_os ( "CARGO_FEATURE_I128" ) . is_some ( ) {
1011 panic ! ( "i128 support was not detected!" ) ;
1112 }
1213
14+ // autocfg doesn't have a direct way to probe for `const fn` yet.
15+ if ac. probe_rustc_version ( 1 , 31 ) {
16+ autocfg:: emit ( "has_const_fn" ) ;
17+ }
18+
1319 autocfg:: rerun_path ( file ! ( ) ) ;
1420}
Original file line number Diff line number Diff line change @@ -92,13 +92,23 @@ pub struct Complex<T> {
9292pub type Complex32 = Complex < f32 > ;
9393pub type Complex64 = Complex < f64 > ;
9494
95- impl < T : Clone + Num > Complex < T > {
95+ impl < T > Complex < T > {
96+ #[ cfg( has_const_fn) ]
97+ /// Create a new Complex
98+ #[ inline]
99+ pub const fn new ( re : T , im : T ) -> Self {
100+ Complex { re : re, im : im }
101+ }
102+
103+ #[ cfg( not( has_const_fn) ) ]
96104 /// Create a new Complex
97105 #[ inline]
98106 pub fn new ( re : T , im : T ) -> Self {
99107 Complex { re : re, im : im }
100108 }
109+ }
101110
111+ impl < T : Clone + Num > Complex < T > {
102112 /// Returns imaginary unit
103113 #[ inline]
104114 pub fn i ( ) -> Self {
You can’t perform that action at this time.
0 commit comments