Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3dd0a7d
Do not call `unwrap` with `signatures` option enabled
JohnTitor Oct 25, 2020
127a6ed
Use Places to express closure/generator Captures
arora-aman Sep 9, 2020
88310cc
Indroduce feature flag for RFC-2229
arora-aman Oct 11, 2020
58e8f8f
Add initial set of testcases for RFC 2229
arora-aman Oct 13, 2020
1453120
Add helper function for Capture Esclations and expressions
arora-aman Oct 17, 2020
8f0c0d6
Initial work for doing minimum capture analysis for RFC-2229
arora-aman Sep 26, 2020
b16815b
Update tests with min capture information
arora-aman Oct 13, 2020
825e9e4
Reduce verbosity of capture analysis logs
roxelo Oct 28, 2020
fa38160
Handle `let _ = x` patterns in closure liveness analysis
arora-aman Nov 1, 2020
be77402
More pattern testcases
arora-aman Nov 5, 2020
abc4004
Remove local testing env var
arora-aman Nov 5, 2020
43423f6
Address review comments
arora-aman Nov 9, 2020
deeb025
Address review comments 2
arora-aman Nov 10, 2020
d0fac05
Add test for capturing enums
arora-aman Nov 11, 2020
443b45f
rustc_target: Change os from "unknown" to "none" for bare metal targets
petrochenkov Nov 11, 2020
1def24c
rustc_target: Normalize vendor from "" to "unknown" for all targets
petrochenkov Nov 11, 2020
e0a8f22
rustc_target: Make sure that in-tree targets follow conventions for o…
petrochenkov Nov 11, 2020
f5e67b5
Add a test for r# identifiers
poliorcetics Nov 12, 2020
9c70696
Ignore tidy linelength
poliorcetics Nov 12, 2020
bd0eb07
Added some unit tests as requested
richkadel Nov 3, 2020
ecfeac5
Use intradoc-links for the whole test, add a @has check
poliorcetics Nov 12, 2020
562d50e
Include llvm-as in llvm-tools-preview component
zec Nov 12, 2020
e4a43fc
Merge changes from rust-lang/rust
zec Nov 12, 2020
eb9f2bb
Overcome Sync issues with non-parallel compiler
richkadel Nov 12, 2020
775f1e5
fix pretty print for qpath
gui1117 Nov 12, 2020
04d41e1
rustc_target: Mark UEFI targets as `is_like_windows`/`is_like_msvc`
petrochenkov Nov 11, 2020
0b4af16
Never inline when `no_sanitize` attributes differ
tmiasko Nov 11, 2020
ae43326
Never inline cold functions
tmiasko Nov 11, 2020
9bb3d6b
Remove check for impossible condition
tmiasko Nov 11, 2020
2879ab7
rustc_parse: Remove optimization for 0-length streams in `collect_tok…
petrochenkov Nov 4, 2020
66cadec
Fix generator inlining by checking for rust-call abi and spread arg
tmiasko Nov 11, 2020
79d853e
Never inline C variadic functions
tmiasko Nov 11, 2020
2a010dd
./x.py test --bless
tmiasko Nov 11, 2020
d486bfc
Normalize function type during validation
tmiasko Nov 12, 2020
99be78d
Always use param_env_reveal_all_normalized in validator
tmiasko Nov 12, 2020
c131063
Added a unit test for BcbCounters
richkadel Nov 13, 2020
309d863
Fix wrong XPath
poliorcetics Nov 13, 2020
b4b0ef3
Addressed feedback
richkadel Nov 13, 2020
bf6902c
Add BTreeMap::retain and BTreeSet::retain
mbrubeck Nov 13, 2020
c50e57f
Log closure as well
arora-aman Nov 13, 2020
a5b7f24
Rollup merge of #78352 - JohnTitor:issue-75229, r=Dylan-DPC
Dylan-DPC Nov 14, 2020
6272915
Rollup merge of #78736 - petrochenkov:lazyenum, r=Aaron1011
Dylan-DPC Nov 14, 2020
0c0e8c4
Rollup merge of #78801 - sexxi-goose:min_capture, r=nikomatsakis
Dylan-DPC Nov 14, 2020
d8fcf18
Rollup merge of #78951 - petrochenkov:unknown, r=ehuss
Dylan-DPC Nov 14, 2020
e427499
Rollup merge of #78959 - petrochenkov:likeuefi, r=nagisa
Dylan-DPC Nov 14, 2020
dd9485e
Rollup merge of #78962 - poliorcetics:rustdoc-raw-ident-test, r=jyn514
Dylan-DPC Nov 14, 2020
09cafd7
Rollup merge of #78963 - richkadel:llvm-coverage-counters-2.0.4, r=tm…
Dylan-DPC Nov 14, 2020
591a39a
Rollup merge of #78966 - tmiasko:inline-never, r=oli-obk
Dylan-DPC Nov 14, 2020
2eceb84
Rollup merge of #78968 - zec:add-llvm-as, r=Mark-Simulacrum
Dylan-DPC Nov 14, 2020
e70291f
Rollup merge of #78969 - tmiasko:normalize, r=davidtwco
Dylan-DPC Nov 14, 2020
9eb4693
Rollup merge of #78980 - thiolliere:gui-fix-qpath, r=estebank
Dylan-DPC Nov 14, 2020
d82ad6c
Rollup merge of #79026 - mbrubeck:btree_retain, r=m-ou-se
Dylan-DPC Nov 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add initial set of testcases for RFC 2229
Co-authored-by: Dhruv Jauhar <[email protected]>
  • Loading branch information
arora-aman and null-sleep committed Nov 11, 2020
commit 58e8f8fd2cac4cfcde6c7a1488dd8657dcacaad8
7 changes: 7 additions & 0 deletions compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
)
.consume_body(body);

log_capture_analysis!(
self,
closure_def_id,
"capture information: {:#?}",
delegate.capture_information
);

if let Some(closure_substs) = infer_kind {
// Unify the (as yet unbound) type variable in the closure
// substs with the kind we inferred.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![feature(capture_disjoint_fields)]
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
#![feature(rustc_attrs)]

// Ensure that capture analysis results in arrays being completely captured.
fn main() {
let mut m = [1, 2, 3, 4, 5];

let mut c = #[rustc_capture_analysis]
//~^ ERROR: attributes on expressions are experimental
|| {
m[0] += 10;
m[1] += 40;
};

c();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0658]: attributes on expressions are experimental
--> $DIR/arrays-completely-captured.rs:9:17
|
LL | let mut c = #[rustc_capture_analysis]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/arrays-completely-captured.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: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0658`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
For closure=DefId(0:4 ~ arrays_completely_captured[317d]::main::{closure#0}): Using new-style capture analysis
For closure=DefId(0:4 ~ arrays_completely_captured[317d]::main::{closure#0}): capture information: {
Place {
base_ty: [i32; 5],
base: Upvar(
UpvarId(HirId { owner: DefId(0:3 ~ arrays_completely_captured[317d]::main), local_id: 1 };`m`;DefId(0:4 ~ arrays_completely_captured[317d]::main::{closure#0})),
),
projections: [],
}: CaptureInfo {
expr_id: Some(
HirId {
owner: DefId(0:3 ~ arrays_completely_captured[317d]::main),
local_id: 12,
},
),
capture_kind: ByRef(
UpvarBorrow(MutBorrow, '_#6r),
),
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// FIXME(arora-aman) add run-pass once 2229 is implemented

#![feature(capture_disjoint_fields)]
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
#![feature(rustc_attrs)]

struct Point {
x: i32,
y: i32,
}

fn main() {
let mut p = Point { x: 10, y: 10 };

let c = #[rustc_capture_analysis]
//~^ ERROR: attributes on expressions are experimental
|| {
println!("{}", p.x);
};

// `c` should only capture `p.x`, therefore mutating `p.y` is allowed.
let py = &mut p.y;

c();
*py = 20;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0658]: attributes on expressions are experimental
--> $DIR/capture-disjoint-field-struct.rs:15:13
|
LL | let c = #[rustc_capture_analysis]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/capture-disjoint-field-struct.rs:3: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: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0658`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
For closure=DefId(0:7 ~ capture_disjoint_field_struct[317d]::main::{closure#0}): Using new-style capture analysis
For closure=DefId(0:7 ~ capture_disjoint_field_struct[317d]::main::{closure#0}): capture information: {
Place {
base_ty: Point,
base: Upvar(
UpvarId(HirId { owner: DefId(0:6 ~ capture_disjoint_field_struct[317d]::main), local_id: 1 };`p`;DefId(0:7 ~ capture_disjoint_field_struct[317d]::main::{closure#0})),
),
projections: [
Projection {
ty: i32,
kind: Field(
0,
0,
),
},
],
}: CaptureInfo {
expr_id: Some(
HirId {
owner: DefId(0:6 ~ capture_disjoint_field_struct[317d]::main),
local_id: 31,
},
),
capture_kind: ByRef(
UpvarBorrow(ImmBorrow, '_#35r),
),
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// FIXME(arora-aman) add run-pass once 2229 is implemented

#![feature(capture_disjoint_fields)]
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
#![feature(rustc_attrs)]

fn main() {
let mut t = (10, 10);

let c = #[rustc_capture_analysis]
//~^ ERROR: attributes on expressions are experimental
|| {
println!("{}", t.0);
};

// `c` only captures t.0, therefore mutating t.1 is allowed.
let t1 = &mut t.1;

c();
*t1 = 20;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0658]: attributes on expressions are experimental
--> $DIR/capture-disjoint-field-tuple.rs:8:13
|
LL | let c = #[rustc_capture_analysis]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/capture-disjoint-field-tuple.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: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0658`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
For closure=DefId(0:4 ~ capture_disjoint_field_tuple[317d]::main::{closure#0}): Using new-style capture analysis
For closure=DefId(0:4 ~ capture_disjoint_field_tuple[317d]::main::{closure#0}): capture information: {
Place {
base_ty: (i32, i32),
base: Upvar(
UpvarId(HirId { owner: DefId(0:3 ~ capture_disjoint_field_tuple[317d]::main), local_id: 1 };`t`;DefId(0:4 ~ capture_disjoint_field_tuple[317d]::main::{closure#0})),
),
projections: [
Projection {
ty: i32,
kind: Field(
0,
0,
),
},
],
}: CaptureInfo {
expr_id: Some(
HirId {
owner: DefId(0:3 ~ capture_disjoint_field_tuple[317d]::main),
local_id: 28,
},
),
capture_kind: ByRef(
UpvarBorrow(ImmBorrow, '_#35r),
),
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
fn main() {
let s = format!("s");

let c = #[rustc_capture_analysis] || {
let c = #[rustc_capture_analysis]
//~^ ERROR: attributes on expressions are experimental
|| {
println!("This uses new capture analyysis to capture s={}", s);
};
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error[E0658]: attributes on expressions are experimental
--> $DIR/feature-gate-capture_disjoint_fields.rs:8:13
|
LL | let c = #[rustc_capture_analysis] || {
LL | let c = #[rustc_capture_analysis]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
For closure=DefId(0:4 ~ feature_gate_capture_disjoint_fields[317d]::main::{closure#0}): Using new-style capture analysis
For closure=DefId(0:4 ~ feature_gate_capture_disjoint_fields[317d]::main::{closure#0}): capture information: {
Place {
base_ty: std::string::String,
base: Upvar(
UpvarId(HirId { owner: DefId(0:3 ~ feature_gate_capture_disjoint_fields[317d]::main), local_id: 1 };`s`;DefId(0:4 ~ feature_gate_capture_disjoint_fields[317d]::main::{closure#0})),
),
projections: [],
}: CaptureInfo {
expr_id: Some(
HirId {
owner: DefId(0:3 ~ feature_gate_capture_disjoint_fields[317d]::main),
local_id: 52,
},
),
capture_kind: ByRef(
UpvarBorrow(ImmBorrow, '_#50r),
),
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// FIXME(arora-aman) add run-pass once 2229 is implemented

#![feature(capture_disjoint_fields)]
//~^ warning the feature `capture_disjoint_fields` is incomplete
#![feature(rustc_attrs)]

struct Filter {
div: i32,
}
impl Filter {
fn allowed(&self, x: i32) -> bool {
x % self.div == 1
}
}

struct Data {
filter: Filter,
list: Vec<i32>,
}
impl Data {
fn update(&mut self) {
// The closure passed to filter only captures self.filter,
// therefore mutating self.list is allowed.
self.list.retain(
//~^ cannot borrow `self.list` as mutable because it is also borrowed as immutable
#[rustc_capture_analysis]
|v| self.filter.allowed(*v),
);
}
}

fn main() {
let mut d = Data { filter: Filter { div: 3 }, list: Vec::new() };

for i in 1..10 {
d.list.push(i);
}

d.update();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/filter-on-struct-member.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[E0502]: cannot borrow `self.list` as mutable because it is also borrowed as immutable
--> $DIR/filter-on-struct-member.rs:22:9
|
LL | self.list.retain(
| ^ ------ immutable borrow later used by call
| _________|
| |
LL | |
LL | | #[rustc_capture_analysis]
LL | | |v| self.filter.allowed(*v),
| | --- ---- first borrow occurs due to use of `self` in closure
| | |
| | immutable borrow occurs here
LL | | );
| |_________^ mutable borrow occurs here

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0502`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
For closure=DefId(0:12 ~ filter_on_struct_member[317d]::{impl#1}::update::{closure#0}): Using new-style capture analysis
For closure=DefId(0:12 ~ filter_on_struct_member[317d]::{impl#1}::update::{closure#0}): capture information: {
Place {
base_ty: &mut Data,
base: Upvar(
UpvarId(HirId { owner: DefId(0:11 ~ filter_on_struct_member[317d]::{impl#1}::update), local_id: 1 };`self`;DefId(0:12 ~ filter_on_struct_member[317d]::{impl#1}::update::{closure#0})),
),
projections: [
Projection {
ty: Data,
kind: Deref,
},
Projection {
ty: Filter,
kind: Field(
0,
0,
),
},
],
}: CaptureInfo {
expr_id: Some(
HirId {
owner: DefId(0:11 ~ filter_on_struct_member[317d]::{impl#1}::update),
local_id: 13,
},
),
capture_kind: ByRef(
UpvarBorrow(ImmBorrow, '_#7r),
),
},
}
Loading