diff options
| author | bors <bors@rust-lang.org> | 2025-02-11 05:27:49 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-02-11 05:27:49 +0000 |
| commit | c182ce9cbc8c29ebc1b4559d027df545e6cdd287 (patch) | |
| tree | a17345e81cf8c0c3db94f827c36b395ebb6ff245 /compiler/rustc_hir_analysis/src | |
| parent | ffa9afef183a3496a277c8da2e61403582a99508 (diff) | |
| parent | 5a44f78269717a926cfab6549ce0b4f323e27d63 (diff) | |
| download | rust-c182ce9cbc8c29ebc1b4559d027df545e6cdd287.tar.gz rust-c182ce9cbc8c29ebc1b4559d027df545e6cdd287.zip | |
Auto merge of #136845 - matthiaskrgr:rollup-ol4np4z, r=matthiaskrgr
Rollup of 7 pull requests
Successful merges:
- #136107 (Introduce CoercePointeeWellformed for coherence checks at typeck stage)
- #136155 (Enable sanitizers on MSVC CI jobs)
- #136524 (Delay bug when method confirmation cannot upcast object pick of self)
- #136584 (Prevent generic pattern types from being used in libstd)
- #136603 (compiler: gate `extern "{abi}"` in ast_lowering)
- #136821 (assign marcoieni and jdno to infra-ci PRs)
- #136825 (Update books)
r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/coherence/builtin.rs | 33 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/errors.rs | 36 |
2 files changed, 69 insertions, 0 deletions
diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 66082f4c282..9da57c330c5 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -48,6 +48,10 @@ pub(super) fn check_trait<'tcx>( checker .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_validated_trait(), + visit_implementation_of_coerce_pointee_validity, + )?; Ok(()) } @@ -783,3 +787,32 @@ fn visit_implementation_of_pointer_like(checker: &Checker<'_>) -> Result<(), Err .with_note(why_disqualified) .emit()) } + +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 })); + }; + let did = def.did(); + // Now get a more precise span of the `struct`. + let span = tcx.def_span(did); + if !def.is_struct() { + return Err(tcx + .dcx() + .emit_err(errors::CoercePointeeNotStruct { span, kind: def.descr().into() })); + } + if !def.repr().transparent() { + return Err(tcx.dcx().emit_err(errors::CoercePointeeNotTransparent { span })); + } + if def.all_fields().next().is_none() { + return Err(tcx.dcx().emit_err(errors::CoercePointeeNoField { span })); + } + Ok(()) +} diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 9769be30226..12750543f4b 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -1181,6 +1181,42 @@ pub(crate) struct DispatchFromDynRepr { } #[derive(Diagnostic)] +#[diag(hir_analysis_coerce_pointee_not_struct, code = E0802)] +pub(crate) struct CoercePointeeNotStruct { + #[primary_span] + pub span: Span, + pub kind: String, +} + +#[derive(Diagnostic)] +#[diag(hir_analysis_coerce_pointee_not_concrete_ty, code = E0802)] +pub(crate) struct CoercePointeeNotConcreteType { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag(hir_analysis_coerce_pointee_no_user_validity_assertion, code = E0802)] +pub(crate) struct CoercePointeeNoUserValidityAssertion { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag(hir_analysis_coerce_pointee_not_transparent, code = E0802)] +pub(crate) struct CoercePointeeNotTransparent { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag(hir_analysis_coerce_pointee_no_field, code = E0802)] +pub(crate) struct CoercePointeeNoField { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] #[diag(hir_analysis_inherent_ty_outside_relevant, code = E0390)] #[help] pub(crate) struct InherentTyOutsideRelevant { |
