DanielKeep/cargo-script

Allow running files without any cargo script header or doc comment at the top

bluss opened this issue · 5 comments

bluss commented

Allow running files without any cargo script header or doc comment at the top

The minimal required header is just ///, right now, but it could maybe be even less (nothing)?

No comment at all should work just fine. There's even a test for it.

bluss commented

Ok, here's a file where I find an error.

internal error: could not parse embedded manifest

macro_rules! trait_group {
    (@as_items $($it:item)*) => ($($it)*);
    (@replace_self with $rep:tt [$($st:tt)*] Self $($tail:tt)*) => {
        trait_group!{@replace_self with $rep [$($st)* $rep] $($tail)*}
    };
    (@replace_self with $rep:tt [$($st:tt)*] $t:tt $($tail:tt)*) => {
        trait_group!{@replace_self with $rep [$($st)* $t] $($tail)*}
    };
    (@replace_self with $rep:tt [$($st:tt)*]) => {
        trait_group!{@as_items $($st)*}
    };
    (pub trait $name:ident : $($t:tt)+) => {
        trait_group!{@as_items pub trait $name : $($t)+ { }}
        trait_group!{@replace_self with T [] impl<T> $name for T where T: $($t)+ { }}
    }
}

use std::ops::Add;

trait_group!(pub trait Test : Add<Self, Output=Self> + Copy);

fn foo<T: Test>(x: T) -> T { x + x }

fn main() { println!("{}", foo(2)); }

Ok, so it turns out the problem was prefix manifests.

The way they worked was that they terminated on the first --- (or longer) that it saw, or when it encountered what looked like Rust code; assuming there was something other than whitespace between the start of the file and the cutoff, it assumed it had found a manifest.

The problem was that this "looks like Rust code" check was implemented by just testing for every token a Rust source file could start with... except for macro_rules!.

Since I had to bump the major version a while ago due to language back compat problems, and I've been meaning to get rid of prefix manifests for a while, I just did that.

There are a few other things I want to sort out before making a new major release, so I'll probably wait a little longer before publishing.

bluss commented

Great, don't see the need of many different ways to specify the manifest anyway.

FYI it also didn't recognize the trait token :p

Could you perhaps upload a new stable version to crates.io?