Skip to content

Suggestion to replace generic args with assoc item bindings doesn't properly deal with const args #151602

@fmease

Description

@fmease

Found this while working on PR #150843.

Suggests binding const argument to assoc type

fn take(_: impl Iterator<0>) {}
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
  --> src/lib.rs:1:17
   |
 1 | fn take(_: impl Iterator<0>) {}
   |                 ^^^^^^^^ expected 0 generic arguments
   |
note: trait defined here, with 0 generic parameters
  --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:40:11
   |
40 | pub trait Iterator {
   |           ^^^^^^^^
help: replace the generic bound with the associated type
   |
 1 | fn take(_: impl Iterator<Item = 0>) {}
   |                          ++++++

Doesn't suggest binding const argument to type assoc const under mGCA

#![feature(min_generic_const_args)]
trait Trait { #[type_const] const K: i32; }
fn take(_: impl Trait<0>) {}
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
 --> src/lib.rs:3:17
  |
3 | fn take(_: impl Trait<0>) {}
  |                 ^^^^^--- help: remove the unnecessary generics
  |                 |
  |                 expected 0 generic arguments
  |
note: trait defined here, with 0 generic parameters
 --> src/lib.rs:2:7
  |
2 | trait Trait { #[type_const] const K: i32; }
  |       ^^^^^

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions