Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does #[automatically_derived] mean?

Tags:

rust

I found #[automatically_derived] in the serde-derive crate when generating the implementations for the derived type:

quote! {
    #[automatically_derived]
    impl #impl_generics _serde::Serialize for #ident #ty_generics #where_clause {
        fn serialize<__S>(&self, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error>
        where
            __S: _serde::Serializer,
        {
            #body
        }
    }
}

What does this mean? When I should use this?

I also found this in several expanded macros, but I couldn't find any description about this line.

like image 333
Tim Diekmann Avatar asked Jul 23 '18 14:07

Tim Diekmann


People also ask

What does ~ mean in math?

The symbol ~ is used to approximate numbers informally. If you want to approximate a number (such as a birth year), use “c.” (meaning circa, the Latin word for “around”) instead. In math (you’ll recognize this if you’re in high school Geometry), this symbol is used to express the fact that two shapes are similar but not congruent.

What is the plural form of the verb 'do'?

The subject of the sentence is the plural noun changes. Therefore, the verb must be plural. As the post states, do is the plural form of the verb. Please help. Do/Does either of you have a pen? While the rule states that the third person singular should be used, the fact that the people are being addressed directly (you) makes me want to use ‘do’.

What does what all mean in a sentence?

“What all” refers to something in all its ramifications. The sentence roughly means “Give me a full explanation of what the clouds do.” how do we recognise noun in a sentence? Is subject always a noun? Which statement is correct? regards! A noun is a person, place, thing, or idea. A subject is always a noun or pronoun.

What about the usage of do and does with I?

What about the usage of Do and Does with I? Please quote some examples. The pronouns I, you, we, and they are always used with the word do. The pronouns he, she, and it are used with does. Examples: I do think it might rain tomorrow.


1 Answers

It is an indication to the compiler that the marked code should not be reported as unused, among other things:

// Don't run unused pass for #[derive()]
if let FnKind::Method(..) = fk {
    let parent = ir.tcx.hir().get_parent_item(id);
    if let Some(Node::Item(i)) = ir.tcx.hir().find(parent) {
        if i.attrs.iter().any(|a| a.check_name(sym::automatically_derived)) {
            return;
        }
    }
}

It also applies to

  • ignoring single use lifetimes
like image 91
Shepmaster Avatar answered Nov 15 '22 09:11

Shepmaster