|
| 1 | +error: getting a pointer from a temporary `String` will result in a dangling pointer |
| 2 | + --> $DIR/instantly-dangling-pointer-temporaries.rs:21:14 |
| 3 | + | |
| 4 | +LL | string().as_ptr(); |
| 5 | + | -------- ^^^^^^ this pointer will immediately be invalid |
| 6 | + | | |
| 7 | + | this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime |
| 8 | + | |
| 9 | + = note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned |
| 10 | + = help: for more information, see https://doc.rust-lang.org/reference/destructors.html |
| 11 | +note: the lint level is defined here |
| 12 | + --> $DIR/instantly-dangling-pointer-temporaries.rs:2:9 |
| 13 | + | |
| 14 | +LL | #![deny(instantly_dangling_pointer)] |
| 15 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 16 | + |
| 17 | +error: getting a pointer from a temporary `String` will result in a dangling pointer |
| 18 | + --> $DIR/instantly-dangling-pointer-temporaries.rs:24:25 |
| 19 | + | |
| 20 | +LL | "hello".to_string().as_ptr(); |
| 21 | + | ------------------- ^^^^^^ this pointer will immediately be invalid |
| 22 | + | | |
| 23 | + | this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime |
| 24 | + | |
| 25 | + = note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned |
| 26 | + = help: for more information, see https://doc.rust-lang.org/reference/destructors.html |
| 27 | + |
| 28 | +error: getting a pointer from a temporary `String` will result in a dangling pointer |
| 29 | + --> $DIR/instantly-dangling-pointer-temporaries.rs:30:26 |
| 30 | + | |
| 31 | +LL | (string() + "hello").as_ptr(); |
| 32 | + | -------------------- ^^^^^^ this pointer will immediately be invalid |
| 33 | + | | |
| 34 | + | this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime |
| 35 | + | |
| 36 | + = note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned |
| 37 | + = help: for more information, see https://doc.rust-lang.org/reference/destructors.html |
| 38 | + |
| 39 | +error: getting a pointer from a temporary `String` will result in a dangling pointer |
| 40 | + --> $DIR/instantly-dangling-pointer-temporaries.rs:65:61 |
| 41 | + | |
| 42 | +LL | (if true { String::new() } else { "hello".into() }).as_ptr(); |
| 43 | + | --------------------------------------------------- ^^^^^^ this pointer will immediately be invalid |
| 44 | + | | |
| 45 | + | this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime |
| 46 | + | |
| 47 | + = note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned |
| 48 | + = help: for more information, see https://doc.rust-lang.org/reference/destructors.html |
| 49 | + |
| 50 | +error: getting a pointer from a temporary `String` will result in a dangling pointer |
| 51 | + --> $DIR/instantly-dangling-pointer-temporaries.rs:74:10 |
| 52 | + | |
| 53 | +LL | / (loop { |
| 54 | +LL | | break String::new(); |
| 55 | +LL | | }) |
| 56 | + | |__________- this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime |
| 57 | +LL | .as_ptr(); |
| 58 | + | ^^^^^^ this pointer will immediately be invalid |
| 59 | + | |
| 60 | + = note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned |
| 61 | + = help: for more information, see https://doc.rust-lang.org/reference/destructors.html |
| 62 | + |
| 63 | +error: getting a pointer from a temporary `String` will result in a dangling pointer |
| 64 | + --> $DIR/instantly-dangling-pointer-temporaries.rs:82:10 |
| 65 | + | |
| 66 | +LL | / match string() { |
| 67 | +LL | | s => s, |
| 68 | +LL | | } |
| 69 | + | |_________- this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime |
| 70 | +LL | .as_ptr(); |
| 71 | + | ^^^^^^ this pointer will immediately be invalid |
| 72 | + | |
| 73 | + = note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned |
| 74 | + = help: for more information, see https://doc.rust-lang.org/reference/destructors.html |
| 75 | + |
| 76 | +error: getting a pointer from a temporary `String` will result in a dangling pointer |
| 77 | + --> $DIR/instantly-dangling-pointer-temporaries.rs:89:18 |
| 78 | + | |
| 79 | +LL | { string() }.as_ptr(); |
| 80 | + | ------------ ^^^^^^ this pointer will immediately be invalid |
| 81 | + | | |
| 82 | + | this `String` is deallocated at the end of the statement, bind it to a variable to extend its lifetime |
| 83 | + | |
| 84 | + = note: pointers do not have a lifetime; when calling `as_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned |
| 85 | + = help: for more information, see https://doc.rust-lang.org/reference/destructors.html |
| 86 | + |
| 87 | +error: getting a pointer from a temporary `Vec<u8>` will result in a dangling pointer |
| 88 | + --> $DIR/instantly-dangling-pointer-temporaries.rs:128:15 |
| 89 | + | |
| 90 | +LL | vec![0u8].as_ptr(); |
| 91 | + | --------- ^^^^^^ this pointer will immediately be invalid |
| 92 | + | | |
| 93 | + | this `Vec<u8>` is deallocated at the end of the statement, bind it to a variable to extend its lifetime |
| 94 | + | |
| 95 | + = note: pointers do not have a lifetime; when calling `as_ptr` the `Vec<u8>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned |
| 96 | + = help: for more information, see https://doc.rust-lang.org/reference/destructors.html |
| 97 | + |
| 98 | +error: aborting due to 8 previous errors |
| 99 | + |
0 commit comments