You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The macro will cause a compiler error if it encounters a function where a struct was expected
Ideally, we would do the same if we encounter a tuple struct where a function was expected (i.e. a lower case tuple struct).
Currently this is handled like a function call (which it is in a way), but that means the struct is constructed on the stack and moved unto the heap afterwards. This does not cause UB, but it can overflow the stack.
However, I could not find a way to do that reliably. The closest i got was the following code:
/// Validates that the given expression is not a tuple struct instantiation of the form `Struct(...)`.////// This is needed to distinguish between function calls and struct instantiations and/// cause a compile error for the latter.fnvalidate_not_tuple_struct(path:&Path) -> TokenStream{// The only way to reject a tuple struct instantiation, but accept a function call that I found is// to shadow the name with a let-binding. For tuple structs, this causes a compiler error,// but not for function calls.let ident = path.segments.last().expect("empty ident not supported");quote_spanned!{path.span()=> {
#[allow(unused)]{
#[allow(unused)]use #path;
#[allow(unused, clippy::let_unit_value)]let #ident = ();
};
}}}
However, that use #path; causes a compiler error for paths like String::from.
The text was updated successfully, but these errors were encountered:
The README currently says:
Ideally, we would do the same if we encounter a tuple struct where a function was expected (i.e. a lower case tuple struct).
Currently this is handled like a function call (which it is in a way), but that means the struct is constructed on the stack and moved unto the heap afterwards. This does not cause UB, but it can overflow the stack.
However, I could not find a way to do that reliably. The closest i got was the following code:
However, that
use #path;
causes a compiler error for paths likeString::from
.The text was updated successfully, but these errors were encountered: