Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not suppress temporary_cstring_as_ptr in macros. #109944

Merged
merged 1 commit into from
Apr 5, 2023

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Apr 4, 2023

There isn't really a reason to skip the lint when part of the expression comes from an expansion.

Fixes #94694

@rustbot
Copy link
Collaborator

rustbot commented Apr 4, 2023

r? @compiler-errors

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 4, 2023
@Noratrieb
Copy link
Member

Weird.
r? Nilstrieb
@bors r+
It seems like this lint could be a lot smarter than just checking for unwrap and expect but well, this probably lints most of the cases with little effort.

@bors
Copy link
Contributor

bors commented Apr 4, 2023

📌 Commit 8528ac6 has been approved by Nilstrieb

It is now in the queue for this repository.

@rustbot rustbot assigned Noratrieb and unassigned compiler-errors Apr 4, 2023
@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 4, 2023
@bors
Copy link
Contributor

bors commented Apr 4, 2023

⌛ Testing commit 8528ac6 with merge 6032700...

@bors
Copy link
Contributor

bors commented Apr 5, 2023

☀️ Test successful - checks-actions
Approved by: Nilstrieb
Pushing 6032700 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 5, 2023
@bors bors merged commit 6032700 into rust-lang:master Apr 5, 2023
@rustbot rustbot added this to the 1.70.0 milestone Apr 5, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6032700): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.5% [0.2%, 1.8%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.6% [1.0%, 2.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.4%, -1.7%] 2
All ❌✅ (primary) - - 0

@cjgillot cjgillot deleted the lint-cstring-macro branch April 5, 2023 20:09
sunfishcode added a commit to sunfishcode/coreutils that referenced this pull request Apr 24, 2023
Rust nightly recently [started] issuing the following warning when
compiling coreutils:

[started]: rust-lang/rust#109944

```
warning: getting the inner pointer of a temporary `CString`
   --> src/uucore/src/lib/features/entries.rs:324:67
    |
324 |                         let data = $fnam(CString::new(k).unwrap().as_ptr());
    |                                          ------------------------ ^^^^^^ this pointer will be invalid
    |                                          |
    |                                          this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
...
340 | f!(getpwnam, getpwuid, uid_t, Passwd);
    | ------------------------------------- in this macro invocation
    |
    = note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
    = help: for more information, see https://doc.rust-lang.org/reference/destructors.html
    = note: `#[warn(temporary_cstring_as_ptr)]` on by default
    = note: this warning originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info)
```

There doesn't seem to be an actual problem in this case, as the pointer is
only used within the statement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linter warning not fired in macro code
6 participants