Skip to content

Commit 08a4ce5

Browse files
committed
Auto merge of #152314 - Zalathar:rollup-4WUNK14, r=Zalathar
Rollup of 2 pull requests Successful merges: - #152310 (Remove `rustdoc` adhoc group) - #152284 (Avoid a bogus THIR span for `let x = offset_of!(..)`)
2 parents c69e1a0 + 1992e71 commit 08a4ce5

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed

compiler/rustc_mir_build/src/thir/cx/block.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ impl<'tcx> ThirBuildCx<'tcx> {
7575
debug!(?pattern);
7676

7777
let span = match local.init {
78-
Some(init) => local.span.with_hi(init.span.hi()),
79-
None => local.span,
78+
Some(init)
79+
if let Some(init_span) =
80+
init.span.find_ancestor_inside_same_ctxt(local.span) =>
81+
{
82+
local.span.with_hi(init_span.hi())
83+
}
84+
Some(_) | None => local.span,
8085
};
8186
let stmt = Stmt {
8287
kind: StmtKind::Let {

tests/ui/span/let-offset-of.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![crate_type = "rlib"]
2+
//@ edition: 2024
3+
//@ check-pass
4+
5+
// Using `offset_of` in the RHS of a let-else statement should not produce
6+
// malformed spans or a blank diagnostic snippet.
7+
//
8+
// Regression test for <https://github.com/rust-lang/rust/pull/152284>.
9+
10+
fn init_to_offset_of() {
11+
use std::mem::offset_of;
12+
struct Foo { field: u32 }
13+
14+
if let x = offset_of!(Foo, field) {}
15+
//~^ WARN irrefutable `if let` pattern
16+
17+
let x = offset_of!(Foo, field) else { return; };
18+
//~^ WARN irrefutable `let...else` pattern
19+
}

tests/ui/span/let-offset-of.stderr

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
warning: irrefutable `if let` pattern
2+
--> $DIR/let-offset-of.rs:14:8
3+
|
4+
LL | if let x = offset_of!(Foo, field) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this pattern will always match, so the `if let` is useless
8+
= help: consider replacing the `if let` with a `let`
9+
= note: `#[warn(irrefutable_let_patterns)]` on by default
10+
11+
warning: irrefutable `let...else` pattern
12+
--> $DIR/let-offset-of.rs:17:5
13+
|
14+
LL | let x = offset_of!(Foo, field) else { return; };
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
|
17+
= note: this pattern will always match, so the `else` clause is useless
18+
= help: consider removing the `else` clause
19+
20+
warning: 2 warnings emitted
21+

tests/ui/thir-print/offset_of.stdout

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ body:
6868
)
6969
else_block: None
7070
hir_id: HirId(DefId(offset_of::concrete).10)
71-
span: $DIR/offset_of.rs:37:5: 1445:57 (#0)
71+
span: $DIR/offset_of.rs:37:5: 37:33 (#0)
7272
}
7373
}
7474
Stmt {
@@ -117,7 +117,7 @@ body:
117117
)
118118
else_block: None
119119
hir_id: HirId(DefId(offset_of::concrete).20)
120-
span: $DIR/offset_of.rs:38:5: 1445:57 (#0)
120+
span: $DIR/offset_of.rs:38:5: 38:33 (#0)
121121
}
122122
}
123123
Stmt {
@@ -166,7 +166,7 @@ body:
166166
)
167167
else_block: None
168168
hir_id: HirId(DefId(offset_of::concrete).30)
169-
span: $DIR/offset_of.rs:39:5: 1445:57 (#0)
169+
span: $DIR/offset_of.rs:39:5: 39:34 (#0)
170170
}
171171
}
172172
Stmt {
@@ -215,7 +215,7 @@ body:
215215
)
216216
else_block: None
217217
hir_id: HirId(DefId(offset_of::concrete).40)
218-
span: $DIR/offset_of.rs:40:5: 1445:57 (#0)
218+
span: $DIR/offset_of.rs:40:5: 40:36 (#0)
219219
}
220220
}
221221
Stmt {
@@ -264,7 +264,7 @@ body:
264264
)
265265
else_block: None
266266
hir_id: HirId(DefId(offset_of::concrete).50)
267-
span: $DIR/offset_of.rs:41:5: 1445:57 (#0)
267+
span: $DIR/offset_of.rs:41:5: 41:36 (#0)
268268
}
269269
}
270270
]
@@ -864,7 +864,7 @@ body:
864864
)
865865
else_block: None
866866
hir_id: HirId(DefId(offset_of::generic).12)
867-
span: $DIR/offset_of.rs:45:5: 1445:57 (#0)
867+
span: $DIR/offset_of.rs:45:5: 45:37 (#0)
868868
}
869869
}
870870
Stmt {
@@ -913,7 +913,7 @@ body:
913913
)
914914
else_block: None
915915
hir_id: HirId(DefId(offset_of::generic).24)
916-
span: $DIR/offset_of.rs:46:5: 1445:57 (#0)
916+
span: $DIR/offset_of.rs:46:5: 46:37 (#0)
917917
}
918918
}
919919
Stmt {
@@ -962,7 +962,7 @@ body:
962962
)
963963
else_block: None
964964
hir_id: HirId(DefId(offset_of::generic).36)
965-
span: $DIR/offset_of.rs:47:5: 1445:57 (#0)
965+
span: $DIR/offset_of.rs:47:5: 47:37 (#0)
966966
}
967967
}
968968
Stmt {
@@ -1011,7 +1011,7 @@ body:
10111011
)
10121012
else_block: None
10131013
hir_id: HirId(DefId(offset_of::generic).48)
1014-
span: $DIR/offset_of.rs:48:5: 1445:57 (#0)
1014+
span: $DIR/offset_of.rs:48:5: 48:37 (#0)
10151015
}
10161016
}
10171017
]

triagebot.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,11 +1488,6 @@ infra-ci = [
14881488
"@jdno",
14891489
"@jieyouxu",
14901490
]
1491-
rustdoc = [
1492-
"@GuillaumeGomez",
1493-
"@notriddle",
1494-
"@fmease",
1495-
]
14961491
docs = [
14971492
"@ehuss",
14981493
"@GuillaumeGomez",

0 commit comments

Comments
 (0)