frontend 0.4.0

rustc's frontend with no LLVM and no std: parsing through MIR, as a library
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
//! This module is very similar to `compare_impl_item`.
//! Most logic is taken from there,
//! since in a very similar way we're comparing some declaration of a signature to an implementation.
//! The major difference is that we don't bother with self types, since for EIIs we're comparing freestanding item.

// `#![no_std]`: these arrive with the standard prelude and name no path, so a `std::`
// search cannot see them - and a `#[derive]` can use them without the name appearing
// in this file at all, which is why they are not trimmed by inspection.
use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;

use alloc::borrow::Cow;
use core::iter;

use crate::rustc_data_structures::fx::FxIndexSet;
use crate::rustc_errors::{Applicability, E0806, struct_span_code_err};
use crate::rustc_hir::attrs::EiiImplResolution;
use crate::rustc_hir::def::DefKind;
use crate::rustc_hir::def_id::{DefId, LocalDefId};
use crate::rustc_hir::{self as hir, FnSig, HirId, ItemKind, find_attr};
use crate::rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
use crate::rustc_infer::traits::{ObligationCause, ObligationCauseCode, TraitErrors};
use crate::rustc_middle::ty::error::{ExpectedFound, TypeError};
use crate::rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeVisitableExt, TypingMode, Unnormalized};
use crate::rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
use crate::rustc_trait_selection::error_reporting::InferCtxtErrorExt;
use crate::rustc_trait_selection::regions::InferCtxtRegionExt;
use crate::rustc_trait_selection::traits::{self, ObligationCtxt};
use tracing::{debug, instrument};

use super::potentially_plural_count;
use crate::rustc_hir_analysis::check::compare_impl_item::{
    CheckNumberOfEarlyBoundRegionsError, check_number_of_early_bound_regions,
};
use crate::rustc_hir_analysis::diagnostics::{
    EiiDefkindMismatch, EiiDefkindMismatchStaticMutability, EiiDefkindMismatchStaticSafety,
    EiiWithGenerics, LifetimesOrBoundsMismatchOnEii,
};

/// Checks whether the signature of some `external_impl`, matches
/// the signature of `declaration`, which it is supposed to be compatible
/// with in order to implement the item.
pub(crate) fn compare_eii_function_types<'tcx>(
    tcx: TyCtxt<'tcx>,
    external_impl: LocalDefId,
    foreign_item: DefId,
    eii_name: Symbol,
    eii_attr_span: Span,
) -> Result<(), ErrorGuaranteed> {
    check_eii_target(tcx, external_impl, foreign_item, eii_name, eii_attr_span)?;
    check_is_structurally_compatible(tcx, external_impl, foreign_item, eii_name, eii_attr_span)?;

    let external_impl_span = tcx.def_span(external_impl);
    let cause = ObligationCause::new(
        external_impl_span,
        external_impl,
        ObligationCauseCode::CompareEii { external_impl, declaration: foreign_item },
    );

    // FIXME(eii): even if we don't support generic functions, we should support explicit outlive bounds here
    let param_env = tcx.param_env(foreign_item);

    let infcx = &tcx.infer_ctxt().build(TypingMode::non_body_analysis());
    let ocx = ObligationCtxt::new_with_diagnostics(infcx);

    // We now need to check that the signature of the implementation is
    // compatible with that of the declaration. We do this by
    // checking that `impl_fty <: trait_fty`.
    //
    // FIXME: We manually instantiate the declaration here as we need
    // to manually compute its implied bounds. Otherwise this could just
    // be ocx.sub(impl_sig, trait_sig).

    let mut wf_tys = FxIndexSet::default();
    let norm_cause = ObligationCause::misc(external_impl_span, external_impl);

    let declaration_sig = tcx.fn_sig(foreign_item).instantiate_identity().skip_norm_wip();
    let declaration_sig = tcx.liberate_late_bound_regions(external_impl.into(), declaration_sig);
    debug!(?declaration_sig);

    let unnormalized_external_impl_sig = infcx.instantiate_binder_with_fresh_vars(
        external_impl_span,
        infer::BoundRegionConversionTime::HigherRankedType,
        tcx.fn_sig(external_impl)
            .instantiate(
                tcx,
                infcx.fresh_args_for_item(external_impl_span, external_impl.to_def_id()),
            )
            .skip_norm_wip(),
    );
    let external_impl_sig = ocx.normalize(
        &norm_cause,
        param_env,
        Unnormalized::new_wip(unnormalized_external_impl_sig),
    );
    debug!(?external_impl_sig);

    // Next, add all inputs and output as well-formed tys. Importantly,
    // we have to do this before normalization, since the normalized ty may
    // not contain the input parameters. See issue #87748.
    wf_tys.extend(declaration_sig.inputs_and_output.iter());
    let declaration_sig =
        ocx.normalize(&norm_cause, param_env, Unnormalized::new_wip(declaration_sig));
    // We also have to add the normalized declaration
    // as we don't normalize during implied bounds computation.
    wf_tys.extend(external_impl_sig.inputs_and_output.iter());

    // FIXME: Copied over from compare impl items, same issue:
    // We'd want to keep more accurate spans than "the method signature" when
    // processing the comparison between the trait and impl fn, but we sadly lose them
    // and point at the whole signature when a trait bound or specific input or output
    // type would be more appropriate. In other places we have a `Vec<Span>`
    // corresponding to their `Vec<Predicate>`, but we don't have that here.
    // Fixing this would improve the output of test `issue-83765.rs`.
    let result = ocx.sup(&cause, param_env, declaration_sig, external_impl_sig);

    if let Err(terr) = result {
        debug!(?external_impl_sig, ?declaration_sig, ?terr, "sub_types failed");

        let emitted = report_eii_mismatch(
            infcx,
            cause,
            param_env,
            terr,
            (foreign_item, declaration_sig),
            (external_impl, external_impl_sig),
            eii_attr_span,
            eii_name,
        );
        return Err(emitted);
    }

    if !(declaration_sig, external_impl_sig).references_error() {
        for ty in unnormalized_external_impl_sig.inputs_and_output {
            ocx.register_obligation(traits::Obligation::new(
                infcx.tcx,
                cause.clone(),
                param_env,
                ty::ClauseKind::WellFormed(ty.into()),
            ));
        }
    }

    // Check that all obligations are satisfied by the implementation's
    // version.
    let errors = ocx.evaluate_obligations_error_on_ambiguity();
    if let TraitErrors::HasErrors(errors) = errors {
        let reported = infcx.err_ctxt().report_fulfillment_errors(errors);
        return Err(reported);
    }

    // Finally, resolve all regions. This catches wily misuses of
    // lifetime parameters.
    let errors = infcx.resolve_regions(external_impl, param_env, wf_tys);
    if !errors.is_empty() {
        return Err(infcx
            .tainted_by_errors()
            .unwrap_or_else(|| infcx.err_ctxt().report_region_errors(external_impl, &errors)));
    }

    Ok(())
}

pub(crate) fn compare_eii_statics<'tcx>(
    tcx: TyCtxt<'tcx>,
    external_impl: LocalDefId,
    external_impl_ty: Ty<'tcx>,
    foreign_item: DefId,
    eii_name: Symbol,
    eii_attr_span: Span,
) -> Result<(), ErrorGuaranteed> {
    check_eii_target(tcx, external_impl, foreign_item, eii_name, eii_attr_span)?;

    let external_impl_span = tcx.def_span(external_impl);
    let cause = ObligationCause::new(
        external_impl_span,
        external_impl,
        ObligationCauseCode::CompareEii { external_impl, declaration: foreign_item },
    );

    let param_env = ParamEnv::empty();

    let infcx = &tcx.infer_ctxt().build(TypingMode::non_body_analysis());
    let ocx = ObligationCtxt::new_with_diagnostics(infcx);

    let declaration_ty = tcx.type_of(foreign_item).instantiate_identity().skip_norm_wip();
    debug!(?declaration_ty);

    // FIXME: Copied over from compare impl items, same issue:
    // We'd want to keep more accurate spans than "the method signature" when
    // processing the comparison between the trait and impl fn, but we sadly lose them
    // and point at the whole signature when a trait bound or specific input or output
    // type would be more appropriate. In other places we have a `Vec<Span>`
    // corresponding to their `Vec<Predicate>`, but we don't have that here.
    // Fixing this would improve the output of test `issue-83765.rs`.
    let result = ocx.sup(&cause, param_env, declaration_ty, external_impl_ty);

    if let Err(terr) = result {
        debug!(?external_impl_ty, ?declaration_ty, ?terr, "sub_types failed");

        let mut diag = struct_span_code_err!(
            tcx.dcx(),
            cause.span,
            E0806,
            "static `{}` has a type that is incompatible with the declaration of `#[{eii_name}]`",
            tcx.item_name(external_impl)
        );
        diag.span_note(eii_attr_span, "expected this because of this attribute");

        return Err(diag.emit());
    }

    // Check that all obligations are satisfied by the implementation's
    // version.
    let errors = ocx.evaluate_obligations_error_on_ambiguity();
    if let TraitErrors::HasErrors(errors) = errors {
        let reported = infcx.err_ctxt().report_fulfillment_errors(errors);
        return Err(reported);
    }

    // Finally, resolve all regions. This catches wily misuses of
    // lifetime parameters.
    let errors = infcx.resolve_regions(external_impl, param_env, []);
    if !errors.is_empty() {
        return Err(infcx
            .tainted_by_errors()
            .unwrap_or_else(|| infcx.err_ctxt().report_region_errors(external_impl, &errors)));
    }

    Ok(())
}

fn check_eii_target(
    tcx: TyCtxt<'_>,
    external_impl: LocalDefId,
    foreign_item: DefId,
    eii_name: Symbol,
    eii_attr_span: Span,
) -> Result<(), ErrorGuaranteed> {
    // Error recovery can resolve the EII target to another value item with the same name,
    // such as a tuple-struct constructor. Skip the comparison in that case and rely on the
    // earlier name-resolution error instead of ICEing while building EII diagnostics.
    // See <https://github.com/rust-lang/rust/issues/153502>.
    if !tcx.is_foreign_item(foreign_item) {
        return Err(tcx.dcx().delayed_bug("EII is a foreign item"));
    }
    let expected_kind = tcx.def_kind(foreign_item);
    let actual_kind = tcx.def_kind(external_impl);

    match expected_kind {
        // Correct target
        _ if expected_kind == actual_kind => Ok(()),
        DefKind::Static { mutability: m1, safety: s1, .. }
            if let DefKind::Static { mutability: m2, safety: s2, .. } = actual_kind =>
        {
            Err(if s1 != s2 {
                tcx.dcx().emit_err(EiiDefkindMismatchStaticSafety { span: eii_attr_span, eii_name })
            } else if m1 != m2 {
                tcx.dcx()
                    .emit_err(EiiDefkindMismatchStaticMutability { span: eii_attr_span, eii_name })
            } else {
                unreachable!()
            })
        }
        // Not checked by attr target checking
        DefKind::Fn | DefKind::Static { .. } => Err(tcx.dcx().emit_err(EiiDefkindMismatch {
            span: eii_attr_span,
            eii_name,
            expected_kind: expected_kind.descr(foreign_item),
        })),
        // Checked by attr target checking
        _ => Err(tcx.dcx().delayed_bug("Attribute should not be allowed by target checking")),
    }
}

/// Checks a bunch of different properties of the impl/trait methods for
/// compatibility, such as asyncness, number of argument, self receiver kind,
/// and number of early- and late-bound generics.
///
/// Corresponds to `check_method_is_structurally_compatible` for impl method compatibility checks.
fn check_is_structurally_compatible<'tcx>(
    tcx: TyCtxt<'tcx>,
    external_impl: LocalDefId,
    declaration: DefId,
    eii_name: Symbol,
    eii_attr_span: Span,
) -> Result<(), ErrorGuaranteed> {
    check_no_generics(tcx, external_impl, declaration, eii_name, eii_attr_span)?;
    check_number_of_arguments(tcx, external_impl, declaration, eii_name, eii_attr_span)?;
    check_early_region_bounds(tcx, external_impl, declaration, eii_attr_span)?;
    Ok(())
}

/// externally implementable items can't have generics
fn check_no_generics<'tcx>(
    tcx: TyCtxt<'tcx>,
    external_impl: LocalDefId,
    _declaration: DefId,
    eii_name: Symbol,
    eii_attr_span: Span,
) -> Result<(), ErrorGuaranteed> {
    let generics = tcx.generics_of(external_impl);
    if generics.own_requires_monomorphization()
        // When an EII implementation is automatically generated by the `#[eii]` macro,
        // it will directly refer to the foreign item, not through a macro.
        // We don't want to emit this error if it's an implementation that's generated by the `#[eii]` macro,
        // since in that case it looks like a duplicate error: the declaration of the EII already can't contain generics.
        // So, we check here if at least one of the eii impls has ImplResolution::Macro, which indicates it's
        // not generated as part of the declaration.
        && find_attr!(tcx, external_impl, EiiImpl(i) if matches!(i.resolution, EiiImplResolution::Macro(_)))
    {
        tcx.dcx().emit_err(EiiWithGenerics {
            span: tcx.def_span(external_impl),
            attr: eii_attr_span,
            eii_name,
            impl_name: tcx.item_name(external_impl),
        });
    }

    Ok(())
}

fn check_early_region_bounds<'tcx>(
    tcx: TyCtxt<'tcx>,
    external_impl: LocalDefId,
    declaration: DefId,
    eii_attr_span: Span,
) -> Result<(), ErrorGuaranteed> {
    let external_impl_generics = tcx.generics_of(external_impl.to_def_id());
    let external_impl_params = external_impl_generics.own_counts().lifetimes;

    let declaration_generics = tcx.generics_of(declaration);
    let declaration_params = declaration_generics.own_counts().lifetimes;

    let Err(CheckNumberOfEarlyBoundRegionsError { span, generics_span, bounds_span, where_span }) =
        check_number_of_early_bound_regions(
            tcx,
            external_impl,
            declaration,
            external_impl_generics,
            external_impl_params,
            declaration_generics,
            declaration_params,
        )
    else {
        return Ok(());
    };

    let mut diag = tcx.dcx().create_err(LifetimesOrBoundsMismatchOnEii {
        span,
        ident: tcx.item_name(external_impl.to_def_id()),
        generics_span,
        bounds_span,
        where_span,
    });

    diag.span_label(eii_attr_span, format!("required because of this attribute"));
    return Err(diag.emit());
}

fn check_number_of_arguments<'tcx>(
    tcx: TyCtxt<'tcx>,
    external_impl: LocalDefId,
    declaration: DefId,
    eii_name: Symbol,
    eii_attr_span: Span,
) -> Result<(), ErrorGuaranteed> {
    let external_impl_fty = tcx.fn_sig(external_impl);
    let declaration_fty = tcx.fn_sig(declaration);
    let declaration_number_args = declaration_fty.skip_binder().inputs().skip_binder().len();
    let external_impl_number_args = external_impl_fty.skip_binder().inputs().skip_binder().len();

    // if the number of args are equal, we're trivially done
    if declaration_number_args == external_impl_number_args {
        Ok(())
    } else {
        Err(report_number_of_arguments_mismatch(
            tcx,
            external_impl,
            declaration,
            eii_name,
            eii_attr_span,
            declaration_number_args,
            external_impl_number_args,
        ))
    }
}

fn report_number_of_arguments_mismatch<'tcx>(
    tcx: TyCtxt<'tcx>,
    external_impl: LocalDefId,
    declaration: DefId,
    eii_name: Symbol,
    eii_attr_span: Span,
    declaration_number_args: usize,
    external_impl_number_args: usize,
) -> ErrorGuaranteed {
    let external_impl_name = tcx.item_name(external_impl.to_def_id());

    let declaration_span = declaration
        .as_local()
        .and_then(|def_id| {
            let declaration_sig = get_declaration_sig(tcx, def_id).expect("foreign item sig");
            let pos = declaration_number_args.saturating_sub(1);
            declaration_sig.decl.inputs.get(pos).map(|arg| {
                if pos == 0 {
                    arg.span
                } else {
                    arg.span.with_lo(declaration_sig.decl.inputs[0].span.lo())
                }
            })
        })
        .or_else(|| tcx.hir_span_if_local(declaration))
        .unwrap_or_else(|| tcx.def_span(declaration));

    let (_, external_impl_sig, _, _) = &tcx.hir_expect_item(external_impl).expect_fn();
    let pos = external_impl_number_args.saturating_sub(1);
    let impl_span = external_impl_sig
        .decl
        .inputs
        .get(pos)
        .map(|arg| {
            if pos == 0 {
                arg.span
            } else {
                arg.span.with_lo(external_impl_sig.decl.inputs[0].span.lo())
            }
        })
        .unwrap_or_else(|| tcx.def_span(external_impl));

    let mut err = struct_span_code_err!(
        tcx.dcx(),
        impl_span,
        E0806,
        "`{external_impl_name}` has {} but #[{eii_name}] requires it to have {}",
        potentially_plural_count(external_impl_number_args, "parameter"),
        declaration_number_args
    );

    err.span_label(
        declaration_span,
        format!("requires {}", potentially_plural_count(declaration_number_args, "parameter")),
    );

    err.span_label(
        impl_span,
        format!(
            "expected {}, found {}",
            potentially_plural_count(declaration_number_args, "parameter"),
            external_impl_number_args
        ),
    );

    err.span_label(eii_attr_span, format!("required because of this attribute"));

    err.emit()
}

