No method named `to_owned` found for type `&'static str`

I have been trying to compile Parity Substrate (https://github.com/paritytech/substrate) but I am getting very weird errors. Looks like rust is broken or sort of....
I am using rust nightly: rustc 1.41.0-nightly (ae1b871cc 2019-12-06)

How can "to_owned" function be non-existent? Here is the output from the log, there are other errors showing up. :

   Fresh crossbeam-epoch v0.8.0
   Fresh primitive-types v0.6.1
   Fresh parking_lot v0.8.0
   Compiling primitive-types v0.5.1
 Running `rustc --crate-name primitive_types /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/primitive-types-0.5.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg 'feature="codec"' --cfg 'feature="impl-codec"' -C metadata=5b770e4233bd35ec -C extra-filename=-5b770e4233bd35ec --out-dir /home/myuser/work/newsub/target/debug/deps -L dependency=/home/myuser/work/newsub/target/debug/deps --extern fixed_hash=/home/myuser/work/newsub/target/debug/deps/libfixed_hash-b55cfd68ad8d0fde.rmeta --extern impl_codec=/home/myuser/work/newsub/target/debug/deps/libimpl_codec-d05ef4dee597c332.rmeta --extern uint=/home/myuser/work/newsub/target/debug/deps/libuint-91a500505529ed06.rmeta 
--cap-lints allow`
error[E0412]: cannot find type `Vec` in this scope
  --> /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/primitive-types-0.5.1/src/lib.rs:47:1
   |
47 | / construct_uint! {
48 | |     /// 128-bit unsigned integer.
49 | |     pub struct U128(2);
50 | | }
   | |_^ not found in this scope
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0412]: cannot find type `Vec` in this scope
  --> /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/primitive-types-0.5.1/src/lib.rs:51:1
   |
51 | / construct_uint! {
52 | |     /// 256-bit unsigned integer.
53 | |     pub struct U256(4);
54 | | }
   | |_^ not found in this scope
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0412]: cannot find type `Vec` in this scope
  --> /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/primitive-types-0.5.1/src/lib.rs:55:1
   |
