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

The span for “trait bound not satisfied” is weird #41817

Closed
nagisa opened this issue May 7, 2017 · 2 comments · Fixed by #65192
Closed

The span for “trait bound not satisfied” is weird #41817

nagisa opened this issue May 7, 2017 · 2 comments · Fixed by #65192
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nagisa
Copy link
Member

nagisa commented May 7, 2017

For following code

pub trait Arbitrary: Sized + 'static {}

impl<'a, A> Arbitrary for ::std::borrow::Cow<'a, A> {}

The error is

error[E0277]: the trait bound `A: std::clone::Clone` is not satisfied
 --> <anon>:3:13
  |
3 | impl<'a, A> Arbitrary for ::std::borrow::Cow<'a, A> {}
  |             ^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `A`
  |
  = help: consider adding a `where A: std::clone::Clone` bound
  = note: required because of the requirements on the impl of `std::borrow::ToOwned` for `A`
  = note: required because it appears within the type `std::borrow::Cow<'a, A>`
  = note: required by `Arbitrary`

Note the span is pointing at Arbitrary, despite error really being about the generic bound A. It should point at A instead.

@nagisa nagisa added A-diagnostics Area: Messages for errors, warnings, and lints I-papercut labels May 7, 2017
@Mark-Simulacrum Mark-Simulacrum added C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed I-papercut labels Jul 26, 2017
@nox
Copy link
Contributor

nox commented Mar 8, 2019

It is kinda a papercut in the case of trait bounds on associated types.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b106643284f7eb37ce6a6f087743952d

struct NotSync(*mut ());

trait AssociatedSync {
    type ShouldBeSync: Sync;
}

struct Dummy;

impl AssociatedSync /* span error points here */ for Dummy {
    type ShouldBeSync = NotSync /* whereas it should probably point here */;
}

@LukasKalbertodt
Copy link
Member

I just attempted to fix it, but I already spent almost two hours into finding the relevant spot in the codebase and gave up for now. Can anyone give me some hints which functions might be relevant? I already roughly understand the functions involved in error reporting and am pretty sure that the wrong span ends up in an ObligationCause. But I have no idea where this span is created. In other words: where the obligation is checked.

@estebank estebank added D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 8, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 19, 2019
…asper

Use structured suggestion for restricting bounds

When a trait bound is not met and restricting a type parameter would
make the restriction hold, use a structured suggestion pointing at an
appropriate place (type param in param list or `where` clause).

Account for opaque parameters where instead of suggesting extending
the `where` clause, we suggest appending the new restriction:
`fn foo(impl Trait + UnmetTrait)`. Fix rust-lang#64565, fix rust-lang#41817, fix rust-lang#24354,
cc rust-lang#26026, cc rust-lang#37808, cc rust-lang#24159, fix rust-lang#37138, fix rust-lang#24354, cc rust-lang#20671.
@bors bors closed this as completed in 7e4ff91 Oct 19, 2019
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-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. 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.

5 participants