New trait solver can't infer types inferable by the old solver
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
We're trying out the new trait solver from #160895 on Fuchsia, and we've found two cases where type inference fails, and so we need to explicitly specify the error. We've got two places so far where we've needed to do that:
- failure in starnix's ebpf_api, see fuchsia bug and fix, code link before the patch
- failure in rust-tuf, see fuchsia bug with fix, code link before patch
The error message looks something like:
error[E0283]: type annotations needed
--> ../../src/starnix/lib/ebpf_api/src/helpers.rs:825:66
|
825 | (bpf_func_id_BPF_FUNC_get_socket_uid, EbpfHelperImpl(bpf_get_socket_uid)),
| ^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `C` declared on the function `bpf_get_socket_uid`
|
= note: the type must implement `SocketUidProgramContext`
= note: cannot satisfy `for<'a> <Self as EbpfProgramContext>::RunContext<'a> == _`
note: required by a bound in `bpf_get_socket_uid`
--> ../../src/starnix/lib/ebpf_api/src/helpers.rs:422:30
|
422 | fn bpf_get_socket_uid<'a, C: SocketUidProgramContext>(
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `bpf_get_socket_uid`
help: consider specifying a concrete type for the type parameter `C`
|
825 | (bpf_func_id_BPF_FUNC_get_socket_uid, EbpfHelperImpl(bpf_get_socket_uid::</* Type */>)),
| ++++++++++++++
Both of these places are pretty big, so I had the Gemini AI help to reduce it down:
pub trait EbpfProgramContext: Sized {
type RunContext<'a>;
}
pub struct EbpfHelperImpl<C: EbpfProgramContext>(
pub for<'a> fn(&mut C::RunContext<'a>),
);
pub fn bpf_get_netns_cookie<C: EbpfProgramContext>(_context: &mut C::RunContext<'_>) {}
pub trait CgroupSockProgramContext: EbpfProgramContext {
fn get_helper() -> EbpfHelperImpl<Self> {
EbpfHelperImpl(bpf_get_netns_cookie)
}
}
With stable, it compiles without error:
% rustup run stable rustc --crate-type lib bar.rs
With nightly I get this error:
% rustup run nightly rustc --crate-type lib bar.rs
error[E0283]: type annotations needed
--> bar.rs:10:24
|
10 | EbpfHelperImpl(bpf_get_netns_cookie)
| ^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `C` declared on the function `bpf_get_netns_cookie`
|
= note: the type must implement `EbpfProgramContext`
= note: cannot satisfy `for<'a> <Self as EbpfProgramContext>::RunContext<'a> == _`
note: required by a bound in `bpf_get_netns_cookie`
--> bar.rs:7:32
|
7 | pub fn bpf_get_netns_cookie<C: EbpfProgramContext>(_context: &mut C::RunContext<'_>) {}
| ^^^^^^^^^^^^^^^^^^ required by this bound in `bpf_get_netns_cookie`
help: consider specifying a concrete type for the type parameter `C`
|
10 | EbpfHelperImpl(bpf_get_netns_cookie::</* Type */>)
| ++++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0283`.
It also made a reproducer for rust-tuf, where the error has a different shape so it might be from a different cause?
pub trait Trait {
type Out;
fn get(&self) -> Self::Out;
}
impl Trait for () {
type Out = ();
fn get(&self) {}
}
pub fn foo(recurse: bool) -> impl Trait<Out = ()> {
if recurse {
let x: &dyn Trait<Out = _> = &foo(false);
let _ = x.get().clone();
}
}
It compiles fine with stable:
% rustup run stable rustc --crate-type lib foo.rs
And fails with nightly:
% rustup run nightly rustc --crate-type lib foo.rs
error[E0282]: type annotations needed
--> foo.rs:12:19
|
12 | let _ = x.get().clone();
| ^^^
|
help: try using a fully qualified path to specify the expected types
|
12 - let _ = x.get().clone();
12 + let _ = <dyn Trait<Out = _> as Trait>::get(x).clone();
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0282`.
Meta
rustup run stable rustc --version --verbose:
rustup run stable rustc --version
rustc 1.98.0 (88d9e12ae 2026-08-18)
rustup run nightly rustc --version --verbose:
rustc 1.100.0-nightly (c656540d6 2026-08-21)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the reduced reproducers in bar.rs and foo.rs with the stable and nightly rustc versions shown in the issue, then compare the new trait solver's inference behavior. Trace the reported E0283 and E0282 constraints and add coverage for both cases; done means nightly accepts the examples without explicit type annotations, matching stable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100