Repository navigation
raise ambiguity error on attribute macro that could be tool attribute - #162597
Conversation
|
@bors try |
This comment has been minimized.
This comment has been minimized.
raise ambiguity error on attribute macro that could be tool attribute
This comment has been minimized.
This comment has been minimized.
|
@bors try |
This comment has been minimized.
This comment has been minimized.
raise ambiguity error on attribute macro that could be tool attribute
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
Looks like the crater run is clean, so I guess we can do this (If the lang team agrees, of course) |
|
So the main drawback here is the same as with built-in attributes - with these rules you cannot add a new built-in tool module without a breakage (maybe theoretical). But if |
This comment has been minimized.
This comment has been minimized.
|
I am assuming that it's intended that the |
|
@bors r+ |
|
📋 This PR cannot be approved because it currently has the following labels: |
|
Ok, waiting on the reference PR. |
|
Reference PR is open at rust-lang/reference#2397 |
|
@bors r+ |
raise ambiguity error on attribute macro that could be tool attribute See rust-lang#162597 (comment) for clean crater run; the errors are unrelated/spurious. We need some sort of ambiguity error in other to implement the [register tool rfc](https://rust-lang.github.io/rfcs/3808-register-tool.html#fixing-name-resolution-errors): > #### Fixing name resolution errors > >Note that `register_tool` changes name resolution, and may give errors if you have a crate named `some_tool`. The compiler will suggest ways to fix the new errors. > >If a tool name conflicts with a crate name, you can disambiguate the crate with `::some_tool`: >```rust >#![register_tool(some_tool)] >extern crate some_tool; > >#[some_tool::attribute] //~ ERROR: is this the tool or a proc-macro? >fn bar() { > // ... >} > >#[::some_tool::attribute] // OK: This is the proc-macro defined in the crate. >fn foo() { > // ... >} >``` >However, if you want to go on to use a tool attribute, >you must rename the crate so it doesn't conflict: >```rust >#![register_tool(some_tool)] >extern crate some_tool as my_library; > >#[some_tool::attribute] // OK: This is the attribute specified by the tool. >fn bar() { > // ... >} >``` >Alternatively, if you only want to use lints, you can use `register_lint_tool` instead of `register_tool`, which will avoid resolution errors. > >Overlaps like this are expected to be rare in practice. This PR implements the ambiguity error (**not** the "leading `::` to disambiguate" part). This is a breaking change if: - someone has a crate or module named diagnostic|miri|rust_analyzer|clippy|rustfmt and exports an attribute macro from it - it is then used it as `#[(diagnostic|miri|rust_analyzer|clippy|rustfmt)::attr_macro]` (rather than `use module_or_crate::attr_macro; #[attr_macro]`) - the same applies for tools registered with `register_tool`, but that's unstable. See rust-lang#158146 for context. This is a simpler version of that PR. This does not implement unconditionally resolving these as tool attributes but does reserve the ability to do so. This would allow things like this to compile: ```rust mod rustfmt {} #[rustfmt::skip] fn main() {} ``` and see also rust-lang#98291 for a case where it would be nice to assume e.g. `#[rustfmt::skip]` is actually a tool attribute and thus inert.
raise ambiguity error on attribute macro that could be tool attribute See rust-lang#162597 (comment) for clean crater run; the errors are unrelated/spurious. We need some sort of ambiguity error in other to implement the [register tool rfc](https://rust-lang.github.io/rfcs/3808-register-tool.html#fixing-name-resolution-errors): > #### Fixing name resolution errors > >Note that `register_tool` changes name resolution, and may give errors if you have a crate named `some_tool`. The compiler will suggest ways to fix the new errors. > >If a tool name conflicts with a crate name, you can disambiguate the crate with `::some_tool`: >```rust >#![register_tool(some_tool)] >extern crate some_tool; > >#[some_tool::attribute] //~ ERROR: is this the tool or a proc-macro? >fn bar() { > // ... >} > >#[::some_tool::attribute] // OK: This is the proc-macro defined in the crate. >fn foo() { > // ... >} >``` >However, if you want to go on to use a tool attribute, >you must rename the crate so it doesn't conflict: >```rust >#![register_tool(some_tool)] >extern crate some_tool as my_library; > >#[some_tool::attribute] // OK: This is the attribute specified by the tool. >fn bar() { > // ... >} >``` >Alternatively, if you only want to use lints, you can use `register_lint_tool` instead of `register_tool`, which will avoid resolution errors. > >Overlaps like this are expected to be rare in practice. This PR implements the ambiguity error (**not** the "leading `::` to disambiguate" part). This is a breaking change if: - someone has a crate or module named diagnostic|miri|rust_analyzer|clippy|rustfmt and exports an attribute macro from it - it is then used it as `#[(diagnostic|miri|rust_analyzer|clippy|rustfmt)::attr_macro]` (rather than `use module_or_crate::attr_macro; #[attr_macro]`) - the same applies for tools registered with `register_tool`, but that's unstable. See rust-lang#158146 for context. This is a simpler version of that PR. This does not implement unconditionally resolving these as tool attributes but does reserve the ability to do so. This would allow things like this to compile: ```rust mod rustfmt {} #[rustfmt::skip] fn main() {} ``` and see also rust-lang#98291 for a case where it would be nice to assume e.g. `#[rustfmt::skip]` is actually a tool attribute and thus inert.
…uwer Rollup of 22 pull requests Successful merges: - #159580 (Reject cfg on expressions that cannot be safely removed) - #162597 (raise ambiguity error on attribute macro that could be tool attribute) - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs) - #163059 (Recover invalid return type until `{`, `}` or `;`) - #163672 (Use runCodeGen Abstraction for new LLVM) - #164028 (Add a future incompat warning for #[no_link]) - #164188 (Suggest adding lifetime for `dyn Trait` in return type) - #164345 (fix: handle `false` in root contexts) - #164494 (drop ands which are a superset of other ands) - #164766 (Unstably introduce MVP edition migration lint `unmarked_unchecked_type_aliases` together with bikeshed attribute `#[rustc_unchecked_type_alias]`) - #164785 (delegation: emit error when there is no field for `Self` mapping) - #164799 (Don't use `IntoIterator` in parallel API) - #164871 (Refactor call argument codegen) - #164648 (parse inline and rustc_force_inline with same parser) - #164811 (fix: Prevent ICE when comparing EII impl against generic declaration) - #164900 (make tool_attrs method to retrieve tool attributes.) - #164993 (copy_nonoverlapping: dont skip ovelrap check when src is fully uninit) - #164996 (miri: add missing alignment check in write_bytes) - #165012 (Remove Span::eq_ctxt()) - #165013 ([tiny] Add missing backticks around lifetime name) - #165024 (rustdoc-search: rank re-export lower) - #165028 (Update enzyme to fix one bug related to higher-order derivatives) > [!WARNING] > This rollup conflicts with pending auto build #165042 and may need to be recreated if the pending build succeeds.
…uwer Rollup of 21 pull requests Successful merges: - #159580 (Reject cfg on expressions that cannot be safely removed) - #162597 (raise ambiguity error on attribute macro that could be tool attribute) - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs) - #163059 (Recover invalid return type until `{`, `}` or `;`) - #163672 (Use runCodeGen Abstraction for new LLVM) - #164028 (Add a future incompat warning for #[no_link]) - #164188 (Suggest adding lifetime for `dyn Trait` in return type) - #164345 (fix: handle `false` in root contexts) - #164494 (drop ands which are a superset of other ands) - #164785 (delegation: emit error when there is no field for `Self` mapping) - #164799 (Don't use `IntoIterator` in parallel API) - #164871 (Refactor call argument codegen) - #164648 (parse inline and rustc_force_inline with same parser) - #164811 (fix: Prevent ICE when comparing EII impl against generic declaration) - #164900 (make tool_attrs method to retrieve tool attributes.) - #164993 (copy_nonoverlapping: dont skip ovelrap check when src is fully uninit) - #164996 (miri: add missing alignment check in write_bytes) - #165012 (Remove Span::eq_ctxt()) - #165013 ([tiny] Add missing backticks around lifetime name) - #165024 (rustdoc-search: rank re-export lower) - #165028 (Update enzyme to fix one bug related to higher-order derivatives)
…uwer Rollup of 21 pull requests Successful merges: - #159580 (Reject cfg on expressions that cannot be safely removed) - #162597 (raise ambiguity error on attribute macro that could be tool attribute) - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs) - #163059 (Recover invalid return type until `{`, `}` or `;`) - #163672 (Use runCodeGen Abstraction for new LLVM) - #164028 (Add a future incompat warning for #[no_link]) - #164188 (Suggest adding lifetime for `dyn Trait` in return type) - #164345 (fix: handle `false` in root contexts) - #164494 (drop ands which are a superset of other ands) - #164785 (delegation: emit error when there is no field for `Self` mapping) - #164799 (Don't use `IntoIterator` in parallel API) - #164871 (Refactor call argument codegen) - #164648 (parse inline and rustc_force_inline with same parser) - #164811 (fix: Prevent ICE when comparing EII impl against generic declaration) - #164900 (make tool_attrs method to retrieve tool attributes.) - #164993 (copy_nonoverlapping: dont skip ovelrap check when src is fully uninit) - #164996 (miri: add missing alignment check in write_bytes) - #165012 (Remove Span::eq_ctxt()) - #165013 ([tiny] Add missing backticks around lifetime name) - #165024 (rustdoc-search: rank re-export lower) - #165028 (Update enzyme to fix one bug related to higher-order derivatives)
…uwer Rollup of 21 pull requests Successful merges: - #159580 (Reject cfg on expressions that cannot be safely removed) - #162597 (raise ambiguity error on attribute macro that could be tool attribute) - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs) - #163059 (Recover invalid return type until `{`, `}` or `;`) - #163672 (Use runCodeGen Abstraction for new LLVM) - #164028 (Add a future incompat warning for #[no_link]) - #164188 (Suggest adding lifetime for `dyn Trait` in return type) - #164345 (fix: handle `false` in root contexts) - #164494 (drop ands which are a superset of other ands) - #164785 (delegation: emit error when there is no field for `Self` mapping) - #164799 (Don't use `IntoIterator` in parallel API) - #164871 (Refactor call argument codegen) - #164648 (parse inline and rustc_force_inline with same parser) - #164811 (fix: Prevent ICE when comparing EII impl against generic declaration) - #164900 (make tool_attrs method to retrieve tool attributes.) - #164993 (copy_nonoverlapping: dont skip ovelrap check when src is fully uninit) - #164996 (miri: add missing alignment check in write_bytes) - #165012 (Remove Span::eq_ctxt()) - #165013 ([tiny] Add missing backticks around lifetime name) - #165024 (rustdoc-search: rank re-export lower) - #165028 (Update enzyme to fix one bug related to higher-order derivatives)
…uwer Rollup of 21 pull requests Successful merges: - #159580 (Reject cfg on expressions that cannot be safely removed) - #162597 (raise ambiguity error on attribute macro that could be tool attribute) - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs) - #163059 (Recover invalid return type until `{`, `}` or `;`) - #163672 (Use runCodeGen Abstraction for new LLVM) - #164028 (Add a future incompat warning for #[no_link]) - #164188 (Suggest adding lifetime for `dyn Trait` in return type) - #164345 (fix: handle `false` in root contexts) - #164494 (drop ands which are a superset of other ands) - #164785 (delegation: emit error when there is no field for `Self` mapping) - #164799 (Don't use `IntoIterator` in parallel API) - #164871 (Refactor call argument codegen) - #164648 (parse inline and rustc_force_inline with same parser) - #164811 (fix: Prevent ICE when comparing EII impl against generic declaration) - #164900 (make tool_attrs method to retrieve tool attributes.) - #164993 (copy_nonoverlapping: dont skip ovelrap check when src is fully uninit) - #164996 (miri: add missing alignment check in write_bytes) - #165012 (Remove Span::eq_ctxt()) - #165013 ([tiny] Add missing backticks around lifetime name) - #165024 (rustdoc-search: rank re-export lower) - #165028 (Update enzyme to fix one bug related to higher-order derivatives)
Rollup merge of #162597 - mejrs:ambiguity, r=petrochenkov raise ambiguity error on attribute macro that could be tool attribute See #162597 (comment) for clean crater run; the errors are unrelated/spurious. We need some sort of ambiguity error in other to implement the [register tool rfc](https://rust-lang.github.io/rfcs/3808-register-tool.html#fixing-name-resolution-errors): > #### Fixing name resolution errors > >Note that `register_tool` changes name resolution, and may give errors if you have a crate named `some_tool`. The compiler will suggest ways to fix the new errors. > >If a tool name conflicts with a crate name, you can disambiguate the crate with `::some_tool`: >```rust >#![register_tool(some_tool)] >extern crate some_tool; > >#[some_tool::attribute] //~ ERROR: is this the tool or a proc-macro? >fn bar() { > // ... >} > >#[::some_tool::attribute] // OK: This is the proc-macro defined in the crate. >fn foo() { > // ... >} >``` >However, if you want to go on to use a tool attribute, >you must rename the crate so it doesn't conflict: >```rust >#![register_tool(some_tool)] >extern crate some_tool as my_library; > >#[some_tool::attribute] // OK: This is the attribute specified by the tool. >fn bar() { > // ... >} >``` >Alternatively, if you only want to use lints, you can use `register_lint_tool` instead of `register_tool`, which will avoid resolution errors. > >Overlaps like this are expected to be rare in practice. This PR implements the ambiguity error (**not** the "leading `::` to disambiguate" part). This is a breaking change if: - someone has a crate or module named diagnostic|miri|rust_analyzer|clippy|rustfmt and exports an attribute macro from it - it is then used it as `#[(diagnostic|miri|rust_analyzer|clippy|rustfmt)::attr_macro]` (rather than `use module_or_crate::attr_macro; #[attr_macro]`) - the same applies for tools registered with `register_tool`, but that's unstable. See #158146 for context. This is a simpler version of that PR. This does not implement unconditionally resolving these as tool attributes but does reserve the ability to do so. This would allow things like this to compile: ```rust mod rustfmt {} #[rustfmt::skip] fn main() {} ``` and see also #98291 for a case where it would be nice to assume e.g. `#[rustfmt::skip]` is actually a tool attribute and thus inert.
View all comments
See #162597 (comment) for clean crater run; the errors are unrelated/spurious.
We need some sort of ambiguity error in other to implement the register tool rfc:
This PR implements the ambiguity error (not the "leading
::to disambiguate" part).This is a breaking change if:
#[(diagnostic|miri|rust_analyzer|clippy|rustfmt)::attr_macro](rather thanuse module_or_crate::attr_macro; #[attr_macro])register_tool, but that's unstable.See #158146 for context. This is a simpler version of that PR.
This does not implement unconditionally resolving these as tool attributes but does reserve the ability to do so. This would allow things like this to compile:
and see also #98291 for a case where it would be nice to assume e.g.
#[rustfmt::skip]is actually a tool attribute and thus inert.