55 | / construct_uint! {
56 | |     /// 512-bits unsigned integer.
57 | |     pub struct U512(8);
58 | | }
   | |_^ not found in this scope
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

   Compiling substrate-bip39 v0.3.1
 Running `rustc --edition=2018 --crate-name substrate_bip39 /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/substrate-bip39-0.3.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 -C metadata=c007034c9abfc446 -C extra-filename=-c007034c9abfc446 --out-dir /home/myuser/work/newsub/target/debug/deps -L dependency=/home/myuser/work/newsub/target/debug/deps --extern hmac=/home/myuser/work/newsub/target/debug/deps/libhmac-75d7415ee7d66ca5.rmeta --extern pbkdf2=/home/myuser/work/newsub/target/debug/deps/libpbkdf2-b17c6e10d37c7dc9.rmeta --extern schnorrkel=/home/myuser/work/newsub/target/debug/deps/libschnorrkel-41d609dcb7bbe93b.rmeta --extern 
sha2=/home/myuser/work/newsub/target/debug/deps/libsha2-0f50b9893b5e5584.rmeta --cap-lints allow -L native=/home/myuser/work/newsub/target/debug/build/clear_on_drop-f587d150ac493b4a/out -L native=/home/myuser/work/newsub/target/debug/build/backtrace-sys-dae8268ed6f8ab38/out`
   Compiling schnorrkel v0.1.1
 Running `rustc --crate-name schnorrkel /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/schnorrkel-0.1.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="std"' --cfg 'feature="u64_backend"' -C metadata=7b5565ad3344c3dc -C extra-filename=-7b5565ad3344c3dc --out-dir /home/myuser/work/newsub/target/debug/deps -L dependency=/home/myuser/work/newsub/target/debug/deps --extern clear_on_drop=/home/myuser/work/newsub/target/debug/deps/libclear_on_drop-5a0034a05013434c.rmeta --extern curve25519_dalek=/home/myuser/work/newsub/target/debug/deps/libcurve25519_dalek-65e9386a8f012498.rmeta --extern 
ed25519_dalek=/home/myuser/work/newsub/target/debug/deps/libed25519_dalek-b02be957f5dabf46.rmeta --extern failure=/home/myuser/work/newsub/target/debug/deps/libfailure-82b700608980d1f3.rmeta --extern merlin=/home/myuser/work/newsub/target/debug/deps/libmerlin-7a30e82ffc5187fd.rmeta --extern rand=/home/myuser/work/newsub/target/debug/deps/librand-340d6201378eece7.rmeta --extern rand_chacha=/home/myuser/work/newsub/target/debug/deps/librand_chacha-2e535663940bee6a.rmeta --extern sha2=/home/myuser/work/newsub/target/debug/deps/libsha2-0f50b9893b5e5584.rmeta --extern sha3=/home/myuser/work/newsub/target/debug/deps/libsha3-0047b1e9c711bdeb.rmeta --extern subtle=/home/myuser/work/newsub/target/debug/deps/libsubtle-f852a10ca2166dba.rmeta --cap-lints allow -L 
native=/home/myuser/work/newsub/target/debug/build/clear_on_drop-f587d150ac493b4a/out -L native=/home/myuser/work/newsub/target/debug/build/backtrace-sys-dae8268ed6f8ab38/out`
   Fresh tokio-reactor v0.1.10
   Compiling libp2p-core v0.13.0
 Running `rustc --edition=2018 --crate-name libp2p_core /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/libp2p-core-0.13.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="libsecp256k1"' --cfg 'feature="secp256k1"' -C metadata=55d2959c2d35bc3c -C extra-filename=-55d2959c2d35bc3c --out-dir /home/myuser/work/newsub/target/debug/deps -L dependency=/home/myuser/work/newsub/target/debug/deps --extern asn1_der=/home/myuser/work/newsub/target/debug/deps/libasn1_der-9647ce416811c448.rmeta --extern bs58=/home/myuser/work/newsub/target/debug/deps/libbs58-099b505de93529c6.rmeta --extern 
bytes=/home/myuser/work/newsub/target/debug/deps/libbytes-5351cb7ca8f8a527.rmeta --extern ed25519_dalek=/home/myuser/work/newsub/target/debug/deps/libed25519_dalek-b02be957f5dabf46.rmeta --extern failure=/home/myuser/work/newsub/target/debug/deps/libfailure-82b700608980d1f3.rmeta --extern fnv=/home/myuser/work/newsub/target/debug/deps/libfnv-b2aa6195f071dbc3.rmeta --extern futures=/home/myuser/work/newsub/target/debug/deps/libfutures-f1d80f634ec34ab0.rmeta --extern lazy_static=/home/myuser/work/newsub/target/debug/deps/liblazy_static-cbf9a4addb74aff2.rmeta --extern secp256k1=/home/myuser/work/newsub/target/debug/deps/libsecp256k1-81eb92f46d48d4f0.rmeta --extern log=/home/myuser/work/newsub/target/debug/deps/liblog-3bc02cd32135eb4b.rmeta --extern 
multistream_select=/home/myuser/work/newsub/target/debug/deps/libmultistream_select-0da9c0e3f27bc4a8.rmeta --extern multiaddr=/home/myuser/work/newsub/target/debug/deps/libparity_multiaddr-248bf62d1aa30e65.rmeta --extern multihash=/home/myuser/work/newsub/target/debug/deps/libparity_multihash-72c4ba1ff5be660c.rmeta --extern parking_lot=/home/myuser/work/newsub/target/debug/deps/libparking_lot-0b75631d1d952cbb.rmeta --extern protobuf=/home/myuser/work/newsub/target/debug/deps/libprotobuf-6292fb745c6f2fb4.rmeta --extern quick_error=/home/myuser/work/newsub/target/debug/deps/libquick_error-df6348e117a9244f.rmeta --extern rand=/home/myuser/work/newsub/target/debug/deps/librand-834d721221dda0de.rmeta --extern 
ring=/home/myuser/work/newsub/target/debug/deps/libring-e45edb8e7ec94c06.rmeta --extern rw_stream_sink=/home/myuser/work/newsub/target/debug/deps/librw_stream_sink-27e308a89488a35a.rmeta --extern sha2=/home/myuser/work/newsub/target/debug/deps/libsha2-0f50b9893b5e5584.rmeta --extern smallvec=/home/myuser/work/newsub/target/debug/deps/libsmallvec-ec0f8fa983224b16.rmeta --extern tokio_executor=/home/myuser/work/newsub/target/debug/deps/libtokio_executor-ff884396307f0286.rmeta --extern tokio_io=/home/myuser/work/newsub/target/debug/deps/libtokio_io-a44249917733ee50.rmeta --extern unsigned_varint=/home/myuser/work/newsub/target/debug/deps/libunsigned_varint-6c5254ace1a7d493.rmeta --extern untrusted=/home/myuser/work/newsub/target/debug/deps/libuntrusted-eb52a4c0f01a7386.rmeta 
--extern void=/home/myuser/work/newsub/target/debug/deps/libvoid-910dde65579f95c7.rmeta --extern wasm_timer=/home/myuser/work/newsub/target/debug/deps/libwasm_timer-4694ae06ab0e307b.rmeta --extern zeroize=/home/myuser/work/newsub/target/debug/deps/libzeroize-ac93ccf2af5f1a0e.rmeta --cap-lints allow -L native=/home/myuser/work/newsub/target/debug/build/clear_on_drop-f587d150ac493b4a/out -L native=/home/myuser/work/newsub/target/debug/build/backtrace-sys-dae8268ed6f8ab38/out -L native=/home/myuser/work/newsub/target/debug/build/ring-0aaa4086469bb882/out`
error[E0599]: no method named `to_owned` found for type `&'static str` in the current scope
  --> /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/primitive-types-0.5.1/src/lib.rs:47:1
   |
