Skip to content

Commit af88f7d

Browse files
committed
Auto merge of rust-lang#120550 - oli-obk:track_errors8, r=estebank
Continue to borrowck even if there were previous errors but only from the perspective of the whole compiler. Individual items should not get borrowcked if their MIR is tainted by errors. r? `@estebank` `@nnethercote`
2 parents 81bef0b + eab2adb commit af88f7d

File tree

214 files changed

+3272
-670
lines changed

Some content is hidden

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

214 files changed

+3272
-670
lines changed

compiler/rustc_borrowck/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,16 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
111111
let (input_body, promoted) = tcx.mir_promoted(def);
112112
debug!("run query mir_borrowck: {}", tcx.def_path_str(def));
113113

114-
if input_body.borrow().should_skip() {
115-
debug!("Skipping borrowck because of injected body");
114+
let input_body: &Body<'_> = &input_body.borrow();
115+
116+
if input_body.should_skip() || input_body.tainted_by_errors.is_some() {
117+
debug!("Skipping borrowck because of injected body or tainted body");
116118
// Let's make up a borrowck result! Fun times!
117119
let result = BorrowCheckResult {
118120
concrete_opaque_types: FxIndexMap::default(),
119121
closure_requirements: None,
120122
used_mut_upvars: SmallVec::new(),
121-
tainted_by_errors: None,
123+
tainted_by_errors: input_body.tainted_by_errors,
122124
};
123125
return tcx.arena.alloc(result);
124126
}
@@ -127,7 +129,6 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
127129

128130
let infcx =
129131
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)).build();
130-
let input_body: &Body<'_> = &input_body.borrow();
131132
let promoted: &IndexSlice<_, _> = &promoted.borrow();
132133
let opt_closure_req = do_mir_borrowck(&infcx, input_body, promoted, None).0;
133134
debug!("mir_borrowck done");

compiler/rustc_hir/src/hir.rs

-4
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ impl Lifetime {
163163
(LifetimeSuggestionPosition::Normal, self.ident.span)
164164
}
165165
}
166-
167-
pub fn is_static(&self) -> bool {
168-
self.res == LifetimeName::Static
169-
}
170166
}
171167

172168
/// A `Path` is essentially Rust's notion of a name; for instance,

compiler/rustc_hir_analysis/src/astconv/mod.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::astconv::errors::prohibit_assoc_ty_binding;
1212
use crate::astconv::generics::{check_generic_arg_count, create_args_for_parent_generic_args};
1313
use crate::bounds::Bounds;
1414
use crate::collect::HirPlaceholderCollector;
15-
use crate::errors::{AmbiguousLifetimeBound, TypeofReservedKeywordUsed};
15+
use crate::errors::AmbiguousLifetimeBound;
1616
use crate::middle::resolve_bound_vars as rbv;
1717
use crate::require_c_abi_if_c_variadic;
1818
use rustc_ast::TraitObjectSyntax;
@@ -30,8 +30,8 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
3030
use rustc_infer::traits::ObligationCause;
3131
use rustc_middle::middle::stability::AllowUnstable;
3232
use rustc_middle::ty::{
33-
self, Const, GenericArgKind, GenericArgsRef, GenericParamDefKind, IsSuggestable, ParamEnv, Ty,
34-
TyCtxt, TypeVisitableExt,
33+
self, Const, GenericArgKind, GenericArgsRef, GenericParamDefKind, ParamEnv, Ty, TyCtxt,
34+
TypeVisitableExt,
3535
};
3636
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
3737
use rustc_span::edit_distance::find_best_match_for_name;
@@ -2539,21 +2539,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
25392539

