Skip to content

Commit 9990165

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

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use rustc_hir as hir;
2+
use std::fmt;
3+
4+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
5+
pub enum BoundConstness {
6+
/// `T: Trait`
7+
NotConst,
8+
/// `T: ~const Trait`
9+
///
10+
/// Requires resolving to const only when we are in a const context.
11+
ConstIfConst,
12+
}
13+
14+
impl BoundConstness {
15+
/// Reduce `self` and `constness` to two possible combined states instead of four.
16+
pub fn and(&mut self, constness: hir::Constness) -> hir::Constness {
17+
match (constness, self) {
18+
(hir::Constness::Const, BoundConstness::ConstIfConst) => hir::Constness::Const,
19+
(_, this) => {
20+
*this = BoundConstness::NotConst;
21+
hir::Constness::NotConst
22+
}
23+
}
24+
}
25+
}
26+
27+
impl fmt::Display for BoundConstness {
28+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29+
match self {
30+
Self::NotConst => f.write_str("normal"),
31+
Self::ConstIfConst => f.write_str("`~const`"),
32+
}
33+
}
34+
}

compiler/rustc_middle/src/ty/mod.rs

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

151+
mod bound_constness;
151152
mod impl_polarity;
152153
mod visibility;
153154

155+
pub use bound_constness::BoundConstness;
154156
pub use impl_polarity::ImplPolarity;
155157
pub use visibility::Visibility;
156158

@@ -247,38 +249,6 @@ pub enum ImplSubject<'tcx> {
247249
Inherent(Ty<'tcx>),
248250
}
249251

250-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
251-
pub enum BoundConstness {
252-
/// `T: Trait`
253-
NotConst,
254-
/// `T: ~const Trait`
255-
///
256-
/// Requires resolving to const only when we are in a const context.
257-
ConstIfConst,
258-
}
259-
260-
impl BoundConstness {
261-
/// Reduce `self` and `constness` to two possible combined states instead of four.
262-
pub fn and(&mut self, constness: hir::Constness) -> hir::Constness {
263-
match (constness, self) {
264-
(hir::Constness::Const, BoundConstness::ConstIfConst) => hir::Constness::Const,
265-
(_, this) => {
266-
*this = BoundConstness::NotConst;
267-
hir::Constness::NotConst
268-
}
269-
}
270-
}
271-
}
272-
273-
impl fmt::Display for BoundConstness {
274-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
275-
match self {
276-
Self::NotConst => f.write_str("normal"),
277-
Self::ConstIfConst => f.write_str("`~const`"),
278-
}
279-
}
280-
}
281-
282252
#[derive(Clone, Debug, PartialEq, Eq, Copy, Hash, TyEncodable, TyDecodable, HashStable)]
283253
#[derive(TypeFoldable, TypeVisitable)]
284254
pub struct ClosureSizeProfileData<'tcx> {

0 commit comments

Comments
 (0)