Skip to content

Fix spans for unsafe binders #141781

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

Merged
merged 1 commit into from
May 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/unsafe-binders/unused-lifetimes-2.fixed
Original file line number Diff line number Diff line change
@@ -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() {}
20 changes: 20 additions & 0 deletions tests/ui/unsafe-binders/unused-lifetimes-2.rs
Original file line number Diff line number Diff line change
@@ -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() {}
16 changes: 16 additions & 0 deletions tests/ui/unsafe-binders/unused-lifetimes-2.stderr
Original file line number Diff line number Diff line change
@@ -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

20 changes: 20 additions & 0 deletions tests/ui/unsafe-binders/unused-lifetimes.fixed
Original file line number Diff line number Diff line change
@@ -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() {}
20 changes: 20 additions & 0 deletions tests/ui/unsafe-binders/unused-lifetimes.rs
Original file line number Diff line number Diff line change
@@ -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() {}
14 changes: 14 additions & 0 deletions tests/ui/unsafe-binders/unused-lifetimes.stderr
Original file line number Diff line number Diff line change
@@ -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

Loading