Skip to content

Compiler suggestion ping-pongs between E0283 and E0562 #113264

Closed
@dvogel

Description

@dvogel

I tried to call the gtk-rs insert_before function, with this signature:

    fn insert_before(&self, parent: &impl IsA<Widget>, next_sibling: Option<&impl IsA<Widget>>);

I got this error:

error[E0283]: type annotations needed
   --> src/ui/task_list.rs:115:46
    |
115 |         scroller.insert_before(&*self.obj(), None);
    |                  -------------               ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
    |                  |
    |                  required by a bound introduced by this call

Along with this suggestion:

    |
410 |     fn insert_before(&self, parent: &impl IsA<Widget>, next_sibling: Option<&impl IsA<Widget>>);
    |                                                                                   ^^^^^^^^^^^ required by this bound in `WidgetExt::insert_before`
help: consider specifying the generic argument
    |
115 |         scroller.insert_before(&*self.obj(), None::<&impl IsA<Widget>>);
    |                                                  +++++++++++++++++++++

That suggestion ran me into a different error:

error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in paths
   --> src/ui/task_list.rs:115:54
    |
115 |         scroller.insert_before(&*self.obj(), None::<&impl IsA<Widget>>);
    |                                                      ^^^^^^^^^^^^^^^^

I would expect the first error to understand that using impl Trait within the path would lead me into E0562 and thus not make that suggestion.

Meta

rustc --version --verbose:

rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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