Skip to content

Commit 20f4a0d

Browse files
committed
fix ICE #138415
1 parent f08d5c0 commit 20f4a0d

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

compiler/rustc_ast_lowering/src/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1724,8 +1724,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
17241724
return;
17251725
};
17261726
let define_opaque = define_opaque.iter().filter_map(|(id, path)| {
1727-
let res = self.resolver.get_partial_res(*id).unwrap();
1728-
let Some(did) = res.expect_full_res().opt_def_id() else {
1727+
let res = self.resolver.get_partial_res(*id);
1728+
let Some(did) = res.and_then(|res| res.expect_full_res().opt_def_id()) else {
17291729
self.dcx().span_delayed_bug(path.span, "should have errored in resolve");
17301730
return None;
17311731
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
extern "C" {
4+
fn a() {
5+
//~^ ERROR incorrect function inside `extern` block
6+
#[define_opaque(String)]
7+
fn c() {}
8+
}
9+
}
10+
11+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: incorrect function inside `extern` block
2+
--> $DIR/invalid-extern-fn-body.rs:4:8
3+
|
4+
LL | extern "C" {
5+
| ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body
6+
LL | fn a() {
7+
| ________^___-
8+
| | |
9+
| | cannot have a body
10+
LL | |
11+
LL | | #[define_opaque(String)]
12+
LL | | fn c() {}
13+
LL | | }
14+
| |_____- help: remove the invalid body: `;`
15+
|
16+
= help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block
17+
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
18+
19+
error: aborting due to 1 previous error
20+

0 commit comments

Comments
 (0)