rust-lang / rust-lang/rust-analyzer

syntax error on edition 2015 anonymous parameters

Open
#16,291 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description


trait ParseError {
    type StreamError;
}
impl<T> ParseError for T {
    type StreamError = ();
}
trait Stream {
    type Error;
}
trait Parser
where
    <Self as Parser>::PartialState: Default,
{
    type PartialState;
    fn parse_mode(&Self, Self::PartialState) {}
}

pub fn main() {}

this compiles with edition 2015.
rustc:

    Checking bar v0.1.0 (/tmp/bar)
warning: anonymous parameters are deprecated and will be removed in the next edition
  --> src/main.rs:16:19
   |
16 |     fn parse_mode(&Self, Self::PartialState) {}
   |                   ^^^^^ help: try naming the parameter or explicitly ignoring it: `_: &Self`
   |
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
   = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
   = note: `#[warn(anonymous_parameters)]` on by default

warning: anonymous parameters are deprecated and will be removed in the next edition
  --> src/main.rs:16:26
   |
16 |     fn parse_mode(&Self, Self::PartialState) {}
   |                          ^^^^^^^^^^^^^^^^^^ help: try naming the parameter or explicitly ignoring it: `_: Self::PartialState`
   |
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
   = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>

warning: `bar` (bin "bar") generated 2 warnings (run `cargo fix --bin "bar"` to apply 2 suggestions)
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s

ra:

// rust-analyzer diagnostics  .
processing crate: bar, module: /tmp/bar/src/main.rs
Diagnostic { code: RustcHardError("syntax-error"), message: "Syntax Error: missing type for function parameter", range: FileRange { file_id: FileId(11), range: 245..245 }, severity: Error, unused: false, experimental: false, fixes: None, main_node: None }
Diagnostic { code: RustcHardError("syntax-error"), message: "Syntax Error: missing type for function parameter", range: FileRange { file_id: FileId(11), range: 265..265 }, severity: Error, unused: false, experimental: false, fixes: None, main_node: None }

diagnostic scan complete

Error: diagnostic error detected

rust-analyzer 1.77.0-nightly (595bc6f 2024-01-05)

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 example in src/main.rs with Rust 2015 and compare rustc's warnings with rust-analyzer's diagnostics. Trace the syntax-error diagnostics for the anonymous parameters; done when valid edition-2015 code is not reported as missing parameter types while edition-2018 behavior remains correct.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.