Skip to content

Conversation

qryxip
Copy link
Collaborator

@qryxip qryxip commented Mar 30, 2020

Fixes #8.

  1. Migrate to syn v1.

  2. Bump the MSRV to 1.42.0.

  3. The new fastout will be like this:

    let __proconio_stdout = ::std::io::stdout();
    let mut __proconio_stdout = ::std::io::BufWriter::new(__proconio_stdout.lock());
    
    // proc-macros can produce `macro_rules!` since Rust 1.40.0
    
    #[allow(unused_macros)]
    macro_rules! print {
        ($($tt:tt)*) => {
            <::std::io::BufWriter<::std::io::StdoutLock<'_>> as ::std::io::Write>::write_fmt(
                &mut __proconio_stdout,
                format_args!($($tt)*),
            )
            .unwrap()
        };
    }
    
    #[allow(unused_macros)]
    macro_rules! println {
        () => {
            <::std::io::BufWriter<::std::io::StdoutLock<'_>> as ::std::io::Write>::write_all(
                &mut __proconio_stdout,
                b"\n",
            )
            .unwrap()
        };
        ($fmt:literal $($tt:tt)*) => {
            <::std::io::BufWriter<::std::io::StdoutLock<'_>> as ::std::io::Write>::write_fmt(
                &mut __proconio_stdout,
                format_args!(::std::concat!($fmt, "\n") $($tt)*),
            )
            .unwrap()
        };
    }
    
    let __proconio_res = {
        // AS IS
        println!("Hello!");
    
        // `print!`/`println!` in closures still produce explicit errors
        //thread::Builder::new()
        //    .stack_size(1024usize.pow(3))
        //    .spawn(|| println!("Hi"))
        //    .unwrap();
    };
    <::std::io::BufWriter<::std::io::StdoutLock> as ::std::io::Write>::flush(
        &mut __proconio_stdout
    ).unwrap();
    return __proconio_res;

    The new implementation does not replace qualified macros i.e. std::print!. std::println!, ::std::print! and ::std::println!. So this change may be breaking.

@statiolake
Copy link
Owner

Looks good to me, including the breaking change about std::println!. Usually, the std:: modifier is rarely used, and if it is still explicitly stated by the user, I think it is safe to assume that the user really wants to call the println! of std. Thanks!

@statiolake statiolake merged commit e6478f6 into statiolake:master Apr 1, 2020
@qryxip qryxip deleted the rewrite-fastout branch April 1, 2020 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[fastout] does not replace macros in match arms
2 participants