Skip to content

Commit 7473869

Browse files
committed
Auto merge of #59235 - pietroalbini:beta-rollup, r=pietroalbini
[beta] Rollup backports Cherry-picked: * Include bounds from promoted constants in NLL #57202 * Warning period for detecting nested impl trait #58608 * Don't promote function calls to nonpromotable things #58784 * Make migrate mode work at item level granularity #58788 * Expand where negative supertrait specific error is shown #58861 * Expand where negative supertrait specific error is shown #58861 Rolled up: * [BETA] Update cargo #59217 r? @ghost
2 parents 744b374 + 0e9e6ec commit 7473869

Some content is hidden

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

53 files changed

+950
-235
lines changed

src/librustc/lint/builtin.rs

+14
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ declare_lint! {
386386
"ambiguous associated items"
387387
}
388388

389+
declare_lint! {
390+
pub NESTED_IMPL_TRAIT,
391+
Warn,
392+
"nested occurrence of `impl Trait` type"
393+
}
394+
389395
/// Does nothing as a lint pass, but registers some `Lint`s
390396
/// that are used by other parts of the compiler.
391397
#[derive(Copy, Clone)]
@@ -457,6 +463,7 @@ impl LintPass for HardwiredLints {
457463
parser::ILL_FORMED_ATTRIBUTE_INPUT,
458464
DEPRECATED_IN_FUTURE,
459465
AMBIGUOUS_ASSOCIATED_ITEMS,
466+
NESTED_IMPL_TRAIT,
460467
)
461468
}
462469
}
@@ -474,6 +481,7 @@ pub enum BuiltinLintDiagnostics {
474481
ElidedLifetimesInPaths(usize, Span, bool, Span, String),
475482
UnknownCrateTypes(Span, String, String),
476483
UnusedImports(String, Vec<(Span, String)>),
484+
NestedImplTrait { outer_impl_trait_span: Span, inner_impl_trait_span: Span },
477485
}
478486

479487
impl BuiltinLintDiagnostics {
@@ -564,6 +572,12 @@ impl BuiltinLintDiagnostics {
564572
);
565573
}
566574
}
575+
BuiltinLintDiagnostics::NestedImplTrait {
576+
outer_impl_trait_span, inner_impl_trait_span
577+
} => {
578+
db.span_label(outer_impl_trait_span, "outer `impl Trait`");
579+
db.span_label(inner_impl_trait_span, "nested `impl Trait` here");
580+
}
567581
}
568582
}
569583
}

src/librustc/middle/expr_use_visitor.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ pub trait Delegate<'tcx> {
8383
assignment_span: Span,
8484
assignee_cmt: &mc::cmt_<'tcx>,
8585
mode: MutateMode);
86+
87+
// A nested closure or generator - only one layer deep.
88+
fn nested_body(&mut self, _body_id: hir::BodyId) {}
8689
}
8790

8891
#[derive(Copy, Clone, PartialEq, Debug)]
@@ -532,8 +535,9 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
532535
self.consume_expr(&base);
533536
}
534537

535-
hir::ExprKind::Closure(.., fn_decl_span, _) => {
536-
self.walk_captures(expr, fn_decl_span)
538+
hir::ExprKind::Closure(_, _, body_id, fn_decl_span, _) => {
539+
self.delegate.nested_body(body_id);
540+
self.walk_captures(expr, fn_decl_span);
537541
}
538542

539543
hir::ExprKind::Box(ref base) => {

src/librustc_borrowck/borrowck/gather_loans/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
152152
.node_type(self.bccx.tcx.hir().node_to_hir_id(id));
153153
gather_moves::gather_decl(self.bccx, &self.move_data, id, ty);
154154
}
155+
156+
fn nested_body(&mut self, body_id: hir::BodyId) {
157+
debug!("nested_body(body_id={:?})", body_id);
158+
// rust-lang/rust#58776: MIR and AST borrow check disagree on where
159+
// certain closure errors are reported. As such migrate borrowck has to
160+
// operate at the level of items, rather than bodies. Check if the
161+
// contained closure had any errors and set `signalled_any_error` if it
162+
// has.
163+
let bccx = self.bccx;
164+
if bccx.tcx.migrate_borrowck() {
165+
if let SignalledError::NoErrorsSeen = bccx.signalled_any_error.get() {
166+
let closure_def_id = bccx.tcx.hir().body_owner_def_id(body_id);
167+
debug!("checking closure: {:?}", closure_def_id);
168+
169+
bccx.signalled_any_error.set(bccx.tcx.borrowck(closure_def_id).signalled_any_error);
170+
}
171+
}
172+
}
155173
}
156174

157175
/// Implements the A-* rules in README.md.

src/librustc_lint/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
353353
reference: "issue #57593 <https://github.com/rust-lang/rust/issues/57593>",
354354
edition: None,
355355
},
356+
FutureIncompatibleInfo {
357+
id: LintId::of(NESTED_IMPL_TRAIT),
358+
reference: "issue #59014 <https://github.com/rust-lang/rust/issues/59014>",
359+
edition: None,
360+
},
356361
]);
357362

