Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 21 additions & 33 deletions exercises/practice/macros/src/compile_fail_tests.rs
Original file line number Diff line number Diff line change
@@ -1,103 +1,91 @@
/// To activate a doctest locally, remove ",ignore" from the code block.
///
/// # Comma separator
///
// To activate a doctest locally, remove ",ignore" from the code block.

/// ```compile_fail,ignore
/// use macros::hashmap;
/// use std::collections::HashMap;
///
/// // using only commas is invalid
/// let _hm: HashMap<_, _> = hashmap!('a', 1);
/// ```
///
/// # Double trailing commas
///
const _COMMA_SEPARATOR: () = ();

/// ```compile_fail,ignore
/// use macros::hashmap;
/// use std::collections::HashMap;
///
/// // a single trailing comma is okay, but two is not
/// let _hm: HashMap<_, _> = hashmap!('a' => 2, ,);
/// ```
///
/// # Only comma
///
const _DOUBLE_TRAILING_COMMAS: () = ();

/// ```compile_fail,ignore
/// use macros::hashmap;
/// use std::collections::HashMap;
///
/// // a single random comma is not valid
/// let _hm: HashMap<(), ()> = hashmap!(,);
/// ```
///
/// # Single argument
///
const _ONLY_COMMA: () = ();

/// ```compile_fail,ignore
/// use macros::hashmap;
/// use std::collections::HashMap;
///
/// // a single argument is invalid
/// let _hm: HashMap<_, _> = hashmap!('a');
/// ```
///
/// # Triple arguments
///
const _SINGLE_ARGUMENT: () = ();

/// ```compile_fail,ignore
/// use macros::hashmap;
/// use std::collections::HashMap;
///
/// // three arguments are invalid
/// hashmap!('a' => 1, 'b');
/// ```
///
/// # Only arrow
///
const _TRIPLE_ARGUMENTS: () = ();

/// ```compile_fail,ignore
/// use macros::hashmap;
/// use std::collections::HashMap;
///
/// // a single random arrow is not valid
/// let _hm: HashMap<(), ()> = hashmap!(=>);
/// ```
///
/// # Trailing arrow
///
const _ONLY_ARROW: () = ();

/// ```compile_fail,ignore
/// use macros::hashmap;
/// use std::collections::HashMap;
///
/// // a trailing => isn't valid either
/// hashmap!('a' => 2, =>);
/// ```
///
/// # Leading comma
///
const _TRAILING_ARROW: () = ();

/// ```compile_fail,ignore
/// use macros::hashmap;
/// use std::collections::HashMap;
///
/// // leading commas are not valid
/// let _hm: HashMap<_, _> = hashmap!(, 'a' => 2);
/// ```
///
/// # Missing comma
///
const _LEADING_COMMA: () = ();

/// ```compile_fail,ignore
/// use macros::hashmap;
/// use std::collections::HashMap;
///
/// // Key value pairs must be separated by commas
/// let _hm: HashMap<_, _> = hashmap!('a' => 1 'b' => 2);
/// ```
///
/// # Missing argument
///
const _MISSING_COMMA: () = ();

/// ```compile_fail,ignore
/// use macros::hashmap;
/// use std::collections::HashMap;
///
/// // an argument should come between each pair of commas
/// let _hm: HashMap<_, _> = hashmap!('a' => 1, , 'b' => 2);
/// ```
///
const _TESTS: () = ();
const _MISSING_ARGUMENT: () = ();
2 changes: 1 addition & 1 deletion exercises/practice/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ macro_rules! hashmap {

/// This module contains doctests, which allows writing tests where a code
/// snippet is supposed to fail to compile. These tests also have "ignore"
/// attributes, makes sure to remove them when solving this exercise locally.
/// attributes, make sure to remove them when solving this exercise locally.
pub mod compile_fail_tests;