diff options
| author | Ding Xiang Fei <dingxiangfei2009@protonmail.ch> | 2025-01-29 06:15:56 +0800 |
|---|---|---|
| committer | Ding Xiang Fei <dingxiangfei2009@protonmail.ch> | 2025-02-09 20:40:42 +0800 |
| commit | c0673246371b1a5ecac940f1ea6418857f932d7c (patch) | |
| tree | 67469e07d6909259ef45948d51ac2c312ba2bb17 /compiler/rustc_hir_analysis/src/coherence/builtin.rs | |
| parent | de405dcb8fbcd0add1e60c75800dac9b8fbe4884 (diff) | |
| download | rust-c0673246371b1a5ecac940f1ea6418857f932d7c.tar.gz rust-c0673246371b1a5ecac940f1ea6418857f932d7c.zip | |
rename the trait to validity and place a feature gate afront
Diffstat (limited to 'compiler/rustc_hir_analysis/src/coherence/builtin.rs')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/coherence/builtin.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index a872bb72bef..c21576a5e7c 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -49,8 +49,8 @@ pub(super) fn check_trait<'tcx>( .check(lang_items.dispatch_from_dyn_trait(), visit_implementation_of_dispatch_from_dyn)?; checker.check(lang_items.pointer_like(), visit_implementation_of_pointer_like)?; checker.check( - lang_items.coerce_pointee_wellformed_trait(), - visit_implementation_of_coerce_pointee_wellformed, + lang_items.coerce_pointee_validated_trait(), + visit_implementation_of_coerce_pointee_validity, )?; Ok(()) } @@ -787,19 +787,21 @@ fn visit_implementation_of_pointer_like(checker: &Checker<'_>) -> Result<(), Err .emit()) } -fn visit_implementation_of_coerce_pointee_wellformed( +fn visit_implementation_of_coerce_pointee_validity( checker: &Checker<'_>, ) -> Result<(), ErrorGuaranteed> { let tcx = checker.tcx; let self_ty = tcx.impl_trait_ref(checker.impl_def_id).unwrap().instantiate_identity().self_ty(); + let span = tcx.def_span(checker.impl_def_id); + if !tcx.is_builtin_derived(checker.impl_def_id.into()) { + return Err(tcx.dcx().emit_err(errors::CoercePointeeNoUserValidityAssertion { span })); + } let ty::Adt(def, _args) = self_ty.kind() else { - return Err(tcx.dcx().emit_err(errors::CoercePointeeNotConcreteType { - span: tcx.def_span(checker.impl_def_id), - })); + return Err(tcx.dcx().emit_err(errors::CoercePointeeNotConcreteType { span })); }; let did = def.did(); - let span = - if let Some(local) = did.as_local() { tcx.source_span(local) } else { tcx.def_span(did) }; + // Now get a more precise span of the `struct`. + let span = tcx.def_span(did); if !def.is_struct() { return Err(tcx .dcx() |
