Skip to content

Point to type argument span when used as trait - #37428

Merged
bors merged 1 commit into
rust-lang:masterfrom
estebank:generic-type-error-span
Nov 9, 2016
Merged

Point to type argument span when used as trait#37428
bors merged 1 commit into
rust-lang:masterfrom
estebank:generic-type-error-span

Conversation

@estebank

Copy link
Copy Markdown
Contributor

Given the following code:

structFoo<T:Clone>(T);use std::ops::Add;impl<T:Clone,Add>AddforFoo<T>{typeOutput = usize;fnadd(self,rhs:Self) -> Self::Output{unimplemented!();}}

present the following output:

error[E0404]: `Add` is not a trait
--> file3.rs:5:21
|
5 | impl<T: Clone, Add> Add for Okok<T> {
| --- ^^^ expected trait, found type parameter
| |
| type parameter defined here

Fixes#35987.

@rust-highfive

Copy link
Copy Markdown
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

Comment threadsrc/libsyntax/ast.rs Outdated

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that this is the best way of getting the type argument's span. Does anyone have a pointer as to an alternative?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember doing such a thing but can't find the PR. From my point of view, this is correct. However I can totally overpass a better solution.

Anything in mind @eddyb?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems okay. If there are duplicate type parameter names, you'll get a different error for that.

@estebank
estebankforce-pushed the generic-type-error-span branch 5 times, most recently from 870fe6a to 169d580CompareOctober 27, 2016 21:25
@estebank

Copy link
Copy Markdown
ContributorAuthor

r? @jonathandturner

Comment threadsrc/test/ui/span/issue-35987.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust uses 4 spaces indent.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@estebank
estebankforce-pushed the generic-type-error-span branch from 169d580 to c56cc5fCompareNovember 7, 2016 05:16
Comment threadsrc/libsyntax/ast.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant. You can do &t.ident.name.as_str() == name instead.

Comment threadsrc/libsyntax/ast.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can return Some(t.span); instead of breaking, and get rid of the local variable span.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, returning is probably slightly cleaner/easier to read.

@sophiajt

Copy link
Copy Markdown
Contributor

A nit or two to fix, but otherwise seems okay to me.

@estebank
estebankforce-pushed the generic-type-error-span branch from c56cc5f to 0037756CompareNovember 8, 2016 19:56
Given the following code:
```rust
struct Foo<T: Clone>(T);
use std::ops::Add;
impl<T: Clone, Add> Add for Foo<T> {
type Output = usize;
fn add(self, rhs: Self) -> Self::Output {
unimplemented!();
}
}
```
present the following output:
```nocode
error[E0404]: `Add` is not a trait
--> file3.rs:5:21
|
5 | impl<T: Clone, Add> Add for Okok<T> {
| --- ^^^ expected trait, found type parameter
| |
| type parameter defined here
```
@estebank
estebankforce-pushed the generic-type-error-span branch from 0037756 to 3edb4fcCompareNovember 8, 2016 22:17
@estebank

Copy link
Copy Markdown
ContributorAuthor

@jonathandturner fixed.

@sanxiyn

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Nov 9, 2016

Copy link
Copy Markdown
Collaborator

📌 Commit 3edb4fc has been approved by sanxiyn

eddyb added a commit to eddyb/rust that referenced this pull request Nov 9, 2016
…=sanxiyn
Point to type argument span when used as trait
Given the following code:
``` rust
struct Foo<T: Clone>(T);
use std::ops::Add;
impl<T: Clone, Add> Add for Foo<T> {
type Output = usize;
fn add(self, rhs: Self) -> Self::Output {
unimplemented!();
}
}
```
present the following output:
``` nocode
error[E0404]: `Add` is not a trait
--> file3.rs:5:21
|
5 | impl<T: Clone, Add> Add for Okok<T> {
| --- ^^^ expected trait, found type parameter
| |
| type parameter defined here
```
Fixesrust-lang#35987.
@eddybeddyb mentioned this pull request Nov 9, 2016
bors added a commit that referenced this pull request Nov 9, 2016
@bors
bors merged commit 3edb4fc into rust-lang:masterNov 9, 2016
@estebank
estebank deleted the generic-type-error-span branch November 9, 2023 05:28
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@estebank@rust-highfive@sophiajt@sanxiyn@bors@GuillaumeGomez@pnkfelix