Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler suggestion ping-pongs between E0283 and E0562 #113264

Closed
dvogel opened this issue Jul 2, 2023 · 1 comment · Fixed by #113310
Closed

Compiler suggestion ping-pongs between E0283 and E0562 #113264

dvogel opened this issue Jul 2, 2023 · 1 comment · Fixed by #113310
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dvogel
Copy link

dvogel commented Jul 2, 2023

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
@dvogel dvogel added the C-bug Category: This is a bug. label Jul 2, 2023
@Noratrieb Noratrieb added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 3, 2023
@workingjubilee workingjubilee added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Jul 3, 2023
@jieyouxu
Copy link
Member

jieyouxu commented Jul 4, 2023

Smaller example

trait T {}

struct S {}

impl S {
    fn owo(&self, _: Option<&impl T>) {}
}

fn main() {
    (S {}).owo(None)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants