Skip to content

Commit 13c2217

Browse files
authored
Unrolled build for rust-lang#138423
Rollup merge of rust-lang#138423 - compiler-errors:delay-emit, r=WaffleLapkin Don't emit error within cast function, propagate it as a `CastError` Minor nitpick from rust-lang#136764. r? `@WaffleLapkin`
2 parents 52daa7d + 5ec462e commit 13c2217

File tree

1 file changed

+19
-14
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+19
-14
lines changed

compiler/rustc_hir_typeck/src/cast.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use rustc_ast::util::parser::ExprPrecedence;
3232
use rustc_data_structures::fx::FxHashSet;
3333
use rustc_errors::codes::*;
3434
use rustc_errors::{Applicability, Diag, ErrorGuaranteed};
35+
use rustc_hir::def_id::DefId;
3536
use rustc_hir::{self as hir, ExprKind};
3637
use rustc_infer::infer::DefineOpaqueTypes;
3738
use rustc_macros::{TypeFoldable, TypeVisitable};
@@ -155,7 +156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
155156
}
156157
}
157158

158-
#[derive(Copy, Clone, Debug)]
159+
#[derive(Debug)]
159160
enum CastError<'tcx> {
160161
ErrorGuaranteed(ErrorGuaranteed),
161162

@@ -182,6 +183,7 @@ enum CastError<'tcx> {
182183
/// when we're typechecking a type parameter with a ?Sized bound.
183184
IntToWideCast(Option<&'static str>),
184185
ForeignNonExhaustiveAdt,
186+
PtrPtrAddingAutoTrait(Vec<DefId>),
185187
}
186188

187189
impl From<ErrorGuaranteed> for CastError<'_> {
@@ -596,6 +598,21 @@ impl<'a, 'tcx> CastCheck<'tcx> {
596598
.with_note("cannot cast an enum with a non-exhaustive variant when it's defined in another crate")
597599
.emit();
598600
}
601+
CastError::PtrPtrAddingAutoTrait(added) => {
602+
fcx.dcx().emit_err(errors::PtrCastAddAutoToObject {
603+
span: self.span,
604+
traits_len: added.len(),
605+
traits: {
606+
let mut traits: Vec<_> = added
607+
.into_iter()
608+
.map(|trait_did| fcx.tcx.def_path_str(trait_did))
609+
.collect();
610+
611+
traits.sort();
612+
traits.into()
613+
},
614+
});
615+
}
599616
}
600617
}
601618

@@ -940,19 +957,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
940957
.collect::<Vec<_>>();
941958

942959
if !added.is_empty() {
943-
tcx.dcx().emit_err(errors::PtrCastAddAutoToObject {
944-
span: self.span,
945-
traits_len: added.len(),
946-
traits: {
947-
let mut traits: Vec<_> = added
948-
.into_iter()
949-
.map(|trait_did| tcx.def_path_str(trait_did))
950-
.collect();
951-
952-
traits.sort();
953-
traits.into()
954-
},
955-
});
960+
return Err(CastError::PtrPtrAddingAutoTrait(added));
956961
}
957962

958963
Ok(CastKind::PtrPtrCast)

0 commit comments

Comments
 (0)