Fix stable/nightly mismatch error cause by proc-macro2

fix #50
This commit is contained in:
Kogia-sima 2021-02-03 02:56:15 +09:00
parent 5c5c57f437
commit 5e12280df1
2 changed files with 10 additions and 2 deletions

View File

@ -131,7 +131,16 @@ fn compile(
config: Config,
) -> Result<CompilationReport, Error> {
let compiler = Compiler::with_config(config);
compiler.compile_file(input_file, &*output_file)
// SAFETY:
// Any token or span constructed after `proc_macro2::fallback::force()` must not
// outlive after `unforce()` because it causes span mismatch error. In this case,
// We must ensure that `result` variable does not hold any token or span.
proc_macro2::fallback::force();
let result = compiler.compile_file(input_file, &*output_file);
proc_macro2::fallback::unforce();
result
}
fn derive_template_impl(tokens: TokenStream) -> Result<TokenStream, syn::Error> {

View File

@ -227,7 +227,6 @@ impl SourceBuilder {
pub fn finalize(mut self) -> Result<TranslatedSource, Error> {
self.source.push_str("\n}");
proc_macro2::fallback::force();
match syn::parse_str::<Block>(&*self.source) {
Ok(ast) => Ok(TranslatedSource {
ast,