Skip to content

Commit

Permalink
rust: Update builtins and sample file (fix #1922) (#1923)
Browse files Browse the repository at this point in the history
* rust: Update builtins (#1922)

* rust: Update sample file (#1922)
  • Loading branch information
nsfisis committed Apr 2, 2023
1 parent 6320e26 commit d3df530
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
13 changes: 7 additions & 6 deletions lib/rouge/lexers/rust.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ def self.keywords
def self.builtins
@builtins ||= Set.new %w(
Add BitAnd BitOr BitXor bool c_char c_double c_float char
c_int clock_t c_long c_longlong Cons Const Copy c_schar c_short
c_int clock_t c_long c_longlong Copy c_schar c_short
c_uchar c_uint c_ulong c_ulonglong c_ushort c_void dev_t DIR
dirent Div Either Eq Err f32 f64 Failure FILE float fpos_t
i16 i32 i64 i8 isize Index ino_t int intptr_t Left mode_t Modulo Mul
Neg Nil None Num off_t Ok Option Ord Owned pid_t Ptr ptrdiff_t
Right Send Shl Shr size_t Some ssize_t str Sub Success time_t
dirent Div Eq Err f32 f64 FILE float fpos_t
i16 i32 i64 i8 isize Index ino_t int intptr_t mode_t Mul
Neg None off_t Ok Option Ord Owned pid_t ptrdiff_t
Send Shl Shr size_t Some ssize_t str Sub time_t
u16 u32 u64 u8 usize uint uintptr_t
Box Vec String Gc Rc Arc
Box Vec String Rc Arc
u128 i128 Result Sync Pin Unpin Sized Drop drop Fn FnMut FnOnce
Clone PartialEq PartialOrd AsMut AsRef From Into Default
DoubleEndedIterator ExactSizeIterator Extend IntoIterator Iterator
FromIterator ToOwned ToString TryFrom TryInto
)
end

Expand Down
50 changes: 25 additions & 25 deletions spec/visual/samples/rust
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
fn f() {
let a = String::new("hello");
let b: &str = a;
io::println(b);
println!("{}", b);
}

fn g() {
let c = String::new("world");
let d: &str;
d = c;
io::println(d);
println!("{}", d);
}

fn h(a: i32) -> i32 {
Expand Down Expand Up @@ -39,53 +39,53 @@ println!(r#"
"New line in a raw string"
"#);

trait iterable<A> {
fn iterate(blk: fn(x: &A) -> bool);
trait Iterable<A> {
fn iterate(&self, blk: impl FnMut(&A) -> bool);
}

impl<A> &[A]: iterable<A> {
fn iterate(f: fn(x: &A) -> bool) {
for vec::each(self) |e| {
impl<A> Iterable<A> for &[A] {
fn iterate(&self, mut f: impl FnMut(&A) -> bool) {
for e in self.iter() {
if !f(e) { break; }
}
}
}

fn length<A, T>(x: T) -> uint
fn length<A, T>(x: T) -> usize
where
T: iterable<A>,
T: Iterable<A>,
{
let mut len = 0;
for x.iterate() |_y| { len += 1 }
x.iterate(|_| { len += 1; true });
return len;
}

fn main() {
let x = vec![0,1,2,3];
// Call a method
for x.iterate() |y| { assert x[*y] == *y; }
for (i, y) in x.iter().enumerate() { assert!(x[i] == *y); }
// Call a parameterized function
assert length(x) == vec::len(x);
assert!(length(&*x) == x.len());
// Call a parameterized function, with type arguments that require
// a borrow
assert length::<int, &[int]>(x) == vec::len(x);
assert!(length::<i32, &[i32]>(&*x) == x.len());

// Now try it with a type that *needs* to be borrowed
let z = [0,1,2,3];
// Call a method
for z.iterate() |y| { assert z[*y] == *y; }
for (i, y) in z.iter().enumerate() { assert!(z[i] == *y); }
// Call a parameterized function
assert length::<int, &[int]>(z) == vec::len(z);
assert!(length::<i32, &[i32]>(&z) == z.len());
}

fn<'a> pointer(&'a u32) {}
fn pointer<'a>(n: &'a u32) {}

fn range() {
let a = 1..2;
let b = 1..;
let c = ..2;
let d = ..;
let e = 5...6;
let e = 5..=6;
}

#[attr1 = "val"];
Expand Down Expand Up @@ -322,7 +322,7 @@ macro_rules! html (
( $($body:tt)* ) => (
parse_node!( []; []; $($body)* )
)
)
);

macro_rules! parse_node (
(
Expand All @@ -333,8 +333,8 @@ macro_rules! parse_node (
) => (
parse_node!(
[$(: $tags ($(:$tag_nodes),*))*];
[$(:$head_nodes,)* :tag(stringify!($head).to_owned(),
~[$($nodes),*])];
[$(:$head_nodes,)* :Box::new(HTMLFragment::Tag(stringify!($head).to_owned(),
vec![$($nodes),*]))];
$($rest)*
)
);
Expand All @@ -358,7 +358,7 @@ macro_rules! parse_node (
) => (
parse_node!(
[$(: $tags ($(:$tag_nodes),*))*];
[$(:$nodes,)* :text(~".")];
[$(:$nodes,)* :Box::new(HTMLFragment::Text(".".to_string()))];
$($rest)*
)
);
Expand All @@ -370,13 +370,13 @@ macro_rules! parse_node (
) => (
parse_node!(
[$(: $tags ($(:$tag_nodes),*))*];
[$(:$nodes,)* :text(stringify!($word).to_owned())];
[$(:$nodes,)* :Box::new(HTMLFragment::Text(stringify!($word).to_owned()))];
$($rest)*
)
);

( []; [:$e:expr]; ) => ( $e );
)
);

fn main() {
let page = html! (
Expand All @@ -390,8 +390,8 @@ fn main() {
}

enum HTMLFragment {
tag(~str, ~[HTMLFragment]),
text(~str),
Tag(String, Vec<Box<HTMLFragment>>),
Text(String),
}

fn int_literals_delimiter() {
Expand Down

0 comments on commit d3df530

Please sign in to comment.