Skip to content

Commit 27ae105

Browse files
Move some declarations from ast to ast_util
1 parent 8ed5765 commit 27ae105

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

source/vir/src/ast.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::messages::{Message, Span};
1010
pub use air::ast::{Binder, Binders};
1111
use num_bigint::BigInt;
1212
use serde::{Deserialize, Serialize};
13-
use std::fmt::Display;
1413
use std::sync::Arc;
1514
use vir_macros::{to_node_impl, ToDebugSNode};
1615

@@ -585,12 +584,6 @@ pub struct SpannedTyped<X> {
585584
pub x: X,
586585
}
587586

588-
impl<X: Display> Display for SpannedTyped<X> {
589-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
590-
write!(f, "{}", self.x)
591-
}
592-
}
593-
594587
/// Patterns for match expressions
595588
pub type Pattern = Arc<SpannedTyped<PatternX>>;
596589
pub type Patterns = Arc<Vec<Pattern>>;
@@ -1280,21 +1273,6 @@ pub enum ArchWordBits {
12801273
Exactly(u32),
12811274
}
12821275

1283-
impl ArchWordBits {
1284-
pub fn min_bits(&self) -> u32 {
1285-
match self {
1286-
ArchWordBits::Either32Or64 => 32,
1287-
ArchWordBits::Exactly(v) => *v,
1288-
}
1289-
}
1290-
pub fn num_bits(&self) -> Option<u32> {
1291-
match self {
1292-
ArchWordBits::Either32Or64 => None,
1293-
ArchWordBits::Exactly(v) => Some(*v),
1294-
}
1295-
}
1296-
}
1297-
12981276
#[derive(Clone, Debug, Serialize, Deserialize)]
12991277
pub struct Arch {
13001278
pub word_bits: ArchWordBits,
@@ -1327,16 +1305,3 @@ pub struct KrateX {
13271305
/// Arch info
13281306
pub arch: Arch,
13291307
}
1330-
1331-
impl FunctionKind {
1332-
pub(crate) fn inline_okay(&self) -> bool {
1333-
match self {
1334-
FunctionKind::Static | FunctionKind::TraitMethodImpl { .. } => true,
1335-
// We don't want to do inlining for MethodDecls. If a MethodDecl has a body,
1336-
// it's a *default* body, so we can't know for sure it hasn't been overridden.
1337-
FunctionKind::TraitMethodDecl { .. } | FunctionKind::ForeignTraitMethodImpl { .. } => {
1338-
false
1339-
}
1340-
}
1341-
}
1342-
}

source/vir/src/ast_util.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ impl fmt::Display for Mode {
7575
}
7676
}
7777

78+
impl<X: fmt::Display> fmt::Display for SpannedTyped<X> {
79+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80+
write!(f, "{}", self.x)
81+
}
82+
}
83+
7884
pub fn type_is_bool(typ: &Typ) -> bool {
7985
matches!(&**typ, TypX::Bool)
8086
}
@@ -908,6 +914,34 @@ impl<A: Clone> VarBinderX<A> {
908914
}
909915
}
910916

917+
impl FunctionKind {
918+
pub(crate) fn inline_okay(&self) -> bool {
919+
match self {
920+
FunctionKind::Static | FunctionKind::TraitMethodImpl { .. } => true,
921+
// We don't want to do inlining for MethodDecls. If a MethodDecl has a body,
922+
// it's a *default* body, so we can't know for sure it hasn't been overridden.
923+
FunctionKind::TraitMethodDecl { .. } | FunctionKind::ForeignTraitMethodImpl { .. } => {
924+
false
925+
}
926+
}
927+
}
928+
}
929+
930+
impl ArchWordBits {
931+
pub fn min_bits(&self) -> u32 {
932+
match self {
933+
ArchWordBits::Either32Or64 => 32,
934+
ArchWordBits::Exactly(v) => *v,
935+
}
936+
}
937+
pub fn num_bits(&self) -> Option<u32> {
938+
match self {
939+
ArchWordBits::Either32Or64 => None,
940+
ArchWordBits::Exactly(v) => Some(*v),
941+
}
942+
}
943+
}
944+
911945
pub fn str_unique_var(s: &str, dis: crate::ast::VarIdentDisambiguate) -> VarIdent {
912946
VarIdent(Arc::new(s.to_string()), dis)
913947
}

0 commit comments

Comments
 (0)