Skip to content

Commit 13730e9

Browse files
Rollup merge of #82136 - edward-shen:mismatched-subst-and-hir, r=lcnr
Fix ICE: Use delay_span_bug for mismatched subst/hir arg Fixes #82126.
2 parents 7292d5f + a4b2faf commit 13730e9

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed

compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -634,14 +634,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
634634
| GenericArgKind::Const(_),
635635
_,
636636
) => {
637-
// I *think* that HIR lowering should ensure this
638-
// doesn't happen, even in erroneous
639-
// programs. Else we should use delay-span-bug.
640-
span_bug!(
637+
// HIR lowering sometimes doesn't catch this in erroneous
638+
// programs, so we need to use delay_span_bug here. See #82126.
639+
self.infcx.tcx.sess.delay_span_bug(
641640
hir_arg.span(),
642-
"unmatched subst and hir arg: found {:?} vs {:?}",
643-
kind,
644-
hir_arg,
641+
&format!("unmatched subst and hir arg: found {:?} vs {:?}", kind, hir_arg),
645642
);
646643
}
647644
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Regression test for #82126. Checks that mismatched lifetimes and types are
2+
// properly handled.
3+
4+
// edition:2018
5+
6+
use std::sync::Mutex;
7+
8+
struct MarketMultiplier {}
9+
10+
impl MarketMultiplier {
11+
fn buy(&mut self) -> &mut usize {
12+
todo!()
13+
}
14+
}
15+
16+
async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_> {
17+
//~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument was supplied
18+
//~^^ ERROR this struct takes 1 type argument but 0 type arguments were supplied
19+
LockedMarket(generator.lock().unwrap().buy())
20+
//~^ ERROR cannot return value referencing temporary value
21+
}
22+
23+
struct LockedMarket<T>(T);
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0107]: this struct takes 0 lifetime arguments but 1 lifetime argument was supplied
2+
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59
3+
|
4+
LL | async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_> {
5+
| ^^^^^^^^^^^^---- help: remove these generics
6+
| |
7+
| expected 0 lifetime arguments
8+
|
9+
note: struct defined here, with 0 lifetime parameters
10+
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:23:8
11+
|
12+
LL | struct LockedMarket<T>(T);
13+
| ^^^^^^^^^^^^
14+
15+
error[E0107]: this struct takes 1 type argument but 0 type arguments were supplied
16+
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59
17+
|
18+
LL | async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_> {
19+
| ^^^^^^^^^^^^ expected 1 type argument
20+
|
21+
note: struct defined here, with 1 type parameter: `T`
22+
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:23:8
23+
|
24+
LL | struct LockedMarket<T>(T);
25+
| ^^^^^^^^^^^^ -
26+
help: add missing type argument
27+
|
28+
LL | async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_, T> {
29+
| ^^^
30+
31+
error[E0515]: cannot return value referencing temporary value
32+
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:19:5
33+
|
34+
LL | LockedMarket(generator.lock().unwrap().buy())
35+
| ^^^^^^^^^^^^^-------------------------^^^^^^^
36+
| | |
37+
| | temporary value created here
38+
| returns a value referencing data owned by the current function
39+
40+
error: aborting due to 3 previous errors
41+
42+
Some errors have detailed explanations: E0107, E0515.
43+
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)