Skip to content

Commit 2f1bc91

Browse files
committed
Auto merge of #60537 - Centril:rollup-42jxz82, r=Centril
Rollup of 9 pull requests Successful merges: - #60429 (Account for paths in incorrect pub qualifier help) - #60449 (Constrain all regions in the concrete type for an opaque type) - #60486 (Place related refactors) - #60513 (Remove -Z borrowck=compare flag) - #60516 (Remove TypeckMir) - #60517 (Reword casting message) - #60520 (Add rustfmt toml) - #60521 (Migrate tidy to rust 2018 edition) - #60527 (Fix async fn lowering ICE with APIT.) Failed merges: r? @ghost
2 parents e232636 + 1599877 commit 2f1bc91

File tree

90 files changed

+562
-1100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+562
-1100
lines changed

rustfmt.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Currently, most of the code in the compiler uses historical style.
2+
#
3+
# For new code, consider running rustfmt with this config (it should
4+
# be picked up automatically).
5+
version = "Two"
6+
use_small_heuristics = "Max"

src/librustc/hir/map/def_collector.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ impl<'a> DefCollector<'a> {
9292
visit::walk_generics(this, generics);
9393

9494
// Walk the generated arguments for the `async fn`.
95-
for a in arguments {
95+
for (i, a) in arguments.iter().enumerate() {
9696
use visit::Visitor;
9797
if let Some(arg) = &a.arg {
9898
this.visit_ty(&arg.ty);
99+
} else {
100+
this.visit_ty(&decl.inputs[i].ty);
99101
}
100102
}
101103

src/librustc/infer/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ impl SuppressRegionErrors {
9797
// If we're on Migrate mode, report AST region errors
9898
BorrowckMode::Migrate => SuppressRegionErrors { suppressed: false },
9999

100-
// If we're on MIR or Compare mode, don't report AST region errors as they should
101-
// be reported by NLL
102-
BorrowckMode::Compare | BorrowckMode::Mir => SuppressRegionErrors { suppressed: true },
100+
// If we're on MIR, don't report AST region errors as they should be reported by NLL
101+
BorrowckMode::Mir => SuppressRegionErrors { suppressed: true },
103102
}
104103
}
105104
}

src/librustc/infer/opaque_types/mod.rs

+84-57
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
use rustc_data_structures::fx::FxHashMap;
2+
use syntax_pos::Span;
3+
14
use crate::hir::def_id::DefId;
25
use crate::hir;
36
use crate::hir::Node;
47
use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin};
58
use crate::infer::outlives::free_region_map::FreeRegionRelations;
6-
use rustc_data_structures::fx::FxHashMap;
79
use crate::traits::{self, PredicateObligation};
810
use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind};
9-
use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder};
10-
use crate::ty::outlives::Component;
11+
use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
1112
use crate::ty::subst::{Kind, InternalSubsts, SubstsRef, UnpackedKind};
1213
use crate::util::nodemap::DefIdMap;
1314

@@ -373,58 +374,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
373374
let least_region = least_region.unwrap_or(self.tcx.lifetimes.re_static);
374375
debug!("constrain_opaque_types: least_region={:?}", least_region);
375376

376-
// Require that the type `concrete_ty` outlives
377-
// `least_region`, modulo any type parameters that appear
378-
// in the type, which we ignore. This is because impl
379-
// trait values are assumed to capture all the in-scope
380-
// type parameters. This little loop here just invokes
381-
// `outlives` repeatedly, draining all the nested
382-
// obligations that result.
383-
let mut types = vec![concrete_ty];
384-
let bound_region = |r| self.sub_regions(infer::CallReturn(span), least_region, r);
385-
while let Some(ty) = types.pop() {
386-
let mut components = smallvec![];
387-
self.tcx.push_outlives_components(ty, &mut components);
388-
while let Some(component) = components.pop() {
389-
match component {
390-
Component::Region(r) => {
391-
bound_region(r);
392-
}
393-
394-
Component::Param(_) => {
395-
// ignore type parameters like `T`, they are captured
396-
// implicitly by the `impl Trait`
397-
}
398-
399-
Component::UnresolvedInferenceVariable(_) => {
400-
// we should get an error that more type
401-
// annotations are needed in this case
402-
self.tcx
403-
.sess
404-
.delay_span_bug(span, "unresolved inf var in opaque");
405-
}
406-
407-
Component::Projection(ty::ProjectionTy {
408-
substs,
409-
item_def_id: _,
410-
}) => {
411-
for k in substs {
412-
match k.unpack() {
413-
UnpackedKind::Lifetime(lt) => bound_region(lt),
414-
UnpackedKind::Type(ty) => types.push(ty),
415-
UnpackedKind::Const(_) => {
416-
// Const parameters don't impose constraints.
417-
}
418-
}
419-
}
420-
}
421-
422-
Component::EscapingProjection(more_components) => {
423-
components.extend(more_components);
424-
}
425-
}
426-
}
427-
}
377+
concrete_ty.visit_with(&mut OpaqueTypeOutlivesVisitor {
378+
infcx: self,
379+
least_region,
380+
span,
381+
});
428382
}
429383

