-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Call out the types that are non local on E0117 #65318
Conversation
r? @varkor (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
src/test/ui/coherence/coherence-fundamental-trait-objects.old.stderr
Outdated
Show resolved
Hide resolved
@@ -60,7 +60,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar | |||
LL | impl Copy for (MyType, MyType) {} | |||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | |||
| | |||
= note: the impl does not reference only types defined in this crate | |||
= note: `(MyType, MyType)` is not defined in the current create |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be MyType
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this error is emitted at all, I think it might be due to the tuple? I don't know how we'd change the wording to be more accurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's possible to impl for MyType
, it should also be possible to impl for (MyType, MyType)
, so I think we should emit the types that are causing the root problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing a trait external to the current crate on a tuple, array or slice of a type from the current crate is not ever allowed. I extended the output to make that a bit clearer, but can add more text if that would help.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | ||
| ^^^^^^^^^^^^^^---------------------- | ||
| | | | ||
| | `(dyn coherence_fundamental_trait_lib::Fundamental<Local> + 'static)` is not defined in the current crate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be `coherence_fundamental_trait_lib::Fundamental<Local>` is not defined in the current crate
. Having the dyn
and lifetime bound is confusing (also + 'static
is default, so needn't be included).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't remove the dyn
, but that shouldn't be too big of a problem.
err.span_label(sp, "impl doesn't use only types from inside the current crate"); | ||
for (ty, is_target_ty) in &tys { | ||
// FIXME: We want to remove the type arguments from the displayed type. | ||
// The reverse of `resolve_vars_if_possible`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone know what the proper way of "reversing" resolve_vars_if_possible
would be?
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate | ||
| ^^^^^^^^^^^^^^---------------------- | ||
| | | | ||
| | `dyn coherence_fundamental_trait_lib::Fundamental<Local>` is not defined in the current crate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can get away with just printing the path, without dyn
or the generics, etc. E.g. here we would just have:
`coherence_fundamental_trait_lib::Fundamental` is not defined in the current crate
because dyn
and <Local>
are red herrings: they're not what's causing the error (if they were, we should have specific error messages calling them out, like array impls).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, I just read your comment here: #65318 (comment). Sorry if I seem like a broken record: I'm just worried that these more specific error messages might be more confusing when they contain this extra information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking over the current test output, and the only cases where we mention dyn
already have dyn
in the code (or would if the user follows the warnings). The dyn
is written unconditionally in the pprinting machinery, and removing would only work for some cases (you could have (dyn T + K)
, which couldn't be represented with acurately bare path).
| ^^^^^---------------^^^^^----- | ||
| | | | | ||
| | | `isize` is not defined in the current crate | ||
| | `usize` is not defined in the current crate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The span for usize
is a bit odd: I would expect it to point to the generic argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have a way to point at specific type params at the moment, but if be happy to add that in a follow up PR.
I do believe it will be fairly involved to get the right span, which is why I'd like to do it after merging this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, sounds good to me :)
src/librustc/traits/coherence.rs
Outdated
@@ -237,7 +237,7 @@ pub fn trait_ref_is_local_or_fundamental<'tcx>( | |||
} | |||
|
|||
pub enum OrphanCheckErr<'tcx> { | |||
NoLocalInputType, | |||
NonLocalInputType(Vec<(Ty<'tcx>, bool)>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice having a comment here explaining what the field means.
r=me with the small span comment addressed. |
@bors r=varkor |
📌 Commit dc41d6f18c6c9756e83a53193e2376531f0cdfeb has been approved by |
☔ The latest upstream changes (presumably #65869) made this pull request unmergeable. Please resolve the merge conflicts. |
@bors r=varkor |
📌 Commit 627691f has been approved by |
Call out the types that are non local on E0117 CC rust-lang#24745.
Call out the types that are non local on E0117 CC rust-lang#24745.
Call out the types that are non local on E0117 CC rust-lang#24745.
Rollup of 5 pull requests Successful merges: - #65294 (Lint ignored `#[inline]` on function prototypes) - #65318 (Call out the types that are non local on E0117) - #65531 (Update backtrace to 0.3.40) - #65562 (Improve the "try using a variant of the expected type" hint.) - #65809 (Add new EFIAPI ABI) Failed merges: r? @ghost
☔ The latest upstream changes (presumably #65919) made this pull request unmergeable. Please resolve the merge conflicts. |
CC #24745.