25402540
Ty::new_array_with_const_len(tcx, self.ast_ty_to_ty(ty), length)
25412541
}
2542-
hir::TyKind::Typeof(e) => {
2543-
let ty_erased = tcx.type_of(e.def_id).instantiate_identity();
2544-
let ty = tcx.fold_regions(ty_erased, |r, _| {
2545-
if r.is_erased() { tcx.lifetimes.re_static } else { r }
2546-
});
2547-
let span = ast_ty.span;
2548-
let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false) {
2549-
(ty, Some((span, Applicability::MachineApplicable)))
2550-
} else {
2551-
(ty, None)
2552-
};
2553-
tcx.dcx().emit_err(TypeofReservedKeywordUsed { span, ty, opt_sugg });
2554-
2555-
ty
2556-
}
2542+
hir::TyKind::Typeof(e) => tcx.type_of(e.def_id).instantiate_identity(),
25572543
hir::TyKind::Infer => {
25582544
// Infer also appears as the type of arguments or return
25592545
// values in an ExprKind::Closure, or as

compiler/rustc_hir_analysis/src/collect/type_of.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use rustc_middle::ty::{self, ImplTraitInTraitData, IsSuggestable, Ty, TyCtxt, Ty
99
use rustc_span::symbol::Ident;
1010
use rustc_span::{Span, DUMMY_SP};
1111

12+
use crate::errors::TypeofReservedKeywordUsed;
13+
1214
use super::bad_placeholder;
1315
use super::ItemCtxt;
1416
pub use opaque::test_opaque_hidden_types;
@@ -39,8 +41,18 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
3941
{
4042
return tcx.types.usize;
4143
}
42-
Node::Ty(&hir::Ty { kind: TyKind::Typeof(ref e), .. }) if e.hir_id == hir_id => {
43-
return tcx.typeck(def_id).node_type(e.hir_id);
44+
Node::Ty(&hir::Ty { kind: TyKind::Typeof(ref e), span, .. }) if e.hir_id == hir_id => {
45+
let ty = tcx.typeck(def_id).node_type(e.hir_id);
46+
let ty = tcx.fold_regions(ty, |r, _| {
47+
if r.is_erased() { ty::Region::new_error_misc(tcx) } else { r }
48+
});
49+
let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false) {
50+
(ty, Some((span, Applicability::MachineApplicable)))
51+
} else {
52+
(ty, None)
53+
};
54+
tcx.dcx().emit_err(TypeofReservedKeywordUsed { span, ty, opt_sugg });
55+
return ty;
4456
}
4557
Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. })
4658
| Node::Item(&Item { kind: ItemKind::GlobalAsm(asm), .. })

compiler/rustc_hir_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
209209

210210
tcx.ensure().check_unused_traits(());
211211

212-
if let Some(reported) = tcx.dcx().has_errors() { Err(reported) } else { Ok(()) }
212+
Ok(())
213213
}
214214

215215
/// A quasi-deprecated helper used in rustdoc and clippy to get

compiler/rustc_mir_build/src/build/mod.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
666666
let yield_ty = args.yield_ty();
667667
let return_ty = args.return_ty();
668668
(
669-
vec![closure_ty, args.resume_ty()],
669+
vec![closure_ty, resume_ty],
670670
return_ty,
671671
Some(Box::new(CoroutineInfo::initial(
672672
tcx.coroutine_kind(def_id).unwrap(),
@@ -675,8 +675,23 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
675675
))),
676676
)
677677
}
678-
_ => {
679-
span_bug!(span, "expected type of closure body to be a closure or coroutine");
678+
ty::CoroutineClosure(did, _args) => {
679+
// FIXME(async_closures): Recover the proper error signature
680+
let inputs = tcx
681+
.closure_user_provided_sig(did.expect_local())
682+
.value
683+
.skip_binder()
684+
.inputs();
685+
686+
let err = Ty::new_error(tcx, guar);
687+
(inputs.iter().map(|_| err).collect(), err, None)
688+
}
689+
ty::Error(_) => (vec![closure_ty, closure_ty], closure_ty, None),
690+
kind => {
691+
span_bug!(
692+
span,
693+
"expected type of closure body to be a closure or coroutine, got {kind:?}"
694+
);
680695
}
681696
}
682697
}

compiler/rustc_mir_build/src/build/scope.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
655655
let drops = if destination.is_some() {
656656
&mut self.scopes.breakable_scopes[break_index].break_drops
657657
} else {
658-
self.scopes.breakable_scopes[break_index].continue_drops.as_mut().unwrap()
658+
let Some(drops) = self.scopes.breakable_scopes[break_index].continue_drops.as_mut()
659+
else {
660+
self.tcx.dcx().span_delayed_bug(
661+
source_info.span,
662+
"unlabelled `continue` within labelled block",
663+
);
664+
self.cfg.terminate(block, source_info, TerminatorKind::Unreachable);
665+
666+
return self.cfg.start_new_block().unit();
667+
};
668+
drops
659669
};
660670

661671
let drop_idx = self.scopes.scopes[scope_index + 1..]

