Skip to content

Commit 9edfe48

Browse files
committed
remove the coherence_leak_check lint
1 parent 7fb2f72 commit 9edfe48

31 files changed

+86
-386
lines changed

Diff for: 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::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

@@ -139,15 +139,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
139139
impl1_def_id: DefId,
140140
impl2_def_id: DefId,
141141
) {
142-
let maybe_overlap = traits::overlapping_impls(
143-
self.tcx,
144-
impl1_def_id,
145-
impl2_def_id,
146-
// We go ahead and just skip the leak check for
147-
// inherent impls without warning.
148-
SkipLeakCheck::Yes,
149-
overlap_mode,
150-
);
142+
let maybe_overlap =
143+
traits::overlapping_impls(self.tcx, impl1_def_id, impl2_def_id, overlap_mode);
151144

152145
if let Some(overlap) = maybe_overlap {
153146
self.check_for_common_items_in_impls(impl1_def_id, impl2_def_id, overlap);

Diff for: 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(),

Diff for: compiler/rustc_infer/src/infer/mod.rs

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

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

267261
/// Once region inference is done, the values for each variable.
@@ -606,7 +600,6 @@ pub struct InferCtxtBuilder<'tcx> {
606600
tcx: TyCtxt<'tcx>,
607601
defining_use_anchor: DefiningAnchor,
608602
considering_regions: bool,
609-
skip_leak_check: bool,
610603
/// Whether we are in coherence mode.
611604
intercrate: bool,
612605
/// Whether we should use the new trait solver in the local inference context,
@@ -624,7 +617,6 @@ impl<'tcx> TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
624617
tcx: self,
625618
defining_use_anchor: DefiningAnchor::Error,
626619
considering_regions: true,
627-
skip_leak_check: false,
628620
intercrate: false,
629621
next_trait_solver: self.next_trait_solver_globally(),
630622
}
@@ -658,11 +650,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
658650
self
659651
}
660652

661-
pub fn skip_leak_check(mut self, skip_leak_check: bool) -> Self {
662-
self.skip_leak_check = skip_leak_check;
663-
self
664-
}
665-
666653
/// Given a canonical value `C` as a starting point, create an
667654
/// inference context that contains each of the bound values
668655
/// within instantiated as a fresh variable. The `f` closure is
@@ -688,15 +675,13 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
688675
tcx,
689676
defining_use_anchor,
690677
considering_regions,
691-
skip_leak_check,
692678
intercrate,
693679
next_trait_solver,
694680
} = *self;
695681
InferCtxt {
696682
tcx,
697683
defining_use_anchor,
698684
considering_regions,
699-
skip_leak_check,
700685
inner: RefCell::new(InferCtxtInner::new()),
701686
lexical_region_resolutions: RefCell::new(None),
702687
selection_cache: Default::default(),

Diff for: 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

Diff for: compiler/rustc_lint/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ fn register_builtins(store: &mut LintStore) {
418418
"converted into hard error, see issue #48950 \
419419
<https://github.com/rust-lang/rust/issues/48950> for more information",
420420
);
421+
store.register_removed(
422+
"coherence_leak_check",
423+
"no longer a warning, see TODO for more information",
424+
);
421425
store.register_removed(
422426
"resolve_trait_on_defaulted_unit",
423427
"converted into hard error, see issue #48950 \

Diff for: 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
///

Diff for: compiler/rustc_trait_selection/src/traits/coherence.rs

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

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

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

@@ -176,7 +161,6 @@ fn fresh_impl_header_normalized<'tcx>(
176161
fn overlap<'tcx>(
177162
tcx: TyCtxt<'tcx>,
178163
track_ambiguity_causes: TrackAmbiguityCauses,
179-
skip_leak_check: SkipLeakCheck,
180164
impl1_def_id: DefId,
181165
impl2_def_id: DefId,
182166
overlap_mode: OverlapMode,
@@ -192,7 +176,6 @@ fn overlap<'tcx>(
192176
let infcx = tcx
193177
.infer_ctxt()
194178
.with_opaque_type_inference(DefiningAnchor::Bubble)
195-
.skip_leak_check(skip_leak_check.is_yes())
196179
.intercrate(true)
197180
.with_next_trait_solver(tcx.next_trait_solver_in_coherence())
198181
.build();
@@ -230,8 +213,15 @@ fn overlap<'tcx>(
230213
}
231214
}
232215

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

