Rollup merge of #135840 - vayunbiyani:omit_intrinsic_unused_param_warning, r=oli-obk

omit unused args warnings for intrinsics without body

potential fix for https://github.com/rust-lang/rust/issues/135598
This commit is contained in:
Matthias Krüger 2025-02-01 01:19:19 +01:00 committed by GitHub
commit 2460b280db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 14 deletions

View file

@ -1522,6 +1522,14 @@ impl<'tcx> Liveness<'_, 'tcx> {
} }
fn warn_about_unused_args(&self, body: &hir::Body<'_>, entry_ln: LiveNode) { fn warn_about_unused_args(&self, body: &hir::Body<'_>, entry_ln: LiveNode) {
if let Some(intrinsic) =
self.ir.tcx.intrinsic(self.ir.tcx.hir().body_owner_def_id(body.id()))
{
if intrinsic.must_be_overridden {
return;
}
}
for p in body.params { for p in body.params {
self.check_unused_vars_in_pat( self.check_unused_vars_in_pat(
p.pat, p.pat,

View file

@ -2,6 +2,7 @@
#![deny(unused_variables)] #![deny(unused_variables)]
#![deny(unused_assignments)] #![deny(unused_assignments)]
#![allow(dead_code, non_camel_case_types, trivial_numeric_casts, dropping_copy_types)] #![allow(dead_code, non_camel_case_types, trivial_numeric_casts, dropping_copy_types)]
#![feature(intrinsics)]
use std::ops::AddAssign; use std::ops::AddAssign;
@ -137,5 +138,10 @@ fn f7() {
drop(a); drop(a);
} }
// unused params warnings are not needed for intrinsic functions without bodies
#[rustc_intrinsic]
unsafe fn simd_shuffle<T, I, U>(a: T, b: T, i: I) -> U;
fn main() { fn main() {
} }

View file

@ -1,5 +1,5 @@
warning: unreachable statement warning: unreachable statement
--> $DIR/liveness-unused.rs:92:9 --> $DIR/liveness-unused.rs:93:9
| |
LL | continue; LL | continue;
| -------- any code following this expression is unreachable | -------- any code following this expression is unreachable
@ -14,7 +14,7 @@ LL | #![warn(unused)]
= note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]` = note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]`
error: unused variable: `x` error: unused variable: `x`
--> $DIR/liveness-unused.rs:8:7 --> $DIR/liveness-unused.rs:9:7
| |
LL | fn f1(x: isize) { LL | fn f1(x: isize) {
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ^ help: if this is intentional, prefix it with an underscore: `_x`
@ -26,25 +26,25 @@ LL | #![deny(unused_variables)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
error: unused variable: `x` error: unused variable: `x`
--> $DIR/liveness-unused.rs:12:8 --> $DIR/liveness-unused.rs:13:8
| |
LL | fn f1b(x: &mut isize) { LL | fn f1b(x: &mut isize) {
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ^ help: if this is intentional, prefix it with an underscore: `_x`
error: unused variable: `x` error: unused variable: `x`
--> $DIR/liveness-unused.rs:20:9 --> $DIR/liveness-unused.rs:21:9
| |
LL | let x: isize; LL | let x: isize;
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ^ help: if this is intentional, prefix it with an underscore: `_x`
error: unused variable: `x` error: unused variable: `x`
--> $DIR/liveness-unused.rs:25:9 --> $DIR/liveness-unused.rs:26:9
| |
LL | let x = 3; LL | let x = 3;
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ^ help: if this is intentional, prefix it with an underscore: `_x`
error: variable `x` is assigned to, but never used error: variable `x` is assigned to, but never used
--> $DIR/liveness-unused.rs:30:13 --> $DIR/liveness-unused.rs:31:13
| |
LL | let mut x = 3; LL | let mut x = 3;
| ^ | ^
@ -52,7 +52,7 @@ LL | let mut x = 3;
= note: consider using `_x` instead = note: consider using `_x` instead
error: value assigned to `x` is never read error: value assigned to `x` is never read
--> $DIR/liveness-unused.rs:32:5 --> $DIR/liveness-unused.rs:33:5
| |
LL | x += 4; LL | x += 4;
| ^ | ^
@ -65,7 +65,7 @@ LL | #![deny(unused_assignments)]
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: variable `z` is assigned to, but never used error: variable `z` is assigned to, but never used
--> $DIR/liveness-unused.rs:37:13 --> $DIR/liveness-unused.rs:38:13
| |
LL | let mut z = 3; LL | let mut z = 3;
| ^ | ^
@ -73,31 +73,31 @@ LL | let mut z = 3;
= note: consider using `_z` instead = note: consider using `_z` instead
error: unused variable: `i` error: unused variable: `i`
--> $DIR/liveness-unused.rs:59:12 --> $DIR/liveness-unused.rs:60:12
| |
LL | Some(i) => { LL | Some(i) => {
| ^ help: if this is intentional, prefix it with an underscore: `_i` | ^ help: if this is intentional, prefix it with an underscore: `_i`
error: unused variable: `x` error: unused variable: `x`
--> $DIR/liveness-unused.rs:79:9 --> $DIR/liveness-unused.rs:80:9
| |
LL | for x in 1..10 { } LL | for x in 1..10 { }
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ^ help: if this is intentional, prefix it with an underscore: `_x`
error: unused variable: `x` error: unused variable: `x`
--> $DIR/liveness-unused.rs:84:10 --> $DIR/liveness-unused.rs:85:10
| |
LL | for (x, _) in [1, 2, 3].iter().enumerate() { } LL | for (x, _) in [1, 2, 3].iter().enumerate() { }
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ^ help: if this is intentional, prefix it with an underscore: `_x`
error: unused variable: `x` error: unused variable: `x`
--> $DIR/liveness-unused.rs:89:13 --> $DIR/liveness-unused.rs:90:13
| |
LL | for (_, x) in [1, 2, 3].iter().enumerate() { LL | for (_, x) in [1, 2, 3].iter().enumerate() {
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ^ help: if this is intentional, prefix it with an underscore: `_x`
error: variable `x` is assigned to, but never used error: variable `x` is assigned to, but never used
--> $DIR/liveness-unused.rs:112:9 --> $DIR/liveness-unused.rs:113:9
| |
LL | let x; LL | let x;
| ^ | ^
@ -105,7 +105,7 @@ LL | let x;
= note: consider using `_x` instead = note: consider using `_x` instead
error: value assigned to `x` is never read error: value assigned to `x` is never read
--> $DIR/liveness-unused.rs:116:9 --> $DIR/liveness-unused.rs:117:9
| |
LL | x = 0; LL | x = 0;
| ^ | ^