430384
/// Given the fully resolved, instantiated type for an opaque
@@ -502,6 +456,80 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
502456
}
503457
}
504458

459+
// Visitor that requires that (almost) all regions in the type visited outlive
460+
// `least_region`. We cannot use `push_outlives_components` because regions in
461+
// closure signatures are not included in their outlives components. We need to
462+
// ensure all regions outlive the given bound so that we don't end up with,
463+
// say, `ReScope` appearing in a return type and causing ICEs when other
464+
// functions end up with region constraints involving regions from other
465+
// functions.
466+
//
467+
// We also cannot use `for_each_free_region` because for closures it includes
468+
// the regions parameters from the enclosing item.
469+
//
470+
// We ignore any type parameters because impl trait values are assumed to
471+
// capture all the in-scope type parameters.
472+
struct OpaqueTypeOutlivesVisitor<'a, 'gcx, 'tcx> {
473+
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
474+
least_region: ty::Region<'tcx>,
475+
span: Span,
476+
}
477+
478+
impl<'tcx> TypeVisitor<'tcx> for OpaqueTypeOutlivesVisitor<'_, '_, 'tcx>
479+
{
480+
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> bool {
481+
t.skip_binder().visit_with(self);
482+
false // keep visiting
483+
}
484+
485+
fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
486+
match *r {
487+
// ignore bound regions, keep visiting
488+
ty::ReLateBound(_, _) => false,
489+
_ => {
490+
self.infcx.sub_regions(infer::CallReturn(self.span), self.least_region, r);
491+
false
492+
}
493+
}
494+
}
495+
496+
fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
497+
// We're only interested in types involving regions
498+
if !ty.flags.intersects(ty::TypeFlags::HAS_FREE_REGIONS) {
499+
return false; // keep visiting
500+
}
501+
502+
match ty.sty {
503+
ty::Closure(def_id, ref substs) => {
504+
// Skip lifetime parameters of the enclosing item(s)
505+
506+
for upvar_ty in substs.upvar_tys(def_id, self.infcx.tcx) {
507+
upvar_ty.visit_with(self);
508+
}
509+
510+
substs.closure_sig_ty(def_id, self.infcx.tcx).visit_with(self);
511+
}
512+
513+
ty::Generator(def_id, ref substs, _) => {
514+
// Skip lifetime parameters of the enclosing item(s)
515+
// Also skip the witness type, because that has no free regions.
516+
517+
for upvar_ty in substs.upvar_tys(def_id, self.infcx.tcx) {
518+
upvar_ty.visit_with(self);
519+
}
520+
521+
substs.return_ty(def_id, self.infcx.tcx).visit_with(self);
522+
substs.yield_ty(def_id, self.infcx.tcx).visit_with(self);
523+
}
524+
_ => {
525+
ty.super_visit_with(self);
526+
}
527+
}
528+
529+
false
530+
}
531+
}
532+
505533
struct ReverseMapper<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
506534
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
507535

@@ -563,8 +591,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx>
563591
// ignore `'static`, as that can appear anywhere
564592
ty::ReStatic |
565593

566-
// ignore `ReScope`, as that can appear anywhere
567-
// See `src/test/run-pass/issue-49556.rs` for example.
594+
// ignore `ReScope`, which may appear in impl Trait in bindings.
568595
ty::ReScope(..) => return r,
569596

570597
_ => { }

