diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-10-21 07:01:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-21 07:01:37 +0200 |
| commit | 62b7293a90452d7d7dcbaa63695e6e1a6cb72a3c (patch) | |
| tree | 217c576f0bb6762d22ee4c3c857258c886c7f1e4 /compiler/rustc_trait_selection/src | |
| parent | 4f6750b86c1881c4d2e1ff2b761296483f5e56d2 (diff) | |
| parent | 61ed4cb5b4d26a9f12ad0b0fb065b4014348a9dd (diff) | |
| download | rust-62b7293a90452d7d7dcbaa63695e6e1a6cb72a3c.tar.gz rust-62b7293a90452d7d7dcbaa63695e6e1a6cb72a3c.zip | |
Rollup merge of #131981 - compiler-errors:bound-constness, r=cjgillot
Remove the `BoundConstness::NotConst` variant I find it easier to represent `BoundConstness::NotConst` as just `None` for some refactorings I'm doing.
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 44373ca4866..dfec5d956c9 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -290,7 +290,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } if tcx.is_lang_item(leaf_trait_ref.def_id(), LangItem::Drop) - && matches!(predicate_constness, ty::BoundConstness::ConstIfConst | ty::BoundConstness::Const) + && matches!(predicate_constness, Some(ty::BoundConstness::ConstIfConst | ty::BoundConstness::Const)) { err.note("`~const Drop` was renamed to `~const Destruct`"); err.note("See <https://github.com/rust-lang/rust/pull/94901> for more details"); @@ -2192,7 +2192,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { &self, trait_predicate: ty::PolyTraitPredicate<'tcx>, message: Option<String>, - predicate_constness: ty::BoundConstness, + predicate_constness: Option<ty::BoundConstness>, append_const_msg: Option<AppendConstMessage>, post_message: String, ) -> String { @@ -2200,19 +2200,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { .and_then(|cannot_do_this| { match (predicate_constness, append_const_msg) { // do nothing if predicate is not const - (ty::BoundConstness::NotConst, _) => Some(cannot_do_this), + (None, _) => Some(cannot_do_this), // suggested using default post message ( - ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst, + Some(ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst), Some(AppendConstMessage::Default), ) => Some(format!("{cannot_do_this} in const contexts")), // overridden post message ( - ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst, + Some(ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst), Some(AppendConstMessage::Custom(custom_msg, _)), ) => Some(format!("{cannot_do_this}{custom_msg}")), // fallback to generic message - (ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst, None) => None, + (Some(ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst), None) => { + None + } } }) .unwrap_or_else(|| { @@ -2358,26 +2360,27 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { p: ty::PolyTraitPredicate<'tcx>, leaf: ty::PolyTraitPredicate<'tcx>, span: Span, - ) -> (ty::PolyTraitPredicate<'tcx>, ty::PolyTraitPredicate<'tcx>, ty::BoundConstness) { + ) -> (ty::PolyTraitPredicate<'tcx>, ty::PolyTraitPredicate<'tcx>, Option<ty::BoundConstness>) + { let trait_ref = p.to_poly_trait_ref(); if !self.tcx.is_lang_item(trait_ref.def_id(), LangItem::EffectsCompat) { - return (p, leaf, ty::BoundConstness::NotConst); + return (p, leaf, None); } let Some(ty::Alias(ty::AliasTyKind::Projection, projection)) = trait_ref.self_ty().no_bound_vars().map(Ty::kind) else { - return (p, leaf, ty::BoundConstness::NotConst); + return (p, leaf, None); }; let constness = trait_ref.skip_binder().args.const_at(1); let constness = if constness == self.tcx.consts.true_ || constness.is_ct_infer() { - ty::BoundConstness::NotConst + None } else if constness == self.tcx.consts.false_ { - ty::BoundConstness::Const + Some(ty::BoundConstness::Const) } else if matches!(constness.kind(), ty::ConstKind::Param(_)) { - ty::BoundConstness::ConstIfConst + Some(ty::BoundConstness::ConstIfConst) } else { self.dcx().span_bug(span, format!("Unknown constness argument: {constness:?}")); }; |
