forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#126581 - GuillaumeGomez:rollup-dx4fadn, r=Gui…
…llaumeGomez Rollup of 3 pull requests Successful merges: - rust-lang#126226 (Make suggestion to change `Fn` to `FnMut` work with methods as well) - rust-lang#126570 (Convert a `span_bug` to a `span_delayed_bug`.) - rust-lang#126580 (Add `run-make/const_fn_mir` missing test annotation) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
8 changed files
with
177 additions
and
57 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 was deleted.
Oops, something went wrong.
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
14 changes: 14 additions & 0 deletions
14
tests/ui/borrowck/unmatched-arg-and-hir-arg-issue-126385.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,14 @@ | ||
// This test was triggering a `span_bug` crash, which was then fixed by | ||
// downgrading it to a `span_delayed_bug`. | ||
|
||
pub struct MyStruct<'field> { | ||
field: &'field [u32], | ||
} | ||
|
||
impl MyStruct<'_> { | ||
pub fn f(field: &[u32]) -> Self<u32> { //~ ERROR type arguments are not allowed on self type | ||
Self { field } //~ ERROR lifetime may not live long enough | ||
} | ||
} | ||
|
||
fn main() {} |
34 changes: 34 additions & 0 deletions
34
tests/ui/borrowck/unmatched-arg-and-hir-arg-issue-126385.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,34 @@ | ||
error[E0109]: type arguments are not allowed on self type | ||
--> $DIR/unmatched-arg-and-hir-arg-issue-126385.rs:9:37 | ||
| | ||
LL | pub fn f(field: &[u32]) -> Self<u32> { | ||
| ---- ^^^ type argument not allowed | ||
| | | ||
| not allowed on self type | ||
| | ||
note: `Self` is of type `MyStruct<'_>` | ||
--> $DIR/unmatched-arg-and-hir-arg-issue-126385.rs:4:12 | ||
| | ||
LL | pub struct MyStruct<'field> { | ||
| ^^^^^^^^ `Self` corresponds to this type | ||
... | ||
LL | impl MyStruct<'_> { | ||
| ----------------- `Self` is on type `MyStruct` in this `impl` | ||
help: the `Self` type doesn't accept type parameters, use the concrete type's name `MyStruct` instead if you want to specify its type parameters | ||
| | ||
LL | pub fn f(field: &[u32]) -> MyStruct<u32> { | ||
| ~~~~~~~~ | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/unmatched-arg-and-hir-arg-issue-126385.rs:10:9 | ||
| | ||
LL | pub fn f(field: &[u32]) -> Self<u32> { | ||
| - --------- return type is MyStruct<'2> | ||
| | | ||
| let's call the lifetime of this reference `'1` | ||
LL | Self { field } | ||
| ^^^^^^^^^^^^^^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0109`. |
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,29 @@ | ||
// Regression test for #125325 | ||
|
||
// Tests that we suggest changing an `impl Fn` param | ||
// to `impl FnMut` when the provided closure arg | ||
// is trying to mutate the closure env. | ||
// Ensures that it works that way for both | ||
// functions and methods | ||
|
||
struct S; | ||
|
||
impl S { | ||
fn assoc_func(&self, _f: impl Fn()) -> usize { | ||
0 | ||
} | ||
} | ||
|
||
fn func(_f: impl Fn()) -> usize { | ||
0 | ||
} | ||
|
||
fn test_func(s: &S) -> usize { | ||
let mut x = (); | ||
s.assoc_func(|| x = ()); | ||
//~^ cannot assign to `x`, as it is a captured variable in a `Fn` closure | ||
func(|| x = ()) | ||
//~^ cannot assign to `x`, as it is a captured variable in a `Fn` closure | ||
} | ||
|
||
fn main() {} |
28 changes: 28 additions & 0 deletions
28
tests/ui/closures/wrong-closure-arg-suggestion-125325.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,28 @@ | ||
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure | ||
--> $DIR/wrong-closure-arg-suggestion-125325.rs:23:21 | ||
| | ||
LL | fn assoc_func(&self, _f: impl Fn()) -> usize { | ||
| --------- change this to accept `FnMut` instead of `Fn` | ||
... | ||
LL | s.assoc_func(|| x = ()); | ||
| --------------^^^^^^- | ||
| | | | | ||
| | | cannot assign | ||
| | in this closure | ||
| expects `Fn` instead of `FnMut` | ||
|
||
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure | ||
--> $DIR/wrong-closure-arg-suggestion-125325.rs:25:13 | ||
| | ||
LL | fn func(_f: impl Fn()) -> usize { | ||
| --------- change this to accept `FnMut` instead of `Fn` | ||
... | ||
LL | func(|| x = ()) | ||
| ---- -- ^^^^^^ cannot assign | ||
| | | | ||
| | in this closure | ||
| expects `Fn` instead of `FnMut` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0594`. |