Skip to content

Commit 5cf6abb

Browse files
Revert rust-lang#72598 for perf run
1 parent e55d3f9 commit 5cf6abb

17 files changed

+58
-203
lines changed

src/libcore/future/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
5656
where
5757
T: Generator<ResumeTy, Yield = ()>,
5858
{
59-
#[rustc_diagnostic_item = "gen_future"]
6059
struct GenFuture<T: Generator<ResumeTy, Yield = ()>>(T);
6160

6261
// We rely on the fact that async/await futures are immovable in order to create

src/librustc_middle/mir/query.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub struct ClosureOutlivesRequirement<'tcx> {
183183
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
184184
#[derive(RustcEncodable, RustcDecodable, HashStable)]
185185
pub enum ConstraintCategory {
186-
Return(ReturnConstraint),
186+
Return,
187187
Yield,
188188
UseAsConst,
189189
UseAsStatic,
@@ -199,7 +199,6 @@ pub enum ConstraintCategory {
199199
SizedBound,
200200
Assignment,
201201
OpaqueType,
202-
ClosureUpvar(hir::HirId),
203202

204203
/// A "boring" constraint (caused by the given location) is one that
205204
/// the user probably doesn't want to see described in diagnostics,
@@ -217,13 +216,6 @@ pub enum ConstraintCategory {
217216
Internal,
218217
}
219218

220-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
221-
#[derive(RustcEncodable, RustcDecodable, HashStable)]
222-
pub enum ReturnConstraint {
223-
Normal,
224-
ClosureUpvar(hir::HirId),
225-
}
226-
227219
/// The subject of a `ClosureOutlivesRequirement` -- that is, the thing
228220
/// that must outlive some region.
229221
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
824824
category:
825825
category
826826
@
827-
(ConstraintCategory::Return(_)
827+
(ConstraintCategory::Return
828828
| ConstraintCategory::CallArgument
829829
| ConstraintCategory::OpaqueType),
830830
from_closure: false,
@@ -1147,7 +1147,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11471147
opt_place_desc: Option<&String>,
11481148
) -> Option<DiagnosticBuilder<'cx>> {
11491149
let return_kind = match category {
1150-
ConstraintCategory::Return(_) => "return",
1150+
ConstraintCategory::Return => "return",
11511151
ConstraintCategory::Yield => "yield",
11521152
_ => return None,
11531153
};
@@ -1261,7 +1261,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12611261
);
12621262

12631263
let msg = match category {
1264-
ConstraintCategory::Return(_) | ConstraintCategory::OpaqueType => {
1264+
ConstraintCategory::Return | ConstraintCategory::OpaqueType => {
12651265
format!("{} is returned here", kind)
12661266
}
12671267
ConstraintCategory::CallArgument => {

src/librustc_mir/borrow_check/diagnostics/region_errors.rs

+16-41
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use rustc_infer::infer::{
55
error_reporting::nice_region_error::NiceRegionError,
66
error_reporting::unexpected_hidden_region_diagnostic, NLLRegionVariableOrigin,
77
};
8-
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
8+
use rustc_middle::mir::ConstraintCategory;
99
use rustc_middle::ty::{self, RegionVid, Ty};
10-
use rustc_span::symbol::{kw, sym};
10+
use rustc_span::symbol::kw;
1111
use rustc_span::Span;
1212

1313
use crate::util::borrowck_errors;
@@ -26,7 +26,7 @@ impl ConstraintDescription for ConstraintCategory {
2626
// Must end with a space. Allows for empty names to be provided.
2727
match self {
2828
ConstraintCategory::Assignment => "assignment ",
29-
ConstraintCategory::Return(_) => "returning this value ",
29+
ConstraintCategory::Return => "returning this value ",
3030
ConstraintCategory::Yield => "yielding this value ",
3131
ConstraintCategory::UseAsConst => "using this value as a constant ",
3232
ConstraintCategory::UseAsStatic => "using this value as a static ",
@@ -37,7 +37,6 @@ impl ConstraintDescription for ConstraintCategory {
3737
ConstraintCategory::SizedBound => "proving this value is `Sized` ",
3838
ConstraintCategory::CopyBound => "copying this value ",
3939
ConstraintCategory::OpaqueType => "opaque type ",
40-
ConstraintCategory::ClosureUpvar(_) => "closure capture ",
4140
ConstraintCategory::Boring
4241
| ConstraintCategory::BoringNoLocation
4342
| ConstraintCategory::Internal => "",
@@ -307,8 +306,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
307306
};
308307

309308
let diag = match (category, fr_is_local, outlived_fr_is_local) {
310-
(ConstraintCategory::Return(kind), true, false) if self.is_closure_fn_mut(fr) => {
311-
self.report_fnmut_error(&errci, kind)
309+
(ConstraintCategory::Return, true, false) if self.is_closure_fn_mut(fr) => {
310+
self.report_fnmut_error(&errci)
312311
}
313312
(ConstraintCategory::Assignment, true, false)
314313
| (ConstraintCategory::CallArgument, true, false) => {
@@ -348,11 +347,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
348347
/// executing...
349348
/// = note: ...therefore, returned references to captured variables will escape the closure
350349
/// ```
351-
fn report_fnmut_error(
352-
&self,
353-
errci: &ErrorConstraintInfo,
354-
kind: ReturnConstraint,
355-
) -> DiagnosticBuilder<'tcx> {
350+
fn report_fnmut_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder<'tcx> {
356351
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
357352

358353
let mut diag = self
@@ -361,39 +356,19 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
361356
.sess
362357
.struct_span_err(*span, "captured variable cannot escape `FnMut` closure body");
363358

364-
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
365-
if let ty::Opaque(def_id, _) = output_ty.kind {
366-
output_ty = self.infcx.tcx.type_of(def_id)
367-
};
368-
369-
debug!("report_fnmut_error: output_ty={:?}", output_ty);
370-
371-
let message = match output_ty.kind {
372-
ty::Closure(_, _) => {
373-
"returns a closure that contains a reference to a captured variable, which then \
374-
escapes the closure body"
375-
}
376-
ty::Adt(def, _) if self.infcx.tcx.is_diagnostic_item(sym::gen_future, def.did) => {
377-
"returns an `async` block that contains a reference to a captured variable, which then \
378-
escapes the closure body"
379-
}
380-
_ => "returns a reference to a captured variable which escapes the closure body",
359+
// We should check if the return type of this closure is in fact a closure - in that
360+
// case, we can special case the error further.
361+
let return_type_is_closure =
362+
self.regioncx.universal_regions().unnormalized_output_ty.is_closure();
363+
let message = if return_type_is_closure {
364+
"returns a closure that contains a reference to a captured variable, which then \
365+
escapes the closure body"
366+
} else {
367+
"returns a reference to a captured variable which escapes the closure body"
381368
};
382369

383370
diag.span_label(*span, message);
384371

385-
if let ReturnConstraint::ClosureUpvar(upvar) = kind {
386-
let def_id = match self.regioncx.universal_regions().defining_ty {
387-
DefiningTy::Closure(def_id, _) => def_id,
388-
ty @ _ => bug!("unexpected DefiningTy {:?}", ty),
389-
};
390-
391-
let upvar_def_span = self.infcx.tcx.hir().span(upvar);
392-
let upvar_span = self.infcx.tcx.upvars_mentioned(def_id).unwrap()[&upvar].span;
393-
diag.span_label(upvar_def_span, "variable defined here");
394-
diag.span_label(upvar_span, "variable captured here");
395-
}
396-
397372
match self.give_region_a_name(*outlived_fr).unwrap().source {
398373
RegionNameSource::NamedEarlyBoundRegion(fr_span)
399374
| RegionNameSource::NamedFreeRegion(fr_span)
@@ -531,7 +506,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
531506
outlived_fr_name.highlight_region_name(&mut diag);
532507

533508
match (category, outlived_fr_is_local, fr_is_local) {
534-
(ConstraintCategory::Return(_), true, _) => {
509+
(ConstraintCategory::Return, true, _) => {
535510
diag.span_label(
536511
*span,
537512
format!(

src/librustc_mir/borrow_check/mod.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ fn do_mir_borrowck<'a, 'tcx>(
216216
&mut flow_inits,
217217
&mdpe.move_data,
218218
&borrow_set,
219-
&upvars,
220219
);
221220

222221
// Dump MIR results into a file, if that is enabled. This let us
@@ -2315,7 +2314,30 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
23152314
/// be `self` in the current MIR, because that is the only time we directly access the fields
23162315
/// of a closure type.
23172316
pub fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option<Field> {
2318-
path_utils::is_upvar_field_projection(self.infcx.tcx, &self.upvars, place_ref, self.body())
2317+
let mut place_projection = place_ref.projection;
2318+
let mut by_ref = false;
2319+
2320+
if let [proj_base @ .., ProjectionElem::Deref] = place_projection {
2321+
place_projection = proj_base;
2322+
by_ref = true;
2323+
}
2324+
2325+
match place_projection {
2326+
[base @ .., ProjectionElem::Field(field, _ty)] => {
2327+
let tcx = self.infcx.tcx;
2328+
let base_ty = Place::ty_from(place_ref.local, base, self.body(), tcx).ty;
2329+
2330+
if (base_ty.is_closure() || base_ty.is_generator())
2331+
&& (!by_ref || self.upvars[field.index()].by_ref)
2332+
{
2333+
Some(*field)
2334+
} else {
2335+
None
2336+
}
2337+
}
2338+
2339+
_ => None,
2340+
}
23192341
}
23202342
}
23212343

src/librustc_mir/borrow_check/nll.rs

-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use crate::borrow_check::{
3939
renumber,
4040
type_check::{self, MirTypeckRegionConstraints, MirTypeckResults},
4141
universal_regions::UniversalRegions,
42-
Upvar,
4342
};
4443

4544
crate type PoloniusOutput = Output<RustcFacts>;
@@ -167,7 +166,6 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
167166
flow_inits: &mut ResultsCursor<'cx, 'tcx, MaybeInitializedPlaces<'cx, 'tcx>>,
168167
move_data: &MoveData<'tcx>,
169168
borrow_set: &BorrowSet<'tcx>,
170-
upvars: &[Upvar],
171169
) -> NllOutput<'tcx> {
172170
let mut all_facts = AllFacts::enabled(infcx.tcx).then_some(AllFacts::default());
173171

@@ -190,7 +188,6 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
190188
flow_inits,
191189
move_data,
192190
elements,
193-
upvars,
194191
);
195192

196193
if let Some(all_facts) = &mut all_facts {

src/librustc_mir/borrow_check/path_utils.rs

+1-37
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use crate::borrow_check::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation};
22
use crate::borrow_check::places_conflict;
33
use crate::borrow_check::AccessDepth;
4-
use crate::borrow_check::Upvar;
54
use crate::dataflow::indexes::BorrowIndex;
65
use rustc_data_structures::graph::dominators::Dominators;
76
use rustc_middle::mir::BorrowKind;
8-
use rustc_middle::mir::{BasicBlock, Body, Field, Location, Place, PlaceRef, ProjectionElem};
7+
use rustc_middle::mir::{BasicBlock, Body, Location, Place};
98
use rustc_middle::ty::TyCtxt;
109

1110
/// Returns `true` if the borrow represented by `kind` is
@@ -136,38 +135,3 @@ pub(super) fn borrow_of_local_data(place: Place<'_>) -> bool {
136135
// Any errors will be caught on the initial borrow
137136
!place.is_indirect()
138137
}
139-
140-
/// If `place` is a field projection, and the field is being projected from a closure type,
141-
/// then returns the index of the field being projected. Note that this closure will always
142-
/// be `self` in the current MIR, because that is the only time we directly access the fields
143-
/// of a closure type.
144-
pub(crate) fn is_upvar_field_projection(
145-
tcx: TyCtxt<'tcx>,
146-
upvars: &[Upvar],
147-
place_ref: PlaceRef<'tcx>,
148-
body: &Body<'tcx>,
149-
) -> Option<Field> {
150-
let mut place_projection = place_ref.projection;
151-
let mut by_ref = false;
152-
153-
if let [proj_base @ .., ProjectionElem::Deref] = place_projection {
154-
place_projection = proj_base;
155-
by_ref = true;
156-
}
157-
158-
match place_projection {
159-
[base @ .., ProjectionElem::Field(field, _ty)] => {
160-
let base_ty = Place::ty_from(place_ref.local, base, body, tcx).ty;
161-
162-
if (base_ty.is_closure() || base_ty.is_generator())
163-
&& (!by_ref || upvars[field.index()].by_ref)
164-
{
165-
Some(*field)
166-
} else {
167-
None
168-
}
169-
}
170-
171-
_ => None,
172-
}
173-
}

src/librustc_mir/borrow_check/region_infer/mod.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_infer::infer::region_constraints::{GenericKind, VarInfos, VerifyBound}
1212
use rustc_infer::infer::{InferCtxt, NLLRegionVariableOrigin, RegionVariableOrigin};
1313
use rustc_middle::mir::{
1414
Body, ClosureOutlivesRequirement, ClosureOutlivesSubject, ClosureRegionRequirements,
15-
ConstraintCategory, Local, Location, ReturnConstraint,
15+
ConstraintCategory, Local, Location,
1616
};
1717
use rustc_middle::ty::{self, subst::SubstsRef, RegionVid, Ty, TyCtxt, TypeFoldable};
1818
use rustc_span::Span;
@@ -2017,7 +2017,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20172017
| ConstraintCategory::BoringNoLocation
20182018
| ConstraintCategory::Internal => false,
20192019
ConstraintCategory::TypeAnnotation
2020-
| ConstraintCategory::Return(_)
2020+
| ConstraintCategory::Return
20212021
| ConstraintCategory::Yield => true,
20222022
_ => constraint_sup_scc != target_scc,
20232023
}
@@ -2042,26 +2042,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20422042

20432043
if let Some(i) = best_choice {
20442044
if let Some(next) = categorized_path.get(i + 1) {
2045-
if matches!(categorized_path[i].0, ConstraintCategory::Return(_))
2045+
if categorized_path[i].0 == ConstraintCategory::Return
20462046
&& next.0 == ConstraintCategory::OpaqueType
20472047
{
20482048
// The return expression is being influenced by the return type being
20492049
// impl Trait, point at the return type and not the return expr.
20502050
return *next;
20512051
}
20522052
}
2053-
2054-
if categorized_path[i].0 == ConstraintCategory::Return(ReturnConstraint::Normal) {
2055-
let field = categorized_path.iter().find_map(|p| {
2056-
if let ConstraintCategory::ClosureUpvar(f) = p.0 { Some(f) } else { None }
2057-
});
2058-
2059-
if let Some(field) = field {
2060-
categorized_path[i].0 =
2061-
ConstraintCategory::Return(ReturnConstraint::ClosureUpvar(field));
2062-
}
2063-
}
2064-
20652053
return categorized_path[i];
20662054
}
20672055

0 commit comments

Comments
 (0)