Skip to content

Commit f828977

Browse files
authored
Unrolled build for rust-lang#134412
Rollup merge of rust-lang#134412 - lcnr:borrowck-cleanup-trivial, r=jackh726 small borrowck cleanup the already approved parts of rust-lang#133909 and rust-lang#133961 r? `@jackh726`
2 parents 604d669 + c76eb22 commit f828977

File tree

14 files changed

+103
-142
lines changed

14 files changed

+103
-142
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
848848
return;
849849
};
850850

851-
let fn_returns = self.infcx.tcx.return_type_impl_or_dyn_traits(suitable_region.def_id);
851+
let fn_returns = self.infcx.tcx.return_type_impl_or_dyn_traits(suitable_region.scope);
852852

853853
let param = if let Some(param) =
854854
find_param_with_region(self.infcx.tcx, self.mir_def_id(), f, outlived_f)
@@ -875,15 +875,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
875875
Some(arg),
876876
captures,
877877
Some((param.param_ty_span, param.param_ty.to_string())),
878-
Some(suitable_region.def_id),
878+
Some(suitable_region.scope),
879879
);
880880
return;
881881
}
882882

883883
let Some((alias_tys, alias_span, lt_addition_span)) = self
884884
.infcx
885885
.tcx
886-
.return_type_impl_or_dyn_traits_with_type_alias(suitable_region.def_id)
886+
.return_type_impl_or_dyn_traits_with_type_alias(suitable_region.scope)
887887
else {
888888
return;
889889
};
@@ -1018,18 +1018,20 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
10181018
return;
10191019
};
10201020

1021-
let Some((ty_sub, _)) =
1022-
self.infcx.tcx.is_suitable_region(self.mir_def_id(), sub).and_then(|anon_reg| {
1023-
find_anon_type(self.infcx.tcx, self.mir_def_id(), sub, &anon_reg.bound_region)
1024-
})
1021+
let Some((ty_sub, _)) = self
1022+
.infcx
1023+
.tcx
1024+
.is_suitable_region(self.mir_def_id(), sub)
1025+
.and_then(|_| find_anon_type(self.infcx.tcx, self.mir_def_id(), sub))
10251026
else {
10261027
return;
10271028
};
10281029

1029-
let Some((ty_sup, _)) =
1030-
self.infcx.tcx.is_suitable_region(self.mir_def_id(), sup).and_then(|anon_reg| {
1031-
find_anon_type(self.infcx.tcx, self.mir_def_id(), sup, &anon_reg.bound_region)
1032-
})
1030+
let Some((ty_sup, _)) = self
1031+
.infcx
1032+
.tcx
1033+
.is_suitable_region(self.mir_def_id(), sup)
1034+
.and_then(|_| find_anon_type(self.infcx.tcx, self.mir_def_id(), sup))
10331035
else {
10341036
return;
10351037
};

compiler/rustc_borrowck/src/lib.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ fn do_mir_borrowck<'tcx>(
141141
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
142142
let def = input_body.source.def_id().expect_local();
143143
let infcx = BorrowckInferCtxt::new(tcx, def);
144+
if let Some(e) = input_body.tainted_by_errors {
145+
infcx.set_tainted_by_errors(e);
146+
}
144147

145148
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
146149
for var_debug_info in &input_body.var_debug_info {
@@ -162,13 +165,6 @@ fn do_mir_borrowck<'tcx>(
162165
}
163166
}
164167

165-
let diags = &mut diags::BorrowckDiags::new();
166-
167-
// Gather the upvars of a closure, if any.
168-
if let Some(e) = input_body.tainted_by_errors {
169-
infcx.set_tainted_by_errors(e);
170-
}
171-
172168
// Replace all regions with fresh inference variables. This
173169
// requires first making our own copy of the MIR. This copy will
174170
// be modified (in place) to contain non-lexical lifetimes. It
@@ -224,6 +220,7 @@ fn do_mir_borrowck<'tcx>(
224220

225221
// We also have a `#[rustc_regions]` annotation that causes us to dump
226222
// information.
223+
let diags = &mut diags::BorrowckDiags::new();
227224
nll::dump_annotation(&infcx, body, &regioncx, &opt_closure_req, &opaque_type_values, diags);
228225

229226
let movable_coroutine =

