diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-05-10 11:10:27 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-05-10 11:10:27 +0000 |
| commit | 9ba6ddb929563e221f0b4cd32949218148b9a1c1 (patch) | |
| tree | deb556609d3a204b1187c4b58d498d5f0544bded | |
| parent | 5b5b54958022911b5ba9afc85b7f58d69e0842f8 (diff) | |
| download | rust-9ba6ddb929563e221f0b4cd32949218148b9a1c1.tar.gz rust-9ba6ddb929563e221f0b4cd32949218148b9a1c1.zip | |
Make the derived obligation cause parent private
4 files changed, 21 insertions, 14 deletions
diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index d28605fc26f..be2d8def954 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -497,7 +497,15 @@ pub struct DerivedObligationCause<'tcx> { pub parent_trait_pred: ty::PolyTraitPredicate<'tcx>, /// The parent trait had this cause. - pub parent_code: Lrc<ObligationCauseCode<'tcx>>, + parent_code: Lrc<ObligationCauseCode<'tcx>>, +} + +impl<'tcx> DerivedObligationCause<'tcx> { + /// Get a reference to the derived obligation cause's parent code. + #[must_use] + pub fn parent_code(&self) -> &ObligationCauseCode<'tcx> { + self.parent_code.as_ref() + } } #[derive(Clone, Debug, TypeFoldable, Lift)] diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 6082d7529c3..81e62f6da06 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1868,7 +1868,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { match code { ObligationCauseCode::BuiltinDerivedObligation(data) => { let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred); - match self.get_parent_trait_ref(&data.parent_code) { + match self.get_parent_trait_ref(data.parent_code()) { Some(t) => Some(t), None => { let ty = parent_trait_ref.skip_binder().self_ty(); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index e4060d1ee5b..1522eedf7fe 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1683,7 +1683,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { _ => {} } - next_code = Some(cause.derived.parent_code.as_ref()); + next_code = Some(cause.derived.parent_code()); } ObligationCauseCode::DerivedObligation(derived_obligation) | ObligationCauseCode::BuiltinDerivedObligation(derived_obligation) => { @@ -1715,7 +1715,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { _ => {} } - next_code = Some(derived_obligation.parent_code.as_ref()); + next_code = Some(derived_obligation.parent_code()); } _ => break, } @@ -2365,8 +2365,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let is_upvar_tys_infer_tuple = if !matches!(ty.kind(), ty::Tuple(..)) { false } else { - if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = - *data.parent_code + if let ObligationCauseCode::BuiltinDerivedObligation(data) = data.parent_code() { let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred); @@ -2393,14 +2392,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { obligated_types.push(ty); let parent_predicate = parent_trait_ref.to_predicate(tcx); - if !self.is_recursive_obligation(obligated_types, &data.parent_code) { + if !self.is_recursive_obligation(obligated_types, data.parent_code()) { // #74711: avoid a stack overflow ensure_sufficient_stack(|| { self.note_obligation_cause_code( err, &parent_predicate, param_env, - &data.parent_code, + data.parent_code(), obligated_types, seen_requirements, ) @@ -2462,7 +2461,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // We don't want to point at the ADT saying "required because it appears within // the type `X`", like we would otherwise do in test `supertrait-auto-trait.rs`. while let ObligationCauseCode::BuiltinDerivedObligation(derived) = - &*data.parent_code + data.parent_code() { let child_trait_ref = self.resolve_vars_if_possible(derived.parent_trait_pred); @@ -2475,7 +2474,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { parent_trait_pred = child_trait_ref; } } - while let ObligationCauseCode::ImplDerivedObligation(child) = &*data.parent_code { + while let ObligationCauseCode::ImplDerivedObligation(child) = data.parent_code() { // Skip redundant recursive obligation notes. See `ui/issue-20413.rs`. let child_trait_pred = self.resolve_vars_if_possible(child.derived.parent_trait_pred); @@ -2506,7 +2505,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err, &parent_predicate, param_env, - &data.parent_code, + data.parent_code(), obligated_types, seen_requirements, ) @@ -2521,7 +2520,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err, &parent_predicate, param_env, - &data.parent_code, + data.parent_code(), obligated_types, seen_requirements, ) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 43fb703456a..300b87aa465 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -1606,9 +1606,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut result_code = code; loop { let parent = match code { - ObligationCauseCode::ImplDerivedObligation(c) => &c.derived.parent_code, + ObligationCauseCode::ImplDerivedObligation(c) => c.derived.parent_code(), ObligationCauseCode::BuiltinDerivedObligation(c) - | ObligationCauseCode::DerivedObligation(c) => &c.parent_code, + | ObligationCauseCode::DerivedObligation(c) => c.parent_code(), _ => break result_code, }; (result_code, code) = (code, parent); |
