Skip to content

Commit 76c427d

Browse files
committed
Auto merge of #100510 - compiler-errors:as-a-treat, r=jackh726
make `TypeError` impl `Copy` r? `@ghost`
2 parents b8c0a01 + 75dfe55 commit 76c427d

File tree

8 files changed

+37
-38
lines changed

8 files changed

+37
-38
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,7 @@ fn try_extract_error_from_region_constraints<'tcx>(
484484
};
485485
nice_error.try_report_from_nll().or_else(|| {
486486
if let SubregionOrigin::Subtype(trace) = cause {
487-
Some(
488-
infcx.report_and_explain_type_error(*trace, &TypeError::RegionsPlaceholderMismatch),
489-
)
487+
Some(infcx.report_and_explain_type_error(*trace, TypeError::RegionsPlaceholderMismatch))
490488
} else {
491489
None
492490
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
457457
}
458458

459459
/// Adds a note if the types come from similarly named crates
460-
fn check_and_note_conflicting_crates(&self, err: &mut Diagnostic, terr: &TypeError<'tcx>) {
460+
fn check_and_note_conflicting_crates(&self, err: &mut Diagnostic, terr: TypeError<'tcx>) {
461461
use hir::def_id::CrateNum;
462462
use rustc_hir::definitions::DisambiguatedDefPathData;
463463
use ty::print::Printer;
@@ -561,7 +561,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
561561
}
562562
}
563563
};
564-
match *terr {
564+
match terr {
565565
TypeError::Sorts(ref exp_found) => {
566566
// if they are both "path types", there's a chance of ambiguity
567567
// due to different versions of the same crate
@@ -583,7 +583,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
583583
err: &mut Diagnostic,
584584
cause: &ObligationCause<'tcx>,
585585
exp_found: Option<ty::error::ExpectedFound<Ty<'tcx>>>,
586-
terr: &TypeError<'tcx>,
586+
terr: TypeError<'tcx>,
587587
) {
588588
match *cause.code() {
589589
ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => {
@@ -1432,7 +1432,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14321432
cause: &ObligationCause<'tcx>,
14331433
secondary_span: Option<(Span, String)>,
14341434
mut values: Option<ValuePairs<'tcx>>,
1435-
terr: &TypeError<'tcx>,
1435+
terr: TypeError<'tcx>,
14361436
swap_secondary_and_primary: bool,
14371437
prefer_label: bool,
14381438
) {
@@ -1713,7 +1713,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17131713
ty::error::TypeError::Sorts(terr)
17141714
if exp_found.map_or(false, |ef| terr.found == ef.found) =>
17151715
{
1716-
Some(*terr)
1716+
Some(terr)
17171717
}
17181718
_ => exp_found,
17191719
};
@@ -2091,7 +2091,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
20912091
pub fn report_and_explain_type_error(
20922092
&self,
20932093
trace: TypeTrace<'tcx>,
2094-
terr: &TypeError<'tcx>,
2094+
terr: TypeError<'tcx>,
20952095
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
20962096
use crate::traits::ObligationCauseCode::MatchExpressionArm;
20972097

@@ -2781,12 +2781,12 @@ pub enum FailureCode {
27812781
}
27822782

27832783
pub trait ObligationCauseExt<'tcx> {
2784-
fn as_failure_code(&self, terr: &TypeError<'tcx>) -> FailureCode;
2784+
fn as_failure_code(&self, terr: TypeError<'tcx>) -> FailureCode;
27852785
fn as_requirement_str(&self) -> &'static str;
27862786
}
27872787

27882788
impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
2789-
fn as_failure_code(&self, terr: &TypeError<'tcx>) -> FailureCode {
2789+
fn as_failure_code(&self, terr: TypeError<'tcx>) -> FailureCode {
27902790
use self::FailureCode::*;
27912791
use crate::traits::ObligationCauseCode::*;
27922792
match self.code() {
@@ -2823,7 +2823,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
28232823
TypeError::IntrinsicCast => {
28242824
Error0308("cannot coerce intrinsics to function pointers")
28252825
}
2826-
TypeError::ObjectUnsafeCoercion(did) => Error0038(*did),
2826+
TypeError::ObjectUnsafeCoercion(did) => Error0038(did),
28272827
_ => Error0308("mismatched types"),
28282828
},
28292829
}

compiler/rustc_infer/src/infer/error_reporting/note.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
107107
match origin {
108108
infer::Subtype(box trace) => {
109109
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
110-
let mut err = self.report_and_explain_type_error(trace, &terr);
110+
let mut err = self.report_and_explain_type_error(trace, terr);
111111
match (*sub, *sup) {
112112
(ty::RePlaceholder(_), ty::RePlaceholder(_)) => {}
113113
(ty::RePlaceholder(_), _) => {
@@ -406,7 +406,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
406406
}
407407
infer::Subtype(box trace) => {
408408
let terr = TypeError::RegionsPlaceholderMismatch;
409-
return self.report_and_explain_type_error(trace, &terr);
409+
return self.report_and_explain_type_error(trace, terr);
410410
}
411411
_ => return self.report_concrete_failure(placeholder_origin, sub, sup),
412412
}

compiler/rustc_infer/src/infer/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1527,8 +1527,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15271527
actual: Ty<'tcx>,
15281528
err: TypeError<'tcx>,
15291529
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
1530-
let trace = TypeTrace::types(cause, true, expected, actual);
1531-
self.report_and_explain_type_error(trace, &err)
1530+
self.report_and_explain_type_error(TypeTrace::types(cause, true, expected, actual), err)
15321531
}
15331532

15341533
pub fn report_mismatched_consts(
@@ -1538,8 +1537,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15381537
actual: ty::Const<'tcx>,
15391538
err: TypeError<'tcx>,
15401539
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
1541-
let trace = TypeTrace::consts(cause, true, expected, actual);
1542-
self.report_and_explain_type_error(trace, &err)
1540+
self.report_and_explain_type_error(TypeTrace::consts(cause, true, expected, actual), err)
15431541
}
15441542

15451543
pub fn replace_bound_vars_with_fresh_vars<T>(

compiler/rustc_middle/src/ty/error.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ impl<T> ExpectedFound<T> {
3030
}
3131

3232
// Data structures used in type unification
33-
#[derive(Clone, Debug, TypeFoldable, TypeVisitable)]
33+
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable)]
34+
#[rustc_pass_by_value]
3435
pub enum TypeError<'tcx> {
3536
Mismatch,
3637
ConstnessMismatch(ExpectedFound<ty::BoundConstness>),
@@ -211,7 +212,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
211212
}
212213

213214
impl<'tcx> TypeError<'tcx> {
214-
pub fn must_include_note(&self) -> bool {
215+
pub fn must_include_note(self) -> bool {
215216
use self::TypeError::*;
216217
match self {
217218
CyclicTy(_) | CyclicConst(_) | UnsafetyMismatch(_) | ConstnessMismatch(_)
@@ -347,7 +348,7 @@ impl<'tcx> TyCtxt<'tcx> {
347348
pub fn note_and_explain_type_err(
348349
self,
349350
diag: &mut Diagnostic,
350-
err: &TypeError<'tcx>,
351+
err: TypeError<'tcx>,
351352
cause: &ObligationCause<'tcx>,
352353
sp: Span,
353354
body_owner_def_id: DefId,
@@ -568,7 +569,7 @@ impl<T> Trait<T> for X {
568569
}
569570
TargetFeatureCast(def_id) => {
570571
let target_spans =
571-
self.get_attrs(*def_id, sym::target_feature).map(|attr| attr.span);
572+
self.get_attrs(def_id, sym::target_feature).map(|attr| attr.span);
572573
diag.note(
573574
"functions with `#[target_feature]` can only be coerced to `unsafe` function pointers"
574575
);
@@ -640,7 +641,7 @@ impl<T> Trait<T> for X {
640641
self,
641642
diag: &mut Diagnostic,
642643
proj_ty: &ty::ProjectionTy<'tcx>,
643-
values: &ExpectedFound<Ty<'tcx>>,
644+
values: ExpectedFound<Ty<'tcx>>,
644645
body_owner_def_id: DefId,
645646
cause_code: &ObligationCauseCode<'_>,
646647
) {

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1507,8 +1507,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
15071507
}
15081508

15091509
self.probe(|_| {
1510-
let err_buf;
1511-
let mut err = &error.err;
1510+
let mut err = error.err;
15121511
let mut values = None;
15131512

15141513
// try to find the mismatched types to report the error with.
@@ -1544,14 +1543,13 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
15441543
| ObligationCauseCode::ObjectCastObligation(..)
15451544
| ObligationCauseCode::OpaqueType
15461545
);
1547-
if let Err(error) = self.at(&obligation.cause, obligation.param_env).eq_exp(
1546+
if let Err(new_err) = self.at(&obligation.cause, obligation.param_env).eq_exp(
15481547
is_normalized_ty_expected,
15491548
normalized_ty,
15501549
data.term,
15511550
) {
15521551
values = Some((data, is_normalized_ty_expected, normalized_ty, data.term));
1553-
err_buf = error;
1554-
err = &err_buf;
1552+
err = new_err;
15551553
}
15561554
}
15571555

compiler/rustc_typeck/src/check/compare_method.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ fn compare_predicate_entailment<'tcx>(
291291
debug!("sub_types failed: impl ty {:?}, trait ty {:?}", impl_fty, trait_fty);
292292

293293
let (impl_err_span, trait_err_span) =
294-
extract_spans_for_error_reporting(&infcx, &terr, &cause, impl_m, trait_m);
294+
extract_spans_for_error_reporting(&infcx, terr, &cause, impl_m, trait_m);
295295

296296
cause.span = impl_err_span;
297297

@@ -381,7 +381,7 @@ fn compare_predicate_entailment<'tcx>(
381381
expected: trait_fty.into(),
382382
found: impl_fty.into(),
383383
})),
384-
&terr,
384+
terr,
385385
false,
386386
false,
387387
);
@@ -468,7 +468,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
468468
#[instrument(level = "debug", skip(infcx))]
469469
fn extract_spans_for_error_reporting<'a, 'tcx>(
470470
infcx: &infer::InferCtxt<'a, 'tcx>,
471-
terr: &TypeError<'_>,
471+
terr: TypeError<'_>,
472472
cause: &ObligationCause<'tcx>,
473473
impl_m: &ty::AssocItem,
474474
trait_m: &ty::AssocItem,
@@ -488,7 +488,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>(
488488
_ => bug!("{:?} is not a TraitItemKind::Fn", trait_m),
489489
});
490490

491-
match *terr {
491+
match terr {
492492
TypeError::ArgumentMutability(i) => {
493493
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
494494
}
@@ -1143,7 +1143,7 @@ pub(crate) fn compare_const_impl<'tcx>(
11431143
expected: trait_ty.into(),
11441144
found: impl_ty.into(),
11451145
})),
1146-
&terr,
1146+
terr,
11471147
false,
11481148
false,
11491149
);

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
578578
// First, check if we just need to wrap some arguments in a tuple.
579579
if let Some((mismatch_idx, terr)) =
580580
compatibility_diagonal.iter().enumerate().find_map(|(i, c)| {
581-
if let Compatibility::Incompatible(Some(terr)) = c { Some((i, terr)) } else { None }
581+
if let Compatibility::Incompatible(Some(terr)) = c {
582+
Some((i, *terr))
583+
} else {
584+
None
585+
}
582586
})
583587
{
584588
// Is the first bad expected argument a tuple?
@@ -707,8 +711,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
707711
let (expected_ty, _) = formal_and_expected_inputs[*expected_idx];
708712
let cause = &self.misc(provided_span);
709713
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
710-
if !matches!(trace.cause.as_failure_code(e), FailureCode::Error0308(_)) {
711-
self.report_and_explain_type_error(trace, e).emit();
714+
if !matches!(trace.cause.as_failure_code(*e), FailureCode::Error0308(_)) {
715+
self.report_and_explain_type_error(trace, *e).emit();
712716
return true;
713717
}
714718
false
@@ -732,7 +736,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
732736
let (provided_ty, provided_arg_span) = provided_arg_tys[*provided_idx];
733737
let cause = &self.misc(provided_arg_span);
734738
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
735-
let mut err = self.report_and_explain_type_error(trace, err);
739+
let mut err = self.report_and_explain_type_error(trace, *err);
736740
self.emit_coerce_suggestions(
737741
&mut err,
738742
&provided_args[*provided_idx],
@@ -802,7 +806,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
802806
Error::Invalid(provided_idx, expected_idx, compatibility) => {
803807
let (formal_ty, expected_ty) = formal_and_expected_inputs[expected_idx];
804808
let (provided_ty, provided_span) = provided_arg_tys[provided_idx];
805-
if let Compatibility::Incompatible(error) = &compatibility {
809+
if let Compatibility::Incompatible(error) = compatibility {
806810
let cause = &self.misc(provided_span);
807811
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
808812
if let Some(e) = error {

0 commit comments

Comments
 (0)