useful debug printouts
The changes to dumping expressions seem particularly useful
This commit is contained in:
parent
af15e529db
commit
754d51ebe4
6 changed files with 31 additions and 13 deletions
|
@ -14,6 +14,7 @@ use rustc_trait_selection::traits::{
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
#[instrument(skip(self), level="debug")]
|
||||||
pub fn check_match(
|
pub fn check_match(
|
||||||
&self,
|
&self,
|
||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
|
@ -26,6 +27,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
let acrb = arms_contain_ref_bindings(arms);
|
let acrb = arms_contain_ref_bindings(arms);
|
||||||
let scrutinee_ty = self.demand_scrutinee_type(scrut, acrb, arms.is_empty());
|
let scrutinee_ty = self.demand_scrutinee_type(scrut, acrb, arms.is_empty());
|
||||||
|
debug!(?scrutinee_ty);
|
||||||
|
|
||||||
// If there are no arms, that is a diverging match; a special case.
|
// If there are no arms, that is a diverging match; a special case.
|
||||||
if arms.is_empty() {
|
if arms.is_empty() {
|
||||||
|
|
|
@ -51,6 +51,7 @@ use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
|
||||||
|
|
||||||
/// Reifies a cast check to be checked once we have full type information for
|
/// Reifies a cast check to be checked once we have full type information for
|
||||||
/// a function context.
|
/// a function context.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct CastCheck<'tcx> {
|
pub struct CastCheck<'tcx> {
|
||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
expr_ty: Ty<'tcx>,
|
expr_ty: Ty<'tcx>,
|
||||||
|
@ -603,12 +604,11 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(fcx), level = "debug")]
|
||||||
pub fn check(mut self, fcx: &FnCtxt<'a, 'tcx>) {
|
pub fn check(mut self, fcx: &FnCtxt<'a, 'tcx>) {
|
||||||
self.expr_ty = fcx.structurally_resolved_type(self.expr.span, self.expr_ty);
|
self.expr_ty = fcx.structurally_resolved_type(self.expr.span, self.expr_ty);
|
||||||
self.cast_ty = fcx.structurally_resolved_type(self.cast_span, self.cast_ty);
|
self.cast_ty = fcx.structurally_resolved_type(self.cast_span, self.cast_ty);
|
||||||
|
|
||||||
debug!("check_cast({}, {:?} as {:?})", self.expr.hir_id, self.expr_ty, self.cast_ty);
|
|
||||||
|
|
||||||
if !fcx.type_is_known_to_be_sized_modulo_regions(self.cast_ty, self.span) {
|
if !fcx.type_is_known_to_be_sized_modulo_regions(self.cast_ty, self.span) {
|
||||||
self.report_cast_to_unsized_type(fcx);
|
self.report_cast_to_unsized_type(fcx);
|
||||||
} else if self.expr_ty.references_error() || self.cast_ty.references_error() {
|
} else if self.expr_ty.references_error() || self.cast_ty.references_error() {
|
||||||
|
|
|
@ -1328,6 +1328,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
||||||
/// The inner coercion "engine". If `expression` is `None`, this
|
/// The inner coercion "engine". If `expression` is `None`, this
|
||||||
/// is a forced-unit case, and hence `expression_ty` must be
|
/// is a forced-unit case, and hence `expression_ty` must be
|
||||||
/// `Nil`.
|
/// `Nil`.
|
||||||
|
#[instrument(skip(self,fcx,augment_error,label_expression_as_expected), level="debug")]
|
||||||
crate fn coerce_inner<'a>(
|
crate fn coerce_inner<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
fcx: &FnCtxt<'a, 'tcx>,
|
fcx: &FnCtxt<'a, 'tcx>,
|
||||||
|
|
|
@ -156,12 +156,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// Note that inspecting a type's structure *directly* may expose the fact
|
/// Note that inspecting a type's structure *directly* may expose the fact
|
||||||
/// that there are actually multiple representations for `Error`, so avoid
|
/// that there are actually multiple representations for `Error`, so avoid
|
||||||
/// that when err needs to be handled differently.
|
/// that when err needs to be handled differently.
|
||||||
|
#[instrument(skip(self), level="debug")]
|
||||||
pub(super) fn check_expr_with_expectation(
|
pub(super) fn check_expr_with_expectation(
|
||||||
&self,
|
&self,
|
||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
expected: Expectation<'tcx>,
|
expected: Expectation<'tcx>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
debug!(">> type-checking: expected={:?}, expr={:?} ", expected, expr);
|
if self.tcx().sess.verbose() {
|
||||||
|
// make this code only run with -Zverbose because it is probably slow
|
||||||
|
if let Ok(lint_str) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
|
||||||
|
if !lint_str.contains("\n") {
|
||||||
|
debug!("expr text: {}", lint_str);
|
||||||
|
} else {
|
||||||
|
let mut lines = lint_str.lines();
|
||||||
|
if let Some(line0) = lines.next() {
|
||||||
|
let remaining_lines = lines.count();
|
||||||
|
debug!("expr text: {}", line0);
|
||||||
|
debug!("expr text: ...(and {} more lines)", remaining_lines);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// True if `expr` is a `Try::from_ok(())` that is a result of desugaring a try block
|
// True if `expr` is a `Try::from_ok(())` that is a result of desugaring a try block
|
||||||
// without the final expr (e.g. `try { return; }`). We don't want to generate an
|
// without the final expr (e.g. `try { return; }`). We don't want to generate an
|
||||||
|
@ -1049,6 +1064,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
|
let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
|
||||||
match cast::CastCheck::new(self, e, t_expr, t_cast, t.span, expr.span) {
|
match cast::CastCheck::new(self, e, t_expr, t_cast, t.span, expr.span) {
|
||||||
Ok(cast_check) => {
|
Ok(cast_check) => {
|
||||||
|
debug!(
|
||||||
|
"check_expr_cast: deferring cast from {:?} to {:?}: {:?}",
|
||||||
|
t_cast,
|
||||||
|
t_expr,
|
||||||
|
cast_check,
|
||||||
|
);
|
||||||
deferred_cast_checks.push(cast_check);
|
deferred_cast_checks.push(cast_check);
|
||||||
t_cast
|
t_cast
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ use std::slice;
|
||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
pub(in super::super) fn check_casts(&self) {
|
pub(in super::super) fn check_casts(&self) {
|
||||||
let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
|
let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
|
||||||
|
debug!("FnCtxt::check_casts: {} deferred checks", deferred_cast_checks.len());
|
||||||
for cast in deferred_cast_checks.drain(..) {
|
for cast in deferred_cast_checks.drain(..) {
|
||||||
cast.check(self);
|
cast.check(self);
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,9 +120,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(self), level = "debug")]
|
||||||
pub fn consume_body(&mut self, body: &hir::Body<'_>) {
|
pub fn consume_body(&mut self, body: &hir::Body<'_>) {
|
||||||
debug!("consume_body(body={:?})", body);
|
|
||||||
|
|
||||||
for param in body.params {
|
for param in body.params {
|
||||||
let param_ty = return_if_err!(self.mc.pat_ty_adjusted(¶m.pat));
|
let param_ty = return_if_err!(self.mc.pat_ty_adjusted(¶m.pat));
|
||||||
debug!("consume_body: param_ty = {:?}", param_ty);
|
debug!("consume_body: param_ty = {:?}", param_ty);
|
||||||
|
@ -243,7 +242,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
||||||
let ExprUseVisitor { ref mc, body_owner: _, delegate: _ } = *self;
|
let ExprUseVisitor { ref mc, body_owner: _, delegate: _ } = *self;
|
||||||
let mut needs_to_be_read = false;
|
let mut needs_to_be_read = false;
|
||||||
for arm in arms.iter() {
|
for arm in arms.iter() {
|
||||||
match mc.cat_pattern(discr_place.clone(), &arm.pat, |place, pat| {
|
return_if_err!(mc.cat_pattern(discr_place.clone(), &arm.pat, |place, pat| {
|
||||||
match &pat.kind {
|
match &pat.kind {
|
||||||
PatKind::Binding(.., opt_sub_pat) => {
|
PatKind::Binding(.., opt_sub_pat) => {
|
||||||
// If the opt_sub_pat is None, than the binding does not count as
|
// If the opt_sub_pat is None, than the binding does not count as
|
||||||
|
@ -290,13 +289,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
||||||
// examined
|
// examined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) {
|
}));
|
||||||
Ok(_) => (),
|
|
||||||
Err(_) => {
|
|
||||||
// If typeck failed, assume borrow is needed.
|
|
||||||
needs_to_be_read = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if needs_to_be_read {
|
if needs_to_be_read {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue