Skip to content

Rollup of 8 pull requests #86588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8eb0c0d
Document associativity of iterator folds.
Kmeakin Jun 17, 2021
f265997
Edition 2021 enables disjoint capture
arora-aman Jun 21, 2021
30793c1
Add documentation for various THIR structs
LeSeulArtichaut Jun 14, 2021
faa6461
Update cargo
ehuss Jun 22, 2021
e629381
chore(rustdoc): Remove unused impl block
notriddle Jun 22, 2021
4d1b3a5
Use `use_verbose` for mir::Constant
fee1-dead Jun 23, 2021
6370567
Updated mir pretty print output
fee1-dead Jun 23, 2021
0bb6bc4
Teach rustc to accept lowercase error codes
inquisitivecrystal Jun 22, 2021
d296ea0
Add bstr to rustc-workspace-hack for rustfmt/cargo.
ehuss Jun 23, 2021
23e5ed1
Check if error code is used
GuillaumeGomez Jun 8, 2021
22a702d
Add check on constant to ensure it's up to date
GuillaumeGomez Jun 8, 2021
12b6d32
Remove unused error codes from error_codes.rs and from EXEMPTED_FROM_…
GuillaumeGomez Jun 8, 2021
20f1b1c
Greatly improve code
GuillaumeGomez Jun 23, 2021
0ab9d01
Handle windows paths as well
GuillaumeGomez Jun 23, 2021
55fd13b
Rollup merge of #86137 - GuillaumeGomez:error-code-cleanup, r=Mark-Si…
JohnTitor Jun 24, 2021
469329d
Rollup merge of #86296 - LeSeulArtichaut:thir-doc, r=nikomatsakis
JohnTitor Jun 24, 2021
0fa4f0b
Rollup merge of #86415 - Kmeakin:iterator-associativity-docs, r=dtolnay
JohnTitor Jun 24, 2021
6b618c8
Rollup merge of #86533 - inquisitivecrystal:lower-case-error-explain,…
JohnTitor Jun 24, 2021
3998c03
Rollup merge of #86536 - sexxi-goose:edition, r=nikomatsakis
JohnTitor Jun 24, 2021
60dae7a
Rollup merge of #86560 - ehuss:update-cargo, r=ehuss
JohnTitor Jun 24, 2021
2322097
Rollup merge of #86561 - notriddle:notriddle/cleanup-rustdoc, r=jyn514
JohnTitor Jun 24, 2021
64c9712
Rollup merge of #86566 - fee1-dead:mir-pretty-print, r=oli-obk
JohnTitor Jun 24, 2021
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
14 changes: 12 additions & 2 deletions compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// We now fake capture information for all variables that are mentioned within the closure
// We do this after handling migrations so that min_captures computes before
if !self.tcx.features().capture_disjoint_fields {
if !enable_precise_capture(self.tcx, span) {
let mut capture_information: InferredCaptureInformation<'tcx> = Default::default();

if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
Expand Down Expand Up @@ -212,7 +212,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// If we have an origin, store it.
if let Some(origin) = delegate.current_origin.clone() {
let origin = if self.tcx.features().capture_disjoint_fields {
let origin = if enable_precise_capture(self.tcx, span) {
(origin.0, restrict_capture_precision(origin.1))
} else {
(origin.0, Place { projections: vec![], ..origin.1 })
Expand Down Expand Up @@ -1924,3 +1924,13 @@ fn determine_place_ancestry_relation(
PlaceAncestryRelation::Divergent
}
}

/// Precise capture is enabled if the feature gate `capture_disjoint_fields` is enabled or if
/// user is using Rust Edition 2021 or higher.
///
/// `span` is the span of the closure.
fn enable_precise_capture(tcx: TyCtxt<'_>, span: Span) -> bool {
// We use span here to ensure that if the closure was generated by a macro with a different
// edition.
tcx.features().capture_disjoint_fields || span.rust_2021()
}
23 changes: 23 additions & 0 deletions src/test/ui/closures/2229_closure_analysis/run_pass/edition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// edition:2021
// run-pass

// Test that edition 2021 enables disjoint capture by default.

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

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

let c = || {
println!("{}", p.x);
};

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

c();
*py = 20;
}