Skip to content

False positive unsafe function call warning for vec![] on nightly #18871

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

Closed
bjorn3 opened this issue Jan 7, 2025 · 1 comment
Closed

False positive unsafe function call warning for vec![] on nightly #18871

bjorn3 opened this issue Jan 7, 2025 · 1 comment
Labels
A-diagnostics diagnostics / error reporting C-bug Category: bug

Comments

@bjorn3
Copy link
Member

bjorn3 commented Jan 7, 2025

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

rustc version: rustc 1.86.0-nightly (1891c2866 2025-01-04)

editor or extension: VSCode

relevant settings: none

repository link (if public, optional):

code snippet to reproduce:

fn foo() {
   vec![0]; //~ call to unsafe function is unsafe and requires an unsafe function or block
}

This happens because vec![] now expands to a alloc::boxed::box_new call which is marked as #[rustc_intrinsic]. Rust-analyzer however doesn't treat it as safe intrinsic. In the past there was a list of hard coded intrinsics that are safe, but nowadays any #[rustc_intrinsic] which doesn't have unsafe as part of their signature is safe (rustc still double checks the declaration I think, but rust-analyzer shouldn't need to).

@bjorn3 bjorn3 added A-diagnostics diagnostics / error reporting C-bug Category: bug labels Jan 7, 2025
@lnicola lnicola closed this as completed Jan 7, 2025
@bjorn3
Copy link
Member Author

bjorn3 commented Jan 7, 2025

Didn't see that issue. And vscode didn't update the extension until I explicitly told it to do so...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants