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
6 changes: 4 additions & 2 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use rustc_ast::util::parser::ExprPrecedence;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::codes::*;
use rustc_errors::{Applicability, Diag, ErrorGuaranteed};
use rustc_hir::def_id::DefId;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{self as hir, ExprKind};
use rustc_infer::infer::DefineOpaqueTypes;
use rustc_macros::{TypeFoldable, TypeVisitable};
Expand Down Expand Up @@ -63,6 +63,7 @@ pub(crate) struct CastCheck<'tcx> {
cast_ty: Ty<'tcx>,
cast_span: Span,
span: Span,
pub body_id: LocalDefId,
}

/// The kind of pointer and associated metadata (thin, length or vtable) - we
Expand Down Expand Up @@ -244,7 +245,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
span: Span,
) -> Result<CastCheck<'tcx>, ErrorGuaranteed> {
let expr_span = expr.span.find_ancestor_inside(span).unwrap_or(expr.span);
let check = CastCheck { expr, expr_ty, expr_span, cast_ty, cast_span, span };
let check =
CastCheck { expr, expr_ty, expr_span, cast_ty, cast_span, span, body_id: fcx.body_id };

// For better error messages, check for some obviously unsized
// cases now. We do a more thorough check at the end, once
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::ops::Deref;
use std::{fmt, iter, mem};
use std::{fmt, iter};

use itertools::Itertools;
use rustc_data_structures::fx::FxIndexSet;
Expand Down Expand Up @@ -72,16 +72,13 @@ pub(crate) enum DivergingBlockBehavior {

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(in super::super) fn check_casts(&mut self) {
// don't hold the borrow to deferred_cast_checks while checking to avoid borrow checker errors
// when writing to `self.param_env`.
let mut deferred_cast_checks = mem::take(&mut *self.deferred_cast_checks.borrow_mut());

let mut deferred_cast_checks = self.root_ctxt.deferred_cast_checks.borrow_mut();
debug!("FnCtxt::check_casts: {} deferred checks", deferred_cast_checks.len());
for cast in deferred_cast_checks.drain(..) {
let body_id = std::mem::replace(&mut self.body_id, cast.body_id);
cast.check(self);
self.body_id = body_id;
}

*self.deferred_cast_checks.borrow_mut() = deferred_cast_checks;
}

pub(in super::super) fn check_asms(&self) {
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/traits/const-traits/issue-103677.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//@ check-pass
//@ revisions: stock cnst
#![cfg_attr(cnst, feature(const_trait_impl))]

const _: fn(&String) = |s| { &*s as &str; };
const _: fn(&String) = |s| {
&*s as &str;
};

fn main() {}
Loading