rust-lang / rust-lang/rust-analyzer

FP type annotations needed

Open
#22,978 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

pub trait EvaluateConstMethods {
    type Trait: TraitWithConstMethods;

    const DATA_3: Data3 = {
        <<<Self::Trait as TraitWithConstMethods>::Method2 as ConstFn<_, _>>::Body<
            <<Self::Trait as TraitWithConstMethods>::Method1 as ConstFn<_, _>>::Body<ContainsData1>,
        > as Contains<_>>::ITEM
    };
}

pub trait TraitWithConstMethods {
    type Method1: ConstFn<Data1, Data2>;

    type Method2: ConstFn<Data2, Data3>;
}

pub trait ConstFn<Arg, Ret> {
    type Body<T: Contains<Arg>>: Contains<Ret>;
}

pub trait Contains<T> {
    const ITEM: T;
}

pub struct ContainsData1;
impl Contains<Data1> for ContainsData1 {
    const ITEM: Data1 = Data1 {};
}

pub struct Data1 {}
pub struct Data2 {}
pub struct Data3 {}

fn main() {}

this compiles with rustc but rust-analyzer diagnostics . shows errors

at crate f, file /tmp/f/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 4, col: 69 } to LineCol { line: 4, col: 70 }: type annotations needed
at crate f, file /tmp/f/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 5, col: 75 } to LineCol { line: 5, col: 76 }: type annotations needed
at crate f, file /tmp/f/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 5, col: 72 } to LineCol { line: 5, col: 73 }: type annotations needed

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the provided /tmp/f/src/main.rs by running rustc and then rust-analyzer diagnostics .. Compare the accepted compiler result with the E0282 diagnostics at the shown locations, then trace the diagnostic path for these associated-type and const-expression annotations. Done means rust-analyzer no longer reports false type-annotation errors for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.