') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Support `?Sized` types in `Rng*: TryRng*` blanket impls by tarcieri · Pull Request #51 · rust-random/rand_core · GitHub
Skip to content

Support ?Sized types in Rng*: TryRng* blanket impls - #51

Merged
dhardy merged 2 commits into
masterfrom
support-unsized-types-in-blanket-impls
Jan 20, 2026
Merged

Support ?Sized types in Rng*: TryRng* blanket impls#51
dhardy merged 2 commits into
masterfrom
support-unsized-types-in-blanket-impls

Conversation

@tarcieri

Copy link
Copy Markdown
Contributor

Adds ?Sized to the bounds of the blanket impls, so unsized types can also be used by way of the blanket impl.

See also: #45

Adds `?Sized` to the bounds of the blanket impls, so unsized types can
also be used by way of the blanket impl.
See also: #45
Comment threadsrc/lib.rs
Comment threadsrc/lib.rs

@baloobaloo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Downsteam changes with that:
RustCrypto/SSH#453

Without:
RustCrypto/formats#2175

@tarcieri

tarcieri commented Jan 19, 2026

Copy link
Copy Markdown
ContributorAuthor

Well this is interesting:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=218bb58ea0812eb2f347d8b5008166ab

It seems like if it were:

pubtraitCryptoRng:RngCore{}

instead of

pubtraitCryptoRng:TryRngCore<Error = Infallible>{

...then the entire problem just goes away without having to add an explicit ?Sized bound on the blanket impl?

Edit: aah nope, I think it still needs this change as well to be able to work with trait objects, and we still need a TryCryptoRng bound for CryptoRng, but with this change it's possible to add an explicit RngCore bound to CryptoRng, like:

pubtraitCryptoRng:RngCore + TryCryptoRng<Error = Infallible>{}

...which will ensure/test that a CryptoRng can always act as an RngCore (and oddly without this change it breaks the tests and I'm not sure why).

I will save that for a followup though, so as not to muddy the issue, unless everyone likes it.

@tarcieri

Copy link
Copy Markdown
ContributorAuthor

@baloo yeah, we use <R: CryptoRng + ?Sized> in several places, so it's going to be really annoying (and ideally not necessary) to change all of those to add a RngCore bound

@dhardy I don't suppose it would be possible to get another prerelease out with this PR (and possibly with the added CryptoRng: RngCore bound)? It's going to be annoying to update to v0.10.0-rc-4 as-is

@baloo

Copy link
Copy Markdown
Contributor

Yeah it's a much better solution than having to add the RngCore to every consumer. An RC would really be appreciated!

@tarcieri

tarcieri commented Jan 20, 2026

Copy link
Copy Markdown
ContributorAuthor

I went ahead and did the bounds change I proposed above in 9966877:

pubtraitCryptoRng:RngCore + TryCryptoRng<Error = Infallible>{}

It's just more explicit and ensures that if a CryptoRng works at all it will work as an RngCore.

I kept it in a separate commit in case you just want the ?Sized change for a stopgap rc

@dhardydhardy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have no problem with this change. I'll make a new release later (not much time now).

Comment threadsrc/lib.rs
Comment on lines -89 to +92
pub trait CryptoRng: TryCryptoRng<Error = Infallible> {}
pub trait CryptoRng: RngCore + TryCryptoRng<Error = Infallible> {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting that this is necessary; it seems to indicate a trait solver issue.

But simple solutions are good!

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I think having explicit bounds even if they're covered by a blanket impl makes the compiler errors much better, because it will tell you explicitly why the bound wasn't satisfied, whereas figuring out why a blanket impl didn't work can be a lot of red herrings

@dhardy
dhardy merged commit f12a2d6 into masterJan 20, 2026
13 checks passed
@dhardy
dhardy deleted the support-unsized-types-in-blanket-impls branch January 20, 2026 10:52
@dhardydhardy mentioned this pull request Jan 20, 2026
@dhardydhardy mentioned this pull request Jan 23, 2026
17 tasks
takumi-earth pushed a commit to earthlings-dev/rand_core that referenced this pull request Jan 27, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@tarcieri@baloo@dhardy