# AI skills based on official guidelines

**URL:** <https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566>\
**Category:** guidelines\
**Created:** [August 31, 2026, 2:02pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566 "2026-08-31T14:02:18Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![HjVT](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hjvt/32/10365_2.png) [@HjVT](https://internals.rust-lang.org/u/HjVT)\
**Post date:** [September 20, 2026, 12:07pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/21 "2026-09-20T12:07:28Z")

</div>

> [@mhaeuser](#):
>
> How many examples of things with absolutely terrible effects or trade-offs both mid and long-term can you name that people avoid? Excessive use of cars? Excessive livestock farming? Sourcing everyday items and components from terrible production sites? Excessive retrieval of natural resources?

I personally do all of those.

Either way, it is faulty argument to compare breaking life-long and societally reinforced habits to not using chatbots that only appeared a couple years ago.

---

<div class="post-metadata">

**Author:** ![mhaeuser](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mhaeuser/32/13785_2.png) [@mhaeuser](https://internals.rust-lang.org/u/mhaeuser)\
**Post date:** [September 20, 2026, 12:49pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/22 "2026-09-20T12:49:04Z")

</div>

> [@HjVT](#):
>
> Either way, it is faulty argument to compare breaking life-long and societally reinforced habits to not using chatbots that only appeared a couple years ago.

The point raised about people declaring their perceived utility of LLMs sufficient to subject everyone to the dramatic consequences obviously includes the force of habit and convenience (the former is a sub-case of the latter). In the light of @zackw’s response, I assume we both do not care much about the force of habit. The argument is only “faulty” if you’re looking for excuses rather than solutions.

I also fail to see how this off-topic progresses anything.

---

<div class="post-metadata">

**Author:** ![fuji-184](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/fuji-184/32/13546_2.png) [@fuji-184](https://internals.rust-lang.org/u/fuji-184)\
**Post date:** [October 11, 2026, 4:43am UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/23 "2026-10-11T04:43:36Z")

</div>

I want to note that skill.md significantly improve the quality of Rust code that I found sometimes is even better than Rust code written manually. This save so much time, it just needs clear guide. Here is a few of mine, the real one is very long, and I keep expanding it to reach more performance guide and how to use unsafe including the unsafe constructs in STD and the requirements :v

# Purpose

Your purpose is to help me with tasks like writing code, fixing code, and understanding code. I will share my goals and projects with you, and you will assist me in crafting the code I need to succeed.

Goals

- Code creation: Whenever possible, write complete code that achieves my goals.

- Education: Teach me about the steps involved in code development.

- Clear instructions: Explain how to implement or build the code in a way that is easy to understand.

- Thorough documentation: Provide clear documentation for each step or part of the code.

Overall direction

- Remember to maintain a positive, patient, and supportive tone throughout.

- Use clear, simple language, assuming a basic level of code understanding.

- Never discuss anything except for coding! If I mention something unrelated to coding, apologize and direct the conversation back to coding topics.

- Keep context across the entire conversation, ensuring that the ideas and responses are related to all the previous turns of conversation.

- If greeted or asked what you can do, please briefly explain your purpose. Keep it concise and to the point, giving some short examples.

Step by step instructions

- Understand my request: Gather the information you need to develop the code. Ask clarifying questions about the purpose, usage, and any other relevant details to ensure you understand the request.

- Show an overview of the solution: Provide a clear overview of what the code will do and how it will work. Explain the development steps, assumptions, and restrictions.

- Show the code and implementation instructions: Present the code in a way that's easy to copy and paste, explaining your reasoning and any variables or parameters that can be adjusted. Offer clear instructions on how to implement the code.

# Rust Language Skill

# Code Style

## Description

Contains guidelines for Rust programming language writing style

## Steps

1. When writing Rust code, use this writing style

2. After writing, double check whether it complies

## Content Guidelines

- Variable names and function names must use snake\_case

- Code must not contain emojis

- Each function must have only 1 task, if there are multiple tasks, break them down into separate functions so that 1 function focuses entirely on performing 1 task

- Global variable names must be written in ALL CAPS

- All modules or namespaces must be imported once at the top of the code, if there are naming collisions, provide an alias that remains descriptive

- Comments should only be placed where commenting is truly necessary, not everywhere. Keep sentences brief, concise, easy to understand, and descriptive using English

- All names in the code such as variable names, function names, and anything else within the code must be written in English. Use descriptive names

- Every unsafe operation must be wrapped inside its own dedicated unsafe block, 1 unsafe block is strictly for 1 unsafe operation

- Always use mimalloc as the global allocator

- Avoid using `clone`, use references or pointers instead. `Clone` is only permitted when a brand new value is genuinely required, never as a fix for borrow checker errors. To resolve borrow errors, redesign the program flow first, only resort to raw pointers if that fails

- Avoid using `Rc` and `Arc`. Use local references and scoped threads if threads need to be joined and do not run purely in the background. If that is not possible, use `ManuallyDrop` and raw pointers

- Avoid using `RefCell`, replace it with `UnsafeCell` or pointers

- Avoid using `dyn` vtables, use generics and traits instead

- Use a vertical slice architecture

- Avoid casting pointers to integers as it strips provenance, use the `.addr()` method instead

# Memory Allocation

## Description

Contains guidelines for selecting memory allocation strategies

## Steps

1. When writing Rust code, use this memory allocation guide

2. After writing, double check whether it complies

## Content Guidelines

- If the number of values is known at compile time, use stack allocation

- If the number of values is unknown at compile time or can grow dynamically, use heap allocation

- Prioritize reusing existing allocations before creating new ones

- When creating a stack collection, use `MaybeUninit`, and avoid arrays because arrays carry a performance cost due to `memset`. Only use arrays if they can be written via `array::from_fn()`. Read the detailed guide specific to `MaybeUninit` in the `MaybeUninit` section

- When creating heap allocations, always use a pre-allocation size of 4KB

- Design memory layouts to be contiguous and CPU cache friendly

- Always use mimalloc as the global allocator

# Branching Guidelines

## Description

Contains guidelines on how to choose the right branching constructs

## Steps

1. When writing Rust code, use this branching guide

2. After writing, double check whether it complies

## Content Guidelines

- If inside a loop processing contiguous data, avoid branching and use branchless programming

- Use pattern matching for multiple branches

- Use `if` and `if let` for single branches

- If branching behavior can be predicted regarding which branch is taken more frequently, use branch hints

# Error Handling

## Description

Contains guidelines for handling errors

## Steps

1. When writing Rust code, use this error handling guide

2. After writing, double check whether it complies

## Content Guidelines

- Use error enum libraries along with the `thiserror` library to handle errors, avoiding `Box<dyn>` and the `anyhow` library

- Use `Result` for recoverable errors, and use `.expect()` with a clear error message for unrecoverable or fatal errors, do not use `unwrap`

- Use the question mark (`?`) syntactic sugar to propagate errors

- For dynamic error messages, use a global memory pool for string buffers in the global memory pool section. Enums should only carry a payload index or error code to keep the Result size as small as possible, ensuring that error propagation only copies a small number of bytes

- If the error payload does not need to be returned, log it in place using the logger library specified in the logging guide section, and have the Result return only the error code

Edit : I don't know why some people reported this post as "off-topic". Because clearly it is "on-topic", talking about skill.md which is the topic of the opening. It looks like just unreasonable don't like LLM behaviour, I also saw someone posted his AI assisted personal project then it was flagged, this is kinda unhealthy. Please be reasonable and chill

---

<div class="post-metadata">

**Author:** ![jmjoy](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jmjoy/32/12891_2.png) [@jmjoy](https://internals.rust-lang.org/u/jmjoy)\
**Post date:** [October 20, 2026, 5:44am UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/24 "2026-10-20T05:44:47Z")

</div>

Any generic guidance Skills like these are junk. They waste tokens and add little value; a good model already knows how to generate generally good code. What you should add are Skills for your personal preferences, such as requiring workspace-managed dependencies in Cargo.toml to be written as `foo = {workspace = true}`.

---

<div class="post-metadata">

**Author:** ![fuji-184](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/fuji-184/32/13546_2.png) [@fuji-184](https://internals.rust-lang.org/u/fuji-184)\
**Post date:** [October 21, 2026, 4:13pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/25 "2026-10-21T16:13:35Z")

</div>

Very wrong, even the frontier model can produce bad code. The most thing I keep receiving, including from frontier models is, doing a lot of unnecerery allocations. The models behave like that because it is what most Rust users write, the model learned from it as the training data. When I first created my skill.md containing guide to write good code, the difference is night and day. The model always reuse allocation, using contigous memory layout, overal it is amazing and better than the most user code there that I encounter

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [October 21, 2026, 4:26pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/26 "2026-10-21T16:26:07Z")

</div>

My favorite is pre-allocating things that only matter on the error codepath (and even then doing a `.clone()` of the allocation). Or making free functions for things that could easily be methods.

---

<div class="post-metadata">

**Author:** ![fuji-184](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/fuji-184/32/13546_2.png) [@fuji-184](https://internals.rust-lang.org/u/fuji-184)\
**Post date:** [October 21, 2026, 4:27pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/27 "2026-10-21T16:27:22Z")

</div>

For example, String is the most unnecerery heap allocation that I encounter. The model loves to spam it eventhough the word is static and known at compile time. It is also because the most Rust code out there also does it that trains the model. So without giving specific guide, it will bombardir String, that ends up many unnecerery slow malloc calls. I wonder why Rust compiler couldn't just promote String that is assigned literal str and never be mutated to ptr pointing to .rodata and then remove the drop call

Curent :

```rust
ptr -> points to heap
len
cap

Emit drop call

```

Promoted to static str after proven it receives literal str and never be mutated :

```rust
ptr -> points to .rodata
len = the len of the bytes
cap = 0

Does not emit drop call

```

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [October 21, 2026, 4:31pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/28 "2026-10-21T16:31:06Z")

</div>

> [@fuji-184](#):
>
> Promoted to static str after proven it receives literal str and never be mutated :
> 
> ```rust
> ptr -> points to .rodata
> len = the len of the bytes
> cap = 0
> 
> Does not emit drop call
> 
> ```

This is the realm of `clippy` (e.g., `unnecessary_string` or something).

---

<div class="post-metadata">

**Author:** ![fuji-184](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/fuji-184/32/13546_2.png) [@fuji-184](https://internals.rust-lang.org/u/fuji-184)\
**Post date:** [October 21, 2026, 4:39pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/29 "2026-10-21T16:39:05Z")

</div>

Yeah, I also prealloc error buffer inside global buffer. I do not use enum with complex data structure payload like Box or String, just enum with u8 payload. So the enum size is small, so it reduce the amount of memory write when calling the function, because returning Result\<T, E\> is doing memory write of the size of T + E, if E is big then it is more memory write. My E is only 1 byte because all the enum variant only carry 1 byte. But if String is used as payload in the enum, every other variant become 24 bytes, so whether using the String variant or not, it does the unnecerery additional 24 bytes memory write

Do not use `.clone()`, but re construct the value directly by calling the struct or the struct's constructor. Because it is faster, `.clone()` does allocation then call memcpy. Constructing the value writing to the memory directly

---

<div class="post-metadata">

**Author:** ![fuji-184](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/fuji-184/32/13546_2.png) [@fuji-184](https://internals.rust-lang.org/u/fuji-184)\
**Post date:** [October 21, 2026, 4:42pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/30 "2026-10-21T16:42:13Z")

</div>

No it is not, because lint != auto optimization by the compiler. The first one requires manual effort, the latter does not, the compiler is the one that does the optimization

---

<div class="post-metadata">

**Author:** ![notriddle](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/notriddle/32/14082_2.png) [@notriddle](https://internals.rust-lang.org/u/notriddle)\
**Post date:** [October 21, 2026, 4:52pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/31 "2026-10-21T16:52:13Z")

</div>

> [@mathstuf](#):
>
> Or making free functions for things that could easily be methods.

What do you mean by “could,” though? A method call can break if a second method with the same name that resolves to the same type is added. Free functions don’t have this problem (unless you use a glob import).

As an extreme example from the standard library, [`iter::once`](https://doc.rust-lang.org/stable/std/iter/fn.once.html) could have been a method on an extension trait:

```rust
trait MakeIter {
    fn once(self) -> Once<Self>;
}
impl<T> MakeIter for T {
    fn once(self) -> Once<Self> { Once(Some(self)) }
}

```

But it’s not, because it’s not worth it.

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [October 21, 2026, 4:55pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/32 "2026-10-21T16:55:11Z")

</div>

> [@fuji-184](#):
>
> No it is not, because lint != auto optimization by the compiler

I much prefer writing the code to be what I want rather than relying on optimizations that I need to look at the assembly to verify.

> [@notriddle](#):
>
> What do you mean by “could,” though?

A greenfield structure with understood `derives`.

```rust
enum Foo { Variant1 }

fn do_thing(foo: Foo, arg1: &str) { /* … */ }

```

In this case: there is zero reason for this to not be a method.

---

<div class="post-metadata">

**Author:** ![fuji-184](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/fuji-184/32/13546_2.png) [@fuji-184](https://internals.rust-lang.org/u/fuji-184)\
**Post date:** [October 21, 2026, 5:05pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/33 "2026-10-21T17:05:05Z")

</div>

> [@mathstuf](#):
>
> I much prefer writing the code to be what I want rather than relying on optimizations that I need to look at the assembly to verify.

Not reasonable, the optimization results same to the unoptimized one. Ptr + len points to the .rodata memory, field cap is preserved. C++ has this unnecerery malloc optimization but it incures branching, this one does not introduce branching because it is done at compile time not runtime

---

<div class="post-metadata">

**Author:** ![fuji-184](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/fuji-184/32/13546_2.png) [@fuji-184](https://internals.rust-lang.org/u/fuji-184)\
**Post date:** [October 21, 2026, 5:11pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/34 "2026-10-21T17:11:11Z")

</div>

For your information, Rust already does that kind of optimization. Struct field reordering, loop unrolling, auto vectorization, etc. They are what makes default Rust program written by user (moreover general user) is faster than language that requires manual effort

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [October 21, 2026, 6:47pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/35 "2026-10-21T18:47:31Z")

</div>

I'm familiar with optimization passes. I'd rather pay the price of transforming the code once to be closer to the desired meaning than to rely upon repeated transforms during every compilation. It also insulates me from optimizer regressions and doesn't require every implementation to reimplement the same logic.

That said, there's nothing that stops Rust from saying "optimization pattern X must be performed" at the language level, but I suspect there will be strong pushback to such requirements.

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/apparentlymart/32/9024_2.png) [@apparentlymart](https://internals.rust-lang.org/u/apparentlymart)\
**Post date:** [October 22, 2026, 12:03am UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/36 "2026-10-22T00:03:52Z")

</div>

I wonder if instead of pre-seeding a set of best practices in "skill" documents, they could instead be implemented as clippy rules (assuming clippy doesn't already have such rules).

That way instead of filling the context with a bunch of extra info _just in case_, the compiler output would "teach" the agent only what's relevant to the code it's just written and then it should presumably iterate again to satisfy the linter.

And of course, a human hand-writing code would get to see the same warnings too, if they are relevant, instead of having to pre-read all of the codebase's documentation first, so work in this area could be helpful for both humans and LLMs simultaneously, instead of doing additional work that only benefits ML agents.

Of course, this does assume that the Clippy maintainers _want_ to include lints for the sorts of things folks want their ML agents to react to (since there's quite some debate above about what the guidance should even _be_), and whether the hints folks want to have are actually possible to implement in a deterministic rules engine like Clippy. 🤔

---

<div class="post-metadata">

**Author:** ![fuji-184](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/fuji-184/32/13546_2.png) [@fuji-184](https://internals.rust-lang.org/u/fuji-184)\
**Post date:** [October 22, 2026, 4:35am UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/37 "2026-10-22T04:35:35Z")

</div>

I have created it in user space level. I parse the Rust syntax, transform it to AST, then transform it to optimized one. Since you want closer to the desired meaning, not having optimized one despite said optimization does not change the result, maybe you should revert back struct field reordering, dissable loop unrolling, dissable auto vectorization, dissable dead code elimination, remove the constructing value directly in the target stack to memcpy, and much more. Don't be cherry picky. Aka the compiler does not optimize anything, despite said optimization does not change the result

If an optimization does not change the result aka same behaviour, there is no reason to not do it. Under the hood, the compiler already does not emit your unoptimized code, but it replaces them with optimized ones as I listed above (and more lists actually). This is what called great compiler, taking the complexity of user space as much as possible. You can't remove complexity, you can only move complexity, if the language does not take the complexity, said complexity will just be offloaded to user. If the language take the complexity, said complexity does not exist in user land. And I much prefer the later, no repeated work, no need to do said complexity/task in every new project manually, because the compiler already handle it under the hood automatically

The key part is here, if an optimization does not change the result aka same behaviour, there is no reason to not do it

It does not need to be run multiple time, just creating a new optimization pass and be run exactly the same as the other optimization passes, be it in Rustc or LLVM

---

<div class="post-metadata">

**Author:** ![farnz](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/farnz/32/6587_2.png) [@farnz](https://internals.rust-lang.org/u/farnz)\
**Post date:** [October 22, 2026, 9:10am UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/38 "2026-10-22T09:10:27Z")

</div>

This could be a good use for an allow-by-default set of Clippy lints akin to the existing "pedantic" and "restriction" sets, but for AI guidance. Then, the new lints don't bother people who aren't using AI to code unless they opt-in, and can be moved to other groups if people think that they're useful to humans.

AI assisted coding can then turn on the whole group; humans cherry-pick the ones they want to use.

---

<div class="post-metadata">

**Author:** ![recatek](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/recatek/32/10626_2.png) [@recatek](https://internals.rust-lang.org/u/recatek)\
**Post date:** [October 22, 2026, 9:25am UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/39 "2026-10-22T09:25:59Z")

</div>

I think better tools for building your own lints would be the best outcome here both for humans and for agents. There's [dylint](https://github.com/trailofbits/dylint) which is handy but it uses its own workflow separate from clippy.

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [October 22, 2026, 2:30pm UTC](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566/40 "2026-10-22T14:30:13Z")

</div>

> [@fuji-184](#):
>
> struct field reordering, dissable loop unrolling, dissable auto vectorization, dissable dead code elimination, remove the constructing value directly in the target stack to memcpy

These are all things that are platform-dependent as to what the "right" answer is. These _are_ part of the optimization layer (and by no means are any of them "required" optimizations).

[Previous page](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566.md?page=1)

[Next page](https://internals.rust-lang.org/t/ai-skills-based-on-official-guidelines/24566.md?page=3)
