Update linkme and linkme-impl to 0.3.31
Test: treehugger
Change-Id: I1f281efe597c15689def7f66a464f68217acbc88
diff --git a/crates/linkme-impl/.android-checksum.json b/crates/linkme-impl/.android-checksum.json
index bc78619..d5f8799 100644
--- a/crates/linkme-impl/.android-checksum.json
+++ b/crates/linkme-impl/.android-checksum.json
@@ -1 +1 @@
-{"package":null,"files":{".cargo-checksum.json":"fb30a2f02145a37703657e6647d875b303ec9c8cdae68bdb59ac9d7f3aec1fbc","Android.bp":"1e59cf36557e1bc36e4d239a3bc3dd47be9bd3cc6b4a7d9a1a51bef3fed8b4c4","Cargo.toml":"e510fa36ebc3163f351b6a56a50bcf3bc1bc6661b0c6af73a63a10e38178d15b","LICENSE":"50f827348bfd5def2df4f30cb41264072cf9c180bd9ed698437e8d85b2482754","METADATA":"6de1444179c7ca7703f44c28e5e656de1b7ab4c67ac7872673eb5b6178ecb4a3","MODULE_LICENSE_APACHE2":"0d6f8afa3940b7f06bebee651376d43bc8b0d5b437337be2696d30377451e93a","cargo_embargo.json":"aa45a963da01d3f018be316cd5b7646a5b413ce2611c5218f2914d2e8a9efd0e","patches/LICENSE.patch":"09cc706c0a547f25f23300db8ce6766c6c6ba9ab8038791dbec6fc710d76fa47","src/args.rs":"14bc47b5aa39d6dbfe5a1ae918f97de484120a9b0f41b21a95a0b6367dae1b9b","src/attr.rs":"32c11c13f51ef80810b5c742d2a3a3fd4f2e6d55ec47b79f99d87c0c02fe0d2c","src/declaration.rs":"1aa17725d63ecb2775b05d80a5b635df0b0919f959fa4dec242a7ca0bbdea4cb","src/element.rs":"3903faf1f3c6ce32508a7f58617facb6741d8d67635242d083666f24b83a50dd","src/hash.rs":"b5925e872cf52fd508c28d86f98c5ccff420536a94335b7bfd7fe19a4378ffe4","src/lib.rs":"870010296a06f37b6400daf3bb65d3e8038d29f37d1888b3b6a6ebcb54ab7fe4","src/linker.rs":"808eff7cad3a7442581625836c996dfb994aef250b452f1c66581946ba0729c4"}}
\ No newline at end of file
+{"package":null,"files":{".cargo-checksum.json":"747ba7b13a35cd9827a86a5a7932ad2e27397081c82378400592b4eaf5d7bf0a","Android.bp":"bbe3e16f376ab3b6c4812e305ae737f327a06cb7750515aa955cd50b97e44f22","Cargo.toml":"306e83437877ad04598faca66929bf605907f2b98812bcce5207667aebc90936","LICENSE":"50f827348bfd5def2df4f30cb41264072cf9c180bd9ed698437e8d85b2482754","METADATA":"6d4f92154d216770256b80197d9831732382d0ade393c8f94ac0f925ad784bf4","MODULE_LICENSE_APACHE2":"0d6f8afa3940b7f06bebee651376d43bc8b0d5b437337be2696d30377451e93a","build.rs":"f25cd4e235ca45167f433cf6f617b6f2b8e99217621f65b0d7f1dcf60914c36e","cargo_embargo.json":"aa45a963da01d3f018be316cd5b7646a5b413ce2611c5218f2914d2e8a9efd0e","patches/LICENSE.patch":"09cc706c0a547f25f23300db8ce6766c6c6ba9ab8038791dbec6fc710d76fa47","src/args.rs":"14bc47b5aa39d6dbfe5a1ae918f97de484120a9b0f41b21a95a0b6367dae1b9b","src/attr.rs":"32c11c13f51ef80810b5c742d2a3a3fd4f2e6d55ec47b79f99d87c0c02fe0d2c","src/declaration.rs":"64113dc9324b222fc23d6f5c2333b2a656038bbaad5f584cb108356d853bbf29","src/element.rs":"e1073e447c89712d9db61a920a2dd34c74fea222351a7303cc210558fa75faff","src/hash.rs":"b5925e872cf52fd508c28d86f98c5ccff420536a94335b7bfd7fe19a4378ffe4","src/lib.rs":"35c50803a2b28ca1e2322f4e2a8e266d6eafd7e175e102e4cc8f558f085484c5","src/linker.rs":"e0ebf146b8cdbe781ba31f782e9775542e1ba6d5bce5764cb402cca96fbdbfc0","src/ty.rs":"78ca0c477687fb943c7bc2871131e1e7d245cc372038080b91196d03ec3ceacf"}}
\ No newline at end of file
diff --git a/crates/linkme-impl/.cargo-checksum.json b/crates/linkme-impl/.cargo-checksum.json
index 37b0e54..858d97b 100644
--- a/crates/linkme-impl/.cargo-checksum.json
+++ b/crates/linkme-impl/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"b16e64ad2d4bed491cca3a7bfdf4f2103135614678ddef178bfcd217571286d7","src/args.rs":"6844fd8ac6acd440fe2bad0dfc1688dd4c370125e248437f6a12a39c5b76380f","src/attr.rs":"8d86db80a3b97689cfee4227e3133516be87537fea706c4b72699216359c24a9","src/declaration.rs":"635f753351ea4415342bb14d94f5f05aa63867fe4e2538e57498ef2889aa3f74","src/element.rs":"ab34aeb5e2c88db91bf8f76d3c247fd0821326029bf074790a5d41bc0b5cfa27","src/hash.rs":"20a352e24890e36593c7d093fe75fe2aa850d72455c5ec90d6d14d519bf478d6","src/lib.rs":"32bdc6bf1680f2c42878a046e4164ffa068483260e8f4808db213e8983d96e76","src/linker.rs":"304a9ead78526ffc8f304d122ef715a2c484e6cdc7179e27838123b274cf5ec9"},"package":"279a77bf40c85a08513aca203635b96610ebf0e37a92cb0cee76e04da100a426"}
\ No newline at end of file
+{"files":{"Cargo.toml":"a14408e9c5255546249c5300f269794810ea2ed624ed5123bc341b97ef2280a7","build.rs":"ebfc0cf7ad1ddd283dd75d13d171c0fed99ddbda3c758d1306a424802e8d389b","src/args.rs":"6844fd8ac6acd440fe2bad0dfc1688dd4c370125e248437f6a12a39c5b76380f","src/attr.rs":"8d86db80a3b97689cfee4227e3133516be87537fea706c4b72699216359c24a9","src/declaration.rs":"4b476d169263641e36ad92332b29316779f730752b4d18fab38f6604d3bef45f","src/element.rs":"443bd5e8e606b3cca49fee4b2bc170d0836ce85f7d004cb92c25c262ad85207a","src/hash.rs":"20a352e24890e36593c7d093fe75fe2aa850d72455c5ec90d6d14d519bf478d6","src/lib.rs":"e137bd2ae9902998d5b454859795640fa6682786cdb50d79016aa99e4d85651c","src/linker.rs":"ed736994fb23af859341486c924677bc02d0b8cbee041b9f65f331549c35ef86","src/ty.rs":"f40aaf3a35496395382fa356dc45238dbee6e44f2236f64c0e03b3d31e7756a2"},"package":"edbe595006d355eaf9ae11db92707d4338cd2384d16866131cc1afdbdd35d8d9"}
\ No newline at end of file
diff --git a/crates/linkme-impl/Android.bp b/crates/linkme-impl/Android.bp
index 5062cb2..655d36f 100644
--- a/crates/linkme-impl/Android.bp
+++ b/crates/linkme-impl/Android.bp
@@ -17,7 +17,7 @@
name: "liblinkme_impl",
crate_name: "linkme_impl",
cargo_env_compat: true,
- cargo_pkg_version: "0.3.10",
+ cargo_pkg_version: "0.3.31",
crate_root: "src/lib.rs",
edition: "2021",
rustlibs: [
diff --git a/crates/linkme-impl/Cargo.toml b/crates/linkme-impl/Cargo.toml
index 72b23e6..0692d84 100644
--- a/crates/linkme-impl/Cargo.toml
+++ b/crates/linkme-impl/Cargo.toml
@@ -13,27 +13,37 @@
edition = "2021"
rust-version = "1.62"
name = "linkme-impl"
-version = "0.3.10"
+version = "0.3.31"
authors = ["David Tolnay <[email protected]>"]
+build = "build.rs"
+autolib = false
+autobins = false
+autoexamples = false
+autotests = false
+autobenches = false
description = "Implementation detail of the linkme crate"
documentation = "https://docs.rs/linkme"
+readme = false
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/linkme"
[package.metadata.docs.rs]
+rustdoc-args = ["--generate-link-to-definition"]
targets = ["x86_64-unknown-linux-gnu"]
[lib]
+name = "linkme_impl"
+path = "src/lib.rs"
proc-macro = true
[dependencies.proc-macro2]
-version = "1.0.2"
+version = "1.0.74"
[dependencies.quote]
-version = "1.0"
+version = "1.0.35"
[dependencies.syn]
-version = "2.0"
+version = "2.0.46"
[features]
used_linker = []
diff --git a/crates/linkme-impl/METADATA b/crates/linkme-impl/METADATA
index 2b0d17f..b04668d 100644
--- a/crates/linkme-impl/METADATA
+++ b/crates/linkme-impl/METADATA
@@ -1,17 +1,17 @@
name: "linkme-impl"
description: "Implementation detail of the linkme crate"
third_party {
- version: "0.3.10"
+ version: "0.3.31"
license_type: NOTICE
last_upgrade_date {
- year: 2023
- month: 6
- day: 1
+ year: 2025
+ month: 1
+ day: 15
}
homepage: "https://crates.io/crates/linkme-impl"
identifier {
type: "Archive"
- value: "https://static.crates.io/crates/linkme-impl/linkme-impl-0.3.10.crate"
- version: "0.3.10"
+ value: "https://static.crates.io/crates/linkme-impl/linkme-impl-0.3.31.crate"
+ version: "0.3.31"
}
}
diff --git a/crates/linkme-impl/build.rs b/crates/linkme-impl/build.rs
new file mode 100644
index 0000000..e6f6d2a
--- /dev/null
+++ b/crates/linkme-impl/build.rs
@@ -0,0 +1,36 @@
+use std::env;
+use std::process::Command;
+use std::str;
+
+fn main() {
+ println!("cargo:rerun-if-changed=build.rs");
+
+ let rustc = match rustc_minor_version() {
+ Some(rustc) => rustc,
+ None => return,
+ };
+
+ if rustc >= 80 {
+ println!("cargo:rustc-check-cfg=cfg(exhaustive)");
+ println!("cargo:rustc-check-cfg=cfg(no_unsafe_attributes)");
+ println!("cargo:rustc-check-cfg=cfg(no_unsafe_extern_blocks)");
+ }
+
+ if rustc < 82 {
+ // https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html#unsafe-attributes
+ println!("cargo:rustc-cfg=no_unsafe_attributes");
+ // https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html#safe-items-with-unsafe-extern
+ println!("cargo:rustc-cfg=no_unsafe_extern_blocks");
+ }
+}
+
+fn rustc_minor_version() -> Option<u32> {
+ let rustc = env::var_os("RUSTC").unwrap();
+ let output = Command::new(rustc).arg("--version").output().ok()?;
+ let version = str::from_utf8(&output.stdout).ok()?;
+ let mut pieces = version.split('.');
+ if pieces.next() != Some("rustc 1") {
+ return None;
+ }
+ pieces.next()?.parse().ok()
+}
diff --git a/crates/linkme-impl/src/declaration.rs b/crates/linkme-impl/src/declaration.rs
index 4d1d9e3..1c12c3b 100644
--- a/crates/linkme-impl/src/declaration.rs
+++ b/crates/linkme-impl/src/declaration.rs
@@ -1,11 +1,8 @@
-use crate::{attr, linker};
+use crate::{attr, linker, ty};
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::parse::{Parse, ParseStream, Result};
-use syn::{
- bracketed, Attribute, Error, GenericArgument, Ident, Lifetime, PathArguments, Token, Type,
- Visibility,
-};
+use syn::{bracketed, Attribute, Error, Ident, Token, Type, Visibility};
struct Declaration {
attrs: Vec<Attribute>,
@@ -29,11 +26,13 @@
let ident: Ident = input.parse()?;
input.parse::<Token![:]>()?;
let ty: Type = input.parse()?;
- input.parse::<Token![=]>()?;
- let content;
- bracketed!(content in input);
- content.parse::<Token![..]>()?;
+ let eq_token: Option<Token![=]> = input.parse()?;
+ if eq_token.is_some() {
+ let content;
+ bracketed!(content in input);
+ content.parse::<Token![..]>()?;
+ }
input.parse::<Token![;]>()?;
@@ -67,7 +66,7 @@
Err(err) => return err.to_compile_error(),
};
- populate_static_lifetimes(&mut ty);
+ ty::populate_static_lifetimes(&mut ty);
let used = if cfg!(feature = "used_linker") {
quote!(#[used(linker)])
@@ -103,17 +102,34 @@
let illumos_dupcheck_start = illumos_section_start.replacen("linkme", "linkm2", 1);
let illumos_dupcheck_stop = illumos_section_stop.replacen("linkme", "linkm2", 1);
- let freebsd_section = linker::freebsd::section(&ident);
- let freebsd_section_start = linker::freebsd::section_start(&ident);
- let freebsd_section_stop = linker::freebsd::section_stop(&ident);
- let freebsd_dupcheck = freebsd_section.replacen("linkme", "linkm2", 1);
- let freebsd_dupcheck_start = freebsd_section_start.replacen("linkme", "linkm2", 1);
- let freebsd_dupcheck_stop = freebsd_section_stop.replacen("linkme", "linkm2", 1);
+ let bsd_section = linker::bsd::section(&ident);
+ let bsd_section_start = linker::bsd::section_start(&ident);
+ let bsd_section_stop = linker::bsd::section_stop(&ident);
+ let bsd_dupcheck = bsd_section.replacen("linkme", "linkm2", 1);
+ let bsd_dupcheck_start = bsd_section_start.replacen("linkme", "linkm2", 1);
+ let bsd_dupcheck_stop = bsd_section_stop.replacen("linkme", "linkm2", 1);
let call_site = Span::call_site();
let link_section_macro_str = format!("_linkme_macro_{}", ident);
let link_section_macro = Ident::new(&link_section_macro_str, call_site);
+ let unsafe_extern = if cfg!(no_unsafe_extern_blocks) {
+ None
+ } else {
+ Some(Token)
+ };
+
+ let (unsafe_attr, link_section_attr) = if cfg!(no_unsafe_attributes) {
+ // #[cfg_attr(all(), link_section = ...)]
+ (
+ Ident::new("cfg_attr", call_site),
+ quote!(all(), link_section),
+ )
+ } else {
+ // #[unsafe(link_section = ...)]
+ (Ident::new("unsafe", call_site), quote!(link_section))
+ };
+
quote! {
#(#attrs)*
#vis static #ident: #linkme_path::DistributedSlice<#ty> = {
@@ -124,64 +140,76 @@
target_os = "ios",
target_os = "tvos",
target_os = "android",
+ target_os = "fuchsia",
target_os = "illumos",
target_os = "freebsd",
+ target_os = "openbsd",
+ target_os = "psp",
))]
- extern "Rust" {
- #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android"), link_name = #linux_section_start)]
+ #unsafe_extern extern "Rust" {
+ #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android", target_os = "fuchsia", target_os = "psp"), link_name = #linux_section_start)]
#[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos"), link_name = #macho_section_start)]
#[cfg_attr(target_os = "illumos", link_name = #illumos_section_start)]
- #[cfg_attr(target_os = "freebsd", link_name = #freebsd_section_start)]
+ #[cfg_attr(any(target_os = "freebsd", target_os = "openbsd"), link_name = #bsd_section_start)]
static LINKME_START: <#ty as #linkme_path::__private::Slice>::Element;
- #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android"), link_name = #linux_section_stop)]
+ #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android", target_os = "fuchsia", target_os = "psp"), link_name = #linux_section_stop)]
#[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos"), link_name = #macho_section_stop)]
#[cfg_attr(target_os = "illumos", link_name = #illumos_section_stop)]
- #[cfg_attr(target_os = "freebsd", link_name = #freebsd_section_stop)]
+ #[cfg_attr(any(target_os = "freebsd", target_os = "openbsd"), link_name = #bsd_section_stop)]
static LINKME_STOP: <#ty as #linkme_path::__private::Slice>::Element;
- #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android"), link_name = #linux_dupcheck_start)]
+ #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android", target_os = "fuchsia", target_os = "psp"), link_name = #linux_dupcheck_start)]
#[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos"), link_name = #macho_dupcheck_start)]
#[cfg_attr(target_os = "illumos", link_name = #illumos_dupcheck_start)]
- #[cfg_attr(target_os = "freebsd", link_name = #freebsd_dupcheck_start)]
+ #[cfg_attr(any(target_os = "freebsd", target_os = "openbsd"), link_name = #bsd_dupcheck_start)]
static DUPCHECK_START: #linkme_path::__private::usize;
- #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android"), link_name = #linux_dupcheck_stop)]
+ #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android", target_os = "fuchsia", target_os = "psp"), link_name = #linux_dupcheck_stop)]
#[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos"), link_name = #macho_dupcheck_stop)]
#[cfg_attr(target_os = "illumos", link_name = #illumos_dupcheck_stop)]
- #[cfg_attr(target_os = "freebsd", link_name = #freebsd_dupcheck_stop)]
+ #[cfg_attr(any(target_os = "freebsd", target_os = "openbsd"), link_name = #bsd_dupcheck_stop)]
static DUPCHECK_STOP: #linkme_path::__private::usize;
}
- #[cfg(target_os = "windows")]
- #[link_section = #windows_section_start]
+ #[cfg(any(target_os = "uefi", target_os = "windows"))]
+ #[#unsafe_attr(#link_section_attr = #windows_section_start)]
static LINKME_START: [<#ty as #linkme_path::__private::Slice>::Element; 0] = [];
- #[cfg(target_os = "windows")]
- #[link_section = #windows_section_stop]
+ #[cfg(any(target_os = "uefi", target_os = "windows"))]
+ #[#unsafe_attr(#link_section_attr = #windows_section_stop)]
static LINKME_STOP: [<#ty as #linkme_path::__private::Slice>::Element; 0] = [];
- #[cfg(target_os = "windows")]
- #[link_section = #windows_dupcheck_start]
+ #[cfg(any(target_os = "uefi", target_os = "windows"))]
+ #[#unsafe_attr(#link_section_attr = #windows_dupcheck_start)]
static DUPCHECK_START: () = ();
- #[cfg(target_os = "windows")]
- #[link_section = #windows_dupcheck_stop]
+ #[cfg(any(target_os = "uefi", target_os = "windows"))]
+ #[#unsafe_attr(#link_section_attr = #windows_dupcheck_stop)]
static DUPCHECK_STOP: () = ();
#used
- #[cfg(any(target_os = "none", target_os = "linux", target_os = "android", target_os = "illumos", target_os = "freebsd"))]
- #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android"), link_section = #linux_section)]
- #[cfg_attr(target_os = "illumos", link_section = #illumos_section)]
- #[cfg_attr(target_os = "freebsd", link_section = #freebsd_section)]
+ #[cfg(any(
+ target_os = "none",
+ target_os = "linux",
+ target_os = "android",
+ target_os = "fuchsia",
+ target_os = "illumos",
+ target_os = "freebsd",
+ target_os = "openbsd",
+ target_os = "psp",
+ ))]
+ #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android", target_os = "fuchsia", target_os = "psp"), #unsafe_attr(#link_section_attr = #linux_section))]
+ #[cfg_attr(target_os = "illumos", #unsafe_attr(#link_section_attr = #illumos_section))]
+ #[cfg_attr(any(target_os = "freebsd", target_os = "openbsd"), #unsafe_attr(#link_section_attr = #bsd_section))]
static mut LINKME_PLEASE: [<#ty as #linkme_path::__private::Slice>::Element; 0] = [];
#used
- #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android"), link_section = #linux_dupcheck)]
- #[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos"), link_section = #macho_dupcheck)]
- #[cfg_attr(target_os = "windows", link_section = #windows_dupcheck)]
- #[cfg_attr(target_os = "illumos", link_section = #illumos_dupcheck)]
- #[cfg_attr(target_os = "freebsd", link_section = #freebsd_dupcheck)]
+ #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android", target_os = "fuchsia", target_os = "psp"), #unsafe_attr(#link_section_attr = #linux_dupcheck))]
+ #[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos"), #unsafe_attr(#link_section_attr = #macho_dupcheck))]
+ #[cfg_attr(any(target_os = "uefi", target_os = "windows"), #unsafe_attr(#link_section_attr = #windows_dupcheck))]
+ #[cfg_attr(target_os = "illumos", #unsafe_attr(#link_section_attr = #illumos_dupcheck))]
+ #[cfg_attr(any(target_os = "freebsd", target_os = "openbsd"), #unsafe_attr(#link_section_attr = #bsd_dupcheck))]
static DUPCHECK: #linkme_path::__private::usize = 1;
#[cfg(not(any(
@@ -191,9 +219,13 @@
target_os = "ios",
target_os = "tvos",
target_os = "windows",
+ target_os = "uefi",
target_os = "android",
+ target_os = "fuchsia",
target_os = "illumos",
target_os = "freebsd",
+ target_os = "openbsd",
+ target_os = "psp",
)))]
#unsupported_platform
@@ -204,10 +236,10 @@
unsafe {
#linkme_path::DistributedSlice::private_new(
#name,
- &LINKME_START,
- &LINKME_STOP,
- &DUPCHECK_START,
- &DUPCHECK_STOP,
+ #linkme_path::__private::ptr::addr_of!(LINKME_START),
+ #linkme_path::__private::ptr::addr_of!(LINKME_STOP),
+ #linkme_path::__private::ptr::addr_of!(DUPCHECK_START),
+ #linkme_path::__private::ptr::addr_of!(DUPCHECK_STOP),
)
}
};
@@ -225,7 +257,7 @@
#![linkme_macho_section = concat!(#macho_section, $key)]
#![linkme_windows_section = concat!(#windows_section, $key)]
#![linkme_illumos_section = concat!(#illumos_section, $key)]
- #![linkme_freebsd_section = concat!(#freebsd_section, $key)]
+ #![linkme_bsd_section = concat!(#bsd_section, $key)]
$item
}
};
@@ -234,24 +266,24 @@
#![linkme_macho_section = $macho_section:expr]
#![linkme_windows_section = $windows_section:expr]
#![linkme_illumos_section = $illumos_section:expr]
- #![linkme_freebsd_section = $freebsd_section:expr]
+ #![linkme_bsd_section = $bsd_section:expr]
$item:item
) => {
#used
- #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android"), link_section = $linux_section)]
- #[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos"), link_section = $macho_section)]
- #[cfg_attr(target_os = "windows", link_section = $windows_section)]
- #[cfg_attr(target_os = "illumos", link_section = $illumos_section)]
- #[cfg_attr(target_os = "freebsd", link_section = $freebsd_section)]
+ #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android", target_os = "fuchsia", target_os = "psp"), #unsafe_attr(#link_section_attr = $linux_section))]
+ #[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos"), #unsafe_attr(#link_section_attr = $macho_section))]
+ #[cfg_attr(any(target_os = "uefi", target_os = "windows"), #unsafe_attr(#link_section_attr = $windows_section))]
+ #[cfg_attr(target_os = "illumos", #unsafe_attr(#link_section_attr = $illumos_section))]
+ #[cfg_attr(any(target_os = "freebsd", target_os = "openbsd"), #unsafe_attr(#link_section_attr = $bsd_section))]
$item
};
($item:item) => {
#used
- #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android"), link_section = #linux_section)]
- #[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos"), link_section = #macho_section)]
- #[cfg_attr(target_os = "windows", link_section = #windows_section)]
- #[cfg_attr(target_os = "illumos", link_section = #illumos_section)]
- #[cfg_attr(target_os = "freebsd", link_section = #freebsd_section)]
+ #[cfg_attr(any(target_os = "none", target_os = "linux", target_os = "android", target_os = "fuchsia", target_os = "psp"), #unsafe_attr(#link_section_attr = #linux_section))]
+ #[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "tvos"), #unsafe_attr(#link_section_attr = #macho_section))]
+ #[cfg_attr(any(target_os = "uefi", target_os = "windows"), #unsafe_attr(#link_section_attr = #windows_section))]
+ #[cfg_attr(target_os = "illumos", #unsafe_attr(#link_section_attr = #illumos_section))]
+ #[cfg_attr(any(target_os = "freebsd", target_os = "openbsd"), #unsafe_attr(#link_section_attr = #bsd_section))]
$item
};
}
@@ -260,43 +292,3 @@
#vis use #link_section_macro as #ident;
}
}
-
-fn populate_static_lifetimes(ty: &mut Type) {
- match ty {
- Type::Array(ty) => populate_static_lifetimes(&mut ty.elem),
- Type::Group(ty) => populate_static_lifetimes(&mut ty.elem),
- Type::Paren(ty) => populate_static_lifetimes(&mut ty.elem),
- Type::Path(ty) => {
- if let Some(qself) = &mut ty.qself {
- populate_static_lifetimes(&mut qself.ty);
- }
- for segment in &mut ty.path.segments {
- if let PathArguments::AngleBracketed(segment) = &mut segment.arguments {
- for arg in &mut segment.args {
- if let GenericArgument::Type(arg) = arg {
- populate_static_lifetimes(arg);
- }
- }
- }
- }
- }
- Type::Ptr(ty) => populate_static_lifetimes(&mut ty.elem),
- Type::Reference(ty) => {
- if ty.lifetime.is_none() {
- ty.lifetime = Some(Lifetime::new("'static", ty.and_token.span));
- }
- populate_static_lifetimes(&mut ty.elem);
- }
- Type::Slice(ty) => populate_static_lifetimes(&mut ty.elem),
- Type::Tuple(ty) => ty.elems.iter_mut().for_each(populate_static_lifetimes),
- Type::ImplTrait(_)
- | Type::Infer(_)
- | Type::Macro(_)
- | Type::Never(_)
- | Type::TraitObject(_)
- | Type::BareFn(_)
- | Type::Verbatim(_) => {}
- #[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
- _ => unimplemented!("unknown Type"),
- }
-}
diff --git a/crates/linkme-impl/src/element.rs b/crates/linkme-impl/src/element.rs
index 7c85e30..18a3cc4 100644
--- a/crates/linkme-impl/src/element.rs
+++ b/crates/linkme-impl/src/element.rs
@@ -1,7 +1,6 @@
-use crate::attr;
+use crate::{attr, ty};
use proc_macro2::{Span, TokenStream, TokenTree};
use quote::{format_ident, quote, quote_spanned};
-use std::iter::FromIterator;
use syn::parse::{Error, Parse, ParseStream, Result};
use syn::punctuated::Punctuated;
use syn::{
@@ -205,10 +204,12 @@
let mut attrs = input.attrs;
let vis = input.vis;
let ident = input.ident;
- let ty = input.ty;
+ let mut ty = input.ty;
let expr = input.expr;
let orig_item = input.orig_item;
+ ty::populate_static_lifetimes(&mut ty);
+
let linkme_path = match attr::linkme_path(&mut attrs) {
Ok(path) => path,
Err(err) => return err.to_compile_error(),
@@ -216,8 +217,8 @@
let sort_key = pos.into_iter().map(|pos| format!("{:04}", pos));
- let new = quote_spanned!(input.start_span=> __new);
- let uninit = quote_spanned!(input.end_span=> #new());
+ let factory = quote_spanned!(input.start_span=> __new);
+ let get = quote_spanned!(input.end_span=> #factory());
quote! {
#path ! {
@@ -227,9 +228,13 @@
)*
#(#attrs)*
#vis static #ident : #ty = {
+ #[allow(clippy::no_effect_underscore_binding)]
unsafe fn __typecheck(_: #linkme_path::__private::Void) {
- let #new = #linkme_path::__private::value::<#ty>;
- #linkme_path::DistributedSlice::private_typecheck(#path, #uninit)
+ #[allow(clippy::ref_option_ref)]
+ let #factory = || -> fn() -> &'static #ty { || &#ident };
+ unsafe {
+ #linkme_path::DistributedSlice::private_typecheck(#path, #get);
+ }
}
#expr
diff --git a/crates/linkme-impl/src/lib.rs b/crates/linkme-impl/src/lib.rs
index d08aba8..2b300c0 100644
--- a/crates/linkme-impl/src/lib.rs
+++ b/crates/linkme-impl/src/lib.rs
@@ -12,6 +12,7 @@
mod element;
mod hash;
mod linker;
+mod ty;
use crate::args::Args;
use crate::hash::hash;
diff --git a/crates/linkme-impl/src/linker.rs b/crates/linkme-impl/src/linker.rs
index 75affe2..2d5aa12 100644
--- a/crates/linkme-impl/src/linker.rs
+++ b/crates/linkme-impl/src/linker.rs
@@ -14,7 +14,7 @@
}
}
-pub mod freebsd {
+pub mod bsd {
use syn::Ident;
pub fn section(ident: &Ident) -> String {
diff --git a/crates/linkme-impl/src/ty.rs b/crates/linkme-impl/src/ty.rs
new file mode 100644
index 0000000..60bd30a
--- /dev/null
+++ b/crates/linkme-impl/src/ty.rs
@@ -0,0 +1,42 @@
+use syn::{GenericArgument, Lifetime, PathArguments, Type};
+
+pub(crate) fn populate_static_lifetimes(ty: &mut Type) {
+ match ty {
+ #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
+ Type::Array(ty) => populate_static_lifetimes(&mut ty.elem),
+ Type::Group(ty) => populate_static_lifetimes(&mut ty.elem),
+ Type::Paren(ty) => populate_static_lifetimes(&mut ty.elem),
+ Type::Path(ty) => {
+ if let Some(qself) = &mut ty.qself {
+ populate_static_lifetimes(&mut qself.ty);
+ }
+ for segment in &mut ty.path.segments {
+ if let PathArguments::AngleBracketed(segment) = &mut segment.arguments {
+ for arg in &mut segment.args {
+ if let GenericArgument::Type(arg) = arg {
+ populate_static_lifetimes(arg);
+ }
+ }
+ }
+ }
+ }
+ Type::Ptr(ty) => populate_static_lifetimes(&mut ty.elem),
+ Type::Reference(ty) => {
+ if ty.lifetime.is_none() {
+ ty.lifetime = Some(Lifetime::new("'static", ty.and_token.span));
+ }
+ populate_static_lifetimes(&mut ty.elem);
+ }
+ Type::Slice(ty) => populate_static_lifetimes(&mut ty.elem),
+ Type::Tuple(ty) => ty.elems.iter_mut().for_each(populate_static_lifetimes),
+ Type::ImplTrait(_)
+ | Type::Infer(_)
+ | Type::Macro(_)
+ | Type::Never(_)
+ | Type::TraitObject(_)
+ | Type::BareFn(_)
+ | Type::Verbatim(_) => {}
+
+ _ => unimplemented!("unknown Type"),
+ }
+}
diff --git a/crates/linkme/.android-checksum.json b/crates/linkme/.android-checksum.json
index b7879c3..1d82f90 100644
--- a/crates/linkme/.android-checksum.json
+++ b/crates/linkme/.android-checksum.json
@@ -1 +1 @@
-{"package":null,"files":{".cargo-checksum.json":"ff828fe92039ba4f006c2a64653ee1fffa316c17709fc9ee1ad9d976a1a862f9","Android.bp":"0e5c69e0ed85d46d30207eac80943fb043be616cf4a260fcc6f9d213566efe73","Cargo.toml":"0ad35faa64eb49ae5d78650e71a61c4e28c28fc5f009446d594bdb6c01df6127","LICENSE":"50f827348bfd5def2df4f30cb41264072cf9c180bd9ed698437e8d85b2482754","LICENSE-APACHE":"50f827348bfd5def2df4f30cb41264072cf9c180bd9ed698437e8d85b2482754","LICENSE-MIT":"38620a3cfaeec97a9197e8c39e436ea7f0bc86699b1f1c35f1aa41785b6d4eac","METADATA":"1dacbdfc3ad76a7354ecfd8c02d574b30196d014f24d02c49fa3efbe614ccb0b","MODULE_LICENSE_APACHE2":"0d6f8afa3940b7f06bebee651376d43bc8b0d5b437337be2696d30377451e93a","README.md":"1a25c9fda0a766bd789142fb4a9d92e77353db7259e3e886a34b3a854c1b947c","cargo_embargo.json":"aa45a963da01d3f018be316cd5b7646a5b413ce2611c5218f2914d2e8a9efd0e","src/distributed_slice.rs":"e361d0cf0d131eafcf0659b9969359e2554346b8faba6aa0a2d519ff156fa0de","src/lib.rs":"0b7349459bbb16633e4a7ef3176dff7c3b3905350f0668bdf282b85bbb42a19e","src/private.rs":"a1128ca43b0446992b132a28b90e38c2a783e433766e462360bd3817a92332bf","tests/compiletest.rs":"8f2cbc080ae802a72afbc627b943e187f66bfe0214f7d989460badb57ddfbb8d","tests/custom_linkme_path.rs":"5c28bf190bf9564cb2c691341dc2279c7f63e695d38ddca777cd899eb6500c92","tests/distributed_slice.rs":"7687f345639867cbe384ba204b1d675e8adf53f72d03a0be809d60c160fd4aa9","tests/example.rs":"4e9443473aeb009d2266fbb8d9c303fb543ec67f14312d15e1d2c6aeb6690ee7","tests/fn_element.rs":"9aeb945b02ea4983636a9744861ff8abfa32c0f0d0dd3a51eb54f04842914fc1","tests/module/mod.rs":"be9c50e3819878ab4ff33f6e8adf503e9d18f7d77fef40e5b906a26705dbe93d","tests/module_2015.rs":"4d507fea5c9bcf7250d67e03da0d4f893bcece3ff533edd763d4ccb119969d53","tests/module_2021.rs":"80054a9ee8c1d06bcdaf08583466ef608a321b530aa07630c4b4892b8c76ac5f","tests/ui/bad_crate_path.rs":"3bede2477feb56279acd06008c87323a7bb6e3d754a42936c1b9ebabeab97fa8","tests/ui/bad_crate_path.stderr":"35d0d42344cd955d662298086903214e215de868e0c3fbe2389164400f6bb3b7","tests/ui/generic_fn.rs":"ed65aa4fdcbc569790f8ee7ce8bc898d6ab4712a20ea7069680485737b755dfa","tests/ui/generic_fn.stderr":"1a5b6d74d35a3f9d8de58dc338ab9ba7d4c2f43c17e420e146022799c3e84ed7","tests/ui/mismatched_types.rs":"891ad4bd815d1ebfcd7febb291240813b69a83907b86dcfdb6bf7567a95205e8","tests/ui/mismatched_types.stderr":"58497a5b30efd1d3f9a4f9adc452582515faa2643ae8e9e7e49bc80f14ffb1dd","tests/ui/mutable.rs":"63cf5c42266378257159250b3d66dced0c01090e336b79501313a7ef799a82bc","tests/ui/mutable.stderr":"773189ea5e6a07788ab2d515f46a93a93367214a088902caf7d37f1ccd34de50","tests/ui/unsupported_item.rs":"f560182db10acf7cdb3994116166c60d27ce616a5b6c8c9228ea39209f361327","tests/ui/unsupported_item.stderr":"ccaf4715155fd6669dab25718efbcc0a0c241408d972a67ae20459f4851c74c4","tests/ui/zerosized.rs":"0958f586d95d06cca5462c64c91f30ac10b37d747ff0c16f78768d3612745e5c","tests/ui/zerosized.stderr":"0baf74294d8988023f8c908841cf8bdd3b288590c319a240e1faef191f1122fb"}}
\ No newline at end of file
+{"package":null,"files":{".cargo-checksum.json":"21f48f30ff2bcdcd154673e0162166d6e5be6aba6aee4a09c29edd321e14eb62","Android.bp":"6db72639a0c260eaf2685e7f9b24708cd400f665ccff84e775cadb557481320f","Cargo.toml":"6126ddbf3c92b18ad2c238dbf2e4a27ba887b1cac0f40e3b8fc0e45b84500fe0","LICENSE":"50f827348bfd5def2df4f30cb41264072cf9c180bd9ed698437e8d85b2482754","LICENSE-APACHE":"50f827348bfd5def2df4f30cb41264072cf9c180bd9ed698437e8d85b2482754","LICENSE-MIT":"38620a3cfaeec97a9197e8c39e436ea7f0bc86699b1f1c35f1aa41785b6d4eac","METADATA":"939e9d658f4eb716c18ac1f531e332c04aa6108df1a80dae0a629785abdf78d5","MODULE_LICENSE_APACHE2":"0d6f8afa3940b7f06bebee651376d43bc8b0d5b437337be2696d30377451e93a","README.md":"3ed710de606cf36723c4390ad979a4001c9bb30466897b561b1f9e69121b0351","cargo_embargo.json":"aa45a963da01d3f018be316cd5b7646a5b413ce2611c5218f2914d2e8a9efd0e","src/distributed_slice.rs":"e7d45eecd466c158c20abcdf2a7e6d214c6b256eb7a7a85145ff35ac50de1654","src/lib.rs":"87c30e3a6f361617e065a870f1e67fdf33d591b7b65950f1ea545a44248088c5","src/private.rs":"86534a07ab4ab440f0559dd2e30ed11c86aa59882b4a5c6901a47f0620a0ce64","tests/compiletest.rs":"5876a4728abd95ed4ed3b78777fe95428d32a32730d7718f58001bdbd4d1e168","tests/custom_linkme_path.rs":"e5654dd57009463688456235deff2588ef0961016ac24fede5f1b1a9f2b6248e","tests/distributed_slice.rs":"8269fc15fb9c00629838ef8f647cb27cd0b3e48edc32181601e5877aea0bf613","tests/example.rs":"caf9d2c0d3eda94bca8c34e6f27dcc3ca83ea011185a4908d9c0bfc65b54be39","tests/fn_element.rs":"24d6514351d9b39d9e86fce4ff9f3d707d68c9bc65f19a1d0a1748ca6b7117b0","tests/module/mod.rs":"b5a84f0d8bba52e092aa8ba422eccf8556750e982f78e395dff0fec18d591d47","tests/module_2015.rs":"4d507fea5c9bcf7250d67e03da0d4f893bcece3ff533edd763d4ccb119969d53","tests/module_2021.rs":"80054a9ee8c1d06bcdaf08583466ef608a321b530aa07630c4b4892b8c76ac5f","tests/ui/attempted_coercion.rs":"986f5668062a143834f7e667bee36ffc24ba1bc70a1834d11084b3d537c3aba1","tests/ui/attempted_coercion.stderr":"e750de4022dcd582651c99684053b4b12e22e3c0528d9572df34a21e2b5a0988","tests/ui/bad_crate_path.rs":"5f2b43f8ee28631f9ce3d28847ee3d080ef6c797538829b7ea1eeb86ea559660","tests/ui/bad_crate_path.stderr":"2a7c6c247881dc83808397e3057738bdd4cc465eb0c917d593603585660a456f","tests/ui/generic_fn.rs":"11008ff7c4c085f7ae62ed6d592ffc050d9fa6cc74bfdb1a47ced5f6cb87138d","tests/ui/generic_fn.stderr":"1a5b6d74d35a3f9d8de58dc338ab9ba7d4c2f43c17e420e146022799c3e84ed7","tests/ui/mismatched_types.rs":"5f952c777838b515f0a096b6cca9ed307df0518f769bdc177549a75c2c101f0c","tests/ui/mismatched_types.stderr":"24637e5d728a9d892e00db93b0491d4d23260a6f1f0ac38e3313bd34501b0c58","tests/ui/mutable.rs":"ee87f2093b55d9de41e1d9934f529b33b72f7f4d0d3c14a65df346be96183c01","tests/ui/mutable.stderr":"daa9acd6fd3527081150820267e8432a40b4cf6a36371a52c56c4b6968f75b37","tests/ui/unsupported_item.rs":"23378fd486b711a8f3d07b619c9d652a5071f6a1960a99aee372ba95a37765fb","tests/ui/unsupported_item.stderr":"ccaf4715155fd6669dab25718efbcc0a0c241408d972a67ae20459f4851c74c4","tests/ui/zerosized.rs":"e4da6f91ce6d03d8a01a8a004295afe9a4385c43602309629b2990a5db6e12fa","tests/ui/zerosized.stderr":"d7d7fa31e99deff19e9b5a40ab199aab29f16fc3466857f48993291d85e83358","tests/win_status_access_violation.rs":"c68795b1d59d1980e6c0ba5b2e900346db642865d2b10ad4194a9cbdbb2b2b61","tests/win_status_illegal_instruction.rs":"cbb4795abddc60e3ce099cb9dcfdb0ba658a49ed5a6924853be4236538d70db8"}}
\ No newline at end of file
diff --git a/crates/linkme/.cargo-checksum.json b/crates/linkme/.cargo-checksum.json
index b2b9ba9..3601eb4 100644
--- a/crates/linkme/.cargo-checksum.json
+++ b/crates/linkme/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"92c63b759fe0a01287c4501d1bbdc82d8faa0879a510d3d5f5e2ca174dc83300","LICENSE-APACHE":"62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"49b76b0377c7325c24fba25b3a8f728a27c05d33e846677a76ded4ab2261738a","src/distributed_slice.rs":"78f484ec672b0197e20cc0cb5ceda404ddc12c15d34d0e58a6f63530d5d32da7","src/lib.rs":"f09743ff9e09dfd28c1ca872db6a91a5692f617dcfdd1a343790d2e3409c2f12","src/private.rs":"c90b56249c735cb60573fd4107dd50c26fad785aacfeeedc89f312707cb3c80f","tests/compiletest.rs":"022a8e400ef813d7ea1875b944549cee5125f6a995dc33e93b48cba3e1b57bd1","tests/custom_linkme_path.rs":"6f7fabc02f2f414762d2eaf3a5a57fbfee53b38854afce37d37a45f520e49233","tests/distributed_slice.rs":"9f6c770642318db5577a51afbaeda5a8cef1de4afee2e7a64ad867fa4f999cc2","tests/example.rs":"37bde9e47524bfe3284f50c9cb6844701187421e6733f087de8f5d371f46ac4f","tests/fn_element.rs":"4188ab0b0eaa58b2360a089d54e7ec0ee1ee48c8fc0aef969f5a1404e12aa102","tests/module/mod.rs":"58acddc9d2ac6f10bec117c58877dfdb4e6a2eea6aae51c4e7e34377417eeeef","tests/module_2015.rs":"6b138d9f7b2a4b91b2b8f7cc4eee204e7ad27d33f4d87ef492ea316d759ad749","tests/module_2021.rs":"61120c3d8156b5af6ac84b47a8b2c4e6ce97b7a17ab3131af57a2fb3d8822564","tests/ui/bad_crate_path.rs":"23ae1110504210eedd2f1736dd78199ed09fed497cca6daf6b7ebafe2b814c3a","tests/ui/bad_crate_path.stderr":"11dd2a52cbaba6b2003f8cb28d95b052b4dbb7059bdb29e78dee0400f5db4a49","tests/ui/generic_fn.rs":"0a7a7cc9a7e09ef9ab46fc15608857463865db3d048019d5c74162defb138f71","tests/ui/generic_fn.stderr":"91cbdf3db736e14f366a78b614fb7ac8843ce2c6abe39fc8f878b3b22d1047ee","tests/ui/mismatched_types.rs":"26d6d3109ab2c0ff2b4eb5e020f29ead104203d1623cdb960e77fe5b1b491112","tests/ui/mismatched_types.stderr":"b0892d809de86f954ef6af2aef5a0fa0e1611fc5aa56ecd71d2a12eea165760c","tests/ui/mutable.rs":"8b2f351572a8ab328d8dd6a9b572772ab26b7e046aac251305783aaa09e4e7fb","tests/ui/mutable.stderr":"a73c5a6bf9831d2792376b3b5f66ce462e90cdf84dceb0acb92e29b49ee5523b","tests/ui/unsupported_item.rs":"6d16c3e3c45f246cbb16c9ae97941cf72e53719ad63f5997c31fcc8a3f3d4a83","tests/ui/unsupported_item.stderr":"f547648e6b400ccc905f85c975e6250e70ae7d9d7846921001a1155b9325629c","tests/ui/zerosized.rs":"c0f027d8a7fdd7b0b6948fb025ab54c9089f31c1d16025d6f6a6dbca4e82cb0f","tests/ui/zerosized.stderr":"26c030366a31962402ebbffa4992d4c4c0cd1adbfac75c4f407cd2eb49206d0e"},"package":"97f3302efc6ebb7b5f0810a1096dbbb44a536711a4576bc89264a8f9a1d634d8"}
\ No newline at end of file
+{"files":{"Cargo.toml":"4fc488b50b47163e4dec9ef371232ad139b0139fc6a021b708ffd40d85d32c5c","LICENSE-APACHE":"62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"014fb852ef8262abd9a7732789d15ec6130a4d8156cafdc89b22c4e7094eebe7","src/distributed_slice.rs":"9e261cfee40990ba371750db4e93d4765e36cfff73f888f49712e577ee72bdef","src/lib.rs":"0976d91bb50601d14a87289dface275f98facfc1bfc8faf4978dc0f94aeaca4b","src/private.rs":"feb8bf28ca5c2a6adcf6e17db636c950df1d9d103ae3461dc8102c72c09ab534","tests/compiletest.rs":"4e381aa8ca3eabb7ac14d1e0c3700b3223e47640547a6988cfa13ad68255f60f","tests/custom_linkme_path.rs":"0a9a4b718007b45f59c15411952682b58a9d692ff0c603d2121c37e92b823cba","tests/distributed_slice.rs":"9cbc09a383f75e05c5d95d696d586069f04ec18916afc1131db7ec6c8e6178c7","tests/example.rs":"490725e38ccd8f9edb98b379e31bf851d269417c62fe912db4be334ca17e645f","tests/fn_element.rs":"3a1699565329936fb18f535ac095bd4213c2c1c694ecd4075216e78ad0c8038e","tests/module/mod.rs":"6062f06c02aae46c656dd8f6d739091a803dc04cf3c82f80977e17490854b0be","tests/module_2015.rs":"6b138d9f7b2a4b91b2b8f7cc4eee204e7ad27d33f4d87ef492ea316d759ad749","tests/module_2021.rs":"61120c3d8156b5af6ac84b47a8b2c4e6ce97b7a17ab3131af57a2fb3d8822564","tests/ui/attempted_coercion.rs":"b034d37e7947d1ae165a78a8b1477a79e18ba4e8d9d448c1780669df27a1db19","tests/ui/attempted_coercion.stderr":"c7c0eda9d6bcdf5fea84b5be9a1cd23e1dd5e68e145897e019938e59decb258c","tests/ui/bad_crate_path.rs":"e007cfd7cbb581d37543b15591cbac3f3519fa5e0b8d5ccf0ea86d535e06f9a9","tests/ui/bad_crate_path.stderr":"4aa9e15819624550ce063d63ba353c479559371a5a8afde2071d3fbc071058f7","tests/ui/generic_fn.rs":"d56cab278fa4f167f1ce6406e60c625c74b7eadfb7ac120c67185dac0b3702bc","tests/ui/generic_fn.stderr":"91cbdf3db736e14f366a78b614fb7ac8843ce2c6abe39fc8f878b3b22d1047ee","tests/ui/mismatched_types.rs":"81e804ef9ec34a17080b95dc8955731c0bd5fdb3c0450b20191c026652c9df42","tests/ui/mismatched_types.stderr":"7e4ee90525f5d9250b232296eb11056a2c525a3d7e226ad9a8da44f11eaaf8a3","tests/ui/mutable.rs":"b5621fa6a1562f83b868910cd89e3730fb8562a5fd0598fcbb7b934e3595ac8f","tests/ui/mutable.stderr":"e66c45648a1f94d0937f84cb7f21c5f37f165b98cbe600687d32cbda4df4338d","tests/ui/unsupported_item.rs":"f172d75ccaf2e54bf0533b590753c7dc993132b43ca2820d1f69574a7c4a4265","tests/ui/unsupported_item.stderr":"f547648e6b400ccc905f85c975e6250e70ae7d9d7846921001a1155b9325629c","tests/ui/zerosized.rs":"9f497d19d4e9d516c3cde52eb5ceab4f526c7e14c20d6b8da2e17ffec1f01244","tests/ui/zerosized.stderr":"763868918df1fd46d642cb6274b5b6a6235302acda44d895a6e666c9f6411a2f","tests/win_status_access_violation.rs":"715181a0d12d9150edf79313f515a83c24f7e08548df00c51dc3b2e17a2273b3","tests/win_status_illegal_instruction.rs":"bc697035e9aac3e68307408ccd7b7773c8230c410b4fd8d591f585a8da1bc2af"},"package":"566336154b9e58a4f055f6dd4cbab62c7dc0826ce3c0a04e63b2d2ecd784cdae"}
\ No newline at end of file
diff --git a/crates/linkme/Android.bp b/crates/linkme/Android.bp
index a9cae47..5e05ffd 100644
--- a/crates/linkme/Android.bp
+++ b/crates/linkme/Android.bp
@@ -18,7 +18,7 @@
host_supported: true,
crate_name: "linkme",
cargo_env_compat: true,
- cargo_pkg_version: "0.3.10",
+ cargo_pkg_version: "0.3.31",
crate_root: "src/lib.rs",
edition: "2021",
proc_macros: ["liblinkme_impl"],
diff --git a/crates/linkme/Cargo.toml b/crates/linkme/Cargo.toml
index 22b17d4..feee17f 100644
--- a/crates/linkme/Cargo.toml
+++ b/crates/linkme/Cargo.toml
@@ -13,8 +13,14 @@
edition = "2021"
rust-version = "1.62"
name = "linkme"
-version = "0.3.10"
+version = "0.3.31"
authors = ["David Tolnay <[email protected]>"]
+build = false
+autolib = false
+autobins = false
+autoexamples = false
+autotests = false
+autobenches = false
description = "Safe cross-platform linker shenanigans"
documentation = "https://docs.rs/linkme"
readme = "README.md"
@@ -23,22 +29,59 @@
"development-tools::build-utils",
"development-tools::procedural-macro-helpers",
"no-std",
+ "no-std::no-alloc",
]
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/linkme"
[package.metadata.docs.rs]
+rustdoc-args = ["--generate-link-to-definition"]
targets = ["x86_64-unknown-linux-gnu"]
[lib]
+name = "linkme"
+path = "src/lib.rs"
doc-scrape-examples = false
[[test]]
+name = "compiletest"
+path = "tests/compiletest.rs"
+
+[[test]]
+name = "custom_linkme_path"
+path = "tests/custom_linkme_path.rs"
+
+[[test]]
+name = "distributed_slice"
+path = "tests/distributed_slice.rs"
+
+[[test]]
+name = "example"
+path = "tests/example.rs"
+
+[[test]]
+name = "fn_element"
+path = "tests/fn_element.rs"
+
+[[test]]
name = "module_2015"
+path = "tests/module_2015.rs"
edition = "2015"
+[[test]]
+name = "module_2021"
+path = "tests/module_2021.rs"
+
+[[test]]
+name = "win_status_access_violation"
+path = "tests/win_status_access_violation.rs"
+
+[[test]]
+name = "win_status_illegal_instruction"
+path = "tests/win_status_illegal_instruction.rs"
+
[dependencies.linkme-impl]
-version = "=0.3.10"
+version = "=0.3.31"
[dev-dependencies.once_cell]
version = "1.16"
@@ -47,7 +90,7 @@
version = "1.0"
[dev-dependencies.trybuild]
-version = "1.0.66"
+version = "1.0.97"
features = ["diff"]
[features]
diff --git a/crates/linkme/METADATA b/crates/linkme/METADATA
index b10cbcc..674dd9b 100644
--- a/crates/linkme/METADATA
+++ b/crates/linkme/METADATA
@@ -1,17 +1,17 @@
name: "linkme"
description: "Safe cross-platform linker shenanigans"
third_party {
- version: "0.3.10"
+ version: "0.3.31"
license_type: NOTICE
last_upgrade_date {
- year: 2023
- month: 6
- day: 1
+ year: 2025
+ month: 1
+ day: 15
}
homepage: "https://crates.io/crates/linkme"
identifier {
type: "Archive"
- value: "https://static.crates.io/crates/linkme/linkme-0.3.10.crate"
- version: "0.3.10"
+ value: "https://static.crates.io/crates/linkme/linkme-0.3.31.crate"
+ version: "0.3.31"
}
}
diff --git a/crates/linkme/README.md b/crates/linkme/README.md
index de15c56..72d5f44 100644
--- a/crates/linkme/README.md
+++ b/crates/linkme/README.md
@@ -5,9 +5,9 @@
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-linkme-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/linkme)
[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/dtolnay/linkme/ci.yml?branch=master&style=for-the-badge" height="20">](https://github.com/dtolnay/linkme/actions?query=branch%3Amaster)
-| Component | Linux | macOS | Windows | FreeBSD | illumos | Other...<sup>†</sup> |
-|:---|:---:|:---:|:---:|:---:|:---:|:---:|
-| [Distributed slice] | 💚 | 💚 | 💚 | 💚 | 💚 | |
+| Component | Linux | macOS | Windows | FreeBSD | OpenBSD | illumos | Other...<sup>†</sup> |
+|:---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
+| [Distributed slice] | 💚 | 💚 | 💚 | 💚 | 💚 | 💚 | |
<b><sup>†</sup></b> We welcome PRs adding support for any platforms not listed
here.
@@ -37,14 +37,13 @@
### Declaration
A static distributed slice is declared by writing `#[distributed_slice]` on a
-static item whose type is `[T]` for some type `T`. The initializer expression
-must be `[..]` to indicate that elements come from elsewhere.
+static item whose type is `[T]` for some type `T`.
```rust
use linkme::distributed_slice;
#[distributed_slice]
-pub static BENCHMARKS: [fn(&mut Bencher)] = [..];
+pub static BENCHMARKS: [fn(&mut Bencher)];
```
### Elements
@@ -120,7 +119,7 @@
use linkme::distributed_slice;
#[distributed_slice]
-pub static BENCHMARKS: [fn(&mut Bencher)] = [..];
+pub static BENCHMARKS: [fn(&mut Bencher)];
// Equivalent to:
//
diff --git a/crates/linkme/src/distributed_slice.rs b/crates/linkme/src/distributed_slice.rs
index d283e6f..a799065 100644
--- a/crates/linkme/src/distributed_slice.rs
+++ b/crates/linkme/src/distributed_slice.rs
@@ -1,3 +1,4 @@
+use core::fmt::{self, Debug};
use core::hint;
use core::mem;
use core::ops::Deref;
@@ -16,8 +17,7 @@
/// ## Declaration
///
/// A static distributed slice may be declared by writing `#[distributed_slice]`
-/// on a static item whose type is `[T]` for some type `T`. The initializer
-/// expression must be `[..]` to indicate that elements come from elsewhere.
+/// on a static item whose type is `[T]` for some type `T`.
///
/// ```
/// # #![cfg_attr(feature = "used_linker", feature(used_with_arg))]
@@ -27,7 +27,7 @@
/// use linkme::distributed_slice;
///
/// #[distributed_slice]
-/// pub static BENCHMARKS: [fn(&mut Bencher)] = [..];
+/// pub static BENCHMARKS: [fn(&mut Bencher)];
/// ```
///
/// The attribute rewrites the `[T]` type of the static into
@@ -54,7 +54,7 @@
/// # pub struct Bencher;
/// #
/// # #[distributed_slice]
-/// # pub static BENCHMARKS: [fn(&mut Bencher)] = [..];
+/// # pub static BENCHMARKS: [fn(&mut Bencher)];
/// # }
/// #
/// # use other_crate::Bencher;
@@ -81,7 +81,7 @@
/// # pub struct Bencher;
/// #
/// # #[distributed_slice]
-/// # pub static BENCHMARKS: [fn(&mut Bencher)] = [..];
+/// # pub static BENCHMARKS: [fn(&mut Bencher)];
/// # }
/// #
/// # use linkme::distributed_slice;
@@ -117,7 +117,7 @@
/// use linkme::distributed_slice;
///
/// #[distributed_slice]
-/// pub static BENCHMARKS: [fn(&mut Bencher)] = [..];
+/// pub static BENCHMARKS: [fn(&mut Bencher)];
///
/// // Equivalent to:
/// //
@@ -162,8 +162,11 @@
target_os = "ios",
target_os = "tvos",
target_os = "android",
+ target_os = "fuchsia",
target_os = "illumos",
- target_os = "freebsd"
+ target_os = "freebsd",
+ target_os = "openbsd",
+ target_os = "psp",
))]
pub const unsafe fn private_new(
name: &'static str,
@@ -184,7 +187,7 @@
}
#[doc(hidden)]
- #[cfg(target_os = "windows")]
+ #[cfg(any(target_os = "uefi", target_os = "windows"))]
pub const unsafe fn private_new(
name: &'static str,
section_start: *const [T; 0],
@@ -211,12 +214,10 @@
#[doc(hidden)]
#[inline]
- pub unsafe fn private_typecheck(self, element: T) {
- mem::forget(element);
+ pub unsafe fn private_typecheck(self, get: fn() -> &'static T) {
+ let _ = get;
}
-}
-impl<T> DistributedSlice<[T]> {
/// Retrieve a contiguous slice containing all the elements linked into this
/// program.
///
@@ -234,7 +235,7 @@
/// use linkme::distributed_slice;
///
/// #[distributed_slice]
- /// static BENCHMARKS: [fn(&mut Bencher)] = [..];
+ /// static BENCHMARKS: [fn(&mut Bencher)];
///
/// fn main() {
/// // Iterate the elements.
@@ -267,6 +268,14 @@
// using the unsafe `private_new`.
None => unsafe { hint::unreachable_unchecked() },
};
+
+ // On Windows, the implementation involves growing a &[T; 0] to
+ // encompass elements that we have asked the linker to place immediately
+ // after that location. The compiler sees this as going "out of bounds"
+ // based on provenance, so we must conceal what is going on.
+ #[cfg(any(target_os = "uefi", target_os = "windows"))]
+ let start = hint::black_box(start);
+
unsafe { slice::from_raw_parts(start, len) }
}
}
@@ -293,3 +302,12 @@
self.static_slice().iter()
}
}
+
+impl<T> Debug for DistributedSlice<[T]>
+where
+ T: Debug + 'static,
+{
+ fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ Debug::fmt(self.static_slice(), formatter)
+ }
+}
diff --git a/crates/linkme/src/lib.rs b/crates/linkme/src/lib.rs
index b51331a..38444ff 100644
--- a/crates/linkme/src/lib.rs
+++ b/crates/linkme/src/lib.rs
@@ -12,9 +12,9 @@
//!
//! # Platform support
//!
-//! | Component | Linux | macOS | Windows | FreeBSD | illumos | Other...<sup>†</sup> |
-//! |:---|:---:|:---:|:---:|:---:|:---:|:---:|
-//! | Distributed slice | 💚 | 💚 | 💚 | 💚 | 💚 | |
+//! | Component | Linux | macOS | Windows | FreeBSD | OpenBSD | illumos | Other...<sup>†</sup> |
+//! |:---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
+//! | Distributed slice | 💚 | 💚 | 💚 | 💚 | 💚 | 💚 | |
//!
//! <br>***<sup>†</sup>*** We welcome PRs adding support for any platforms not
//! listed here.
@@ -32,8 +32,7 @@
//! of the API. The basic idea is as follows.
//!
//! A static distributed slice is declared by writing `#[distributed_slice]` on
-//! a static item whose type is `[T]` for some type `T`. The initializer
-//! expression must be `[..]` to indicate that elements come from elsewhere.
+//! a static item whose type is `[T]` for some type `T`.
//!
//! ```
//! # #![cfg_attr(feature = "used_linker", feature(used_with_arg))]
@@ -43,7 +42,7 @@
//! use linkme::distributed_slice;
//!
//! #[distributed_slice]
-//! pub static BENCHMARKS: [fn(&mut Bencher)] = [..];
+//! pub static BENCHMARKS: [fn(&mut Bencher)];
//! ```
//!
//! Slice elements may be registered into a distributed slice by a
@@ -60,7 +59,7 @@
//! # pub struct Bencher;
//! #
//! # #[distributed_slice]
-//! # pub static BENCHMARKS: [fn(&mut Bencher)] = [..];
+//! # pub static BENCHMARKS: [fn(&mut Bencher)];
//! # }
//! #
//! # use other_crate::Bencher;
@@ -86,7 +85,7 @@
//! # struct Bencher;
//! #
//! # #[distributed_slice]
-//! # static BENCHMARKS: [fn(&mut Bencher)] = [..];
+//! # static BENCHMARKS: [fn(&mut Bencher)];
//! #
//! fn main() {
//! // Iterate the elements.
@@ -104,15 +103,46 @@
//! let len = BENCHMARKS.len();
//! }
//! ```
+//!
+//! <br>
+//!
+//! <details>
+//! <summary>Workaround for buggy IDEs</summary>
+//!
+//! JetBrains's Rust IDE uses an outdated Rust parser that treats distributed
+//! slice declarations as invalid syntax, despite being supported in stable
+//! rustc for over 3.5 years.
+//! See <https://youtrack.jetbrains.com/issue/RUST-12953>.
+//!
+//! If you hit this, you can work around it by adding a dummy initializer
+//! expression to the slice.
+//!
+//! ```
+//! # #![cfg_attr(feature = "used_linker", feature(used_with_arg))]
+//! #
+//! # use linkme::distributed_slice;
+//! #
+//! # struct Bencher;
+//! #
+//! #[distributed_slice]
+//! pub static BENCHMARKS: [fn(&mut Bencher)] = [..];
+//! #
+//! # const _: &str = stringify! {
+//! ^^^^^^
+//! # };
+//! ```
+//! </details>
#![no_std]
-#![doc(html_root_url = "https://docs.rs/linkme/0.3.10")]
+#![doc(html_root_url = "https://docs.rs/linkme/0.3.31")]
+#![deny(unsafe_op_in_unsafe_fn)]
#![allow(
clippy::doc_markdown,
clippy::empty_enum,
clippy::expl_impl_clone_on_copy,
clippy::manual_assert,
clippy::missing_panics_doc,
+ clippy::missing_safety_doc,
clippy::must_use_candidate,
clippy::unused_self
)]
diff --git a/crates/linkme/src/private.rs b/crates/linkme/src/private.rs
index 508ef4f..f9f859b 100644
--- a/crates/linkme/src/private.rs
+++ b/crates/linkme/src/private.rs
@@ -1,7 +1,13 @@
+#[doc(hidden)]
pub use core::assert;
+#[doc(hidden)]
pub use core::mem;
+#[doc(hidden)]
pub use core::primitive::usize;
+#[doc(hidden)]
+pub use core::ptr;
+#[doc(hidden)]
pub trait Slice {
type Element;
}
@@ -10,8 +16,5 @@
type Element = T;
}
+#[doc(hidden)]
pub enum Void {}
-
-pub fn value<T>() -> T {
- panic!()
-}
diff --git a/crates/linkme/tests/compiletest.rs b/crates/linkme/tests/compiletest.rs
index 7974a62..23a6a06 100644
--- a/crates/linkme/tests/compiletest.rs
+++ b/crates/linkme/tests/compiletest.rs
@@ -1,5 +1,5 @@
-#[rustversion::attr(not(nightly), ignore)]
-#[cfg_attr(miri, ignore)]
+#[rustversion::attr(not(nightly), ignore = "requires nightly")]
+#[cfg_attr(miri, ignore = "incompatible with miri")]
#[test]
fn ui() {
let t = trybuild::TestCases::new();
diff --git a/crates/linkme/tests/custom_linkme_path.rs b/crates/linkme/tests/custom_linkme_path.rs
index daee74f..4c65700 100644
--- a/crates/linkme/tests/custom_linkme_path.rs
+++ b/crates/linkme/tests/custom_linkme_path.rs
@@ -7,7 +7,7 @@
#[distributed_slice]
#[linkme(crate = crate::link_me)]
- pub static SLICE: [i32] = [..];
+ pub static SLICE: [i32];
#[test]
fn test_slice() {
@@ -16,7 +16,7 @@
#[distributed_slice]
#[linkme(crate = crate::link_me)]
- pub static FUNCTIONS: [fn()] = [..];
+ pub static FUNCTIONS: [fn()];
#[test]
fn test_functions() {
diff --git a/crates/linkme/tests/distributed_slice.rs b/crates/linkme/tests/distributed_slice.rs
index f8ab487..225938a 100644
--- a/crates/linkme/tests/distributed_slice.rs
+++ b/crates/linkme/tests/distributed_slice.rs
@@ -1,10 +1,12 @@
#![cfg_attr(feature = "used_linker", feature(used_with_arg))]
+#![allow(unknown_lints, non_local_definitions)] // FIXME
+#![deny(rust_2024_compatibility, unsafe_op_in_unsafe_fn)]
use linkme::distributed_slice;
use once_cell::sync::Lazy;
#[distributed_slice]
-static SHENANIGANS: [i32] = [..];
+static SHENANIGANS: [i32];
#[distributed_slice(SHENANIGANS)]
static N: i32 = 9;
@@ -30,17 +32,17 @@
#[test]
fn test_empty() {
#[distributed_slice]
- static EMPTY: [i32] = [..];
+ static EMPTY: [i32];
assert!(EMPTY.is_empty());
}
#[test]
fn test_non_copy() {
- struct NonCopy(i32);
+ pub struct NonCopy(#[allow(dead_code)] pub i32);
#[distributed_slice]
- static NONCOPY: [NonCopy] = [..];
+ static NONCOPY: [NonCopy];
#[distributed_slice(NONCOPY)]
static ELEMENT: NonCopy = NonCopy(9);
@@ -51,7 +53,7 @@
#[test]
fn test_interior_mutable() {
#[distributed_slice]
- static MUTABLE: [Lazy<i32>] = [..];
+ static MUTABLE: [Lazy<i32>];
#[distributed_slice(MUTABLE)]
static ELEMENT: Lazy<i32> = Lazy::new(|| -1);
@@ -63,10 +65,18 @@
#[test]
fn test_elided_lifetime() {
#[distributed_slice]
- pub static MYSLICE: [&str] = [..];
+ pub static MYSLICE: [&str];
#[distributed_slice(MYSLICE)]
static ELEMENT: &str = "...";
assert!(!MYSLICE.is_empty());
+ assert_eq!(MYSLICE[0], "...");
+}
+
+#[test]
+fn test_legacy_syntax() {
+ // Rustc older than 1.43 requires an initializer expression.
+ #[distributed_slice]
+ pub static LEGACY: [&str] = [..];
}
diff --git a/crates/linkme/tests/example.rs b/crates/linkme/tests/example.rs
index bbe439b..5aadbe9 100644
--- a/crates/linkme/tests/example.rs
+++ b/crates/linkme/tests/example.rs
@@ -7,7 +7,7 @@
pub struct Bencher;
#[distributed_slice]
-pub static BENCHMARKS: [fn(&mut Bencher)] = [..];
+pub static BENCHMARKS: [fn(&mut Bencher)];
#[distributed_slice(BENCHMARKS)]
static BENCH_DESERIALIZE: fn(&mut Bencher) = bench_deserialize;
diff --git a/crates/linkme/tests/fn_element.rs b/crates/linkme/tests/fn_element.rs
index a80508f..9e76bf0 100644
--- a/crates/linkme/tests/fn_element.rs
+++ b/crates/linkme/tests/fn_element.rs
@@ -4,19 +4,19 @@
use linkme::distributed_slice;
#[distributed_slice]
-pub static SLICE1: [fn()] = [..];
+pub static SLICE1: [fn()];
#[distributed_slice(SLICE1)]
fn foo() {}
#[distributed_slice]
-pub static SLICE2: [for<'a, 'b> fn(&'a &'b ())] = [..];
+pub static SLICE2: [for<'a, 'b> fn(&'a &'b ())];
#[distributed_slice(SLICE2)]
fn bar<'a, 'b>(_: &'a &'b ()) {}
#[distributed_slice]
-pub static SLICE3: [unsafe extern "C" fn() -> i32] = [..];
+pub static SLICE3: [unsafe extern "C" fn() -> i32];
#[distributed_slice(SLICE3)]
unsafe extern "C" fn baz() -> i32 {
diff --git a/crates/linkme/tests/module/mod.rs b/crates/linkme/tests/module/mod.rs
index 0fe3e5b..13136a0 100644
--- a/crates/linkme/tests/module/mod.rs
+++ b/crates/linkme/tests/module/mod.rs
@@ -2,7 +2,7 @@
use linkme::distributed_slice;
#[distributed_slice]
- pub static SLICE: [i32] = [..];
+ pub static SLICE: [i32];
#[test]
fn test_mod_slice() {
diff --git a/crates/linkme/tests/ui/attempted_coercion.rs b/crates/linkme/tests/ui/attempted_coercion.rs
new file mode 100644
index 0000000..96a2511
--- /dev/null
+++ b/crates/linkme/tests/ui/attempted_coercion.rs
@@ -0,0 +1,11 @@
+#![cfg_attr(feature = "used_linker", feature(used_with_arg))]
+
+use linkme::distributed_slice;
+
+#[distributed_slice]
+pub static SLICE: [&'static str];
+
+#[distributed_slice(SLICE)]
+static ELEMENT: &&str = &"uhoh";
+
+fn main() {}
diff --git a/crates/linkme/tests/ui/attempted_coercion.stderr b/crates/linkme/tests/ui/attempted_coercion.stderr
new file mode 100644
index 0000000..5936779
--- /dev/null
+++ b/crates/linkme/tests/ui/attempted_coercion.stderr
@@ -0,0 +1,15 @@
+error[E0308]: mismatched types
+ --> tests/ui/attempted_coercion.rs:9:17
+ |
+8 | #[distributed_slice(SLICE)]
+ | --------------------------- arguments to this function are incorrect
+9 | static ELEMENT: &&str = &"uhoh";
+ | ^^^^^ expected `str`, found `&'static str`
+ |
+ = note: expected fn pointer `fn() -> &'static &'static str`
+ found fn pointer `fn() -> &'static &'static &'static str`
+note: method defined here
+ --> src/distributed_slice.rs
+ |
+ | pub unsafe fn private_typecheck(self, get: fn() -> &'static T) {
+ | ^^^^^^^^^^^^^^^^^
diff --git a/crates/linkme/tests/ui/bad_crate_path.rs b/crates/linkme/tests/ui/bad_crate_path.rs
index ce2e563..c3594f1 100644
--- a/crates/linkme/tests/ui/bad_crate_path.rs
+++ b/crates/linkme/tests/ui/bad_crate_path.rs
@@ -8,10 +8,10 @@
#[distributed_slice]
#[linkme(crate = path::to::missing)]
-pub static SLICE1: [&'static str] = [..];
+pub static SLICE1: [&'static str];
#[distributed_slice]
-pub static SLICE2: [&'static str] = [..];
+pub static SLICE2: [&'static str];
#[distributed_slice(SLICE2)]
#[linkme(crate = path::to::missing)]
diff --git a/crates/linkme/tests/ui/bad_crate_path.stderr b/crates/linkme/tests/ui/bad_crate_path.stderr
index a4e5cef..e6b5c93 100644
--- a/crates/linkme/tests/ui/bad_crate_path.stderr
+++ b/crates/linkme/tests/ui/bad_crate_path.stderr
@@ -5,12 +5,6 @@
| ^^^^^^^ could not find `missing` in `to`
error[E0433]: failed to resolve: could not find `missing` in `to`
- --> tests/ui/bad_crate_path.rs:17:28
- |
-17 | #[linkme(crate = path::to::missing)]
- | ^^^^^^^ could not find `missing` in `to`
-
-error[E0433]: failed to resolve: could not find `missing` in `to`
--> tests/ui/bad_crate_path.rs:10:28
|
10 | #[linkme(crate = path::to::missing)]
@@ -26,6 +20,12 @@
|
17 | #[linkme(crate = path::to::missing)]
| ^^^^^^^ could not find `missing` in `to`
+
+error[E0433]: failed to resolve: could not find `missing` in `to`
+ --> tests/ui/bad_crate_path.rs:17:28
+ |
+17 | #[linkme(crate = path::to::missing)]
+ | ^^^^^^^ could not find `missing` in `to`
|
help: consider importing this struct
|
diff --git a/crates/linkme/tests/ui/generic_fn.rs b/crates/linkme/tests/ui/generic_fn.rs
index cb9be03..beb74af 100644
--- a/crates/linkme/tests/ui/generic_fn.rs
+++ b/crates/linkme/tests/ui/generic_fn.rs
@@ -3,7 +3,7 @@
use linkme::distributed_slice;
#[distributed_slice]
-pub static SLICES: [fn()] = [..];
+pub static SLICES: [fn()];
#[distributed_slice(SLICES)]
fn type_param<T>() {}
diff --git a/crates/linkme/tests/ui/mismatched_types.rs b/crates/linkme/tests/ui/mismatched_types.rs
index 611c8a9..34bf059 100644
--- a/crates/linkme/tests/ui/mismatched_types.rs
+++ b/crates/linkme/tests/ui/mismatched_types.rs
@@ -5,7 +5,7 @@
pub struct Bencher;
#[distributed_slice]
-pub static BENCHMARKS: [fn(&mut Bencher)] = [..];
+pub static BENCHMARKS: [fn(&mut Bencher)];
#[distributed_slice(BENCHMARKS)]
static BENCH_WTF: usize = 999;
diff --git a/crates/linkme/tests/ui/mismatched_types.stderr b/crates/linkme/tests/ui/mismatched_types.stderr
index 643d1a1..3ce2fb0 100644
--- a/crates/linkme/tests/ui/mismatched_types.stderr
+++ b/crates/linkme/tests/ui/mismatched_types.stderr
@@ -6,12 +6,12 @@
11 | static BENCH_WTF: usize = 999;
| ^^^^^ expected fn pointer, found `usize`
|
- = note: expected fn pointer `for<'a> fn(&'a mut Bencher)`
- found type `usize`
+ = note: expected fn pointer `fn() -> &'static for<'a> fn(&'a mut Bencher)`
+ found fn pointer `fn() -> &'static usize`
note: method defined here
--> src/distributed_slice.rs
|
- | pub unsafe fn private_typecheck(self, element: T) {
+ | pub unsafe fn private_typecheck(self, get: fn() -> &'static T) {
| ^^^^^^^^^^^^^^^^^
error[E0308]: mismatched types
@@ -22,10 +22,10 @@
14 | fn wrong_bench_fn<'a>(_: &'a mut ()) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Bencher`, found `()`
|
- = note: expected fn pointer `for<'a> fn(&'a mut Bencher)`
- found fn pointer `for<'a> fn(&'a mut ())`
+ = note: expected fn pointer `fn() -> &'static for<'a> fn(&'a mut Bencher)`
+ found fn pointer `fn() -> &'static for<'a> fn(&'a mut ())`
note: method defined here
--> src/distributed_slice.rs
|
- | pub unsafe fn private_typecheck(self, element: T) {
+ | pub unsafe fn private_typecheck(self, get: fn() -> &'static T) {
| ^^^^^^^^^^^^^^^^^
diff --git a/crates/linkme/tests/ui/mutable.rs b/crates/linkme/tests/ui/mutable.rs
index 39db0d0..42abc8c 100644
--- a/crates/linkme/tests/ui/mutable.rs
+++ b/crates/linkme/tests/ui/mutable.rs
@@ -3,7 +3,7 @@
use linkme::distributed_slice;
#[distributed_slice]
-pub static mut SLICE: [i32] = [..];
+pub static mut SLICE: [i32];
#[distributed_slice(BENCHMARKS)]
static mut ELEMENT: i32 = -1;
diff --git a/crates/linkme/tests/ui/mutable.stderr b/crates/linkme/tests/ui/mutable.stderr
index c23e194..1403f9c 100644
--- a/crates/linkme/tests/ui/mutable.stderr
+++ b/crates/linkme/tests/ui/mutable.stderr
@@ -1,7 +1,7 @@
error: static mut is not supported by distributed_slice
--> tests/ui/mutable.rs:6:12
|
-6 | pub static mut SLICE: [i32] = [..];
+6 | pub static mut SLICE: [i32];
| ^^^
error: static mut is not supported by distributed_slice
diff --git a/crates/linkme/tests/ui/unsupported_item.rs b/crates/linkme/tests/ui/unsupported_item.rs
index e218ce5..6890020 100644
--- a/crates/linkme/tests/ui/unsupported_item.rs
+++ b/crates/linkme/tests/ui/unsupported_item.rs
@@ -3,7 +3,7 @@
use linkme::distributed_slice;
#[distributed_slice]
-pub static SLICE: [&'static str] = [..];
+pub static SLICE: [&'static str];
#[distributed_slice(SLICE)]
extern crate std as _std;
diff --git a/crates/linkme/tests/ui/zerosized.rs b/crates/linkme/tests/ui/zerosized.rs
index 3965cee..df488af 100644
--- a/crates/linkme/tests/ui/zerosized.rs
+++ b/crates/linkme/tests/ui/zerosized.rs
@@ -5,6 +5,6 @@
pub struct Unit;
#[distributed_slice]
-pub static ZEROSIZED: [Unit] = [..];
+pub static ZEROSIZED: [Unit];
fn main() {}
diff --git a/crates/linkme/tests/ui/zerosized.stderr b/crates/linkme/tests/ui/zerosized.stderr
index 2443140..39f1556 100644
--- a/crates/linkme/tests/ui/zerosized.stderr
+++ b/crates/linkme/tests/ui/zerosized.stderr
@@ -2,6 +2,7 @@
--> tests/ui/zerosized.rs:7:1
|
7 | #[distributed_slice]
- | ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: ::linkme::__private::mem::size_of::<<[Unit] as\n ::linkme::__private::Slice>::Element>() > 0', $DIR/tests/ui/zerosized.rs:7:1
+ | ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: ::linkme::__private::mem::size_of::<<[Unit] as
+ ::linkme::__private::Slice>::Element>() > 0', $DIR/tests/ui/zerosized.rs:7:1
|
= note: this error originates in the macro `::linkme::__private::assert` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/crates/linkme/tests/win_status_access_violation.rs b/crates/linkme/tests/win_status_access_violation.rs
new file mode 100644
index 0000000..aea0387
--- /dev/null
+++ b/crates/linkme/tests/win_status_access_violation.rs
@@ -0,0 +1,29 @@
+#![cfg_attr(feature = "used_linker", feature(used_with_arg))]
+
+use linkme::distributed_slice;
+
+#[distributed_slice]
+static ITEMS: [&'static str];
+
+#[distributed_slice(ITEMS)]
+static ITEM1: &'static str = "item1";
+
+// Regression test for https://github.com/dtolnay/linkme/issues/67.
+//
+// Must be run with `--release`.
+#[test]
+fn win_status_access_violation() {
+ let mut last_address = None;
+ for item in ITEMS {
+ // Do some busy work to push the compiler into optimizing the code in a
+ // particularly "bad" way. This is derived from experimentation.
+ let address = item as *const &str as usize;
+ if let Some(last) = last_address {
+ assert_eq!(address - last, std::mem::size_of::<&str>());
+ }
+ last_address = Some(address);
+
+ // Should not cause STATUS_ACCESS_VIOLATION.
+ println!("{} {:?}", item.len(), item.as_bytes());
+ }
+}
diff --git a/crates/linkme/tests/win_status_illegal_instruction.rs b/crates/linkme/tests/win_status_illegal_instruction.rs
new file mode 100644
index 0000000..b6a6799
--- /dev/null
+++ b/crates/linkme/tests/win_status_illegal_instruction.rs
@@ -0,0 +1,41 @@
+#![cfg_attr(feature = "used_linker", feature(used_with_arg))]
+
+use linkme::distributed_slice;
+
+pub struct Item {
+ pub name: &'static str,
+}
+
+impl Item {
+ #[inline(never)]
+ fn len(&self) -> usize {
+ self.name.len()
+ }
+}
+
+#[distributed_slice]
+static ITEMS: [Item];
+
+#[distributed_slice(ITEMS)]
+static ITEM1: Item = Item { name: "item1" };
+
+// Regression test for https://github.com/dtolnay/linkme/issues/67.
+//
+// Must be run with `--release`.
+#[test]
+fn win_status_illegal_instruction() {
+ let mut last_address = None;
+ for item in ITEMS {
+ // Do some busy work to push the compiler into optimizing the code in a
+ // particularly "bad" way. This is derived from experimentation.
+ let address = item as *const Item as usize;
+ if let Some(last) = last_address {
+ assert_eq!(address - last, std::mem::size_of::<Item>());
+ }
+ last_address = Some(address);
+ println!("{} {:?}", item.len(), item.name);
+
+ // Should not cause STATUS_ILLEGAL_INSTRUCTION.
+ assert_eq!(item.len(), 5);
+ }
+}
diff --git a/pseudo_crate/Cargo.lock b/pseudo_crate/Cargo.lock
index 984e54a..4034e94 100644
--- a/pseudo_crate/Cargo.lock
+++ b/pseudo_crate/Cargo.lock
@@ -2969,18 +2969,18 @@
[[package]]
name = "linkme"
-version = "0.3.10"
+version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "97f3302efc6ebb7b5f0810a1096dbbb44a536711a4576bc89264a8f9a1d634d8"
+checksum = "566336154b9e58a4f055f6dd4cbab62c7dc0826ce3c0a04e63b2d2ecd784cdae"
dependencies = [
"linkme-impl",
]
[[package]]
name = "linkme-impl"
-version = "0.3.10"
+version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "279a77bf40c85a08513aca203635b96610ebf0e37a92cb0cee76e04da100a426"
+checksum = "edbe595006d355eaf9ae11db92707d4338cd2384d16866131cc1afdbdd35d8d9"
dependencies = [
"proc-macro2 1.0.93",
"quote 1.0.38",
@@ -3001,20 +3001,11 @@
[[package]]
name = "litrs"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b487d13a3f4b465df87895a37b24e364907019afa12d943528df5b7abe0836f1"
-dependencies = [
- "proc-macro2 1.0.93",
-]
-
-[[package]]
-name = "litrs"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5"
dependencies = [
- "proc-macro2 1.0.92",
+ "proc-macro2 1.0.93",
]
[[package]]
@@ -3338,18 +3329,6 @@
[[package]]
name = "mockall_derive"
-version = "0.12.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af7cbce79ec385a1d4f54baa90a76401eb15d9cab93685f62e7e9f942aa00ae2"
-dependencies = [
- "cfg-if",
- "proc-macro2 1.0.93",
- "quote 1.0.38",
- "syn 2.0.96",
-]
-
-[[package]]
-name = "mockall_derive"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25ca3004c2efe9011bd4e461bd8256445052b9615405b4f7ea43fc8ca5c20898"
@@ -3634,7 +3613,7 @@
dependencies = [
"proc-macro2 1.0.93",
"quote 1.0.38",
- "syn 2.0.90",
+ "syn 2.0.96",
]
[[package]]
@@ -4371,7 +4350,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834"
dependencies = [
- "bitflags 2.6.0",
+ "bitflags 2.7.0",
]
[[package]]
@@ -5229,9 +5208,9 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d9ef545650e79f30233c0003bcc2504d7efac6dad25fca40744de773fe2049c"
dependencies = [
- "proc-macro2 1.0.92",
+ "proc-macro2 1.0.93",
"quote 1.0.38",
- "syn 2.0.90",
+ "syn 2.0.96",
]
[[package]]
diff --git a/pseudo_crate/Cargo.toml b/pseudo_crate/Cargo.toml
index e24e8f0..b2f861a 100644
--- a/pseudo_crate/Cargo.toml
+++ b/pseudo_crate/Cargo.toml
@@ -173,8 +173,8 @@
libusb1-sys = "=0.7.0"
libz-sys = "=1.1.8"
linked-hash-map = "=0.5.6"
-linkme = "=0.3.10"
-linkme-impl = "=0.3.10"
+linkme = "=0.3.31"
+linkme-impl = "=0.3.31"
litrs = "=0.4.1"
lock_api = "=0.4.12"
log = "=0.4.22"