compiler/rustc_mir_transform/src/ffi_unwind_calls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
5959
ty::Closure(..) => Abi::RustCall,
6060
ty::CoroutineClosure(..) => Abi::RustCall,
6161
ty::Coroutine(..) => Abi::Rust,
62+
ty::Error(_) => return false,
6263
_ => span_bug!(body.span, "unexpected body ty: {:?}", body_ty),
6364
};
6465
let body_can_unwind = layout::fn_can_unwind(tcx, Some(def_id), body_abi);

compiler/rustc_parse/src/parser/expr.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -2911,12 +2911,22 @@ impl<'a> Parser<'a> {
29112911
Ok(arm) => arms.push(arm),
29122912
Err(e) => {
29132913
// Recover by skipping to the end of the block.
2914-
e.emit();
2914+
let guar = e.emit();
29152915
self.recover_stmt();
29162916
let span = lo.to(self.token.span);
29172917
if self.token == token::CloseDelim(Delimiter::Brace) {
29182918
self.bump();
29192919
}
2920+
// Always push at least one arm to make the match non-empty
2921+
arms.push(Arm {
2922+
attrs: Default::default(),
2923+
pat: self.mk_pat(span, ast::PatKind::Err(guar)),
2924+
guard: None,
2925+
body: Some(self.mk_expr_err(span)),
2926+
span,
2927+
id: DUMMY_NODE_ID,
2928+
is_placeholder: false,
2929+
});
29202930
return Ok(self.mk_expr_with_attrs(
29212931
span,
29222932
ExprKind::Match(scrutinee, arms),

compiler/rustc_passes/src/liveness.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ enum LiveNodeKind {
123123
VarDefNode(Span, HirId),
124124
ClosureNode,
125125
ExitNode,
126+
ErrNode,
126127
}
127128

128129
fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
@@ -133,6 +134,7 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
133134
VarDefNode(s, _) => format!("Var def node [{}]", sm.span_to_diagnostic_string(s)),
134135
ClosureNode => "Closure node".to_owned(),
135136
ExitNode => "Exit node".to_owned(),
137+
ErrNode => "Error node".to_owned(),
136138
}
137139
}
138140

@@ -967,10 +969,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
967969

968970
// Now that we know the label we're going to,
969971
// look it up in the continue loop nodes table
970-
self.cont_ln
971-
.get(&sc)
972-
.cloned()
973-
.unwrap_or_else(|| span_bug!(expr.span, "continue to unknown label"))
972+
self.cont_ln.get(&sc).cloned().unwrap_or_else(|| {
973+
self.ir.tcx.dcx().span_delayed_bug(expr.span, "continue to unknown label");
974+
self.ir.add_live_node(ErrNode)
975+
})
974976
}
975977

976978
hir::ExprKind::Assign(ref l, ref r, _) => {

src/tools/clippy/clippy_lints/src/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn check_fn_inner<'tcx>(
176176
_ => None,
177177
});
178178
for bound in lifetimes {
179-
if !bound.is_static() && !bound.is_elided() {
179+
if bound.res != LifetimeName::Static && !bound.is_elided() {
180180
return;
181181
}
182182
}

tests/incremental/const-generics/issue-62536.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// revisions:cfail1
2+
3+
#![allow(unused_variables)]
4+
25
struct S<T, const N: usize>([T; N]);
36

47
fn f<T, const N: usize>(x: T) -> S<T, {N}> { panic!() }

tests/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// revisions: cfail
22
#![feature(generic_const_exprs)]
3-
#![allow(incomplete_features, unused_braces)]
3+
#![allow(incomplete_features, unused_braces, unused_variables)]
44

55
trait Delegates<T> {}
66

tests/incremental/struct_change_field_name.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// [cfail2] compile-flags: -Z query-dep-graph -Z assert-incr-state=loaded
77

88
#![feature(rustc_attrs)]
9+
#![allow(unused_variables)]
910

1011
#[cfg(rpass1)]
1112
pub struct X {

tests/rustdoc-ui/issues/issue-102986.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | y: (typeof("hey"),),
66
|
77
help: consider replacing `typeof(...)` with an actual type
88
|
9-
LL | y: (&'static str,),
10-
| ~~~~~~~~~~~~
9+
LL | y: (&str,),
10+
| ~~~~
1111

1212
error: aborting due to 1 previous error
1313

0 commit comments

Comments
 (0)