compiler/rustc_infer/src/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -689,15 +689,15 @@ impl<'tcx> InferCtxt<'tcx> {
689689
/// Require that the region `r` be equal to one of the regions in
690690
/// the set `regions`.
691691
#[instrument(skip(self), level = "debug")]
692-
pub fn member_constraint(
692+
pub fn add_member_constraint(
693693
&self,
694694
key: ty::OpaqueTypeKey<'tcx>,
695695
definition_span: Span,
696696
hidden_ty: Ty<'tcx>,
697697
region: ty::Region<'tcx>,
698698
in_regions: Lrc<Vec<ty::Region<'tcx>>>,
699699
) {
700-
self.inner.borrow_mut().unwrap_region_constraints().member_constraint(
700+
self.inner.borrow_mut().unwrap_region_constraints().add_member_constraint(
701701
key,
702702
definition_span,
703703
hidden_ty,

compiler/rustc_infer/src/infer/opaque_types/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl<'tcx> InferCtxt<'tcx> {
364364
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
365365
tcx: self.tcx,
366366
op: |r| {
367-
self.member_constraint(
367+
self.add_member_constraint(
368368
opaque_type_key,
369369
span,
370370
concrete_ty,

compiler/rustc_infer/src/infer/region_constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
466466
}
467467
}
468468

469-
pub(super) fn member_constraint(
469+
pub(super) fn add_member_constraint(
470470
&mut self,
471471
key: ty::OpaqueTypeKey<'tcx>,
472472
definition_span: Span,

compiler/rustc_middle/src/ty/context.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1119,10 +1119,10 @@ impl<'tcx> CommonConsts<'tcx> {
11191119
/// either a `ReEarlyParam` or `ReLateParam`.
11201120
#[derive(Debug)]
11211121
pub struct FreeRegionInfo {
1122-
/// `LocalDefId` of the free region.
1123-
pub def_id: LocalDefId,
1124-
/// the bound region corresponding to free region.
1125-
pub bound_region: ty::BoundRegionKind,
1122+
/// `LocalDefId` of the scope.
1123+
pub scope: LocalDefId,
1124+
/// the `DefId` of the free region.
1125+
pub region_def_id: DefId,
11261126
/// checks if bound region is in Impl Item
11271127
pub is_impl_item: bool,
11281128
}
@@ -1960,7 +1960,7 @@ impl<'tcx> TyCtxt<'tcx> {
19601960
generic_param_scope: LocalDefId,
19611961
mut region: Region<'tcx>,
19621962
) -> Option<FreeRegionInfo> {
1963-
let (suitable_region_binding_scope, bound_region) = loop {
1963+
let (suitable_region_binding_scope, region_def_id) = loop {
19641964
let def_id =
19651965
region.opt_param_def_id(self, generic_param_scope.to_def_id())?.as_local()?;
19661966
let scope = self.local_parent(def_id);
@@ -1970,10 +1970,7 @@ impl<'tcx> TyCtxt<'tcx> {
19701970
region = self.map_opaque_lifetime_to_parent_lifetime(def_id);
19711971
continue;
19721972
}
1973-
break (
1974-
scope,
1975-
ty::BoundRegionKind::Named(def_id.into(), self.item_name(def_id.into())),
1976-
);
1973+
break (scope, def_id.into());
19771974
};
19781975

19791976
let is_impl_item = match self.hir_node_by_def_id(suitable_region_binding_scope) {
@@ -1982,7 +1979,7 @@ impl<'tcx> TyCtxt<'tcx> {
19821979
_ => false,
19831980
};
19841981

1985-
Some(FreeRegionInfo { def_id: suitable_region_binding_scope, bound_region, is_impl_item })
1982+
Some(FreeRegionInfo { scope: suitable_region_binding_scope, region_def_id, is_impl_item })
19861983
}
19871984

19881985
/// Given a `DefId` for an `fn`, return all the `dyn` and `impl` traits in its return type.

compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/different_lifetimes.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
6363
}
6464

6565
// Determine whether the sub and sup consist of both anonymous (elided) regions.
66-
let anon_reg_sup = self.tcx().is_suitable_region(self.generic_param_scope, sup)?;
66+
let sup_info = self.tcx().is_suitable_region(self.generic_param_scope, sup)?;
6767

68-
let anon_reg_sub = self.tcx().is_suitable_region(self.generic_param_scope, sub)?;
69-
let scope_def_id_sup = anon_reg_sup.def_id;
70-
let bregion_sup = anon_reg_sup.bound_region;
71-
let scope_def_id_sub = anon_reg_sub.def_id;
72-
let bregion_sub = anon_reg_sub.bound_region;
68+
let sub_info = self.tcx().is_suitable_region(self.generic_param_scope, sub)?;
7369

74-
let ty_sup = find_anon_type(self.tcx(), self.generic_param_scope, sup, &bregion_sup)?;
70+
let ty_sup = find_anon_type(self.tcx(), self.generic_param_scope, sup)?;
7571

76-
let ty_sub = find_anon_type(self.tcx(), self.generic_param_scope, sub, &bregion_sub)?;
72+
let ty_sub = find_anon_type(self.tcx(), self.generic_param_scope, sub)?;
7773

78-
debug!(
79-
"try_report_anon_anon_conflict: found_param1={:?} sup={:?} br1={:?}",
80-
ty_sub, sup, bregion_sup
81-
);
82-
debug!(
83-
"try_report_anon_anon_conflict: found_param2={:?} sub={:?} br2={:?}",
84-
ty_sup, sub, bregion_sub
85-
);
74+
debug!("try_report_anon_anon_conflict: found_param1={:?} sup={:?}", ty_sub, sup);
75+
debug!("try_report_anon_anon_conflict: found_param2={:?} sub={:?}", ty_sup, sub);
8676

8777
let (ty_sup, ty_fndecl_sup) = ty_sup;
8878
let (ty_sub, ty_fndecl_sub) = ty_sub;
@@ -93,9 +83,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
9383
self.find_param_with_region(sub, sub)?;
9484

9585
let sup_is_ret_type =
96-
self.is_return_type_anon(scope_def_id_sup, bregion_sup, ty_fndecl_sup);
86+
self.is_return_type_anon(sup_info.scope, sup_info.region_def_id, ty_fndecl_sup);
9787
let sub_is_ret_type =
98-
self.is_return_type_anon(scope_def_id_sub, bregion_sub, ty_fndecl_sub);
88+
self.is_return_type_anon(sub_info.scope, sub_info.region_def_id, ty_fndecl_sub);
9989

10090
debug!(
10191
"try_report_anon_anon_conflict: sub_is_ret_type={:?} sup_is_ret_type={:?}",

compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/find_anon_type.rs

+36-56
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::ops::ControlFlow;
22

33
use rustc_hir as hir;
4-
use rustc_hir::def_id::LocalDefId;
4+
use rustc_hir::def_id::{DefId, LocalDefId};
55
use rustc_hir::intravisit::{self, Visitor};
66
use rustc_middle::hir::map::Map;
77
use rustc_middle::hir::nested_filter;
@@ -28,16 +28,15 @@ pub fn find_anon_type<'tcx>(
2828
tcx: TyCtxt<'tcx>,
2929
generic_param_scope: LocalDefId,
3030
region: Region<'tcx>,
31-
br: &ty::BoundRegionKind,
3231
) -> Option<(&'tcx hir::Ty<'tcx>, &'tcx hir::FnSig<'tcx>)> {
3332
let anon_reg = tcx.is_suitable_region(generic_param_scope, region)?;
34-
let fn_sig = tcx.hir_node_by_def_id(anon_reg.def_id).fn_sig()?;
33+
let fn_sig = tcx.hir_node_by_def_id(anon_reg.scope).fn_sig()?;
3534

3635
fn_sig
3736
.decl
3837
.inputs
3938
.iter()
40-
.find_map(|arg| find_component_for_bound_region(tcx, arg, br))
39+
.find_map(|arg| find_component_for_bound_region(tcx, arg, anon_reg.region_def_id))
4140
.map(|ty| (ty, fn_sig))
4241
}
4342

@@ -46,9 +45,9 @@ pub fn find_anon_type<'tcx>(
4645
fn find_component_for_bound_region<'tcx>(
4746
tcx: TyCtxt<'tcx>,
4847
arg: &'tcx hir::Ty<'tcx>,
49-
br: &ty::BoundRegionKind,
48+
region_def_id: DefId,
5049
) -> Option<&'tcx hir::Ty<'tcx>> {
51-
FindNestedTypeVisitor { tcx, bound_region: *br, current_index: ty::INNERMOST }
50+
FindNestedTypeVisitor { tcx, region_def_id, current_index: ty::INNERMOST }
5251
.visit_ty(arg)
5352
.break_value()
5453
}
@@ -62,9 +61,8 @@ fn find_component_for_bound_region<'tcx>(
6261
// specific part of the type in the error message.
6362
struct FindNestedTypeVisitor<'tcx> {
6463
tcx: TyCtxt<'tcx>,
65-
// The bound_region corresponding to the Refree(freeregion)
66-
// associated with the anonymous region we are looking for.
67-
bound_region: ty::BoundRegionKind,
64+
// The `DefId` of the region we're looking for.
65+
region_def_id: DefId,
6866
current_index: ty::DebruijnIndex,
6967
}
7068

@@ -96,48 +94,39 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
9694
hir::TyKind::Ref(lifetime, _) => {
9795
// the lifetime of the Ref
9896
let hir_id = lifetime.hir_id;
99-
match (self.tcx.named_bound_var(hir_id), self.bound_region) {
97+
match self.tcx.named_bound_var(hir_id) {
10098
// Find the index of the named region that was part of the
10199
// error. We will then search the function parameters for a bound
102100
// region at the right depth with the same index
103-
(
104-
Some(rbv::ResolvedArg::EarlyBound(id)),
105-
ty::BoundRegionKind::Named(def_id, _),
106-
) => {
107-
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
108-
if id.to_def_id() == def_id {
101+
Some(rbv::ResolvedArg::EarlyBound(id)) => {
102+
debug!("EarlyBound id={:?}", id);
103+
if id.to_def_id() == self.region_def_id {
109104
return ControlFlow::Break(arg);
110105
}
111106
}
112107

113108
// Find the index of the named region that was part of the
114109
// error. We will then search the function parameters for a bound
115110
// region at the right depth with the same index
116-
(
117-
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)),
118-
ty::BoundRegionKind::Named(def_id, _),
119-
) => {
111+
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)) => {
120112
debug!(
121113
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
122114
debruijn_index
123115
);
124-
debug!("LateBound id={:?} def_id={:?}", id, def_id);
125-
if debruijn_index == self.current_index && id.to_def_id() == def_id {
116+
debug!("LateBound id={:?}", id);
117+
if debruijn_index == self.current_index
118+
&& id.to_def_id() == self.region_def_id
119+
{
126120
return ControlFlow::Break(arg);
127121
}
128122
}
129123

130-
(
131-
Some(
132-
rbv::ResolvedArg::StaticLifetime
133-
| rbv::ResolvedArg::Free(_, _)
134-
| rbv::ResolvedArg::EarlyBound(_)
135-
| rbv::ResolvedArg::LateBound(_, _, _)
136-
| rbv::ResolvedArg::Error(_),
137-
)
138-
| None,
139-
_,
140-
) => {
124+
Some(
125+
rbv::ResolvedArg::StaticLifetime
126+
| rbv::ResolvedArg::Free(_, _)
127+
| rbv::ResolvedArg::Error(_),
128+
)
129+
| None => {
141130
debug!("no arg found");
142131
}
143132
}
@@ -151,7 +140,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
151140
return if intravisit::walk_ty(
152141
&mut TyPathVisitor {
153142
tcx: self.tcx,
154-
bound_region: self.bound_region,
143+
region_def_id: self.region_def_id,
155144
current_index: self.current_index,
156145
},
157146
arg,
@@ -179,7 +168,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
179168
// specific part of the type in the error message.
180169
struct TyPathVisitor<'tcx> {
181170
tcx: TyCtxt<'tcx>,
182-
bound_region: ty::BoundRegionKind,
171+
region_def_id: DefId,
183172
current_index: ty::DebruijnIndex,
184173
}
185174

@@ -192,38 +181,29 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
192181
}
193182

194183
fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) -> Self::Result {
195-
match (self.tcx.named_bound_var(lifetime.hir_id), self.bound_region) {
184+
match self.tcx.named_bound_var(lifetime.hir_id) {
196185
// the lifetime of the TyPath!
197-
(Some(rbv::ResolvedArg::EarlyBound(id)), ty::BoundRegionKind::Named(def_id, _)) => {
198-
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
199-
if id.to_def_id() == def_id {
186+
Some(rbv::ResolvedArg::EarlyBound(id)) => {
187+
debug!("EarlyBound id={:?}", id);
188+
if id.to_def_id() == self.region_def_id {
200189
return ControlFlow::Break(());
201190
}
202191
}
203192

204-
(
205-
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)),
206-
ty::BoundRegionKind::Named(def_id, _),
207-
) => {
193+
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)) => {
208194
debug!("FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}", debruijn_index,);
209195
debug!("id={:?}", id);
210-
debug!("def_id={:?}", def_id);
211-
if debruijn_index == self.current_index && id.to_def_id() == def_id {
196+
if debruijn_index == self.current_index && id.to_def_id() == self.region_def_id {
212197
return ControlFlow::Break(());
213198
}
214199
}
215200

216-
(
217-
Some(
218-
rbv::ResolvedArg::StaticLifetime
219-
| rbv::ResolvedArg::EarlyBound(_)
220-
| rbv::ResolvedArg::LateBound(_, _, _)
221-
| rbv::ResolvedArg::Free(_, _)
222-
| rbv::ResolvedArg::Error(_),
223-
)
224-
| None,
225-
_,
226-
) => {
201+
Some(
202+
rbv::ResolvedArg::StaticLifetime
203+
| rbv::ResolvedArg::Free(_, _)
204+
| rbv::ResolvedArg::Error(_),
205+
)
206+
| None => {
227207
debug!("no arg found");
228208
}
229209
}

0 commit comments

Comments
 (0)