Skip to content

Commit 6d831fd

Browse files
committed
remove the coherence_leak_check lint
1 parent 3c659f3 commit 6d831fd

31 files changed

+87
-386
lines changed

compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_index::IndexVec;
77
use rustc_middle::traits::specialization_graph::OverlapMode;
88
use rustc_middle::ty::{self, TyCtxt};
99
use rustc_span::{ErrorGuaranteed, Symbol};
10-
use rustc_trait_selection::traits::{self, SkipLeakCheck};
10+
use rustc_trait_selection::traits;
1111
use smallvec::SmallVec;
1212
use std::collections::hash_map::Entry;
1313

@@ -145,15 +145,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
145145
impl1_def_id: DefId,
146146
impl2_def_id: DefId,
147147
) -> Result<(), ErrorGuaranteed> {
148-
let maybe_overlap = traits::overlapping_impls(
149-
self.tcx,
150-
impl1_def_id,
151-
impl2_def_id,
152-
// We go ahead and just skip the leak check for
153-
// inherent impls without warning.
154-
SkipLeakCheck::Yes,
155-
overlap_mode,
156-
);
148+
let maybe_overlap =
149+
traits::overlapping_impls(self.tcx, impl1_def_id, impl2_def_id, overlap_mode);
157150

158151
if let Some(overlap) = maybe_overlap {
159152
self.check_for_common_items_in_impls(impl1_def_id, impl2_def_id, overlap)

compiler/rustc_infer/src/infer/at.rs

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ impl<'tcx> InferCtxt<'tcx> {
7878
tcx: self.tcx,
7979
defining_use_anchor: self.defining_use_anchor,
8080
considering_regions: self.considering_regions,
81-
skip_leak_check: self.skip_leak_check,
8281
inner: self.inner.clone(),
8382
lexical_region_resolutions: self.lexical_region_resolutions.clone(),
8483
selection_cache: self.selection_cache.clone(),

compiler/rustc_infer/src/infer/mod.rs

-15
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,6 @@ pub struct InferCtxt<'tcx> {
258258
/// solving is left to borrowck instead.
259259
pub considering_regions: bool,
260260

261-
/// If set, this flag causes us to skip the 'leak check' during
262-
/// higher-ranked subtyping operations. This flag is a temporary one used
263-
/// to manage the removal of the leak-check: for the time being, we still run the
264-
/// leak-check, but we issue warnings.
265-
skip_leak_check: bool,
266-
267261
pub inner: RefCell<InferCtxtInner<'tcx>>,
268262

269263
/// Once region inference is done, the values for each variable.
@@ -611,7 +605,6 @@ pub struct InferCtxtBuilder<'tcx> {
611605
tcx: TyCtxt<'tcx>,
612606
defining_use_anchor: DefiningAnchor,
613607
considering_regions: bool,
614-
skip_leak_check: bool,
615608
/// Whether we are in coherence mode.
616609
intercrate: bool,
617610
/// Whether we should use the new trait solver in the local inference context,
@@ -629,7 +622,6 @@ impl<'tcx> TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
629622
tcx: self,
630623
defining_use_anchor: DefiningAnchor::Error,
631624
considering_regions: true,
632-
skip_leak_check: false,
633625
intercrate: false,
634626
next_trait_solver: self.next_trait_solver_globally(),
635627
}
@@ -663,11 +655,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
663655
self
664656
}
665657

666-
pub fn skip_leak_check(mut self, skip_leak_check: bool) -> Self {
667-
self.skip_leak_check = skip_leak_check;
668-
self
669-
}
670-
671658
/// Given a canonical value `C` as a starting point, create an
672659
/// inference context that contains each of the bound values
673660
/// within instantiated as a fresh variable. The `f` closure is
@@ -693,15 +680,13 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
693680
tcx,
694681
defining_use_anchor,
695682
considering_regions,
696-
skip_leak_check,
697683
intercrate,
698684
next_trait_solver,
699685
} = *self;
700686
InferCtxt {
701687
tcx,
702688
defining_use_anchor,
703689
considering_regions,
704-
skip_leak_check,
705690
inner: RefCell::new(InferCtxtInner::new()),
706691
lexical_region_resolutions: RefCell::new(None),
707692
selection_cache: Default::default(),

compiler/rustc_infer/src/infer/relate/higher_ranked.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,11 @@ impl<'tcx> InferCtxt<'tcx> {
116116
outer_universe: ty::UniverseIndex,
117117
only_consider_snapshot: Option<&CombinedSnapshot<'tcx>>,
118118
) -> RelateResult<'tcx, ()> {
119-
// If the user gave `-Zno-leak-check`, or we have been
120-
// configured to skip the leak check, then skip the leak check
121-
// completely. The leak check is deprecated. Any legitimate
122-
// subtyping errors that it would have caught will now be
123-
// caught later on, during region checking. However, we
124-
// continue to use it for a transition period.
125-
if self.tcx.sess.opts.unstable_opts.no_leak_check || self.skip_leak_check {
119+
// If the user gave `-Zno-leak-check`, then skip the leak check
120+
// completely. While we considered to remove the leak check at
121+
// some point, we are now confident that it will remain in some
122+
// form or another.
123+
if self.tcx.sess.opts.unstable_opts.no_leak_check {
126124
return Ok(());
127125
}
128126

compiler/rustc_lint/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ fn register_builtins(store: &mut LintStore) {
416416
"converted into hard error, see issue #48950 \
417417
<https://github.com/rust-lang/rust/issues/48950> for more information",
418418
);
419+
store.register_removed(
420+
"coherence_leak_check",
421+
"no longer a warning, see issue #119820 \
422+
<https://github.com/rust-lang/rust/issues/119820> for more information",
423+
);
419424
store.register_removed(
420425
"resolve_trait_on_defaulted_unit",
421426
"converted into hard error, see issue #48950 \

compiler/rustc_lint_defs/src/builtin.rs

-41
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ declare_lint_pass! {
2525
BREAK_WITH_LABEL_AND_LOOP,
2626
BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
2727
CENUM_IMPL_DROP_CAST,
28-
COHERENCE_LEAK_CHECK,
2928
CONFLICTING_REPR_HINTS,
3029
CONST_EVALUATABLE_UNCHECKED,
3130
CONST_ITEM_MUTATION,
@@ -1467,46 +1466,6 @@ declare_lint! {
14671466
};
14681467
}
14691468

1470-
declare_lint! {
1471-
/// The `coherence_leak_check` lint detects conflicting implementations of
1472-
/// a trait that are only distinguished by the old leak-check code.
1473-
///
1474-
/// ### Example
1475-
///
1476-
/// ```rust
1477-
/// trait SomeTrait { }
1478-
/// impl SomeTrait for for<'a> fn(&'a u8) { }
1479-
/// impl<'a> SomeTrait for fn(&'a u8) { }
1480-
/// ```
1481-
///
1482-
/// {{produces}}
1483-
///
1484-
/// ### Explanation
1485-
///
1486-
/// In the past, the compiler would accept trait implementations for
1487-
/// identical functions that differed only in where the lifetime binder
1488-
/// appeared. Due to a change in the borrow checker implementation to fix
1489-
/// several bugs, this is no longer allowed. However, since this affects
1490-
/// existing code, this is a [future-incompatible] lint to transition this
1491-
/// to a hard error in the future.
1492-
///
1493-
/// Code relying on this pattern should introduce "[newtypes]",
1494-
/// like `struct Foo(for<'a> fn(&'a u8))`.
1495-
///
1496-
/// See [issue #56105] for more details.
1497-
///
1498-
/// [issue #56105]: https://github.com/rust-lang/rust/issues/56105
1499-
/// [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction
1500-
/// [future-incompatible]: ../index.md#future-incompatible-lints
1501-
pub COHERENCE_LEAK_CHECK,
1502-
Warn,
1503-
"distinct impls distinguished only by the leak-check code",
1504-
@future_incompatible = FutureIncompatibleInfo {
1505-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
1506-
reference: "issue #56105 <https://github.com/rust-lang/rust/issues/56105>",
1507-
};
1508-
}
1509-
15101469
declare_lint! {
15111470
/// The `deprecated` lint detects use of deprecated items.
15121471
///

compiler/rustc_trait_selection/src/traits/coherence.rs

+14-24
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt;
1414
use crate::traits::select::IntercrateAmbiguityCause;
1515
use crate::traits::structural_normalize::StructurallyNormalizeExt;
1616
use crate::traits::NormalizeExt;
17-
use crate::traits::SkipLeakCheck;
1817
use crate::traits::{
1918
Obligation, ObligationCause, ObligationCtxt, PredicateObligation, PredicateObligations,
2019
SelectionContext,
@@ -85,12 +84,11 @@ impl TrackAmbiguityCauses {
8584
/// If there are types that satisfy both impls, returns `Some`
8685
/// with a suitably-freshened `ImplHeader` with those types
8786
/// substituted. Otherwise, returns `None`.
88-
#[instrument(skip(tcx, skip_leak_check), level = "debug")]
87+
#[instrument(skip(tcx), level = "debug")]
8988
pub fn overlapping_impls(
9089
tcx: TyCtxt<'_>,
9190
impl1_def_id: DefId,
9291
impl2_def_id: DefId,
93-
skip_leak_check: SkipLeakCheck,
9492
overlap_mode: OverlapMode,
9593
) -> Option<OverlapResult<'_>> {
9694
// Before doing expensive operations like entering an inference context, do
@@ -115,27 +113,14 @@ pub fn overlapping_impls(
115113
return None;
116114
}
117115

118-
let _overlap_with_bad_diagnostics = overlap(
119-
tcx,
120-
TrackAmbiguityCauses::No,
121-
skip_leak_check,
122-
impl1_def_id,
123-
impl2_def_id,
124-
overlap_mode,
125-
)?;
116+
let _overlap_with_bad_diagnostics =
117+
overlap(tcx, TrackAmbiguityCauses::No, impl1_def_id, impl2_def_id, overlap_mode)?;
126118

127119
// In the case where we detect an error, run the check again, but
128120
// this time tracking intercrate ambiguity causes for better
129121
// diagnostics. (These take time and can lead to false errors.)
130-
let overlap = overlap(
131-
tcx,
132-
TrackAmbiguityCauses::Yes,
133-
skip_leak_check,
134-
impl1_def_id,
135-
impl2_def_id,
136-
overlap_mode,
137-
)
138-
.unwrap();
122+
let overlap =
123+
overlap(tcx, TrackAmbiguityCauses::Yes, impl1_def_id, impl2_def_id, overlap_mode).unwrap();
139124
Some(overlap)
140125
}
141126

@@ -177,7 +162,6 @@ fn fresh_impl_header_normalized<'tcx>(
177162
fn overlap<'tcx>(
178163
tcx: TyCtxt<'tcx>,
179164
track_ambiguity_causes: TrackAmbiguityCauses,
180-
skip_leak_check: SkipLeakCheck,
181165
impl1_def_id: DefId,
182166
impl2_def_id: DefId,
183167
overlap_mode: OverlapMode,
@@ -193,7 +177,6 @@ fn overlap<'tcx>(
193177
let infcx = tcx
194178
.infer_ctxt()
195179
.with_opaque_type_inference(DefiningAnchor::Bubble)
196-
.skip_leak_check(skip_leak_check.is_yes())
197180
.intercrate(true)
198181
.with_next_trait_solver(tcx.next_trait_solver_in_coherence())
199182
.build();
@@ -231,8 +214,15 @@ fn overlap<'tcx>(
231214
}
232215
}
233216

234-
// We toggle the `leak_check` by using `skip_leak_check` when constructing the
235-
// inference context, so this may be a noop.
217+
// Detect any region errors caused by equating these two impls.
218+
//
219+
// Only higher ranked region errors are possible here, given that we
220+
// replaced all parameter regions with existentials.
221+
//
222+
// Unlike a full region check, which sometimes incompletely handles
223+
// `TypeOutlives` constraints, the leak check is a complete. While the
224+
// leak check does not detect all region errors, it never
225+
// fails in cases which would later pass full region checking.
236226
if infcx.leak_check(ty::UniverseIndex::ROOT, None).is_err() {
237227
debug!("overlap: leak check failed");
238228
return None;

compiler/rustc_trait_selection/src/traits/mod.rs

-18
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,6 @@ pub use self::util::{get_vtable_index_of_object_method, impl_item_is_final, upca
7171

7272
pub use rustc_infer::traits::*;
7373

74-
/// Whether to skip the leak check, as part of a future compatibility warning step.
75-
///
76-
/// The "default" for skip-leak-check corresponds to the current
77-
/// behavior (do not skip the leak check) -- not the behavior we are
78-
/// transitioning into.
79-
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
80-
pub enum SkipLeakCheck {
81-
Yes,
82-
#[default]
83-
No,
84-
}
85-
86-
impl SkipLeakCheck {
87-
fn is_yes(self) -> bool {
88-
self == SkipLeakCheck::Yes
89-
}
90-
}
91-
9274
/// The mode that trait queries run in.
9375
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
9476
pub enum TraitQueryMode {

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc_errors::{codes::*, DelayDm, Diagnostic};
2424
use rustc_hir::def_id::{DefId, LocalDefId};
2525
use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt};
2626
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
27-
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
2827
use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS;
2928
use rustc_span::{sym, ErrorGuaranteed, Span, DUMMY_SP};
3029

@@ -460,7 +459,6 @@ fn report_conflicting_impls<'tcx>(
460459
Some(kind) => {
461460
let lint = match kind {
462461
FutureCompatOverlapErrorKind::Issue33140 => ORDER_DEPENDENT_TRAIT_OBJECTS,
463-
FutureCompatOverlapErrorKind::LeakCheck => COHERENCE_LEAK_CHECK,
464462
};
465463
tcx.node_span_lint(
466464
lint,

0 commit comments

Comments
 (0)