diff options
| author | bors <bors@rust-lang.org> | 2023-05-04 13:44:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-05-04 13:44:38 +0000 |
| commit | eac35583d2ffb5ed9e564dee0822c9a244058ee0 (patch) | |
| tree | 1b4e010fb54cdbf7796655e36da371d6f378bb20 /compiler/rustc_hir_analysis/src | |
| parent | 6f8c0557e0b73c73a8a7163a15f4a5a3feca7d5c (diff) | |
| parent | b4d992fec740dc9a6ff42a0500026fe5b25db74a (diff) | |
| download | rust-eac35583d2ffb5ed9e564dee0822c9a244058ee0.tar.gz rust-eac35583d2ffb5ed9e564dee0822c9a244058ee0.zip | |
Auto merge of #111174 - matthiaskrgr:rollup-ncnqivh, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #110859 (Explicitly reject negative and reservation drop impls) - #111020 (Validate resolution for SelfCtor too.) - #111024 (Use the full Fingerprint when stringifying Svh) - #111027 (Remove `allow(rustc::potential_query_instability)` for `builtin_macros`) - #111039 (Encode def span for foreign return-position `impl Trait` in trait) - #111070 (Don't suffix `RibKind` variants) - #111094 (Add needs-unwind annotations to tests that need stack unwinding) - #111103 (correctly recurse when expanding anon consts) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/dropck.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/errors.rs | 14 |
2 files changed, 30 insertions, 1 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/dropck.rs b/compiler/rustc_hir_analysis/src/check/dropck.rs index 64dff8e68b8..bae80807f71 100644 --- a/compiler/rustc_hir_analysis/src/check/dropck.rs +++ b/compiler/rustc_hir_analysis/src/check/dropck.rs @@ -1,7 +1,6 @@ // FIXME(@lcnr): Move this module out of `rustc_hir_analysis`. // // We don't do any drop checking during hir typeck. -use crate::hir::def_id::{DefId, LocalDefId}; use rustc_errors::{struct_span_err, ErrorGuaranteed}; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation}; @@ -9,6 +8,9 @@ use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::util::IgnoreRegions; use rustc_middle::ty::{self, Predicate, Ty, TyCtxt}; +use crate::errors; +use crate::hir::def_id::{DefId, LocalDefId}; + /// This function confirms that the `Drop` implementation identified by /// `drop_impl_did` is not any more specialized than the type it is /// attached to (Issue #8142). @@ -27,6 +29,19 @@ use rustc_middle::ty::{self, Predicate, Ty, TyCtxt}; /// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`). /// pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), ErrorGuaranteed> { + match tcx.impl_polarity(drop_impl_did) { + ty::ImplPolarity::Positive => {} + ty::ImplPolarity::Negative => { + return Err(tcx.sess.emit_err(errors::DropImplPolarity::Negative { + span: tcx.def_span(drop_impl_did), + })); + } + ty::ImplPolarity::Reservation => { + return Err(tcx.sess.emit_err(errors::DropImplPolarity::Reservation { + span: tcx.def_span(drop_impl_did), + })); + } + } let dtor_self_type = tcx.type_of(drop_impl_did).subst_identity(); let dtor_predicates = tcx.predicates_of(drop_impl_did); match dtor_self_type.kind() { diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 25ad1bed763..c0ee777722e 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -823,3 +823,17 @@ pub(crate) struct MissingTildeConst { #[primary_span] pub span: Span, } + +#[derive(Diagnostic)] +pub(crate) enum DropImplPolarity { + #[diag(hir_analysis_drop_impl_negative)] + Negative { + #[primary_span] + span: Span, + }, + #[diag(hir_analysis_drop_impl_reservation)] + Reservation { + #[primary_span] + span: Span, + }, +} |
