fn test_highlighting() {
check_highlighting(
r#"
+//- proc_macros: identity, mirror
+//- /main.rs crate:main deps:foo
use inner::{self as inner_mod};
mod inner {}
pub trait Copy {}
}
+#[proc_macros::identity]
pub mod ops {
#[lang = "fn_once"]
pub trait FnOnce<Args> {}
pub trait Fn<Args>: FnMut<Args> {}
}
-
-struct Foo {
- pub x: i32,
- pub y: i32,
+proc_macros::mirror! {
+ {
+ ,i32 :x pub
+ ,i32 :y pub
+ } Foo struct
}
trait Bar where Self: {
str();
}
-static mut STATIC_MUT: i32 = 0;
-
fn foo<'a, T>() -> T {
foo::<'a, i32>()
}
}
}
+macro_rules! dont_color_me_braces {
+ () => {0}
+}
+
macro_rules! noop {
($expr:expr) => {
$expr
// comment
fn main() {
println!("Hello, {}!", 92);
+ dont_color_me_braces!();
let mut vec = Vec::new();
if true {
let x = 92;
vec.push(Foo { x, y: 1 });
}
- unsafe {
- vec.set_len(0);
- STATIC_MUT = 1;
- }
for e in vec {
// Do nothing
noop!(noop!(1));
let mut x = 42;
+ x += 1;
let y = &mut x;
let z = &y;
let a = |x| x;
let bar = Foo::baz;
- let baz = -42;
- let baz = -baz;
+ let baz = (-42,);
+ let baz = -baz.0;
let _ = !true;
futures::join!(f1, f2);
}
-unsafe trait Dangerous {}
-impl Dangerous for () {}
+fn use_foo_items() {
+ let bob = foo::Person {
+ name: "Bob",
+ age: foo::consts::NUMBER,
+ };
+
+ let control_flow = foo::identity(foo::ControlFlow::Continue);
+
+ if control_flow.should_die() {
+ foo::die!();
+ }
+}
+
+pub enum Bool { True, False }
+
+impl Bool {
+ pub const fn to_primitive(self) -> bool {
+ matches!(self, Self::True)
+ }
+}
+const USAGE_OF_BOOL:bool = Bool::True.to_primitive();
+
+//- /foo.rs crate:foo
+pub struct Person {
+ pub name: &'static str,
+ pub age: u8,
+}
+
+pub enum ControlFlow {
+ Continue,
+ Die,
+}
+
+impl ControlFlow {
+ pub fn should_die(self) -> bool {
+ matches!(self, ControlFlow::Die)
+ }
+}
+
+pub fn identity<T>(x: T) -> T { x }
+
+pub mod consts {
+ pub const NUMBER: i64 = 92;
+}
+
+macro_rules! die {
+ () => {
+ panic!();
+ };
+}
"#
.trim(),
expect_file!["./test_data/highlighting.html"],
.filter(|it| it.highlight.tag == HlTag::Symbol(SymbolKind::Function))
.count()
};
- assert_eq!(hash, 1632);
+ assert_eq!(hash, 1616);
}
#[test]
.highlight_range(FileRange { file_id, range: TextRange::at(45.into(), 1.into()) })
.unwrap();
- assert_eq!(&highlights[0].highlight.to_string(), "field.declaration");
+ assert_eq!(&highlights[0].highlight.to_string(), "field.declaration.public");
}
#[test]
})
}
#[rustc_builtin_macro]
-macro_rules! format_args_nl {
- ($fmt:expr) => {{ /* compiler built-in */ }};
- ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
+#[macro_export]
+macro_rules! format_args {}
+#[rustc_builtin_macro]
+#[macro_export]
+macro_rules! const_format_args {}
+#[rustc_builtin_macro]
+#[macro_export]
+macro_rules! format_args_nl {}
+
+mod panic {
+ pub macro panic_2015 {
+ () => (
+ $crate::panicking::panic("explicit panic")
+ ),
+ ($msg:literal $(,)?) => (
+ $crate::panicking::panic($msg)
+ ),
+ // Use `panic_str` instead of `panic_display::<&str>` for non_fmt_panic lint.
+ ($msg:expr $(,)?) => (
+ $crate::panicking::panic_str($msg)
+ ),
+ // Special-case the single-argument case for const_panic.
+ ("{}", $arg:expr $(,)?) => (
+ $crate::panicking::panic_display(&$arg)
+ ),
+ ($fmt:expr, $($arg:tt)+) => (
+ $crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
+ ),
+ }
+}
+
+#[rustc_builtin_macro(std_panic)]
+#[macro_export]
+macro_rules! panic {}
+#[rustc_builtin_macro]
+macro_rules! assert {}
+
+macro_rules! toho {
+ () => ($crate::panic!("not yet implemented"));
+ ($($arg:tt)+) => ($crate::panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
}
fn main() {
println!("{ничоси}", ничоси = 92);
println!("{:x?} {} ", thingy, n2);
+ panic!("{}", 0);
+ panic!("more {}", 1);
+ assert!(true, "{}", 1);
+ assert!(true, "{} asdasd", 1);
+ toho!("{}fmt", 0);
}"#
.trim(),
expect_file!["./test_data/highlight_strings.html"],
fn test_unsafe_highlighting() {
check_highlighting(
r#"
+static mut MUT_GLOBAL: Struct = Struct { field: 0 };
+static GLOBAL: Struct = Struct { field: 0 };
unsafe fn unsafe_fn() {}
union Union {
b: f32,
}
-struct HasUnsafeFn;
-
-impl HasUnsafeFn {
+struct Struct { field: i32 }
+impl Struct {
unsafe fn unsafe_method(&self) {}
}
-struct TypeForStaticMut {
- a: u8
-}
-
-static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
-
#[repr(packed)]
struct Packed {
a: u16,
}
+unsafe trait UnsafeTrait {}
+unsafe impl UnsafeTrait for Packed {}
+impl !UnsafeTrait for () {}
+
+fn unsafe_trait_bound<T: UnsafeTrait>(_: T) {}
+
trait DoTheAutoref {
fn calls_autoref(&self);
}
Union { b: 0 } => (),
Union { a } => (),
}
- HasUnsafeFn.unsafe_method();
+ Struct { field: 0 }.unsafe_method();
// unsafe deref
- let y = *x;
+ *x;
// unsafe access to a static mut
- let a = global_mut.a;
+ MUT_GLOBAL.field;
+ GLOBAL.field;
// unsafe ref of packed fields
let packed = Packed { a: 0 };