Skip to content

Commit ba62d89

Browse files
committed
Changed for Rust stable version compatibility
1 parent 02bdf08 commit ba62d89

File tree

3 files changed

+20
-40
lines changed

3 files changed

+20
-40
lines changed

src/config.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::default::Default;
22
use std::collections::HashSet;
33

4-
use proc_macro2;
54
use syn::{self, Token, parenthesized};
65
use syn::parse::{Parse, ParseStream};
76

@@ -39,9 +38,7 @@ impl Config {
3938
match parsed {
4039
Ok(parsed_attrib) => parsed_attributes.push(parsed_attrib),
4140
Err(e) => {
42-
let diag = e.span().unstable()
43-
.error(format!("{}", e));
44-
return Err(DiagnosticError::new_with_syn_error(diag, e));
41+
return Err(DiagnosticError::new_with_syn_error(format!("{}", e), e));
4542
}
4643
}
4744
}

src/error.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
use std::result;
2-
use proc_macro::Diagnostic;
32
use syn;
43

54
pub struct DiagnosticError {
6-
diagnostic: Diagnostic,
5+
diagnostic: String,
76
#[allow(dead_code)]
87
syn_error: Option<syn::parse::Error>,
98
}
109

1110
impl DiagnosticError {
12-
pub fn new(diagnostic: Diagnostic) -> DiagnosticError {
11+
pub fn new(diagnostic: String) -> DiagnosticError {
1312
DiagnosticError {
1413
diagnostic,
1514
syn_error: None,
1615
}
1716
}
18-
pub fn new_with_syn_error(diagnostic: Diagnostic, syn_error: syn::parse::Error) -> DiagnosticError {
17+
pub fn new_with_syn_error(diagnostic: String, syn_error: syn::parse::Error) -> DiagnosticError {
1918
DiagnosticError {
2019
diagnostic,
2120
syn_error: Some(syn_error),
@@ -28,7 +27,7 @@ impl DiagnosticError {
2827
}
2928

3029
pub fn emit(self) {
31-
self.diagnostic.emit();
30+
println!("{}", &self.diagnostic);
3231
}
3332
}
3433

src/lib.rs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@
171171
//! }
172172
//! ```
173173
//!
174-
#![feature(extern_crate_item_prelude)]
175-
#![feature(proc_macro_diagnostic)]
174+
//#![feature(extern_crate_item_prelude)]
175+
//#![feature(proc_macro_diagnostic)]
176176
#![recursion_limit="128"]
177177
extern crate proc_macro;
178178

@@ -228,9 +228,7 @@ fn lru_cache_impl(attr: Attr, item: TokenStream) -> Result<TokenStream> {
228228
let mut original_fn: syn::ItemFn = match syn::parse(item.clone()) {
229229
Ok(ast) => ast,
230230
Err(e) => {
231-
let diag = proc_macro2::Span::call_site().unstable()
232-
.error("lru_cache may only be used on functions");
233-
return Err(DiagnosticError::new_with_syn_error(diag, e));
231+
return Err(DiagnosticError::new_with_syn_error(String::from("lru_cache may only be used on functions"), e));
234232
}
235233
};
236234

@@ -365,9 +363,7 @@ fn get_cache_fn_return_type(original_fn: &syn::ItemFn) -> Result<Box<syn::Type>>
365363
if let syn::ReturnType::Type(_, ref ty) = original_fn.decl.output {
366364
Ok(ty.clone())
367365
} else {
368-
let diag = original_fn.ident.span().unstable()
369-
.error("There's no point of caching the output of a function that has no output");
370-
return Err(DiagnosticError::new(diag));
366+
return Err(DiagnosticError::new(String::from("There's no point of caching the output of a function that has no output")));
371367
}
372368
}
373369

@@ -407,15 +403,11 @@ fn get_args_and_types(f: &syn::ItemFn, config: &config::Config) ->
407403

408404
for input in &f.decl.inputs {
409405
match input {
410-
syn::FnArg::SelfValue(p) => {
411-
let diag = p.span().unstable()
412-
.error("`self` arguments are currently unsupported by lru_cache");
413-
return Err(DiagnosticError::new(diag));
406+
syn::FnArg::SelfValue(_p) => {
407+
return Err(DiagnosticError::new(String::from("`self` arguments are currently unsupported by lru_cache")));
414408
}
415-
syn::FnArg::SelfRef(p) => {
416-
let diag = p.span().unstable()
417-
.error("`&self` arguments are currently unsupported by lru_cache");
418-
return Err(DiagnosticError::new(diag));
409+
syn::FnArg::SelfRef(_p) => {
410+
return Err(DiagnosticError::new(String::from("`&self` arguments are currently unsupported by lru_cache")));
419411
}
420412
syn::FnArg::Captured(arg_captured) => {
421413
let mut segments: syn::punctuated::Punctuated<_, Token![::]> = syn::punctuated::Punctuated::new();
@@ -424,9 +416,7 @@ fn get_args_and_types(f: &syn::ItemFn, config: &config::Config) ->
424416
arg_name = pat_ident.ident.clone();
425417
segments.push(syn::PathSegment { ident: pat_ident.ident.clone(), arguments: syn::PathArguments::None });
426418
} else {
427-
let diag = arg_captured.span().unstable()
428-
.error("unsupported argument kind");
429-
return Err(DiagnosticError::new(diag));
419+
return Err(DiagnosticError::new(String::from("unsupported argument kind")));
430420
}
431421

432422
let arg_path = syn::Expr::Path(syn::ExprPath { attrs: Vec::new(), qself: None, path: syn::Path { leading_colon: None, segments } });
@@ -435,10 +425,8 @@ fn get_args_and_types(f: &syn::ItemFn, config: &config::Config) ->
435425

436426
// If the arg type is a reference, remove the reference because the arg will be cloned
437427
if let syn::Type::Reference(type_reference) = &arg_captured.ty {
438-
if let Some(m) = type_reference.mutability {
439-
let diag = m.span.unstable()
440-
.error("`mut` reference arguments are not supported as this could lead to incorrect results being stored");
441-
return Err(DiagnosticError::new(diag));
428+
if let Some(_m) = type_reference.mutability {
429+
return Err(DiagnosticError::new(String::from("`mut` reference arguments are not supported as this could lead to incorrect results being stored")));
442430
}
443431
types.push(type_reference.elem.as_ref().to_owned()); // as_ref -> to_owned unboxes the type
444432
} else {
@@ -451,15 +439,11 @@ fn get_args_and_types(f: &syn::ItemFn, config: &config::Config) ->
451439

452440
call_args.push(arg_path);
453441
},
454-
syn::FnArg::Inferred(p) => {
455-
let diag = p.span().unstable()
456-
.error("inferred arguments are currently unsupported by lru_cache");
457-
return Err(DiagnosticError::new(diag));
442+
syn::FnArg::Inferred(_p) => {
443+
return Err(DiagnosticError::new(String::from("inferred arguments are currently unsupported by lru_cache")));
458444
}
459-
syn::FnArg::Ignored(p) => {
460-
let diag = p.span().unstable()
461-
.error("ignored arguments are currently unsupported by lru_cache");
462-
return Err(DiagnosticError::new(diag));
445+
syn::FnArg::Ignored(_p) => {
446+
return Err(DiagnosticError::new(String::from("ignored arguments are currently unsupported by lru_cache")));
463447
}
464448
}
465449
}

0 commit comments

Comments
 (0)