Skip to content

Commit 5854e46

Browse files
committed
Move ty::ImplPolarity to its own little module (cute)
1 parent e467f43 commit 5854e46

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use std::fmt;
2+
3+
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable, Debug)]
4+
#[derive(TypeFoldable, TypeVisitable)]
5+
pub enum ImplPolarity {
6+
/// `impl Trait for Type`
7+
Positive,
8+
/// `impl !Trait for Type`
9+
Negative,
10+
/// `#[rustc_reservation_impl] impl Trait for Type`
11+
///
12+
/// This is a "stability hack", not a real Rust feature.
13+
/// See #64631 for details.
14+
Reservation,
15+
}
16+
17+
impl ImplPolarity {
18+
/// Flips polarity by turning `Positive` into `Negative` and `Negative` into `Positive`.
19+
pub fn flip(&self) -> Option<ImplPolarity> {
20+
match self {
21+
ImplPolarity::Positive => Some(ImplPolarity::Negative),
22+
ImplPolarity::Negative => Some(ImplPolarity::Positive),
23+
ImplPolarity::Reservation => None,
24+
}
25+
}
26+
}
27+
28+
impl fmt::Display for ImplPolarity {
29+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30+
match self {
31+
Self::Positive => f.write_str("positive"),
32+
Self::Negative => f.write_str("negative"),
33+
Self::Reservation => f.write_str("reservation"),
34+
}
35+
}
36+
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ mod structural_impls;
148148
mod sty;
149149
mod typeck_results;
150150

151+
mod impl_polarity;
151152
mod visibility;
152153

154+
pub use impl_polarity::ImplPolarity;
153155
pub use visibility::Visibility;
154156

155157
pub struct ResolverOutputs {
@@ -245,41 +247,6 @@ pub enum ImplSubject<'tcx> {
245247
Inherent(Ty<'tcx>),
246248
}
247249

248-
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable, Debug)]
249-
#[derive(TypeFoldable, TypeVisitable)]
250-
pub enum ImplPolarity {
251-
/// `impl Trait for Type`
252-
Positive,
253-
/// `impl !Trait for Type`
254-
Negative,
255-
/// `#[rustc_reservation_impl] impl Trait for Type`
256-
///
257-
/// This is a "stability hack", not a real Rust feature.
258-
/// See #64631 for details.
259-
Reservation,
260-
}
261-
262-
impl ImplPolarity {
263-
/// Flips polarity by turning `Positive` into `Negative` and `Negative` into `Positive`.
264-
pub fn flip(&self) -> Option<ImplPolarity> {
265-
match self {
266-
ImplPolarity::Positive => Some(ImplPolarity::Negative),
267-
ImplPolarity::Negative => Some(ImplPolarity::Positive),
268-
ImplPolarity::Reservation => None,
269-
}
270-
}
271-
}
272-
273-
impl fmt::Display for ImplPolarity {
274-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
275-
match self {
276-
Self::Positive => f.write_str("positive"),
277-
Self::Negative => f.write_str("negative"),
278-
Self::Reservation => f.write_str("reservation"),
279-
}
280-
}
281-
}
282-
283250
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
284251
pub enum BoundConstness {
285252
/// `T: Trait`

0 commit comments

Comments
 (0)