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

Call out the types that are non local on E0117 #65318

Merged
merged 8 commits into from
Oct 29, 2019

Conversation

estebank
Copy link
Contributor

CC #24745.

@rust-highfive
Copy link
Collaborator

r? @varkor

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 11, 2019
@rust-highfive

This comment has been minimized.

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

@estebank estebank Oct 23, 2019

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
Copy link
Member

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).

Copy link
Contributor Author

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`.
Copy link
Contributor Author

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
Copy link
Member

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).

Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

@varkor varkor Oct 24, 2019

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.

Copy link
Contributor Author

@estebank estebank Oct 24, 2019

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.

Copy link
Member

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 :)

@@ -237,7 +237,7 @@ pub fn trait_ref_is_local_or_fundamental<'tcx>(
}

pub enum OrphanCheckErr<'tcx> {
NoLocalInputType,
NonLocalInputType(Vec<(Ty<'tcx>, bool)>),
Copy link
Member

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.

@varkor
Copy link
Member

varkor commented Oct 24, 2019

r=me with the small span comment addressed.

@varkor varkor added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 25, 2019
@estebank
Copy link
Contributor Author

@bors r=varkor

@bors
Copy link
Contributor

bors commented Oct 27, 2019

📌 Commit dc41d6f18c6c9756e83a53193e2376531f0cdfeb has been approved by varkor

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 27, 2019
@bors
Copy link
Contributor

bors commented Oct 27, 2019

☔ The latest upstream changes (presumably #65869) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 27, 2019
@estebank
Copy link
Contributor Author

@bors r=varkor

@bors
Copy link
Contributor

bors commented Oct 28, 2019

📌 Commit 627691f has been approved by varkor

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 28, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 29, 2019
Call out the types that are non local on E0117

CC rust-lang#24745.
Centril added a commit to Centril/rust that referenced this pull request Oct 29, 2019
Call out the types that are non local on E0117

CC rust-lang#24745.
Centril added a commit to Centril/rust that referenced this pull request Oct 29, 2019
Call out the types that are non local on E0117

CC rust-lang#24745.
bors added a commit that referenced this pull request Oct 29, 2019
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
@bors
Copy link
Contributor

bors commented Oct 29, 2019

☔ The latest upstream changes (presumably #65919) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 29, 2019
@bors bors merged commit 627691f into rust-lang:master Oct 29, 2019
@estebank estebank deleted the coherence branch November 9, 2023 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants