Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
chorman0773 committed Aug 27, 2024
1 parent fae1f0a commit f07f3c1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
2 changes: 1 addition & 1 deletion autobuild
8 changes: 7 additions & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ impl XLangFrontend for RustFrontend {
let parsed = do_mod(&mut lexed.into_iter().peekmore()).unwrap();
println!("{:?}", parsed);
let mut defs = Definitions::new(props);
convert_crate(&mut defs, &parsed, CrateType::Bin, Symbol::intern(crate_name)).unwrap();
convert_crate(
&mut defs,
&parsed,
CrateType::Bin,
Symbol::intern(crate_name),
)
.unwrap();

eprintln!("{}", defs);
defs.set_current_crate_name(crate_name);
Expand Down
9 changes: 3 additions & 6 deletions rust/src/sema/cx/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ use super::ConstExpr;
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct AllocId(u32);


#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub enum CxEvalValue{
pub enum CxEvalValue {
Const(ConstExpr),
LocalAddr(RefKind, Mutability, AllocId, )
LocalAddr(RefKind, Mutability, AllocId),
}

pub struct MirEvaluator{

}
pub struct MirEvaluator {}
38 changes: 26 additions & 12 deletions rust/src/sema/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,26 @@ impl FnType {
.all(|(a, b)| a.matches_ignore_bounds(b))
}

pub fn substitute_generics(&self, args: &GenericArgs) -> Self{
let retty = Box::new(self.retty.copy_span(|retty| retty.substitute_generics(args)));
let paramtys = self.paramtys.iter().map(|paramty| paramty.copy_span(|paramty| paramty.substitute_generics(args))).collect();

Self{safety: self.safety, constness: self.constness, asyncness: self.asyncness, tag: self.tag, iscvarargs: self.iscvarargs, retty, paramtys}
pub fn substitute_generics(&self, args: &GenericArgs) -> Self {
let retty = Box::new(
self.retty
.copy_span(|retty| retty.substitute_generics(args)),
);
let paramtys = self
.paramtys
.iter()
.map(|paramty| paramty.copy_span(|paramty| paramty.substitute_generics(args)))
.collect();

Self {
safety: self.safety,
constness: self.constness,
asyncness: self.asyncness,
tag: self.tag,
iscvarargs: self.iscvarargs,
retty,
paramtys,
}
}
}

Expand Down Expand Up @@ -625,19 +640,18 @@ impl core::fmt::Display for FnType {
}
}

impl SemaLifetime{

pub fn erase(&self) -> Self{
match self{
impl SemaLifetime {
pub fn erase(&self) -> Self {
match self {
Self::Region(reg) => Self::ErasedRegion,
this => *this,
}
}

pub fn substitute_generics(&self, args: &GenericArgs) -> Self{
pub fn substitute_generics(&self, args: &GenericArgs) -> Self {
match self {
Self::Bound(id) => {
match args.get(*id){
match args.get(*id) {
Some(GenericArg::Lifetime(life)) => *life,
Some(_) => panic!("Expected a lifetime for {id}"),
None => Self::Bound(*id), // This is a locally bound lifetime from a `for<'a>` (which isn't carried into sema types)
Expand Down Expand Up @@ -793,7 +807,7 @@ impl Type {
Type::Pointer(mt, ty) => Type::Pointer(*mt, Box::new(ty.copy_span(|ty| ty.substitute_generics(args)))),
Type::Array(ty, cx) => Type::Array(Box::new(ty.copy_span(|ty| ty.substitute_generics(args))), cx.copy_span(|cx| cx.substitute_generics(args))),
Type::Reference(life, mt, ty) => Type::Reference(life.as_ref().map(|life| Box::new(life.copy_span(|life| life.substitute_generics(args)))), *mt, Box::new(ty.copy_span(|ty| ty.substitute_generics(args)))),
Type::DropFlags(ty) => Type::DropFlags(Box::new(ty.substitute_generics(args))),
Type::DropFlags(ty) => Type::DropFlags(Box::new(ty.substitute_generics(args))),
Type::UnresolvedLangItem(_, _) |
Type::IncompleteAlias(_) |
Type::Inferable(_) |
Expand Down
17 changes: 6 additions & 11 deletions xlang/xlang_abi/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,13 @@ impl<'a> StringView<'a> {
}

/// Obtains a raw pointer to the beginning of the string.
///
///
/// ## Safety
///
/// The returned `*const u8` is valid for the length of the string view up to the lifetime `'a`.
///
/// The returned `*const u8` is valid for the length of the string view up to the lifetime `'a`.
/// When using the pointer you must not write through it
#[must_use]
pub const fn as_ptr(&self) -> *const u8{
pub const fn as_ptr(&self) -> *const u8 {
self.begin.as_ptr()
}

Expand Down Expand Up @@ -506,17 +506,12 @@ impl<'a> StringView<'a> {
#[must_use]
#[allow(clippy::cast_sign_loss)] // allocation size is `[0,isize::MAX)` so this can never possibly overflow
pub const fn into_byte_span(self) -> Span<'a, u8> {
unsafe {
Span::from_raw_parts(
self.as_ptr(),
self.len(),
)
}
unsafe { Span::from_raw_parts(self.as_ptr(), self.len()) }
}

/// Borrows the string view as a [`Span`] over the UTF-8 Bytes of the [`StringView`].
#[must_use]
pub const fn as_byte_span(&self) -> Span<u8>{
pub const fn as_byte_span(&self) -> Span<u8> {
self.into_byte_span()
}

Expand Down

0 comments on commit f07f3c1

Please sign in to comment.