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

E0194 needs to be updated to new format #35280

Closed
sophiajt opened this issue Aug 4, 2016 · 8 comments
Closed

E0194 needs to be updated to new format #35280

sophiajt opened this issue Aug 4, 2016 · 8 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@sophiajt
Copy link
Contributor

sophiajt commented Aug 4, 2016

From: src/test/compile-fail/E0194.rs

Error E0194 needs a span_label, updating it from:

error[E0194]: type parameter `T` shadows another type parameter of the same name
  --> src/test/compile-fail/E0194.rs:13:5
   |
13 |     fn do_something_else<T: Clone>(&self, bar: T); //~ ERROR E0194
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To:

error[E0194]: type parameter `T` shadows another type parameter of the same name
  --> src/test/compile-fail/E0194.rs:13:5
   |
13 |     fn do_something_else<T: Clone>(&self, bar: T); //~ ERROR E0194
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `T` shadows another type parameter

Bonus: the span can be shortened and we can reference the other T

error[E0194]: type parameter `T` shadows another type parameter of the same name
  --> src/test/compile-fail/E0194.rs:13:5
   |
11 | trait Foo<T> {
   |           - first `T` declared here
12 |     fn do_something(&self) -> T;
13 |     fn do_something_else<T: Clone>(&self, bar: T); //~ ERROR E0194
   |                          ^ shadows another type parameter
@sophiajt sophiajt added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-diagnostics Area: Messages for errors, warnings, and lints E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Aug 4, 2016
@leikahing
Copy link
Contributor

I'll work on this one.

@leikahing
Copy link
Contributor

leikahing commented Aug 6, 2016

@jonathandturner @nikomatsakis I'm working on the bonus portion of this issue but I'm wondering if either of you have any pointers about where to start exploring with manipulating the spans and getting more context out of it so that I can get something that looks like this:

   |
13 |     fn do_something_else<T: Clone>(&self, bar: T); //~ ERROR E0194
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Into this expanded context?

   |
11 | trait Foo<T> {
   |           - first `T` declared here
12 |     fn do_something(&self) -> T;
13 |     fn do_something_else<T: Clone>(&self, bar: T); //~ ERROR E0194

@nikomatsakis
Copy link
Contributor

@birryree any chance we can chat on IRC? :)

@nikomatsakis
Copy link
Contributor

@birryree ok I did a bit of investigating. At the point where error E0194 is issued, we have access to a ty::Generics which in turn contains TypeParameterDef data (in fact, we are iterating over those). These data-structures, like most of ty, is not directly tied to the source (it may for example originate from another crate, for which the source nodes are not available), but -- at least for local nodes -- we can map back to a HIR node (i.e., to the source). We do this by using the field def_id: DefId on the TypeParameterDef. If you have this, you can map a DefId to a NodeId using tcx.map.as_local_node_id(def_id) (it gives you back an Option because the DefId may refer to something from another crate, in general -- but not in this case, so you should be able to just unwrap it). That will give you a NodeId, which is an index into the HIR. You can then use this NodeId to lookup the HIR node by calling tcx.map.find(node_id). This gives you back an Option too (maybe the node-id isn't mapped to anything...), but in this case we expect to find Some(NodeTyParam(ty_param)) (the variant NodeTyParam is defined in rustc::hir::map). The ty_param is a pointer into the HIR, and you can get the span by doing ty_param.span.

Whew!

@leikahing
Copy link
Contributor

@nikomatsakis - Whoa, thanks for the detailed response! Sorry I didn't get back to you sooner - I'm currently headed to a conference. @jonathandturner gave me some pointers over the weekend which helped me get started on the bonus part, so I have been doing some exploration on-and-off into the source to get the steps down for doing what I need.

Your post definitely helps me move in the right direction (I was exploring with tcx.map.span_if_local which seemed like the right way but wasn't quite getting what I wanted).

Thanks again!

@sophiajt
Copy link
Contributor Author

@birryree - are you still interested in this one? If not, I can release it and let someone else volunteer.

@leikahing
Copy link
Contributor

@jonathandturner Yes, sorry - I already have the changes local, about to make a PR.

leikahing added a commit to leikahing/rust that referenced this issue Aug 27, 2016
@leikahing
Copy link
Contributor

Bonus section is being tracked by #36057 because I wanted to commit the non-bonus part of the update before I committed/made a PR for my additional bonus fixes (as they may require some extra review).

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Aug 29, 2016
…jonathandturner

Update E0194 to new error format

Fixes rust-lang#35280 to update E0194 to support new error message format. Part of rust-lang#35233.

A separate Github issue rust-lang#36057 tracks the bonus portion of the original ticket.

r? @jonathandturner
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Aug 30, 2016
…jonathandturner

Update E0194 to new error format

Fixes rust-lang#35280 to update E0194 to support new error message format. Part of rust-lang#35233.

A separate Github issue rust-lang#36057 tracks the bonus portion of the original ticket.

r? @jonathandturner
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Aug 30, 2016
…jonathandturner

Update E0194 to new error format

Fixes rust-lang#35280 to update E0194 to support new error message format. Part of rust-lang#35233.

A separate Github issue rust-lang#36057 tracks the bonus portion of the original ticket.

r? @jonathandturner
leikahing added a commit to leikahing/rust that referenced this issue Aug 30, 2016
…ng#36057. Adding expanded notes/context for what trait a parameter shadows as part of E0194 error messages.
leikahing added a commit to leikahing/rust that referenced this issue Aug 30, 2016
…ng#36057. Adding expanded notes/context for what trait a parameter shadows as part of E0194 error messages.
sophiajt pushed a commit to sophiajt/rust that referenced this issue Aug 30, 2016
…thandturner

Bonus format for E0194

Bonus fix for rust-lang#35280. Part of rust-lang#35233. Fixes rust-lang#36057. Adding expanded notes/context for what trait a parameter shadows as part of E0194 error messages.

Errors for E0194 now look like this:

```
$> ./build/x86_64-apple-darwin/stage1/bin/rustc src/test/compile-fail/E0194.rs
error[E0194]: type parameter `T` shadows another type parameter of the same name
  --> src/test/compile-fail/E0194.rs:13:26
   |
11 | trait Foo<T> { //~ NOTE first `T` declared here
   |           - first `T` declared here
12 |     fn do_something(&self) -> T;
13 |     fn do_something_else<T: Clone>(&self, bar: T);
   |                          ^ shadows another type parameter

error: aborting due to previous error
```

r? @jonathandturner
leikahing added a commit to leikahing/rust that referenced this issue Aug 31, 2016
…ng#36057. Adding expanded notes/context for what trait a parameter shadows as part of E0194 error messages.
sophiajt pushed a commit to sophiajt/rust that referenced this issue Aug 31, 2016
…thandturner

Bonus format for E0194

Bonus fix for rust-lang#35280. Part of rust-lang#35233. Fixes rust-lang#36057. Adding expanded notes/context for what trait a parameter shadows as part of E0194 error messages.

Errors for E0194 now look like this:

```
$> ./build/x86_64-apple-darwin/stage1/bin/rustc src/test/compile-fail/E0194.rs
error[E0194]: type parameter `T` shadows another type parameter of the same name
  --> src/test/compile-fail/E0194.rs:13:26
   |
11 | trait Foo<T> { //~ NOTE first `T` declared here
   |           - first `T` declared here
12 |     fn do_something(&self) -> T;
13 |     fn do_something_else<T: Clone>(&self, bar: T);
   |                          ^ shadows another type parameter

error: aborting due to previous error
```

r? @jonathandturner
sophiajt pushed a commit to sophiajt/rust that referenced this issue Aug 31, 2016
…thandturner

Bonus format for E0194

Bonus fix for rust-lang#35280. Part of rust-lang#35233. Fixes rust-lang#36057. Adding expanded notes/context for what trait a parameter shadows as part of E0194 error messages.

Errors for E0194 now look like this:

```
$> ./build/x86_64-apple-darwin/stage1/bin/rustc src/test/compile-fail/E0194.rs
error[E0194]: type parameter `T` shadows another type parameter of the same name
  --> src/test/compile-fail/E0194.rs:13:26
   |
11 | trait Foo<T> { //~ NOTE first `T` declared here
   |           - first `T` declared here
12 |     fn do_something(&self) -> T;
13 |     fn do_something_else<T: Clone>(&self, bar: T);
   |                          ^ shadows another type parameter

error: aborting due to previous error
```

r? @jonathandturner
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 E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

No branches or pull requests

3 participants