Skip to content

Commit 749af61

Browse files
authored
Rollup merge of #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 a66a9f6 + 0f3976b commit 749af61

File tree

214 files changed

+3235
-664
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

+3235
-664
lines changed

compiler/rustc_borrowck/src/lib.rs

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

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

127129
let infcx =
128130
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)).build();
129-
let input_body: &Body<'_> = &input_body.borrow();
130131
let promoted: &IndexSlice<_, _> = &promoted.borrow();
131132
let opt_closure_req = do_mir_borrowck(&infcx, input_body, promoted, None).0;
132133
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;
@@ -2537,21 +2537,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
25372537

25382538
Ty::new_array_with_const_len(tcx, self.ast_ty_to_ty(ty), length)
25392539
}
2540-
hir::TyKind::Typeof(e) => {
2541-
let ty_erased = tcx.type_of(e.def_id).instantiate_identity();
2542-
let ty = tcx.fold_regions(ty_erased, |r, _| {
2543-
if r.is_erased() { tcx.lifetimes.re_static } else { r }
2544-
});
2545-
let span = ast_ty.span;
2546-
let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false) {
2547-
(ty, Some((span, Applicability::MachineApplicable)))
2548-
} else {
2549-
(ty, None)
2550-
};
2551-
tcx.dcx().emit_err(TypeofReservedKeywordUsed { span, ty, opt_sugg });
2552-
2553-
ty
2554-
}
2540+
hir::TyKind::Typeof(e) => tcx.type_of(e.def_id).instantiate_identity(),
25552541
hir::TyKind::Infer => {
25562542
// Infer also appears as the type of arguments or return
25572543
// 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

+6-2
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,12 @@ 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::Error(_) => (vec![closure_ty, closure_ty], closure_ty, None),
679+
kind => {
680+
span_bug!(
681+
span,
682+
"expected type of closure body to be a closure or coroutine, got {kind:?}"
683+
);
680684
}
681685
}
682686
}

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
@@ -58,6 +58,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
5858
ty::FnDef(..) => body_ty.fn_sig(tcx).abi(),
5959
ty::Closure(..) => Abi::RustCall,
6060
ty::Coroutine(..) => Abi::Rust,
61+
ty::Error(_) => return false,
6162
_ => span_bug!(body.span, "unexpected body ty: {:?}", body_ty),
6263
};
6364
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

@@ -962,10 +964,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
962964

963965
// Now that we know the label we're going to,
964966
// look it up in the continue loop nodes table
965-
self.cont_ln
966-
.get(&sc)
967-
.cloned()
968-
.unwrap_or_else(|| span_bug!(expr.span, "continue to unknown label"))
967+
self.cont_ln.get(&sc).cloned().unwrap_or_else(|| {
968+
self.ir.tcx.dcx().span_delayed_bug(expr.span, "continue to unknown label");
969+
self.ir.add_live_node(ErrNode)
970+
})
969971
}
970972

971973
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)