惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
Y
Y Combinator Blog
博客园 - Franky
D
Docker
B
Blog RSS Feed
M
MIT News - Artificial intelligence
雷峰网
雷峰网
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
S
SegmentFault 最新的问题
GbyAI
GbyAI
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
B
Blog
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
Vercel News
Vercel News
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News

The Rust Programming Language Forum - Latest posts

What's everyone working on this week (21/2026)? Rust Function Call with one Param Iced + Canvas + Text: How do I create a style for canvas text "Value dropped while borrowed" as a lifetime mismatch Weird `use of moved value` behaviour Slightly surprising behavior of a while loop Clap: how to disable options after a certain positional argument How do i tell rust-analyzer what kind of bracket to use for a macro? Iterator + Borrow Checker: Work around borrowing already borrowed mutable variable Requesting data via mavlink SKILLS.md for Rust development 🧵 Stringlet UTF-8 Hack Option Niche? Iterator + Map - How do divide every element, including the last element, by the last element Why can't we store returned value of a function in a variable if one of the parameters goes out of scope My first crate :D, floop: A more convenient and less error prone replacement for loop `{ select! { .. }}` Sorting is slow because architectures are wrong — zan-sort redesigns the architecture, not the algorithm Iced Font - Create a custom monospace font to display dollar amounts Is the UnsafePinned RFC wrong about being able to return `&mut T` from `get_mut_unchecked`? Fixing Polars 0.37 compilation errors: Hashbrown 0.17 dependency conflict and decimal parsing Any plans for improving error diagnostic in Rust 2.0? How do I build completely offline? Is `&mut T -> &mut ManuallyDrop<T>` well-defined and sound? Would you use this? — fixtura, declarative fake data injection for tests Foreign trait restrictions on native types make generics hard to use Cargo Exclude Directive Compiler reasoning around a modulo counter Multiple mutable references to elements within one vector Handling non-`Send` data in a `Send` closure Review: Static Multi Pool Allocator Rmquickjs - High-level MicroQuickJS bindings for Rust
Can a future used only by `async fn` assume it won&#39;t ...
@jacobsa Aar · 2026-04-24 · via The Rust Programming Language Forum - Latest posts
Hi all, I thought about this more and I don't think the consensus above necessairly makes sense. You all seem to think the status quo is appropriate because it allows the compiler to optimize away the last state machine transition (from state that returns to "I have returned" state). But it certainly can't do that in general, as it may introduce UB depending on what that state does. Here is a super simple example: // # Safety // // The caller must guarantee the Option is Some. async unsafe fn take_some<T>(o: &mut Option<T>) -> T { unsafe { o.take().unwrap_unchecked() } } This can be called to obtain a Future , which is explicitly documented as allowing polling again after completion. As far as I can tell that means the compiler is forced to insert a transition to a state that will panic if polled again or else it will cause UB in safe code like this function: fn inefficient_take_that_might_panic<T>(o: &mut Option<T>) -> Option<T> { if o.is_none() { return None; } // Safety: we confirmed this is Some. let mut future = pin!(unsafe { take_some(o) }); let result = match future .as_mut() .poll(&mut Context::from_waker(Waker::noop())) { Poll::Ready(result) => result, _ => std::unreachable!(), }; // Totally valid by the Future docs. let _ = future.poll(&mut Context::from_waker(Waker::noop())); Some(result) } I'm pretty sure you can come up with similar examples that don't involve the unsafe keyword as well.