47 | / construct_uint! {
48 | |     /// 128-bit unsigned integer.
49 | |     pub struct U128(2);
50 | | }
   | |_^ method not found in `&'static str`
   |
   = help: items from traits can only be used if the trait is in scope
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
38 | use fixed_hash::alloc::borrow::ToOwned;
   |

error[E0599]: no method named `to_owned` found for type `&'static str` in the current scope
  --> /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/primitive-types-0.5.1/src/lib.rs:51:1
   |
51 | / construct_uint! {
52 | |     /// 256-bit unsigned integer.
53 | |     pub struct U256(4);
54 | | }
   | |_^ method not found in `&'static str`
   |
   = help: items from traits can only be used if the trait is in scope
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
38 | use fixed_hash::alloc::borrow::ToOwned;
   |

   Fresh yamux v0.2.2
   Compiling librocksdb-sys v6.2.4
 Running `rustc --crate-name build_script_build /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/librocksdb-sys-6.2.4/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="bzip2"' --cfg 'feature="default"' --cfg 'feature="lz4"' --cfg 'feature="snappy"' --cfg 'feature="static"' --cfg 'feature="zlib"' --cfg 'feature="zstd"' -C metadata=dc9f19fd13d89d49 -C extra-filename=-dc9f19fd13d89d49 --out-dir /home/myuser/work/newsub/target/debug/build/librocksdb-sys-dc9f19fd13d89d49 -L dependency=/home/myuser/work/newsub/target/debug/deps --extern bindgen=/home/myuser/work/newsub/target/debug/deps/libbindgen-fc46b2e62969ac8d.rlib --extern 
cc=/home/myuser/work/newsub/target/debug/deps/libcc-1283709ef612c87c.rlib --extern glob=/home/myuser/work/newsub/target/debug/deps/libglob-465545bfb4872e71.rlib --cap-lints allow -L native=/home/myuser/work/newsub/target/debug/build/libloading-3deec99698281a21/out -L native=/home/myuser/work/newsub/target/debug/build/backtrace-sys-dae8268ed6f8ab38/out`
error[E0599]: no method named `to_owned` found for type `&'static str` in the current scope
  --> /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/primitive-types-0.5.1/src/lib.rs:55:1
   |
55 | / construct_uint! {
56 | |     /// 512-bits unsigned integer.
57 | |     pub struct U512(8);
58 | | }
   | |_^ method not found in `&'static str`
   |
   = help: items from traits can only be used if the trait is in scope
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
38 | use fixed_hash::alloc::borrow::ToOwned;

That doesn't look right. It's as if you're missing the standard library. Have you tried another nighty? rustup accepts a date to install other nightly versions.

1 Like

Well , some of the code is compiling with "no_std" attribute , for example this verbose output shows a different std library is used:

 Running `rustc --edition=2018 --crate-name sp_runtime_interface primitives/runtime-interface/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="disable_target_static_assertions"' --cfg 'feature="environmental"' --cfg 'feature="externalities"' --cfg 'feature="std"' --cfg 'feature="wasm-interface"' -C metadata=75ccaef0411990b8 -C extra-filename=-75ccaef0411990b8 --out-dir /home/myuser/work/newsub/target/debug/deps -C incremental=/home/myuser/work/newsub/target/debug/incremental -L dependency=/home/myuser/work/newsub/target/debug/deps --extern environmental=/home/myuser/work/newsub/target/debug/deps/libenvironmental-2d231219b775a839.rmeta --extern 
codec=/home/myuser/work/newsub/target/debug/deps/libparity_scale_codec-30505dc129a71626.rmeta --extern primitive_types=/home/myuser/work/newsub/target/debug/deps/libprimitive_types-639dced981668548.rmeta --extern externalities=/home/myuser/work/newsub/target/debug/deps/libsp_externalities-8bdd4fb95bb5b7d8.rmeta --extern sp_runtime_interface_proc_macro=/home/myuser/work/newsub/target/debug/deps/libsp_runtime_interface_proc_macro-aa5d19fac181ba14.so --extern rstd=/home/myuser/work/newsub/target/debug/deps/libsp_std-9de2c6c87816d8cc.rmeta --extern wasm_interface=/home/myuser/work/newsub/target/debug/deps/libsp_wasm_interface-6fd4b6d9d9031753.rmeta --extern static_assertions=/home/myuser/work/newsub/target/debug/deps/libstatic_assertions-d55f434d659a87eb.rmeta`
error[E0599]: no method named `to_owned` found for type `&'static str` in the current scope
  --> /home/myuser/.cargo/registry/src/github.com-1ecc6299db9ec823/primitive-types-0.5.1/src/lib.rs:47:1
   |
47 | / construct_uint! {
48 | |     /// 128-bit unsigned integer.
49 | |     pub struct U128(2);
50 | | }
   | |_^ method not found in `&'static str`

In that case this code is simply not compatible with no_std. to_owned() requires a memory allocator which is not available in no_std environment.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.