mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Generate error delegation when delegation is not resolved
This commit is contained in:
@@ -152,10 +152,21 @@ pub(crate) fn lower_delegation(
|
||||
) -> 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) => {
|
||||
|
||||
@@ -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() {}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user