Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> DelegationResults<'hir> {
let span = self.lower_span(delegation.path.segments.last().unwrap().ident.span);

let ids = self.get_delegation_ids(
self.resolver.delegation_infos[&self.local_def_id(item_id)].resolution_node,
span,
);
// Delegation can be unresolved in illegal places such as function bodies in extern blocks (see #151356)
let ids = if let Some(delegation_info) =
self.resolver.delegation_infos.get(&self.local_def_id(item_id))
{
self.get_delegation_ids(delegation_info.resolution_node, span)
} else {
return self.generate_delegation_error(
self.dcx().span_delayed_bug(
span,
format!("LoweringContext: the delegation {:?} is unresolved", item_id),
),
span,
delegation,
);
};

match ids {
Ok(ids) => {
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/delegation/unresolved-delegation-ice-151356.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![allow(incomplete_features)]
#![feature(fn_delegation)]

extern "C" {
fn a() {
//~^ ERROR incorrect function inside `extern` block
reuse foo {}
}
}

pub fn main() {}
19 changes: 19 additions & 0 deletions tests/ui/delegation/unresolved-delegation-ice-151356.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error: incorrect function inside `extern` block
--> $DIR/unresolved-delegation-ice-151356.rs:5: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 | | reuse foo {}
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

Loading