Diff for: compiler/rustc_trait_selection/src/traits/mod.rs

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

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

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

Diff for: 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::{error_code, 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::{Span, DUMMY_SP};
3029

@@ -441,7 +440,6 @@ fn report_conflicting_impls<'tcx>(
441440
Some(kind) => {
442441
let lint = match kind {
443442
FutureCompatOverlapErrorKind::Issue33140 => ORDER_DEPENDENT_TRAIT_OBJECTS,
444-
FutureCompatOverlapErrorKind::LeakCheck => COHERENCE_LEAK_CHECK,
445443
};
446444
tcx.struct_span_lint_hir(
447445
lint,

Diff for: compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs

+21-55
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub use rustc_middle::traits::specialization_graph::*;
1111
#[derive(Copy, Clone, Debug)]
1212
pub enum FutureCompatOverlapErrorKind {
1313
Issue33140,
14-
LeakCheck,
1514
}
1615

1716
#[derive(Debug)]
@@ -118,64 +117,31 @@ impl<'tcx> ChildrenExt<'tcx> for Children {
118117
}
119118
};
120119

121-
let report_overlap_error = |overlap: traits::coherence::OverlapResult<'tcx>,
122-
last_lint: &mut _| {
123-
// Found overlap, but no specialization; error out or report future-compat warning.
124-
125-
// Do we *still* get overlap if we disable the future-incompatible modes?
126-
let should_err = traits::overlapping_impls(
127-
tcx,
128-
possible_sibling,
129-
impl_def_id,
130-
traits::SkipLeakCheck::default(),
131-
overlap_mode,
132-
)
133-
.is_some();
134-
135-
let error = create_overlap_error(overlap);
136-
137-
if should_err {
138-
Err(error)
139-
} else {
140-
*last_lint = Some(FutureCompatOverlapError {
141-
error,
142-
kind: FutureCompatOverlapErrorKind::LeakCheck,
143-
});
144-
145-
Ok((false, false))
146-
}
147-
};
148-
149120
let last_lint_mut = &mut last_lint;
150-
let (le, ge) = traits::overlapping_impls(
151-
tcx,
152-
possible_sibling,
153-
impl_def_id,
154-
traits::SkipLeakCheck::Yes,
155-
overlap_mode,
156-
)
157-
.map_or(Ok((false, false)), |overlap| {
158-
if let Some(overlap_kind) =
159-
tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling)
160-
{
161-
match overlap_kind {
162-
ty::ImplOverlapKind::Permitted { marker: _ } => {}
163-
ty::ImplOverlapKind::Issue33140 => {
164-
*last_lint_mut = Some(FutureCompatOverlapError {
165-
error: create_overlap_error(overlap),
166-
kind: FutureCompatOverlapErrorKind::Issue33140,
167-
});
121+
let (le, ge) =
122+
traits::overlapping_impls(tcx, possible_sibling, impl_def_id, overlap_mode)
123+
.map_or(Ok((false, false)), |overlap| {
124+
if let Some(overlap_kind) =
125+
tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling)
126+
{
127+
match overlap_kind {
128+
ty::ImplOverlapKind::Permitted { marker: _ } => {}
129+
ty::ImplOverlapKind::Issue33140 => {
130+
*last_lint_mut = Some(FutureCompatOverlapError {
131+
error: create_overlap_error(overlap),
132+
kind: FutureCompatOverlapErrorKind::Issue33140,
133+
});
134+
}
135+
}
136+
137+
return Ok((false, false));
168138
}
169-
}
170-
171-
return Ok((false, false));
172-
}
173139

174-
let le = tcx.specializes((impl_def_id, possible_sibling));
175-
let ge = tcx.specializes((possible_sibling, impl_def_id));
140+
let le = tcx.specializes((impl_def_id, possible_sibling));
141+
let ge = tcx.specializes((possible_sibling, impl_def_id));
176142

177-
if le == ge { report_overlap_error(overlap, last_lint_mut) } else { Ok((le, ge)) }
178-
})?;
143+
if le == ge { Err(create_overlap_error(overlap)) } else { Ok((le, ge)) }
144+
})?;
179145

180146
if le && !ge {
181147
debug!(

0 commit comments

Comments
 (0)