pub(crate) struct FnParseMode {
    pub req_name: fn(_: Edition) -> bool,
    pub req_body: bool,
}
Expand description

Parsing configuration for functions.

The syntax of function items is slightly different within trait definitions, impl blocks, and modules. It is still parsed using the same code, just with different flags set, so that even when the input is wrong and produces a parse error, it still gets into the AST and the rest of the parser and type checker can run.

Fields§

§req_name: fn(_: Edition) -> bool

A function pointer that decides if, per-parameter p, p must have a pattern or just a type. This field affects parsing of the parameters list.

fn foo(alef: A) -> X { X::new() }
       -----^^ affects parsing this part of the function signature
       |
       if req_name returns false, then this name is optional

fn bar(A) -> X;
       ^
       |
       if req_name returns true, this is an error

Calling this function pointer should only return false if:

  • The item is being parsed inside of a trait definition. Within an impl block or a module, it should always evaluate to true.
  • The span is from Edition 2015. In particular, you can get a 2015 span inside a 2021 crate using macros.
§req_body: bool

If this flag is set to true, then plain, semicolon-terminated function prototypes are not allowed here.

fn foo(alef: A) -> X { X::new() }
                     ^^^^^^^^^^^^
                     |
                     this is always allowed

fn bar(alef: A, bet: B) -> X;
                            ^
                            |
                            if req_body is set to true, this is an error

This field should only be set to false if the item is inside of a trait definition or extern block. Within an impl block or a module, it should always be set to true.

Trait Implementations§

source§

impl Clone for FnParseMode

source§

fn clone(&self) -> FnParseMode

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Copy for FnParseMode

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere
T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 16 bytes