Skip to content

Commit 439803d

Browse files
committed
Remove unuseful enums.
1 parent d716dc9 commit 439803d

File tree

1 file changed

+16
-60
lines changed

1 file changed

+16
-60
lines changed

compiler/rustc_passes/src/stability.rs

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -41,67 +41,23 @@ enum AnnotationKind {
4141
Container,
4242
}
4343

44-
/// Whether to inherit deprecation flags for nested items. In most cases, we do want to inherit
45-
/// deprecation, because nested items rarely have individual deprecation attributes, and so
46-
/// should be treated as deprecated if their parent is. However, default generic parameters
47-
/// have separate deprecation attributes from their parents, so we do not wish to inherit
48-
/// deprecation in this case. For example, inheriting deprecation for `T` in `Foo<T>`
49-
/// would cause a duplicate warning arising from both `Foo` and `T` being deprecated.
50-
#[derive(Clone)]
51-
enum InheritDeprecation {
52-
Yes,
53-
No,
54-
}
55-
56-
impl InheritDeprecation {
57-
fn yes(&self) -> bool {
58-
matches!(self, InheritDeprecation::Yes)
59-
}
60-
}
61-
62-
/// Whether to inherit const stability flags for nested items. In most cases, we do not want to
63-
/// inherit const stability: just because an enclosing `fn` is const-stable does not mean
64-
/// all `extern` imports declared in it should be const-stable! However, trait methods
65-
/// inherit const stability attributes from their parent and do not have their own.
66-
enum InheritConstStability {
67-
Yes,
68-
No,
69-
}
70-
71-
impl InheritConstStability {
72-
fn yes(&self) -> bool {
73-
matches!(self, InheritConstStability::Yes)
74-
}
75-
}
76-
77-
enum InheritStability {
78-
Yes,
79-
No,
80-
}
81-
82-
impl InheritStability {
83-
fn yes(&self) -> bool {
84-
matches!(self, InheritStability::Yes)
85-
}
86-
}
87-
88-
fn inherit_deprecation(def_kind: DefKind) -> InheritDeprecation {
44+
fn inherit_deprecation(def_kind: DefKind) -> bool {
8945
match def_kind {
90-
DefKind::LifetimeParam | DefKind::TyParam | DefKind::ConstParam => InheritDeprecation::No,
91-
_ => InheritDeprecation::Yes,
46+
DefKind::LifetimeParam | DefKind::TyParam | DefKind::ConstParam => false,
47+
_ => true,
9248
}
9349
}
9450

95-
fn inherit_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> InheritConstStability {
51+
fn inherit_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
9652
let def_kind = tcx.def_kind(def_id);
9753
match def_kind {
9854
DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => {
9955
match tcx.def_kind(tcx.local_parent(def_id)) {
100-
DefKind::Impl { of_trait: true } => InheritConstStability::Yes,
101-
_ => InheritConstStability::No,
56+
DefKind::Impl { of_trait: true } => true,
57+
_ => false,
10258
}
10359
}
104-
_ => InheritConstStability::No,
60+
_ => false,
10561
}
10662
}
10763

@@ -145,7 +101,7 @@ fn lookup_deprecation_entry(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Depre
145101
);
146102

147103
let Some(depr) = depr else {
148-
if inherit_deprecation(tcx.def_kind(def_id)).yes() {
104+
if inherit_deprecation(tcx.def_kind(def_id)) {
149105
let parent_id = tcx.opt_local_parent(def_id)?;
150106
let parent_depr = tcx.lookup_deprecation_entry(parent_id)?;
151107
return Some(parent_depr);
@@ -158,10 +114,10 @@ fn lookup_deprecation_entry(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Depre
158114
Some(DeprecationEntry::local(depr, def_id))
159115
}
160116

161-
fn inherit_stability(def_kind: DefKind) -> InheritStability {
117+
fn inherit_stability(def_kind: DefKind) -> bool {
162118
match def_kind {
163-
DefKind::Field | DefKind::Variant | DefKind::Ctor(..) => InheritStability::Yes,
164-
_ => InheritStability::No,
119+
DefKind::Field | DefKind::Variant | DefKind::Ctor(..) => true,
120+
_ => false,
165121
}
166122
}
167123

@@ -193,7 +149,7 @@ fn lookup_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Stability> {
193149

194150
let Some(parent) = tcx.opt_local_parent(def_id) else { return Some(FORCE_UNSTABLE) };
195151

196-
if inherit_deprecation(tcx.def_kind(def_id)).yes() {
152+
if inherit_deprecation(tcx.def_kind(def_id)) {
197153
let parent = tcx.lookup_stability(parent)?;
198154
if parent.is_unstable() {
199155
return Some(parent);
@@ -212,7 +168,7 @@ fn lookup_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Stability> {
212168
return Some(stab);
213169
}
214170

215-
if inherit_deprecation(tcx.def_kind(def_id)).yes() {
171+
if inherit_deprecation(tcx.def_kind(def_id)) {
216172
let Some(parent) = tcx.opt_local_parent(def_id) else {
217173
return tcx
218174
.sess
@@ -222,7 +178,7 @@ fn lookup_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Stability> {
222178
.then_some(FORCE_UNSTABLE);
223179
};
224180
let parent = tcx.lookup_stability(parent)?;
225-
if parent.is_unstable() || inherit_stability(tcx.def_kind(def_id)).yes() {
181+
if parent.is_unstable() || inherit_stability(tcx.def_kind(def_id)) {
226182
return Some(parent);
227183
}
228184
}
@@ -249,7 +205,7 @@ fn lookup_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ConstSt
249205
if !tcx.features().staged_api() {
250206
// Propagate unstability. This can happen even for non-staged-api crates in case
251207
// -Zforce-unstable-if-unmarked is set.
252-
if inherit_deprecation(tcx.def_kind(def_id)).yes() {
208+
if inherit_deprecation(tcx.def_kind(def_id)) {
253209
let parent = tcx.opt_local_parent(def_id)?;
254210
let parent_stab = tcx.lookup_stability(parent)?;
255211
if parent_stab.is_unstable()
@@ -301,7 +257,7 @@ fn lookup_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ConstSt
301257
// immediate children.
302258
// FIXME(const_trait_impl): how is this supposed to interact with `#[rustc_const_stable_indirect]`?
303259
// Currently, once that is set, we do not inherit anything from the parent any more.
304-
if inherit_const_stability(tcx, def_id).yes() {
260+
if inherit_const_stability(tcx, def_id) {
305261
let parent = tcx.opt_local_parent(def_id)?;
306262
let parent = tcx.lookup_const_stability(parent)?;
307263
if parent.is_const_unstable() {

0 commit comments

Comments
 (0)