rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

RFC: Autogenerated Attribute

Open Aversefun opened this issue 4 months ago • 2 comments

Summary

This RFC introduces an attribute for marking files as autogenerated. This syntax can be used by everything from rustbindgen to protoc (protobuf compiler) and understood by humans and tools alike.

mod foo {
	#![autogenerated(
		by = "example tool",
		suppress_lints = false,
		format = true,
		regen_hint = "./regen_example_tool",
		document = false,
		stable_api = true,
	)]
	// autogenerated code here...
}

Rendered

Aversefun avatar Aug 24 '25 18:08 Aversefun

Consider alternative: use @generated text in comments, which is used by Meta, and adopted by various tools already (in particular, rustfmt understands it). Like this:

// @generated by my schema compiler

The advantage of @generated marker is that

  • it is not specific to rust
  • tools that need to understand whether the file is generated do not need to parse rust syntax; only check for for @generated marker in the file header
  • easier to implement on both generator and parser site

This proposal RFC might be over-engineered a bit: in 99% of cases one just needs to know whether file is generated or not.

stepancheg avatar Aug 28 '25 18:08 stepancheg

I love this idea it would be great for wgsl_to_wgpu's bindgen.

Notes:

  • I feel that regen_hint should be split into regen_perams(array) and regen_cmd(string)
  • by should have a related version field, so the tool version can be identified, maybe renaming it to generator with an optional generator_version

TimTheBig avatar Oct 01 '25 19:10 TimTheBig