diff options
| author | Takayuki Maeda <takoyaki0316@gmail.com> | 2025-03-23 17:02:42 +0900 |
|---|---|---|
| committer | Takayuki Maeda <takoyaki0316@gmail.com> | 2025-03-23 17:02:42 +0900 |
| commit | 20f4a0d586fcb27936f07f001bf128b2f407b018 (patch) | |
| tree | 45fce4e1b0e3e6155271fa27f62e6d6ba13ae024 | |
| parent | f08d5c01e69436891ff1c181385d0e078a8482ec (diff) | |
| download | rust-20f4a0d586fcb27936f07f001bf128b2f407b018.tar.gz rust-20f4a0d586fcb27936f07f001bf128b2f407b018.zip | |
fix ICE #138415
3 files changed, 33 insertions, 2 deletions
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index bd011d59aaa..518349343b3 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1724,8 +1724,8 @@ impl<'hir> LoweringContext<'_, 'hir> { return; }; let define_opaque = define_opaque.iter().filter_map(|(id, path)| { - let res = self.resolver.get_partial_res(*id).unwrap(); - let Some(did) = res.expect_full_res().opt_def_id() else { + let res = self.resolver.get_partial_res(*id); + let Some(did) = res.and_then(|res| res.expect_full_res().opt_def_id()) else { self.dcx().span_delayed_bug(path.span, "should have errored in resolve"); return None; }; diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid-extern-fn-body.rs b/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid-extern-fn-body.rs new file mode 100644 index 00000000000..d873af44adf --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid-extern-fn-body.rs @@ -0,0 +1,11 @@ +#![feature(type_alias_impl_trait)] + +extern "C" { + fn a() { + //~^ ERROR incorrect function inside `extern` block + #[define_opaque(String)] + fn c() {} + } +} + +pub fn main() {} diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid-extern-fn-body.stderr b/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid-extern-fn-body.stderr new file mode 100644 index 00000000000..2e944257d8f --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid-extern-fn-body.stderr @@ -0,0 +1,20 @@ +error: incorrect function inside `extern` block + --> $DIR/invalid-extern-fn-body.rs:4:8 + | +LL | extern "C" { + | ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body +LL | fn a() { + | ________^___- + | | | + | | cannot have a body +LL | | +LL | | #[define_opaque(String)] +LL | | fn c() {} +LL | | } + | |_____- help: remove the invalid body: `;` + | + = 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 + = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html + +error: aborting due to 1 previous error + |
