Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions syntax/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::syntax::atom::Atom::{self, *};
use crate::syntax::report::Errors;
use crate::syntax::{
error, ident, trivial, Api, Array, Enum, ExternFn, ExternType, Impl, Lang, Receiver, Ref,
Signature, SliceRef, Struct, Trait, Ty1, Type, TypeAlias, Types,
RustName, Signature, SliceRef, Struct, Trait, Ty1, Type, TypeAlias, Types,
};
use proc_macro2::{Delimiter, Group, Ident, TokenStream};
use quote::{quote, ToTokens};
Expand All @@ -27,7 +27,7 @@ fn do_typecheck(cx: &mut Check) {

for ty in cx.types {
match ty {
Type::Ident(ident) => check_type_ident(cx, &ident.rust),
Type::Ident(ident) => check_type_ident(cx, ident),
Type::RustBox(ptr) => check_type_box(cx, ptr),
Type::RustVec(ty) => check_type_rust_vec(cx, ty),
Type::UniquePtr(ptr) => check_type_unique_ptr(cx, ptr),
Expand Down Expand Up @@ -61,7 +61,8 @@ impl Check<'_> {
}
}

fn check_type_ident(cx: &mut Check, ident: &Ident) {
fn check_type_ident(cx: &mut Check, name: &RustName) {
let ident = &name.rust;
if Atom::from(ident).is_none()
&& !cx.types.structs.contains_key(ident)
&& !cx.types.enums.contains_key(ident)
Expand All @@ -70,6 +71,11 @@ fn check_type_ident(cx: &mut Check, ident: &Ident) {
{
let msg = format!("unsupported type: {}", ident);
cx.error(ident, &msg);
return;
}

if !name.generics.lifetimes.is_empty() {
cx.error(name, "type with lifetime parameter is not supported yet");
}
}

Expand Down
25 changes: 25 additions & 0 deletions syntax/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,31 @@ fn parse_type_path(ty: &TypePath) -> Result<Type> {
return Ok(Type::Ref(inner));
}
}
} else {
let mut lifetimes = Punctuated::new();
let mut only_lifetimes = true;
for pair in generic.args.pairs() {
let (param, punct) = pair.into_tuple();
if let GenericArgument::Lifetime(param) = param {
lifetimes.push_value(param.clone());
if let Some(punct) = punct {
lifetimes.push_punct(*punct);
}
} else {
only_lifetimes = false;
break;
}
}
if only_lifetimes {
return Ok(Type::Ident(RustName {
rust: ident,
generics: Lifetimes {
lt_token: Some(generic.lt_token),
lifetimes,
gt_token: Some(generic.gt_token),
},
}));
}
}
}
PathArguments::Parenthesized(_) => {}
Expand Down
3 changes: 2 additions & 1 deletion syntax/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ impl ToTokens for Signature {

impl ToTokens for RustName {
fn to_tokens(&self, tokens: &mut TokenStream) {
let RustName { rust, generics: _ } = self;
let RustName { rust, generics } = self;
rust.to_tokens(tokens);
generics.to_tokens(tokens);
}
}

Expand Down