src/librustc/mir/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2059,10 +2059,13 @@ impl<'tcx> Place<'tcx> {
20592059

20602060
/// Finds the innermost `Local` from this `Place`.
20612061
pub fn base_local(&self) -> Option<Local> {
2062-
match self {
2063-
Place::Base(PlaceBase::Local(local)) => Some(*local),
2064-
Place::Projection(box Projection { base, elem: _ }) => base.base_local(),
2065-
Place::Base(PlaceBase::Static(..)) => None,
2062+
let mut place = self;
2063+
loop {
2064+
match place {
2065+
Place::Projection(proj) => place = &proj.base,
2066+
Place::Base(PlaceBase::Static(_)) => return None,
2067+
Place::Base(PlaceBase::Local(local)) => return Some(*local),
2068+
}
20662069
}
20672070
}
20682071

src/librustc/session/config.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ pub enum PrintRequest {
462462
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
463463
pub enum BorrowckMode {
464464
Mir,
465-
Compare,
466465
Migrate,
467466
}
468467

@@ -471,7 +470,6 @@ impl BorrowckMode {
471470
/// on the AST borrow check if the MIR-based one errors.
472471
pub fn migrate(self) -> bool {
473472
match self {
474-
BorrowckMode::Compare => false,
475473
BorrowckMode::Mir => false,
476474
BorrowckMode::Migrate => true,
477475
}
@@ -480,7 +478,6 @@ impl BorrowckMode {
480478
/// Should we emit the AST-based borrow checker errors?
481479
pub fn use_ast(self) -> bool {
482480
match self {
483-
BorrowckMode::Compare => true,
484481
BorrowckMode::Mir => false,
485482
BorrowckMode::Migrate => false,
486483
}
@@ -1214,7 +1211,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12141211
identify_regions: bool = (false, parse_bool, [UNTRACKED],
12151212
"make unnamed regions display as '# (where # is some non-ident unique id)"),
12161213
borrowck: Option<String> = (None, parse_opt_string, [UNTRACKED],
1217-
"select which borrowck is used (`ast`, `mir`, `migrate`, or `compare`)"),
1214+
"select which borrowck is used (`mir` or `migrate`)"),
12181215
time_passes: bool = (false, parse_bool, [UNTRACKED],
12191216
"measure time of each rustc pass"),
12201217
time: bool = (false, parse_bool, [UNTRACKED],
@@ -2315,7 +2312,6 @@ pub fn build_session_options_and_crate_config(
23152312
let borrowck_mode = match debugging_opts.borrowck.as_ref().map(|s| &s[..]) {
23162313
None | Some("migrate") => BorrowckMode::Migrate,
23172314
Some("mir") => BorrowckMode::Mir,
2318-
Some("compare") => BorrowckMode::Compare,
23192315
Some(m) => early_error(error_format, &format!("unknown borrowck mode `{}`", m)),
23202316
};
23212317

src/librustc_mir/borrow_check/borrow_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
210210

211211
self.insert_as_pending_if_two_phase(location, &assigned_place, kind, idx);
212212

213-
if let Some(local) = borrowed_place.root_local() {
213+
if let Some(local) = borrowed_place.base_local() {
214214
self.local_map.entry(local).or_default().insert(idx);
215215
}
216216
}

src/librustc_mir/borrow_check/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18311831
}
18321832

18331833
place = base;
1834-
continue;
18351834
}
18361835
}
18371836
}

src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ pub(super) fn generate<'gcx, 'tcx>(
4747
mir.local_decls.indices().collect()
4848
} else {
4949
let free_regions = {
50-
let borrowck_context = typeck.borrowck_context.as_ref().unwrap();
5150
regions_that_outlive_free_regions(
5251
typeck.infcx.num_region_vars(),
53-
&borrowck_context.universal_regions,
54-
&borrowck_context.constraints.outlives_constraints,
52+
&typeck.borrowck_context.universal_regions,
53+
&typeck.borrowck_context.constraints.outlives_constraints,
5554
)
5655
};
5756
compute_live_locals(typeck.tcx(), &free_regions, mir)

src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -517,16 +517,15 @@ impl LivenessContext<'_, '_, '_, '_, 'tcx> {
517517

518518
let tcx = typeck.tcx();
519519
tcx.for_each_free_region(&value, |live_region| {
520-
let borrowck_context = typeck.borrowck_context.as_mut().unwrap();
521-
let live_region_vid = borrowck_context
520+
let live_region_vid = typeck.borrowck_context
522521
.universal_regions
523522
.to_region_vid(live_region);
524-
borrowck_context
523+
typeck.borrowck_context
525524
.constraints
526525
.liveness_constraints
527526
.add_elements(live_region_vid, live_at);
528527

529-
if let Some(facts) = borrowck_context.all_facts {
528+
if let Some(facts) = typeck.borrowck_context.all_facts {
530529
for point in live_at.iter() {
531530
let loc = elements.to_location(point);
532531
facts.region_live_at.push((live_region_vid, location_table.start_index(loc)));

0 commit comments

Comments
 (0)