]> git.lizzy.rs Git - rust.git/blobdiff - tests/target/macros.rs
Preserve trailing comma on macro call when using mixed layout
[rust.git] / tests / target / macros.rs
index d47063d255c263a9dc0c223ecc3a5e65e89572af..76e538bb85d49fe6a0a0426778153b73a6d87831 100644 (file)
@@ -15,6 +15,8 @@
 fn main() {
     foo!();
 
+    foo!(,);
+
     bar!(a, b, c);
 
     bar!(a, b, c,);
@@ -33,6 +35,10 @@ fn main() {
     );
 
     trailingcomma!(a, b, c,);
+    // Preserve trailing comma only when necessary.
+    ok!(file.seek(SeekFrom::Start(
+        table.map(|table| fixture.offset(table)).unwrap_or(0),
+    )));
 
     noexpr!( i am not an expression, OK? );
 
@@ -117,7 +123,7 @@ fn main() {
         20, 21, 22);
 
     // #1092
-    chain!(input, a:take!(max_size), || []);
+    chain!(input, a: take!(max_size), || []);
 }
 
 impl X {
@@ -131,14 +137,13 @@ fn issue_1279() {
 fn issue_1555() {
     let hello = &format!(
         "HTTP/1.1 200 OK\r\nServer: {}\r\n\r\n{}",
-        "65454654654654654654654655464",
-        "4"
+        "65454654654654654654654655464", "4"
     );
 }
 
 fn issue1178() {
     macro_rules! foo {
-        (#[$attr:meta] $name:ident) => {}
+        (#[$attr:meta] $name:ident) => {};
     }
 
     foo!(
@@ -204,7 +209,7 @@ fn issue_1921() {
             acc += 1;
             acc += 2;
             acc
-        }
+        };
     }
 }
 
@@ -240,3 +245,719 @@ fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() {
         )
     );
 }
+
+// #878
+macro_rules! try_opt {
+    ($expr:expr) => {
+        match $expr {
+            Some(val) => val,
+
+            None => {
+                return None;
+            }
+        }
+    };
+}
+
+// #2214
+// macro call whose argument is an array with trailing comma.
+fn issue2214() {
+    make_test!(
+        str_searcher_ascii_haystack,
+        "bb",
+        "abbcbbd",
+        [
+            Reject(0, 1),
+            Match(1, 3),
+            Reject(3, 4),
+            Match(4, 6),
+            Reject(6, 7),
+        ]
+    );
+}
+
+fn special_case_macros() {
+    let p = eprint!();
+    let q = eprint!("{}", 1);
+    let r = eprint!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    let s = eprint!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    let q = eprintln!("{}", 1);
+    let r = eprintln!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    let s = eprintln!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    let q = format!("{}", 1);
+    let r = format!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    let s = format!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    let q = format_args!("{}", 1);
+    let r = format_args!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    let s = format_args!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    let q = print!("{}", 1);
+    let r = print!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    let s = print!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    let q = println!("{}", 1);
+    let r = println!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    let s = println!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    let q = unreachable!("{}", 1);
+    let r = unreachable!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    let s = unreachable!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    debug!("{}", 1);
+    debug!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    debug!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    error!("{}", 1);
+    error!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    error!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    info!("{}", 1);
+    info!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    info!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    panic!("{}", 1);
+    panic!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    panic!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    warn!("{}", 1);
+    warn!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+    );
+    warn!(
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    assert!();
+    assert!(result == 42);
+    assert!(result == 42, "Ahoy there, {}!", target);
+    assert!(
+        result == 42,
+        "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
+        result,
+        input,
+        expected
+    );
+    assert!(
+        result == 42,
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    assert_eq!();
+    assert_eq!(left);
+    assert_eq!(left, right);
+    assert_eq!(left, right, "Ahoy there, {}!", target);
+    assert_eq!(
+        left, right,
+        "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
+        result, input, expected
+    );
+    assert_eq!(
+        first_realllllllllllly_long_variable_that_doesnt_fit_one_one_line,
+        second_reallllllllllly_long_variable_that_doesnt_fit_one_one_line,
+        "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
+        result,
+        input,
+        expected
+    );
+    assert_eq!(
+        left + 42,
+        right,
+        "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
+        result,
+        input,
+        expected
+    );
+    assert_eq!(
+        left,
+        right,
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    write!(&mut s, "Ahoy there, {}!", target);
+    write!(
+        &mut s,
+        "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
+        result, input, expected
+    );
+    write!(
+        &mut s,
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+
+    writeln!(&mut s, "Ahoy there, {}!", target);
+    writeln!(
+        &mut s,
+        "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
+        result, input, expected
+    );
+    writeln!(
+        &mut s,
+        "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
+        1,
+        2,
+        3,
+        4,
+        5,
+        6,
+        7,
+        8,
+        9,
+        10,
+        11,
+        12,
+        13,
+        14,
+        15,
+        16,
+        17,
+        18,
+        19,
+        20,
+        21,
+        22,
+        23,
+        24,
+        25,
+        26
+    );
+}
+
+// #1209
+impl Foo {
+    /// foo
+    pub fn foo(&self) -> Bar<foo!()> {}
+}
+
+// #819
+fn macro_in_pattern_position() {
+    let x = match y {
+        foo!() => (),
+        bar!(a, b, c) => (),
+        bar!(a, b, c,) => (),
+        baz!(1 + 2 + 3, quux.kaas()) => (),
+        quux!(
+            AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
+            BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
+        ) => (),
+    };
+}
+
+macro foo() {}
+
+pub macro bar($x:ident + $y:expr;) {
+    fn foo($x: Foo) {
+        long_function(
+            a_long_argument_to_a_long_function_is_what_this_is(AAAAAAAAAAAAAAAAAAAAAAAAAAAA),
+            $x.bar($y),
+        );
+    }
+}
+
+macro foo() {
+    // a comment
+    fn foo() {
+        // another comment
+        bar();
+    }
+}
+
+// #2574
+macro_rules! test {
+    () => {{}};
+}
+
+macro lex_err($kind: ident $(, $body: expr)*) {
+    Err(QlError::LexError(LexError::$kind($($body,)*)))
+}
+
+// Preserve trailing comma on item-level macro with `()` or `[]`.
+methods![get, post, delete,];
+methods!(get, post, delete,);
+
+// #2588
+macro_rules! m {
+    () => {
+        r#"
+            test
+        "#
+    };
+}
+fn foo() {
+    f!{r#"
+            test
+       "#};
+}
+
+// #2591
+fn foo() {
+    match 0u32 {
+        0 => (),
+        _ => unreachable!(/* obviously */),
+    }
+}
+
+fn foo() {
+    let _ = column!(/* here */);
+}
+
+// #2616
+// Preserve trailing comma when using mixed layout for macro call.
+fn foo() {
+    foo!(
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
+    );
+    foo!(
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+    );
+}