forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#64852 - Baranowski:param_note_52082, r=este…
…bank Print ParamTy span when accessing a field (rust-lang#52082)
- Loading branch information
Showing
6 changed files
with
188 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/ui/typeck/issue-52082-type-param-shadows-existing-type.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Fix issue 52082: Confusing error if accidentially defining a type paramter with the same name as | ||
// an existing type | ||
// | ||
// To this end, make sure that when trying to retrieve a field of a (reference to) type parameter, | ||
// rustc points to the point where the parameter was defined. | ||
#[derive(Debug)] | ||
struct Point | ||
{ | ||
x: i32, | ||
y: i32 | ||
} | ||
|
||
impl Point | ||
{ | ||
fn add(a: &Point, b: &Point) -> Point | ||
{ | ||
Point {x: a.x + b.x, y: a.y + b.y} | ||
} | ||
} | ||
|
||
trait Eq | ||
{ | ||
fn equals_ref<T>(a: &T, b: &T) -> bool; | ||
fn equals_val<T>(a: T, b: T) -> bool; | ||
} | ||
|
||
impl Eq for Point | ||
{ | ||
fn equals_ref<Point>(a: &Point, b: &Point) -> bool | ||
{ | ||
a.x == b.x && a.y == b.y //~ ERROR no field `x` on type `&Point` [E0609] | ||
//~|ERROR no field `x` on type `&Point` [E0609] | ||
//~|ERROR no field `y` on type `&Point` [E0609] | ||
//~|ERROR no field `y` on type `&Point` [E0609] | ||
} | ||
|
||
fn equals_val<Point>(a: Point, b: Point) -> bool | ||
{ | ||
a.x == b.x && a.y == b.y //~ ERROR no field `x` on type `Point` [E0609] | ||
//~|ERROR no field `x` on type `Point` [E0609] | ||
//~|ERROR no field `y` on type `Point` [E0609] | ||
//~|ERROR no field `y` on type `Point` [E0609] | ||
} | ||
} | ||
|
||
fn main() | ||
{ | ||
let p1 = Point {x: 0, y: 10}; | ||
let p2 = Point {x: 20, y: 42}; | ||
println!("{:?}", Point::add(&p1, &p2)); | ||
println!("p1: {:?}, p2: {:?}", p1, p2); | ||
println!("&p1 == &p2: {:?}", Point::equals_ref(&p1, &p2)); | ||
println!("p1 == p2: {:?}", Point::equals_val(p1, p2)); | ||
} |
75 changes: 75 additions & 0 deletions
75
src/test/ui/typeck/issue-52082-type-param-shadows-existing-type.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
error[E0609]: no field `x` on type `&Point` | ||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:11 | ||
| | ||
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool | ||
| ----- type parameter 'Point' declared here | ||
LL | { | ||
LL | a.x == b.x && a.y == b.y | ||
| ^ | ||
|
||
error[E0609]: no field `x` on type `&Point` | ||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:18 | ||
| | ||
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool | ||
| ----- type parameter 'Point' declared here | ||
LL | { | ||
LL | a.x == b.x && a.y == b.y | ||
| ^ | ||
|
||
error[E0609]: no field `y` on type `&Point` | ||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:25 | ||
| | ||
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool | ||
| ----- type parameter 'Point' declared here | ||
LL | { | ||
LL | a.x == b.x && a.y == b.y | ||
| ^ | ||
|
||
error[E0609]: no field `y` on type `&Point` | ||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:32 | ||
| | ||
LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool | ||
| ----- type parameter 'Point' declared here | ||
LL | { | ||
LL | a.x == b.x && a.y == b.y | ||
| ^ | ||
|
||
error[E0609]: no field `x` on type `Point` | ||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:11 | ||
| | ||
LL | fn equals_val<Point>(a: Point, b: Point) -> bool | ||
| ----- type parameter 'Point' declared here | ||
LL | { | ||
LL | a.x == b.x && a.y == b.y | ||
| ^ | ||
|
||
error[E0609]: no field `x` on type `Point` | ||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:18 | ||
| | ||
LL | fn equals_val<Point>(a: Point, b: Point) -> bool | ||
| ----- type parameter 'Point' declared here | ||
LL | { | ||
LL | a.x == b.x && a.y == b.y | ||
| ^ | ||
|
||
error[E0609]: no field `y` on type `Point` | ||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:25 | ||
| | ||
LL | fn equals_val<Point>(a: Point, b: Point) -> bool | ||
| ----- type parameter 'Point' declared here | ||
LL | { | ||
LL | a.x == b.x && a.y == b.y | ||
| ^ | ||
|
||
error[E0609]: no field `y` on type `Point` | ||
--> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:32 | ||
| | ||
LL | fn equals_val<Point>(a: Point, b: Point) -> bool | ||
| ----- type parameter 'Point' declared here | ||
LL | { | ||
LL | a.x == b.x && a.y == b.y | ||
| ^ | ||
|
||
error: aborting due to 8 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0609`. |