Skip to content

fix(str): import alloc::borrow::ToOwned in no_std + alloc builds#1280

Merged
Benoît Cortier (CBenoit) merged 1 commit into
Devolutions:masterfrom
lamco-admin:fix/str-import-alloc-borrow-toowned
May 18, 2026
Merged

fix(str): import alloc::borrow::ToOwned in no_std + alloc builds#1280
Benoît Cortier (CBenoit) merged 1 commit into
Devolutions:masterfrom
lamco-admin:fix/str-import-alloc-borrow-toowned

Conversation

@glamberson
Copy link
Copy Markdown
Contributor

Summary

Closes the no_std + alloc compile failure in ironrdp-str flagged as
Category A of the workspace feature-matrix scan in #1123
(#1123 (comment)).

Approach

ironrdp-str/src/prefixed.rs and ironrdp-str/src/unframed.rs both
define impl From<&str> blocks that call s.to_owned() to lift the
borrowed string into an owned representation. .to_owned() is a method
from the alloc::borrow::ToOwned trait. In std builds the std prelude
brings ToOwned into scope automatically; the alloc prelude does not.
With --no-default-features --features alloc the call sites fail with
E0599: no method named 'to_owned' found for reference '&str' in the current scope.

Adds:

#[cfg(not(feature = "std"))]
use alloc::borrow::ToOwned;

to both files, matching the existing pattern that gates the
use alloc::{string::String, vec::Vec}; imports on the same cfg.
lib.rs already gates these modules behind #[cfg(feature = "alloc")],
so alloc is guaranteed available wherever the import compiles.

Verification

  • cargo check -p ironrdp-str — green
  • cargo check -p ironrdp-str --features std — green
  • cargo check -p ironrdp-str --no-default-features --features alloc — green (was failing before)
  • cargo check -p ironrdp-str --no-default-features — green
  • cargo xtask check fmt -v — green
  • cargo xtask check lints -v — green
  • cargo xtask check tests -v — green
  • cargo xtask check typos -v — green

References

ironrdp-str's prefixed and unframed modules call .to_owned() on &str
in their From<&str> impls. In std builds the std prelude brings ToOwned
into scope automatically, but the alloc prelude does not — so the calls
fail with E0599 when the crate is compiled with
--no-default-features --features alloc.

Adds `#[cfg(not(feature = "std"))] use alloc::borrow::ToOwned;` to both
files, matching the existing pattern that gates the
`use alloc::{string::String, vec::Vec}` imports on the same cfg.

  cargo check -p ironrdp-str
  cargo check -p ironrdp-str --features std
  cargo check -p ironrdp-str --no-default-features --features alloc
  cargo check -p ironrdp-str --no-default-features

All four feature combinations now compile cleanly.
Copy link
Copy Markdown
Member

@CBenoit Benoît Cortier (CBenoit) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM!

@CBenoit Benoît Cortier (CBenoit) merged commit fa78084 into Devolutions:master May 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants