Point to type argument span when used as trait#37428
Conversation
|
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. |
src/libsyntax/ast.rs
Outdated
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Seems okay. If there are duplicate type parameter names, you'll get a different error for that.
870fe6a to
169d580
Compare
src/test/ui/span/issue-35987.rs
Outdated
169d580 to
c56cc5f
Compare
src/libsyntax/ast.rs
Outdated
There was a problem hiding this comment.
This is redundant. You can do &t.ident.name.as_str() == name instead.
src/libsyntax/ast.rs
Outdated
There was a problem hiding this comment.
You can return Some(t.span); instead of breaking, and get rid of the local variable span.
There was a problem hiding this comment.
Yeah, returning is probably slightly cleaner/easier to read.
|
A nit or two to fix, but otherwise seems okay to me. |
c56cc5f to
0037756
Compare
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
```
0037756 to
3edb4fc
Compare
|
@jonathandturner fixed. |
|
@bors r+ |
|
📌 Commit 3edb4fc has been approved by |
…=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
```
Fixes rust-lang#35987.
Given the following code:
present the following output:
Fixes #35987.