fn report_eii_mismatch<'tcx>(
    infcx: &InferCtxt<'tcx>,
    mut cause: ObligationCause<'tcx>,
    param_env: ty::ParamEnv<'tcx>,
    terr: TypeError<'tcx>,
    (declaration_did, declaration_sig): (DefId, ty::FnSig<'tcx>),
    (external_impl_did, external_impl_sig): (LocalDefId, ty::FnSig<'tcx>),
    eii_attr_span: Span,
    eii_name: Symbol,
) -> ErrorGuaranteed {
    let tcx = infcx.tcx;
    let (impl_err_span, trait_err_span, external_impl_name) =
        extract_spans_for_error_reporting(infcx, terr, &cause, declaration_did, external_impl_did);

    let mut diag = struct_span_code_err!(
        tcx.dcx(),
        impl_err_span,
        E0806,
        "function `{}` has a type that is incompatible with the declaration of `#[{eii_name}]`",
        external_impl_name
    );

    diag.span_note(eii_attr_span, "expected this because of this attribute");

    match &terr {
        TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(_, i) => {
            if declaration_sig.inputs().len() == *i {
                // Suggestion to change output type. We do not suggest in `async` functions
                // to avoid complex logic or incorrect output.
                if let ItemKind::Fn { sig, .. } = &tcx.hir_expect_item(external_impl_did).kind
                    && !sig.header.asyncness.is_async()
                {
                    let msg = "change the output type to match the declaration";
                    let ap = Applicability::MachineApplicable;
                    match sig.decl.output {
                        hir::FnRetTy::DefaultReturn(sp) => {
                            let sugg = format!(" -> {}", declaration_sig.output());
                            diag.span_suggestion_verbose(sp, msg, sugg, ap);
                        }
                        hir::FnRetTy::Return(hir_ty) => {
                            let sugg = declaration_sig.output();
                            diag.span_suggestion_verbose(hir_ty.span, msg, sugg, ap);
                        }
                    };
                };
            } else if let Some(trait_ty) = declaration_sig.inputs().get(*i) {
                diag.span_suggestion_verbose(
                    impl_err_span,
                    "change the parameter type to match the declaration",
                    trait_ty,
                    Applicability::MachineApplicable,
                );
            }
        }
        _ => {}
    }

    cause.span = impl_err_span;
    infcx.err_ctxt().note_type_err(
        &mut diag,
        &cause,
        trait_err_span.map(|sp| (sp, Cow::from("type in declaration"), false)),
        Some(param_env.and(infer::ValuePairs::PolySigs(ExpectedFound {
            expected: ty::Binder::dummy(declaration_sig),
            found: ty::Binder::dummy(external_impl_sig),
        }))),
        terr,
        false,
        None,
    );

    diag.emit()
}

#[instrument(level = "debug", skip(infcx))]
fn extract_spans_for_error_reporting<'tcx>(
    infcx: &infer::InferCtxt<'tcx>,
    terr: TypeError<'_>,
    cause: &ObligationCause<'tcx>,
    declaration: DefId,
    external_impl: LocalDefId,
) -> (Span, Option<Span>, Ident) {
    let tcx = infcx.tcx;
    let (mut external_impl_args, external_impl_name) = {
        let item = tcx.hir_expect_item(external_impl);
        let (ident, sig, _, _) = item.expect_fn();
        (sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span())), ident)
    };

    let declaration_args = declaration.as_local().map(|def_id| {
        if let Some(sig) = get_declaration_sig(tcx, def_id) {
            sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span()))
        } else {
            panic!("expected {def_id:?} to be a foreign function");
        }
    });

    match terr {
        TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(ExpectedFound { .. }, i) => (
            external_impl_args.nth(i).unwrap(),
            declaration_args.and_then(|mut args| args.nth(i)),
            external_impl_name,
        ),
        _ => (
            cause.span,
            tcx.hir_span_if_local(declaration).or_else(|| Some(tcx.def_span(declaration))),
            external_impl_name,
        ),
    }
}

fn get_declaration_sig<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Option<&'tcx FnSig<'tcx>> {
    let hir_id: HirId = tcx.local_def_id_to_hir_id(def_id);
    tcx.hir_fn_sig_by_hir_id(hir_id)
}