Rollup merge of #141781 - matthewjasper:unused-unsafe-lifetimes, r=compiler-errors

Fix spans for unsafe binders

closes rust-lang/rust#141758

r? ``@compiler-errors``
This commit is contained in:
Jubilee 2025-05-30 13:52:28 -07:00 committed by GitHub
commit 955ebfc7d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 111 additions and 2 deletions

View File

@ -934,8 +934,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
)
}
TyKind::UnsafeBinder(unsafe_binder) => {
// FIXME(unsafe_binder): Better span
let span = ty.span;
let span = ty.span.shrink_to_lo().to(unsafe_binder.inner_ty.span.shrink_to_lo());
self.with_generic_param_rib(
&unsafe_binder.generic_params,
RibKind::Normal,

View File

@ -0,0 +1,20 @@
// regression test for #141758
//@ run-rustfix
//@ check-pass
#![warn(unused_lifetimes)]
#![allow(incomplete_features, unused_imports, dead_code)]
#![feature(unsafe_binders)]
use std::unsafe_binder::unwrap_binder;
#[derive(Copy, Clone)]
pub struct S([usize; 8]);
// Regression test for <https://github.com/rust-lang/rust/issues/141418>.
pub fn by_value(_x: unsafe<'a> &'a S) -> usize {
//~^ WARN lifetime parameter `'b` never used
0
}
fn main() {}

View File

@ -0,0 +1,20 @@
// regression test for #141758
//@ run-rustfix
//@ check-pass
#![warn(unused_lifetimes)]
#![allow(incomplete_features, unused_imports, dead_code)]
#![feature(unsafe_binders)]
use std::unsafe_binder::unwrap_binder;
#[derive(Copy, Clone)]
pub struct S([usize; 8]);
// Regression test for <https://github.com/rust-lang/rust/issues/141418>.
pub fn by_value(_x: unsafe<'a, 'b> &'a S) -> usize {
//~^ WARN lifetime parameter `'b` never used
0
}
fn main() {}

View File

@ -0,0 +1,16 @@
warning: lifetime parameter `'b` never used
--> $DIR/unused-lifetimes-2.rs:15:32
|
LL | pub fn by_value(_x: unsafe<'a, 'b> &'a S) -> usize {
| --^^
| |
| help: elide the unused lifetime
|
note: the lint level is defined here
--> $DIR/unused-lifetimes-2.rs:5:9
|
LL | #![warn(unused_lifetimes)]
| ^^^^^^^^^^^^^^^^
warning: 1 warning emitted

View File

@ -0,0 +1,20 @@
// regression test for #141758
//@ run-rustfix
//@ check-pass
#![warn(unused_lifetimes)]
#![allow(incomplete_features, unused_imports, dead_code)]
#![feature(unsafe_binders)]
use std::unsafe_binder::unwrap_binder;
#[derive(Copy, Clone)]
pub struct S([usize; 8]);
// Regression test for <https://github.com/rust-lang/rust/issues/141418>.
pub fn by_value(_x: S) -> usize {
//~^ WARN lifetime parameter `'a` never used
0
}
fn main() {}

View File

@ -0,0 +1,20 @@
// regression test for #141758
//@ run-rustfix
//@ check-pass
#![warn(unused_lifetimes)]
#![allow(incomplete_features, unused_imports, dead_code)]
#![feature(unsafe_binders)]
use std::unsafe_binder::unwrap_binder;
#[derive(Copy, Clone)]
pub struct S([usize; 8]);
// Regression test for <https://github.com/rust-lang/rust/issues/141418>.
pub fn by_value(_x: unsafe<'a> S) -> usize {
//~^ WARN lifetime parameter `'a` never used
0
}
fn main() {}

View File

@ -0,0 +1,14 @@
warning: lifetime parameter `'a` never used
--> $DIR/unused-lifetimes.rs:15:28
|
LL | pub fn by_value(_x: unsafe<'a> S) -> usize {
| -------^^-- help: elide the unused lifetime
|
note: the lint level is defined here
--> $DIR/unused-lifetimes.rs:5:9
|
LL | #![warn(unused_lifetimes)]
| ^^^^^^^^^^^^^^^^
warning: 1 warning emitted