-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #80635 - sexxi-goose:use-place-instead-of-symbol, r=n…
…ikomatsakis` Improve diagnostics when closure doesn't meet trait bound Improves the diagnostics when closure doesn't meet trait bound by modifying `TypeckResuts::closure_kind_origins` such that `hir::Place` is used instead of `Symbol`. Using `hir::Place` to describe which capture influenced the decision of selecting a trait a closure satisfies to (Fn/FnMut/FnOnce, Copy) allows us to show precise path in the diagnostics when `capture_disjoint_field` feature is enabled. Closes rust-lang/project-rfc-2229/issues/21 r? ```@nikomatsakis```
- Loading branch information
Showing
16 changed files
with
328 additions
and
23 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
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
31 changes: 31 additions & 0 deletions
31
...ui/closures/2229_closure_analysis/diagnostics/closure-origin-multi-variant-diagnostics.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,31 @@ | ||
#![feature(capture_disjoint_fields)] | ||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete | ||
//~| `#[warn(incomplete_features)]` on by default | ||
//~| see issue #53488 <https://github.com/rust-lang/rust/issues/53488> | ||
|
||
// Check that precise paths are being reported back in the error message. | ||
|
||
|
||
enum MultiVariant { | ||
Point(i32, i32), | ||
Meta(i32) | ||
} | ||
|
||
fn main() { | ||
let mut point = MultiVariant::Point(10, -10,); | ||
|
||
let mut meta = MultiVariant::Meta(1); | ||
|
||
let c = || { | ||
if let MultiVariant::Point(ref mut x, _) = point { | ||
*x += 1; | ||
} | ||
|
||
if let MultiVariant::Meta(ref mut v) = meta { | ||
*v += 1; | ||
} | ||
}; | ||
|
||
let a = c; | ||
let b = c; //~ ERROR use of moved value: `c` [E0382] | ||
} |
26 changes: 26 additions & 0 deletions
26
...losures/2229_closure_analysis/diagnostics/closure-origin-multi-variant-diagnostics.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,26 @@ | ||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/closure-origin-multi-variant-diagnostics.rs:1:12 | ||
| | ||
LL | #![feature(capture_disjoint_fields)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information | ||
|
||
error[E0382]: use of moved value: `c` | ||
--> $DIR/closure-origin-multi-variant-diagnostics.rs:30:13 | ||
| | ||
LL | let a = c; | ||
| - value moved here | ||
LL | let b = c; | ||
| ^ value used here after move | ||
| | ||
note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `point.0` out of its environment | ||
--> $DIR/closure-origin-multi-variant-diagnostics.rs:20:52 | ||
| | ||
LL | if let MultiVariant::Point(ref mut x, _) = point { | ||
| ^^^^^ | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0382`. |
26 changes: 26 additions & 0 deletions
26
...i/closures/2229_closure_analysis/diagnostics/closure-origin-single-variant-diagnostics.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,26 @@ | ||
#![feature(capture_disjoint_fields)] | ||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete | ||
//~| `#[warn(incomplete_features)]` on by default | ||
//~| see issue #53488 <https://github.com/rust-lang/rust/issues/53488> | ||
|
||
// Check that precise paths are being reported back in the error message. | ||
|
||
enum SingleVariant { | ||
Point(i32, i32), | ||
} | ||
|
||
fn main() { | ||
let mut point = SingleVariant::Point(10, -10); | ||
|
||
let c = || { | ||
// FIXME(project-rfc-2229#24): Change this to be a destructure pattern | ||
// once this is fixed, to remove the warning. | ||
if let SingleVariant::Point(ref mut x, _) = point { | ||
//~^ WARNING: irrefutable if-let pattern | ||
*x += 1; | ||
} | ||
}; | ||
|
||
let b = c; | ||
let a = c; //~ ERROR use of moved value: `c` [E0382] | ||
} |
37 changes: 37 additions & 0 deletions
37
...osures/2229_closure_analysis/diagnostics/closure-origin-single-variant-diagnostics.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,37 @@ | ||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/closure-origin-single-variant-diagnostics.rs:1:12 | ||
| | ||
LL | #![feature(capture_disjoint_fields)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information | ||
|
||
warning: irrefutable if-let pattern | ||
--> $DIR/closure-origin-single-variant-diagnostics.rs:18:9 | ||
| | ||
LL | / if let SingleVariant::Point(ref mut x, _) = point { | ||
LL | | | ||
LL | | *x += 1; | ||
LL | | } | ||
| |_________^ | ||
| | ||
= note: `#[warn(irrefutable_let_patterns)]` on by default | ||
|
||
error[E0382]: use of moved value: `c` | ||
--> $DIR/closure-origin-single-variant-diagnostics.rs:25:13 | ||
| | ||
LL | let b = c; | ||
| - value moved here | ||
LL | let a = c; | ||
| ^ value used here after move | ||
| | ||
note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `point.0` out of its environment | ||
--> $DIR/closure-origin-single-variant-diagnostics.rs:18:53 | ||
| | ||
LL | if let SingleVariant::Point(ref mut x, _) = point { | ||
| ^^^^^ | ||
|
||
error: aborting due to previous error; 2 warnings emitted | ||
|
||
For more information about this error, try `rustc --explain E0382`. |
25 changes: 25 additions & 0 deletions
25
src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-struct-diagnostics.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,25 @@ | ||
#![feature(capture_disjoint_fields)] | ||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete | ||
//~| `#[warn(incomplete_features)]` on by default | ||
//~| see issue #53488 <https://github.com/rust-lang/rust/issues/53488> | ||
|
||
// Check that precise paths are being reported back in the error message. | ||
|
||
struct Y { | ||
y: X | ||
} | ||
|
||
struct X { | ||
a: u32, | ||
b: u32, | ||
} | ||
|
||
fn main() { | ||
let mut x = Y { y: X { a: 5, b: 0 } }; | ||
let hello = || { | ||
x.y.a += 1; | ||
}; | ||
|
||
let b = hello; | ||
let c = hello; //~ ERROR use of moved value: `hello` [E0382] | ||
} |
Oops, something went wrong.