Skip to content

Commit 955ebfc

Browse files
Rollup merge of #141781 - matthewjasper:unused-unsafe-lifetimes, r=compiler-errors
Fix spans for unsafe binders closes #141758 r? ``@compiler-errors``
2 parents f91dc5d + 4a18439 commit 955ebfc

File tree

7 files changed

+111
-2
lines changed

7 files changed

+111
-2
lines changed

compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
934934
)
935935
}
936936
TyKind::UnsafeBinder(unsafe_binder) => {
937-
// FIXME(unsafe_binder): Better span
938-
let span = ty.span;
937+
let span = ty.span.shrink_to_lo().to(unsafe_binder.inner_ty.span.shrink_to_lo());
939938
self.with_generic_param_rib(
940939
&unsafe_binder.generic_params,
941940
RibKind::Normal,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// regression test for #141758
2+
//@ run-rustfix
3+
//@ check-pass
4+
5+
#![warn(unused_lifetimes)]
6+
#![allow(incomplete_features, unused_imports, dead_code)]
7+
#![feature(unsafe_binders)]
8+
9+
use std::unsafe_binder::unwrap_binder;
10+
11+
#[derive(Copy, Clone)]
12+
pub struct S([usize; 8]);
13+
14+
// Regression test for <https://github.com/rust-lang/rust/issues/141418>.
15+
pub fn by_value(_x: unsafe<'a> &'a S) -> usize {
16+
//~^ WARN lifetime parameter `'b` never used
17+
0
18+
}
19+
20+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// regression test for #141758
2+
//@ run-rustfix
3+
//@ check-pass
4+
5+
#![warn(unused_lifetimes)]
6+
#![allow(incomplete_features, unused_imports, dead_code)]
7+
#![feature(unsafe_binders)]
8+
9+
use std::unsafe_binder::unwrap_binder;
10+
11+
#[derive(Copy, Clone)]
12+
pub struct S([usize; 8]);
13+
14+
// Regression test for <https://github.com/rust-lang/rust/issues/141418>.
15+
pub fn by_value(_x: unsafe<'a, 'b> &'a S) -> usize {
16+
//~^ WARN lifetime parameter `'b` never used
17+
0
18+
}
19+
20+
fn main() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: lifetime parameter `'b` never used
2+
--> $DIR/unused-lifetimes-2.rs:15:32
3+
|
4+
LL | pub fn by_value(_x: unsafe<'a, 'b> &'a S) -> usize {
5+
| --^^
6+
| |
7+
| help: elide the unused lifetime
8+
|
9+
note: the lint level is defined here
10+
--> $DIR/unused-lifetimes-2.rs:5:9
11+
|
12+
LL | #![warn(unused_lifetimes)]
13+
| ^^^^^^^^^^^^^^^^
14+
15+
warning: 1 warning emitted
16+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// regression test for #141758
2+
//@ run-rustfix
3+
//@ check-pass
4+
5+
#![warn(unused_lifetimes)]
6+
#![allow(incomplete_features, unused_imports, dead_code)]
7+
#![feature(unsafe_binders)]
8+
9+
use std::unsafe_binder::unwrap_binder;
10+
11+
#[derive(Copy, Clone)]
12+
pub struct S([usize; 8]);
13+
14+
// Regression test for <https://github.com/rust-lang/rust/issues/141418>.
15+
pub fn by_value(_x: S) -> usize {
16+
//~^ WARN lifetime parameter `'a` never used
17+
0
18+
}
19+
20+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// regression test for #141758
2+
//@ run-rustfix
3+
//@ check-pass
4+
5+
#![warn(unused_lifetimes)]
6+
#![allow(incomplete_features, unused_imports, dead_code)]
7+
#![feature(unsafe_binders)]
8+
9+
use std::unsafe_binder::unwrap_binder;
10+
11+
#[derive(Copy, Clone)]
12+
pub struct S([usize; 8]);
13+
14+
// Regression test for <https://github.com/rust-lang/rust/issues/141418>.
15+
pub fn by_value(_x: unsafe<'a> S) -> usize {
16+
//~^ WARN lifetime parameter `'a` never used
17+
0
18+
}
19+
20+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: lifetime parameter `'a` never used
2+
--> $DIR/unused-lifetimes.rs:15:28
3+
|
4+
LL | pub fn by_value(_x: unsafe<'a> S) -> usize {
5+
| -------^^-- help: elide the unused lifetime
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unused-lifetimes.rs:5:9
9+
|
10+
LL | #![warn(unused_lifetimes)]
11+
| ^^^^^^^^^^^^^^^^
12+
13+
warning: 1 warning emitted
14+

0 commit comments

Comments
 (0)