358363
// Register renamed and removed lints.

src/librustc_metadata/cstore_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ impl cstore::CStore {
439439

440440
let source_file = sess.parse_sess.source_map().new_source_file(source_name, def.body);
441441
let local_span = Span::new(source_file.start_pos, source_file.end_pos, NO_EXPANSION);
442-
let (body, errors) = source_file_to_stream(&sess.parse_sess, source_file, None);
443-
emit_unclosed_delims(&errors, &sess.diagnostic());
442+
let (body, mut errors) = source_file_to_stream(&sess.parse_sess, source_file, None);
443+
emit_unclosed_delims(&mut errors, &sess.diagnostic());
444444

445445
// Mark the attrs as used
446446
let attrs = data.get_item_attrs(id.index, sess);

src/librustc_mir/borrow_check/mod.rs

+5-23
Original file line numberDiff line numberDiff line change
@@ -329,30 +329,12 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
329329
// When borrowck=migrate, check if AST-borrowck would
330330
// error on the given code.
331331

332-
// rust-lang/rust#55492: loop over parents to ensure that
333-
// errors that AST-borrowck only detects in some parent of
334-
// a closure still allows NLL to signal an error.
335-
let mut curr_def_id = def_id;
336-
let signalled_any_error = loop {
337-
match tcx.borrowck(curr_def_id).signalled_any_error {
338-
SignalledError::NoErrorsSeen => {
339-
// keep traversing (and borrow-checking) parents
340-
}
341-
SignalledError::SawSomeError => {
342-
// stop search here
343-
break SignalledError::SawSomeError;
344-
}
345-
}
346-
347-
if tcx.is_closure(curr_def_id) {
348-
curr_def_id = tcx.parent_def_id(curr_def_id)
349-
.expect("a closure must have a parent_def_id");
350-
} else {
351-
break SignalledError::NoErrorsSeen;
352-
}
353-
};
332+
// rust-lang/rust#55492, rust-lang/rust#58776 check the base def id
333+
// for errors. AST borrowck is responsible for aggregating
334+
// `signalled_any_error` from all of the nested closures here.
335+
let base_def_id = tcx.closure_base_def_id(def_id);
354336

355-
match signalled_any_error {
337+
match tcx.borrowck(base_def_id).signalled_any_error {
356338
SignalledError::NoErrorsSeen => {
357339
// if AST-borrowck signalled no errors, then
358340
// downgrade all the buffered MIR-borrowck errors

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,6 @@ pub trait ClosureRegionRequirementsExt<'gcx, 'tcx> {
13571357
fn apply_requirements(
13581358
&self,
13591359
tcx: TyCtxt<'_, 'gcx, 'tcx>,
1360-
location: Location,
13611360
closure_def_id: DefId,
13621361
closure_substs: &'tcx ty::subst::Substs<'tcx>,
13631362
) -> Vec<QueryRegionConstraint<'tcx>>;
@@ -1388,13 +1387,12 @@ impl<'gcx, 'tcx> ClosureRegionRequirementsExt<'gcx, 'tcx> for ClosureRegionRequi
13881387
fn apply_requirements(
13891388
&self,
13901389
tcx: TyCtxt<'_, 'gcx, 'tcx>,
1391-
location: Location,
13921390
closure_def_id: DefId,
13931391
closure_substs: &'tcx ty::subst::Substs<'tcx>,
13941392
) -> Vec<QueryRegionConstraint<'tcx>> {
13951393
debug!(
1396-
"apply_requirements(location={:?}, closure_def_id={:?}, closure_substs={:?})",
1397-
location, closure_def_id, closure_substs
1394+
"apply_requirements(closure_def_id={:?}, closure_substs={:?})",
1395+
closure_def_id, closure_substs
13981396
);
13991397

14001398
// Extract the values of the free regions in `closure_substs`

src/librustc_mir/borrow_check/nll/region_infer/values.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ impl<N: Idx> LivenessValues<N> {
154154
/// Creates a new set of "region values" that tracks causal information.
155155
/// Each of the regions in num_region_variables will be initialized with an
156156
/// empty set of points and no causal information.
157-
crate fn new(elements: &Rc<RegionValueElements>) -> Self {
157+
crate fn new(elements: Rc<RegionValueElements>) -> Self {
158158
Self {
159-
elements: elements.clone(),
160159
points: SparseBitMatrix::new(elements.num_points),
160+
elements: elements,
161161
}
162162
}
163163

src/librustc_mir/borrow_check/nll/renumber.rs

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> {
4747
}
4848

4949
impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
50+
fn visit_mir(&mut self, mir: &mut Mir<'tcx>) {
51+
for promoted in mir.promoted.iter_mut() {
52+
self.visit_mir(promoted);
53+
}
54+
55+
self.super_mir(mir);
56+
}
57+
5058
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
5159
debug!("visit_ty(ty={:?}, ty_context={:?})", ty, ty_context);
5260

0 commit comments

Comments
 (0)