[
  {
    "path": ".github/FUNDING.yml",
    "content": "github: dtolnay\n"
  },
  {
    "path": ".github/workflows/ci.yml",
    "content": "name: CI\n\non:\n  push:\n  pull_request:\n  workflow_dispatch:\n  schedule: [cron: \"40 1 * * *\"]\n\npermissions:\n  contents: read\n\nenv:\n  RUSTFLAGS: -Dwarnings\n\njobs:\n  pre_ci:\n    uses: dtolnay/.github/.github/workflows/pre_ci.yml@master\n\n  test:\n    name: Rust ${{matrix.rust}}\n    needs: pre_ci\n    if: needs.pre_ci.outputs.continue\n    runs-on: ubuntu-latest\n    strategy:\n      fail-fast: false\n      matrix:\n        rust: [nightly, beta, stable, 1.85.0, 1.71.0]\n    timeout-minutes: 45\n    steps:\n      - uses: actions/checkout@v6\n      - uses: dtolnay/rust-toolchain@master\n        with:\n          toolchain: ${{matrix.rust}}\n      - name: Enable type layout randomization\n        run: echo RUSTFLAGS=${RUSTFLAGS}\\ -Zrandomize-layout >> $GITHUB_ENV\n        if: matrix.rust == 'nightly'\n      - run: cargo check\n      - run: cargo test\n        if: matrix.rust != '1.71.0'\n      - uses: actions/upload-artifact@v6\n        if: matrix.rust == 'nightly' && always()\n        with:\n          name: Cargo.lock\n          path: Cargo.lock\n        continue-on-error: true\n\n  minimal:\n    name: Minimal versions\n    needs: pre_ci\n    if: needs.pre_ci.outputs.continue\n    runs-on: ubuntu-latest\n    timeout-minutes: 45\n    steps:\n      - uses: actions/checkout@v6\n      - uses: dtolnay/rust-toolchain@nightly\n      - run: cargo generate-lockfile -Z minimal-versions\n      - run: cargo check --locked\n\n  doc:\n    name: Documentation\n    needs: pre_ci\n    if: needs.pre_ci.outputs.continue\n    runs-on: ubuntu-latest\n    timeout-minutes: 45\n    env:\n      RUSTDOCFLAGS: -Dwarnings\n    steps:\n      - uses: actions/checkout@v6\n      - uses: dtolnay/rust-toolchain@nightly\n      - uses: dtolnay/install@cargo-docs-rs\n      - run: cargo docs-rs\n\n  clippy:\n    name: Clippy\n    runs-on: ubuntu-latest\n    if: github.event_name != 'pull_request'\n    timeout-minutes: 45\n    steps:\n      - uses: actions/checkout@v6\n      - uses: dtolnay/rust-toolchain@clippy\n      - run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic\n\n  miri:\n    name: Miri\n    needs: pre_ci\n    if: needs.pre_ci.outputs.continue\n    runs-on: ubuntu-latest\n    timeout-minutes: 45\n    steps:\n      - uses: actions/checkout@v6\n      - uses: dtolnay/rust-toolchain@miri\n      - run: cargo miri setup\n      - run: cargo miri test\n        env:\n          MIRIFLAGS: -Zmiri-strict-provenance\n\n  outdated:\n    name: Outdated\n    runs-on: ubuntu-latest\n    if: github.event_name != 'pull_request'\n    timeout-minutes: 45\n    steps:\n      - uses: actions/checkout@v6\n      - uses: dtolnay/rust-toolchain@stable\n      - uses: dtolnay/install@cargo-outdated\n      - run: cargo outdated --workspace --exit-code 1\n"
  },
  {
    "path": ".gitignore",
    "content": "/target/\n/Cargo.lock\n"
  },
  {
    "path": "Cargo.toml",
    "content": "[package]\nname = \"inherent\"\nversion = \"1.0.13\"\nauthors = [\"David Tolnay <dtolnay@gmail.com>\"]\ncategories = [\"rust-patterns\", \"no-std\", \"no-std::no-alloc\"]\ndescription = \"Make trait methods callable without the trait in scope\"\ndocumentation = \"https://docs.rs/inherent\"\nedition = \"2021\"\nlicense = \"MIT OR Apache-2.0\"\nrepository = \"https://github.com/dtolnay/inherent\"\nrust-version = \"1.71\"\n\n[lib]\nproc-macro = true\n\n[dependencies]\nproc-macro2 = \"1.0.74\"\nquote = \"1.0.35\"\nsyn = { version = \"2.0.46\", features = [\"full\"] }\n\n[dev-dependencies]\nrustversion = \"1.0.13\"\ntrybuild = { version = \"1.0.108\", features = [\"diff\"] }\n\n[package.metadata.docs.rs]\ntargets = [\"x86_64-unknown-linux-gnu\"]\nrustdoc-args = [\n    \"--generate-link-to-definition\",\n    \"--generate-macro-expansion\",\n    \"--extern-html-root-url=core=https://doc.rust-lang.org\",\n    \"--extern-html-root-url=alloc=https://doc.rust-lang.org\",\n    \"--extern-html-root-url=std=https://doc.rust-lang.org\",\n    \"--extern-html-root-url=proc_macro=https://doc.rust-lang.org\",\n]\n"
  },
  {
    "path": "LICENSE-APACHE",
    "content": "                              Apache License\n                        Version 2.0, January 2004\n                     http://www.apache.org/licenses/\n\nTERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n1. Definitions.\n\n   \"License\" shall mean the terms and conditions for use, reproduction,\n   and distribution as defined by Sections 1 through 9 of this document.\n\n   \"Licensor\" shall mean the copyright owner or entity authorized by\n   the copyright owner that is granting the License.\n\n   \"Legal Entity\" shall mean the union of the acting entity and all\n   other entities that control, are controlled by, or are under common\n   control with that entity. For the purposes of this definition,\n   \"control\" means (i) the power, direct or indirect, to cause the\n   direction or management of such entity, whether by contract or\n   otherwise, or (ii) ownership of fifty percent (50%) or more of the\n   outstanding shares, or (iii) beneficial ownership of such entity.\n\n   \"You\" (or \"Your\") shall mean an individual or Legal Entity\n   exercising permissions granted by this License.\n\n   \"Source\" form shall mean the preferred form for making modifications,\n   including but not limited to software source code, documentation\n   source, and configuration files.\n\n   \"Object\" form shall mean any form resulting from mechanical\n   transformation or translation of a Source form, including but\n   not limited to compiled object code, generated documentation,\n   and conversions to other media types.\n\n   \"Work\" shall mean the work of authorship, whether in Source or\n   Object form, made available under the License, as indicated by a\n   copyright notice that is included in or attached to the work\n   (an example is provided in the Appendix below).\n\n   \"Derivative Works\" shall mean any work, whether in Source or Object\n   form, that is based on (or derived from) the Work and for which the\n   editorial revisions, annotations, elaborations, or other modifications\n   represent, as a whole, an original work of authorship. For the purposes\n   of this License, Derivative Works shall not include works that remain\n   separable from, or merely link (or bind by name) to the interfaces of,\n   the Work and Derivative Works thereof.\n\n   \"Contribution\" shall mean any work of authorship, including\n   the original version of the Work and any modifications or additions\n   to that Work or Derivative Works thereof, that is intentionally\n   submitted to Licensor for inclusion in the Work by the copyright owner\n   or by an individual or Legal Entity authorized to submit on behalf of\n   the copyright owner. For the purposes of this definition, \"submitted\"\n   means any form of electronic, verbal, or written communication sent\n   to the Licensor or its representatives, including but not limited to\n   communication on electronic mailing lists, source code control systems,\n   and issue tracking systems that are managed by, or on behalf of, the\n   Licensor for the purpose of discussing and improving the Work, but\n   excluding communication that is conspicuously marked or otherwise\n   designated in writing by the copyright owner as \"Not a Contribution.\"\n\n   \"Contributor\" shall mean Licensor and any individual or Legal Entity\n   on behalf of whom a Contribution has been received by Licensor and\n   subsequently incorporated within the Work.\n\n2. Grant of Copyright License. Subject to the terms and conditions of\n   this License, each Contributor hereby grants to You a perpetual,\n   worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n   copyright license to reproduce, prepare Derivative Works of,\n   publicly display, publicly perform, sublicense, and distribute the\n   Work and such Derivative Works in Source or Object form.\n\n3. Grant of Patent License. Subject to the terms and conditions of\n   this License, each Contributor hereby grants to You a perpetual,\n   worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n   (except as stated in this section) patent license to make, have made,\n   use, offer to sell, sell, import, and otherwise transfer the Work,\n   where such license applies only to those patent claims licensable\n   by such Contributor that are necessarily infringed by their\n   Contribution(s) alone or by combination of their Contribution(s)\n   with the Work to which such Contribution(s) was submitted. If You\n   institute patent litigation against any entity (including a\n   cross-claim or counterclaim in a lawsuit) alleging that the Work\n   or a Contribution incorporated within the Work constitutes direct\n   or contributory patent infringement, then any patent licenses\n   granted to You under this License for that Work shall terminate\n   as of the date such litigation is filed.\n\n4. Redistribution. You may reproduce and distribute copies of the\n   Work or Derivative Works thereof in any medium, with or without\n   modifications, and in Source or Object form, provided that You\n   meet the following conditions:\n\n   (a) You must give any other recipients of the Work or\n       Derivative Works a copy of this License; and\n\n   (b) You must cause any modified files to carry prominent notices\n       stating that You changed the files; and\n\n   (c) You must retain, in the Source form of any Derivative Works\n       that You distribute, all copyright, patent, trademark, and\n       attribution notices from the Source form of the Work,\n       excluding those notices that do not pertain to any part of\n       the Derivative Works; and\n\n   (d) If the Work includes a \"NOTICE\" text file as part of its\n       distribution, then any Derivative Works that You distribute must\n       include a readable copy of the attribution notices contained\n       within such NOTICE file, excluding those notices that do not\n       pertain to any part of the Derivative Works, in at least one\n       of the following places: within a NOTICE text file distributed\n       as part of the Derivative Works; within the Source form or\n       documentation, if provided along with the Derivative Works; or,\n       within a display generated by the Derivative Works, if and\n       wherever such third-party notices normally appear. The contents\n       of the NOTICE file are for informational purposes only and\n       do not modify the License. You may add Your own attribution\n       notices within Derivative Works that You distribute, alongside\n       or as an addendum to the NOTICE text from the Work, provided\n       that such additional attribution notices cannot be construed\n       as modifying the License.\n\n   You may add Your own copyright statement to Your modifications and\n   may provide additional or different license terms and conditions\n   for use, reproduction, or distribution of Your modifications, or\n   for any such Derivative Works as a whole, provided Your use,\n   reproduction, and distribution of the Work otherwise complies with\n   the conditions stated in this License.\n\n5. Submission of Contributions. Unless You explicitly state otherwise,\n   any Contribution intentionally submitted for inclusion in the Work\n   by You to the Licensor shall be under the terms and conditions of\n   this License, without any additional terms or conditions.\n   Notwithstanding the above, nothing herein shall supersede or modify\n   the terms of any separate license agreement you may have executed\n   with Licensor regarding such Contributions.\n\n6. Trademarks. This License does not grant permission to use the trade\n   names, trademarks, service marks, or product names of the Licensor,\n   except as required for reasonable and customary use in describing the\n   origin of the Work and reproducing the content of the NOTICE file.\n\n7. Disclaimer of Warranty. Unless required by applicable law or\n   agreed to in writing, Licensor provides the Work (and each\n   Contributor provides its Contributions) on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n   implied, including, without limitation, any warranties or conditions\n   of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n   PARTICULAR PURPOSE. You are solely responsible for determining the\n   appropriateness of using or redistributing the Work and assume any\n   risks associated with Your exercise of permissions under this License.\n\n8. Limitation of Liability. In no event and under no legal theory,\n   whether in tort (including negligence), contract, or otherwise,\n   unless required by applicable law (such as deliberate and grossly\n   negligent acts) or agreed to in writing, shall any Contributor be\n   liable to You for damages, including any direct, indirect, special,\n   incidental, or consequential damages of any character arising as a\n   result of this License or out of the use or inability to use the\n   Work (including but not limited to damages for loss of goodwill,\n   work stoppage, computer failure or malfunction, or any and all\n   other commercial damages or losses), even if such Contributor\n   has been advised of the possibility of such damages.\n\n9. Accepting Warranty or Additional Liability. While redistributing\n   the Work or Derivative Works thereof, You may choose to offer,\n   and charge a fee for, acceptance of support, warranty, indemnity,\n   or other liability obligations and/or rights consistent with this\n   License. However, in accepting such obligations, You may act only\n   on Your own behalf and on Your sole responsibility, not on behalf\n   of any other Contributor, and only if You agree to indemnify,\n   defend, and hold each Contributor harmless for any liability\n   incurred by, or claims asserted against, such Contributor by reason\n   of your accepting any such warranty or additional liability.\n\nEND OF TERMS AND CONDITIONS\n"
  },
  {
    "path": "LICENSE-MIT",
    "content": "Permission is hereby granted, free of charge, to any\nperson obtaining a copy of this software and associated\ndocumentation files (the \"Software\"), to deal in the\nSoftware without restriction, including without\nlimitation the rights to use, copy, modify, merge,\npublish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software\nis furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice\nshall be included in all copies or substantial portions\nof the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF\nANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED\nTO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\nPARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\nSHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR\nIN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "\\#\\[inherent\\]\n==============\n\n[<img alt=\"github\" src=\"https://img.shields.io/badge/github-dtolnay/inherent-8da0cb?style=for-the-badge&labelColor=555555&logo=github\" height=\"20\">](https://github.com/dtolnay/inherent)\n[<img alt=\"crates.io\" src=\"https://img.shields.io/crates/v/inherent.svg?style=for-the-badge&color=fc8d62&logo=rust\" height=\"20\">](https://crates.io/crates/inherent)\n[<img alt=\"docs.rs\" src=\"https://img.shields.io/badge/docs.rs-inherent-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs\" height=\"20\">](https://docs.rs/inherent)\n[<img alt=\"build status\" src=\"https://img.shields.io/github/actions/workflow/status/dtolnay/inherent/ci.yml?branch=master&style=for-the-badge\" height=\"20\">](https://github.com/dtolnay/inherent/actions?query=branch%3Amaster)\n\nThis crate provides an attribute macro to make trait methods callable without\nthe trait in scope.\n\n```toml\n[dependencies]\ninherent = \"1.0\"\n```\n\n## Example\n\n```rust\nmod types {\n    use inherent::inherent;\n\n    trait Trait {\n        fn f(self);\n    }\n\n    pub struct Struct;\n\n    #[inherent]\n    impl Trait for Struct {\n        pub fn f(self) {}\n    }\n}\n\nfn main() {\n    // types::Trait is not in scope, but method can be called.\n    types::Struct.f();\n}\n```\n\nWithout the `inherent` macro on the trait impl, this would have failed with the\nfollowing error:\n\n```console\nerror[E0599]: no method named `f` found for type `types::Struct` in the current scope\n  --> src/main.rs:18:19\n   |\n8  |     pub struct Struct;\n   |     ------------------ method `f` not found for this\n...\n18 |     types::Struct.f();\n   |                   ^\n   |\n   = help: items from traits can only be used if the trait is implemented and in scope\n   = note: the following trait defines an item `f`, perhaps you need to implement it:\n           candidate #1: `types::Trait`\n```\n\nThe `inherent` macro expands to inherent methods on the `Self` type of the trait\nimpl that forward to the trait methods. In the case above, the generated code\nwould be:\n\n```rust\nimpl Struct {\n    pub fn f(self) {\n        <Self as Trait>::f(self)\n    }\n}\n```\n\n<br>\n\n#### License\n\n<sup>\nLicensed under either of <a href=\"LICENSE-APACHE\">Apache License, Version\n2.0</a> or <a href=\"LICENSE-MIT\">MIT license</a> at your option.\n</sup>\n\n<br>\n\n<sub>\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in this crate by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n</sub>\n"
  },
  {
    "path": "src/expand.rs",
    "content": "use crate::parse::TraitImpl;\nuse crate::verbatim::VerbatimFn;\nuse proc_macro2::{Span, TokenStream};\nuse quote::{quote, quote_spanned};\nuse syn::{Attribute, FnArg, Ident, ImplItem, Pat, Path, Signature, Visibility};\n\npub fn inherent(mut input: TraitImpl) -> TokenStream {\n    let impl_token = &input.impl_token;\n    let generics = &input.generics;\n    let where_clause = &input.generics.where_clause;\n    let trait_ = &input.trait_;\n    let ty = &input.self_ty;\n\n    let fwd_methods: Vec<_> = input\n        .items\n        .iter()\n        .filter_map(|item| match item {\n            ImplItem::Fn(method) => Some(fwd_method(\n                trait_,\n                &method.attrs,\n                &method.vis,\n                &method.sig,\n                method.block.brace_token.span.join(),\n            )),\n            ImplItem::Verbatim(tokens) => {\n                if let Ok(method) = syn::parse2::<VerbatimFn>(tokens.clone()) {\n                    Some(fwd_method(\n                        trait_,\n                        &method.attrs,\n                        &method.vis,\n                        &method.sig,\n                        method.semi_token.span,\n                    ))\n                } else {\n                    None\n                }\n            }\n            _ => None,\n        })\n        .collect();\n\n    input.items = input\n        .items\n        .into_iter()\n        .filter_map(|item| match item {\n            ImplItem::Fn(mut method) => {\n                method.vis = Visibility::Inherited;\n                Some(ImplItem::Fn(method))\n            }\n            ImplItem::Verbatim(tokens) => {\n                if syn::parse2::<VerbatimFn>(tokens.clone()).is_ok() {\n                    None\n                } else {\n                    Some(ImplItem::Verbatim(tokens))\n                }\n            }\n            item => Some(item),\n        })\n        .collect();\n\n    let body = quote_spanned!(input.brace_token.span=> { #(#fwd_methods)* });\n\n    quote! {\n        #impl_token #generics #ty #where_clause #body\n\n        #input\n    }\n}\n\nfn fwd_method(\n    trait_: &Path,\n    attrs: &[Attribute],\n    vis: &Visibility,\n    sig: &Signature,\n    body_span: Span,\n) -> TokenStream {\n    let constness = &sig.constness;\n    let asyncness = &sig.asyncness;\n    let unsafety = &sig.unsafety;\n    let abi = &sig.abi;\n    let fn_token = sig.fn_token;\n    let ident = &sig.ident;\n    let generics = &sig.generics;\n    let output = &sig.output;\n    let where_clause = &sig.generics.where_clause;\n\n    let (arg_pat, arg_val): (Vec<_>, Vec<_>) = sig\n        .inputs\n        .pairs()\n        .enumerate()\n        .map(|(i, pair)| {\n            let (input, comma_token) = pair.into_tuple();\n            match input {\n                FnArg::Receiver(receiver) => {\n                    let self_token = receiver.self_token;\n                    if receiver.reference.is_some() {\n                        (quote!(#receiver #comma_token), quote!(#self_token))\n                    } else {\n                        (quote!(#self_token #comma_token), quote!(#self_token))\n                    }\n                }\n                FnArg::Typed(arg) => {\n                    let var = match arg.pat.as_ref() {\n                        Pat::Ident(pat) => pat.ident.clone(),\n                        _ => Ident::new(&format!(\"__arg{}\", i), Span::call_site()),\n                    };\n                    let colon_token = arg.colon_token;\n                    let ty = &arg.ty;\n                    (quote!(#var #colon_token #ty #comma_token), quote!(#var))\n                }\n            }\n        })\n        .unzip();\n\n    let types = generics.type_params().map(|param| &param.ident);\n    let wait = asyncness.map(|_| quote!(.await));\n    let body = quote!(<Self as #trait_>::#ident::<#(#types,)*>(#(#arg_val,)*) #wait);\n    let block = quote_spanned!(body_span=> { #body });\n    let args = quote_spanned!(sig.paren_token.span=> (#(#arg_pat)*));\n\n    let has_doc = attrs.iter().any(|attr| attr.path().is_ident(\"doc\"));\n    let default_doc = if has_doc {\n        None\n    } else {\n        let mut link = String::new();\n        for segment in &trait_.segments {\n            link += &segment.ident.to_string();\n            link += \"::\";\n        }\n        let msg = format!(\"See [`{}{}`]\", link, ident);\n        Some(quote!(#[doc = #msg]))\n    };\n\n    quote! {\n        #(#attrs)*\n        #default_doc\n        #vis #constness #asyncness #unsafety #abi #fn_token #ident #generics #args #output #where_clause #block\n    }\n}\n"
  },
  {
    "path": "src/lib.rs",
    "content": "//! [![github]](https://github.com/dtolnay/inherent)&ensp;[![crates-io]](https://crates.io/crates/inherent)&ensp;[![docs-rs]](https://docs.rs/inherent)\n//!\n//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github\n//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust\n//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs\n//!\n//! <br>\n//!\n//! ##### An attribute macro to make trait methods callable without the trait in scope.\n//!\n//! # Example\n//!\n//! ```rust\n//! mod types {\n//!     use inherent::inherent;\n//!\n//!     trait Trait {\n//!         fn f(self);\n//!     }\n//!\n//!     pub struct Struct;\n//!\n//!     #[inherent]\n//!     impl Trait for Struct {\n//!         pub fn f(self) {}\n//!     }\n//! }\n//!\n//! fn main() {\n//!     // types::Trait is not in scope, but method can be called.\n//!     types::Struct.f();\n//! }\n//! ```\n//!\n//! Without the `inherent` macro on the trait impl, this would have failed with the\n//! following error:\n//!\n//! ```console\n//! error[E0599]: no method named `f` found for type `types::Struct` in the current scope\n//!   --> src/main.rs:18:19\n//!    |\n//! 8  |     pub struct Struct;\n//!    |     ------------------ method `f` not found for this\n//! ...\n//! 18 |     types::Struct.f();\n//!    |                   ^\n//!    |\n//!    = help: items from traits can only be used if the trait is implemented and in scope\n//!    = note: the following trait defines an item `f`, perhaps you need to implement it:\n//!            candidate #1: `types::Trait`\n//! ```\n//!\n//! The `inherent` macro expands to inherent methods on the `Self` type of the trait\n//! impl that forward to the trait methods. In the case above, the generated code\n//! would be:\n//!\n//! ```rust\n//! # trait Trait {\n//! #     fn f(self);\n//! # }\n//! #\n//! # pub struct Struct;\n//! #\n//! # impl Trait for Struct {\n//! #     fn f(self) {}\n//! # }\n//! #\n//! impl Struct {\n//!     pub fn f(self) {\n//!         <Self as Trait>::f(self)\n//!     }\n//! }\n//! ```\n\n#![doc(html_root_url = \"https://docs.rs/inherent/1.0.13\")]\n#![allow(\n    clippy::default_trait_access,\n    clippy::module_name_repetitions,\n    clippy::needless_doctest_main,\n    clippy::needless_pass_by_value,\n    clippy::uninlined_format_args\n)]\n\nextern crate proc_macro;\n\nmod expand;\nmod parse;\nmod verbatim;\n\nuse proc_macro::TokenStream;\nuse syn::parse::Nothing;\nuse syn::parse_macro_input;\n\nuse crate::parse::TraitImpl;\n\n#[proc_macro_attribute]\npub fn inherent(args: TokenStream, input: TokenStream) -> TokenStream {\n    parse_macro_input!(args as Nothing);\n    let input = parse_macro_input!(input as TraitImpl);\n    expand::inherent(input).into()\n}\n"
  },
  {
    "path": "src/parse.rs",
    "content": "use proc_macro2::{Span, TokenStream};\nuse quote::ToTokens;\nuse syn::parse::{Error, Parse, ParseStream, Result};\nuse syn::token::Brace;\nuse syn::{Attribute, Generics, ImplItem, ItemImpl, Path, Token, Type};\n\n#[derive(Clone)]\npub struct TraitImpl {\n    pub attrs: Vec<Attribute>,\n    pub defaultness: Option<Token![default]>,\n    pub unsafety: Option<Token![unsafe]>,\n    pub impl_token: Token![impl],\n    pub generics: Generics,\n    pub trait_: Path,\n    pub for_token: Token![for],\n    pub self_ty: Type,\n    pub brace_token: Brace,\n    pub items: Vec<ImplItem>,\n}\n\nimpl Parse for TraitImpl {\n    fn parse(input: ParseStream) -> Result<Self> {\n        let imp: ItemImpl = input.parse()?;\n\n        let Some((_bang_token, trait_, for_token)) = imp.trait_ else {\n            return Err(Error::new(\n                Span::call_site(),\n                \"must be placed on a trait impl\",\n            ));\n        };\n\n        Ok(TraitImpl {\n            attrs: imp.attrs,\n            defaultness: imp.defaultness,\n            unsafety: imp.unsafety,\n            impl_token: imp.impl_token,\n            generics: imp.generics,\n            trait_,\n            for_token,\n            self_ty: *imp.self_ty,\n            brace_token: imp.brace_token,\n            items: imp.items,\n        })\n    }\n}\n\nimpl ToTokens for TraitImpl {\n    fn to_tokens(&self, tokens: &mut TokenStream) {\n        let imp = self.clone();\n\n        ItemImpl::to_tokens(\n            &ItemImpl {\n                attrs: imp.attrs,\n                defaultness: imp.defaultness,\n                unsafety: imp.unsafety,\n                impl_token: imp.impl_token,\n                generics: imp.generics,\n                trait_: Some((None, imp.trait_, imp.for_token)),\n                self_ty: Box::new(imp.self_ty),\n                brace_token: imp.brace_token,\n                items: imp.items,\n            },\n            tokens,\n        );\n    }\n}\n"
  },
  {
    "path": "src/verbatim.rs",
    "content": "use proc_macro2::TokenStream;\nuse quote::{ToTokens, TokenStreamExt};\nuse syn::parse::{Parse, ParseStream, Result};\nuse syn::{Attribute, Signature, Token, Visibility};\n\npub struct VerbatimFn {\n    pub attrs: Vec<Attribute>,\n    pub vis: Visibility,\n    pub defaultness: Option<Token![default]>,\n    pub sig: Signature,\n    pub semi_token: Token![;],\n}\n\nimpl Parse for VerbatimFn {\n    fn parse(input: ParseStream) -> Result<Self> {\n        Ok(VerbatimFn {\n            attrs: input.call(Attribute::parse_outer)?,\n            vis: input.parse()?,\n            defaultness: input.parse()?,\n            sig: input.parse()?,\n            semi_token: input.parse()?,\n        })\n    }\n}\n\nimpl ToTokens for VerbatimFn {\n    fn to_tokens(&self, tokens: &mut TokenStream) {\n        tokens.append_all(&self.attrs);\n        self.vis.to_tokens(tokens);\n        self.defaultness.to_tokens(tokens);\n        self.sig.to_tokens(tokens);\n        self.semi_token.to_tokens(tokens);\n    }\n}\n"
  },
  {
    "path": "tests/compiletest.rs",
    "content": "#[rustversion::attr(not(nightly), ignore = \"requires nightly\")]\n#[cfg_attr(miri, ignore = \"incompatible with miri\")]\n#[test]\nfn ui() {\n    let t = trybuild::TestCases::new();\n    t.compile_fail(\"tests/ui/*.rs\");\n}\n"
  },
  {
    "path": "tests/test.rs",
    "content": "mod types {\n    use inherent::inherent;\n\n    trait Trait {\n        fn f<T: ?Sized>(self);\n        // A default method\n        fn g(&self) {}\n\n        #[rustversion::since(1.75)]\n        async fn a(&self);\n    }\n\n    pub struct Struct;\n\n    #[inherent]\n    impl Trait for Struct {\n        pub fn f<T: ?Sized>(self) {}\n        pub fn g(&self);\n\n        #[rustversion::since(1.75)]\n        pub async fn a(&self) {}\n    }\n}\n\n#[test]\nfn test() {\n    // types::Trait is not in scope.\n    let s = types::Struct;\n    s.g();\n    s.f::<str>();\n}\n\n#[rustversion::since(1.75)]\n#[test]\nfn test_async() {\n    fn assert_future<T: std::future::Future<Output = ()>>(_: T) {}\n\n    let s = types::Struct;\n    assert_future(s.a());\n}\n"
  },
  {
    "path": "tests/ui/associated-type.rs",
    "content": "use inherent::inherent;\n\npub trait Trait {\n    type Assoc;\n    fn f() -> Self::Assoc;\n}\n\npub struct Struct;\n\n#[inherent]\nimpl Trait for Struct {\n    type Assoc = ();\n\n    // TODO: https://github.com/dtolnay/inherent/issues/15\n    fn f() -> Self::Assoc {}\n}\n\nfn main() {}\n"
  },
  {
    "path": "tests/ui/associated-type.stderr",
    "content": "error[E0223]: ambiguous associated type\n  --> tests/ui/associated-type.rs:15:15\n   |\n15 |     fn f() -> Self::Assoc {}\n   |               ^^^^^^^^^^^\n   |\nhelp: use fully-qualified syntax\n   |\n15 -     fn f() -> Self::Assoc {}\n15 +     fn f() -> <Struct as Trait>::Assoc {}\n   |\n"
  },
  {
    "path": "tests/ui/blanket-impl.rs",
    "content": "use inherent::inherent;\n\ntrait A {\n    fn a(&self);\n}\n\n#[inherent]\nimpl<T> A for T {\n    fn a(&self) {}\n}\n\nfn main() {}\n"
  },
  {
    "path": "tests/ui/blanket-impl.stderr",
    "content": "error[E0118]: no nominal type found for inherent implementation\n --> tests/ui/blanket-impl.rs:8:1\n  |\n8 | impl<T> A for T {\n  | ^^^^^^^^^^^^^^^ impl requires a nominal type\n  |\n  = note: either implement a trait on it or create a newtype to wrap it instead\n"
  },
  {
    "path": "tests/ui/not-trait-impl.rs",
    "content": "use inherent::inherent;\n\nstruct Struct;\n\n#[inherent]\nimpl Struct {\n    fn f() {}\n}\n\nfn main() {}\n"
  },
  {
    "path": "tests/ui/not-trait-impl.stderr",
    "content": "error: must be placed on a trait impl\n --> tests/ui/not-trait-impl.rs:5:1\n  |\n5 | #[inherent]\n  | ^^^^^^^^^^^\n  |\n  = note: this error originates in the attribute macro `inherent` (in Nightly builds, run with -Z macro-backtrace for more info)\n"
  },
  {
    "path": "tests/ui/not-visible.rs",
    "content": "mod types {\n    use inherent::inherent;\n\n    trait Trait {\n        fn f();\n    }\n\n    pub struct Struct;\n\n    #[inherent]\n    impl Trait for Struct {\n        fn f() {}\n    }\n}\n\nfn main() {\n    types::Struct::f();\n}\n"
  },
  {
    "path": "tests/ui/not-visible.stderr",
    "content": "error[E0624]: associated function `f` is private\n  --> tests/ui/not-visible.rs:17:20\n   |\n12 |         fn f() {}\n   |         ------ private associated function defined here\n...\n17 |     types::Struct::f();\n   |                    ^ private associated function\n"
  }
]