File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -110,9 +110,13 @@ fn main() {
110110}
111111```
112112
113- Polymorphic type and ` Into<T> ` : [ link] ( https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=70746dda53fe77e47ea1c8f68e6ef169 ) .
113+ Polymorphic type and ` Into<T> ` : [ link] ( https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=6e83d0668f7734f455e5b90980d791f9 ) .
114114
115115``` rust
116+ #![allow(unused_variables)]
117+ #![allow(unused_assignments)]
118+
119+ #[derive(Debug )]
116120struct DontPanic ;
117121
118122fn do_not_panic () -> DontPanic { DontPanic }
@@ -136,7 +140,22 @@ fn print_int<T: Into<i32>>(val: T) {
136140}
137141
138142fn main () {
143+ // This works.
139144 print_string (do_not_panic ());
140145 print_int (do_not_panic ());
146+
147+ // Can do this btw!
148+ let mut v = Vec :: new ();
149+ v . push (do_not_panic (). into ());
150+ v . push (do_not_panic (). into ());
151+ v . push (do_not_panic ()); // But at least one must specify the actual type!
152+ println! (" {:?}" , v );
153+
154+ // Same with Option: either at least one proper assignment, or explicit type spec.
155+ let mut o : Option <_ > = None ;
156+ o = None ;
157+ o = None ;
158+ o = Some (true ); // Need either this assignment or an explicit type annotation.
159+ o = None ;
141160}
142161```
You can’t perform that action at this time.
0 commit comments