Skip to content

Commit 6d94167

Browse files
Cameron SteffenCameron Steffen
authored andcommitted
move cstring tests
1 parent 5eeadcf commit 6d94167

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

tests/ui/cstring.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {}
2+
3+
#[allow(result_unwrap_used)]
4+
fn temporary_cstring() {
5+
use std::ffi::CString;
6+
7+
CString::new("foo").unwrap().as_ptr();
8+
}

tests/ui/cstring.stderr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: function is never used: `temporary_cstring`
2+
--> $DIR/cstring.rs:4:1
3+
|
4+
4 | fn temporary_cstring() {
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D dead-code` implied by `-D warnings`
8+
9+
error: you are getting the inner pointer of a temporary `CString`
10+
--> $DIR/cstring.rs:7:5
11+
|
12+
7 | CString::new("foo").unwrap().as_ptr();
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
= note: `-D temporary-cstring-as-ptr` implied by `-D warnings`
16+
= note: that pointer will be invalid outside this expression
17+
help: assign the `CString` to a variable to extend its lifetime
18+
--> $DIR/cstring.rs:7:5
19+
|
20+
7 | CString::new("foo").unwrap().as_ptr();
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+

tests/ui/methods.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,3 @@ fn str_extend_chars() {
453453
let f = HasChars;
454454
s.extend(f.chars());
455455
}
456-
457-
#[allow(result_unwrap_used)]
458-
fn temporary_cstring() {
459-
use std::ffi::CString;
460-
461-
CString::new("foo").unwrap().as_ptr();
462-
}

tests/ui/methods.stderr

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -567,17 +567,3 @@ error: calling `.extend(_.chars())`
567567
447 | s.extend(def.chars());
568568
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(&def)`
569569

570-
error: you are getting the inner pointer of a temporary `CString`
571-
--> $DIR/methods.rs:461:5
572-
|
573-
461 | CString::new("foo").unwrap().as_ptr();
574-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
575-
|
576-
= note: `-D temporary-cstring-as-ptr` implied by `-D warnings`
577-
= note: that pointer will be invalid outside this expression
578-
help: assign the `CString` to a variable to extend its lifetime
579-
--> $DIR/methods.rs:461:5
580-
|
581-
461 | CString::new("foo").unwrap().as_ptr();
582-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
583-

0 commit comments

Comments
 (0)