Skip to content

Commit 4d76429

Browse files
committed
Add instrument to is_fn_trait_compatible
1 parent f606e33 commit 4d76429

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

Diff for: compiler/rustc_hir_typeck/src/callee.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_span::symbol::{Ident, sym};
1919
use rustc_trait_selection::error_reporting::traits::DefIdOrName;
2020
use rustc_trait_selection::infer::InferCtxtExt as _;
2121
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
22-
use tracing::{debug, instrument};
22+
use tracing::{debug, instrument, trace};
2323

2424
use super::method::MethodCallee;
2525
use super::method::probe::ProbeScope;
@@ -494,6 +494,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
494494
// have been normalized before.
495495
let fn_sig = self.instantiate_binder_with_fresh_vars(call_expr.span, infer::FnCall, fn_sig);
496496
let fn_sig = self.normalize(call_expr.span, fn_sig);
497+
trace!(?fn_sig);
497498

498499
self.check_argument_types(
499500
call_expr.span,
@@ -544,6 +545,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
544545
}
545546
}
546547

548+
let fn_sig = self.resolve_vars_if_possible(fn_sig);
549+
trace!(?fn_sig);
547550
fn_sig.output()
548551
}
549552

Diff for: compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
182182

183183
/// Check an expr with an expectation type which may be used to eagerly
184184
/// guide inference when evaluating that expr.
185-
#[instrument(skip(self, expr), level = "debug")]
186185
pub(super) fn check_expr_with_expectation(
187186
&self,
188187
expr: &'tcx hir::Expr<'tcx>,
@@ -195,6 +194,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
195194
/// the arguments of a [`ExprKind::Call`] when evaluating its callee that
196195
/// is an [`ExprKind::Path`]. We use this to refine the spans for certain
197196
/// well-formedness guarantees for the path expr.
197+
#[instrument(skip(self, expr), level = "debug")]
198198
pub(super) fn check_expr_with_expectation_and_args(
199199
&self,
200200
expr: &'tcx hir::Expr<'tcx>,

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_span::{DUMMY_SP, Span, sym};
2727
use rustc_trait_selection::error_reporting::infer::{FailureCode, ObligationCauseExt};
2828
use rustc_trait_selection::infer::InferCtxtExt;
2929
use rustc_trait_selection::traits::{self, ObligationCauseCode, ObligationCtxt, SelectionContext};
30-
use tracing::debug;
30+
use tracing::{debug, trace};
3131
use {rustc_ast as ast, rustc_hir as hir};
3232

3333
use crate::Expectation::*;
@@ -314,8 +314,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
314314
// 1. Unify the provided argument with the expected type
315315
let expectation = Expectation::rvalue_hint(self, expected_input_ty);
316316

317+
trace!(?expectation);
318+
317319
let checked_ty = self.check_expr_with_expectation(provided_arg, expectation);
318320

321+
trace!(?checked_ty);
322+
let checked_ty = self.resolve_vars_with_obligations(checked_ty);
323+
trace!(?checked_ty);
324+
319325
// 2. Coerce to the most detailed type that could be coerced
320326
// to, which is `expected_ty` if `rvalue_hint` returns an
321327
// `ExpectHasType(expected_ty)`, or the `formal_ty` otherwise.
@@ -326,6 +332,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
326332
// fulfillment error to be more accurate.
327333
let coerced_ty = self.resolve_vars_with_obligations(coerced_ty);
328334

335+
trace!(?coerced_ty);
336+
329337
let coerce_error =
330338
self.coerce(provided_arg, checked_ty, coerced_ty, AllowTwoPhase::Yes, None).err();
331339
if coerce_error.is_some() {
@@ -343,6 +351,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
343351
// If neither check failed, the types are compatible
344352
match formal_ty_error {
345353
Ok(InferOk { obligations, value: () }) => {
354+
trace!(?obligations);
346355
self.register_predicates(obligations);
347356
Compatibility::Compatible
348357
}
@@ -421,6 +430,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
421430
}
422431
}
423432

433+
for input in formal_input_tys.iter() {
434+
let input = self.resolve_vars_if_possible(*input);
435+
trace!(?input);
436+
}
437+
424438
if c_variadic && provided_arg_count < minimum_input_count {
425439
err_code = E0060;
426440
}

Diff for: compiler/rustc_type_ir/src/ty_kind.rs

+2
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,10 @@ impl<I: Interner> FnSig<I> {
887887
self.inputs_and_output.output()
888888
}
889889

890+
#[tracing::instrument(skip(self), ret)]
890891
pub fn is_fn_trait_compatible(self) -> bool {
891892
let FnSig { safety, abi, c_variadic, .. } = self;
893+
tracing::debug!(?c_variadic, ?safety, ?abi);
892894
!c_variadic && safety.is_safe() && abi.is_rust()
893895
}
894896
}

0 commit comments

Comments
 (0)