Skip to content

Commit 5ac0b2d

Browse files
committed
Auto merge of rust-lang#122347 - oli-obk:track_errors13, r=compiler-errors
Revert "Auto merge of rust-lang#122140 - oli-obk:track_errors13, r=davidtwco" This reverts commit 65cd843, reversing changes made to d255c6a. reverts rust-lang#122140 It was a large regression in wall time due to trashing CPU caches
2 parents c7fed9f + 96d24f2 commit 5ac0b2d

33 files changed

+443
-419
lines changed

compiler/rustc_driver_impl/src/pretty.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
336336
ThirTree => {
337337
let tcx = ex.tcx();
338338
let mut out = String::new();
339-
rustc_hir_analysis::check_crate(tcx);
340-
if tcx.dcx().has_errors().is_some() {
339+
if rustc_hir_analysis::check_crate(tcx).is_err() {
341340
FatalError.raise();
342341
}
343342
debug!("pretty printing THIR tree");
@@ -349,8 +348,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
349348
ThirFlat => {
350349
let tcx = ex.tcx();
351350
let mut out = String::new();
352-
rustc_hir_analysis::check_crate(tcx);
353-
if tcx.dcx().has_errors().is_some() {
351+
if rustc_hir_analysis::check_crate(tcx).is_err() {
354352
FatalError.raise();
355353
}
356354
debug!("pretty printing THIR flat");

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@ use rustc_hir::intravisit::{self, Visitor};
55
use rustc_hir::{self as hir, def, Expr, ImplItem, Item, Node, TraitItem};
66
use rustc_middle::hir::nested_filter;
77
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
8-
use rustc_span::{sym, DUMMY_SP};
8+
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
99

1010
use crate::errors::{TaitForwardCompat, TypeOf, UnconstrainedOpaqueType};
1111

12-
pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) {
12+
pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
13+
let mut res = Ok(());
1314
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
1415
for id in tcx.hir().items() {
1516
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
1617
let type_of = tcx.type_of(id.owner_id).instantiate_identity();
1718

18-
tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of });
19+
res = Err(tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of }));
1920
}
2021
}
2122
}
23+
res
2224
}
2325

2426
/// Checks "defining uses" of opaque `impl Trait` in associated types.

compiler/rustc_hir_analysis/src/lib.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ mod outlives;
9898
pub mod structured_errors;
9999
mod variance;
100100

101+
use rustc_errors::ErrorGuaranteed;
101102
use rustc_hir as hir;
102103
use rustc_middle::middle;
103104
use rustc_middle::query::Providers;
@@ -155,13 +156,11 @@ pub fn provide(providers: &mut Providers) {
155156
hir_wf_check::provide(providers);
156157
}
157158

158-
pub fn check_crate(tcx: TyCtxt<'_>) {
159+
pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
159160
let _prof_timer = tcx.sess.timer("type_check_crate");
160161

161162
if tcx.features().rustc_attrs {
162-
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx));
163-
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx));
164-
collect::test_opaque_hidden_types(tcx);
163+
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx))?;
165164
}
166165

167166
tcx.sess.time("coherence_checking", || {
@@ -177,6 +176,14 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
177176
let _ = tcx.ensure().crate_inherent_impls_overlap_check(());
178177
});
179178

179+
if tcx.features().rustc_attrs {
180+
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx))?;
181+
}
182+
183+
if tcx.features().rustc_attrs {
184+
collect::test_opaque_hidden_types(tcx)?;
185+
}
186+
180187
// Make sure we evaluate all static and (non-associated) const items, even if unused.
181188
// If any of these fail to evaluate, we do not want this crate to pass compilation.
182189
tcx.hir().par_body_owners(|item_def_id| {
@@ -191,6 +198,21 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
191198
// Freeze definitions as we don't add new ones at this point. This improves performance by
192199
// allowing lock-free access to them.
193200
tcx.untracked().definitions.freeze();
201+
202+
// FIXME: Remove this when we implement creating `DefId`s
203+
// for anon constants during their parents' typeck.
204+
// Typeck all body owners in parallel will produce queries
205+
// cycle errors because it may typeck on anon constants directly.
206+
tcx.hir().par_body_owners(|item_def_id| {
207+
let def_kind = tcx.def_kind(item_def_id);
208+
if !matches!(def_kind, DefKind::AnonConst) {
209+
tcx.ensure().typeck(item_def_id);
210+
}
211+
});
212+
213+
tcx.ensure().check_unused_traits(());
214+
215+
Ok(())
194216
}
195217

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

compiler/rustc_hir_analysis/src/outlives/test.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use rustc_middle::ty::{self, TyCtxt};
2-
use rustc_span::symbol::sym;
2+
use rustc_span::{symbol::sym, ErrorGuaranteed};
33

4-
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
4+
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
5+
let mut res = Ok(());
56
for id in tcx.hir().items() {
67
// For unit testing: check for a special "rustc_outlives"
78
// attribute and report an error with various results if found.
@@ -22,7 +23,8 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
2223
for p in pred {
2324
err.note(p);
2425
}
25-
err.emit();
26+
res = Err(err.emit());
2627
}
2728
}
29+
res
2830
}

compiler/rustc_hir_analysis/src/variance/test.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ use rustc_hir::def::DefKind;
22
use rustc_hir::def_id::CRATE_DEF_ID;
33
use rustc_middle::ty::TyCtxt;
44
use rustc_span::symbol::sym;
5+
use rustc_span::ErrorGuaranteed;
56

67
use crate::errors;
78

8-
pub fn test_variance(tcx: TyCtxt<'_>) {
9+
pub fn test_variance(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
10+
let mut res = Ok(());
911
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) {
1012
for id in tcx.hir().items() {
1113
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
1214
let variances_of = tcx.variances_of(id.owner_id);
1315

14-
tcx.dcx().emit_err(errors::VariancesOf {
16+
res = Err(tcx.dcx().emit_err(errors::VariancesOf {
1517
span: tcx.def_span(id.owner_id),
1618
variances_of: format!("{variances_of:?}"),
17-
});
19+
}));
1820
}
1921
}
2022
}
@@ -25,10 +27,11 @@ pub fn test_variance(tcx: TyCtxt<'_>) {
2527
if tcx.has_attr(id.owner_id, sym::rustc_variance) {
2628
let variances_of = tcx.variances_of(id.owner_id);
2729

28-
tcx.dcx().emit_err(errors::VariancesOf {
30+
res = Err(tcx.dcx().emit_err(errors::VariancesOf {
2931
span: tcx.def_span(id.owner_id),
3032
variances_of: format!("{variances_of:?}"),
31-
});
33+
}));
3234
}
3335
}
36+
res
3437
}

compiler/rustc_interface/src/passes.rs

+15-18
Original file line numberDiff line numberDiff line change
@@ -734,22 +734,19 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
734734
});
735735

736736
// passes are timed inside typeck
737-
rustc_hir_analysis::check_crate(tcx);
737+
rustc_hir_analysis::check_crate(tcx)?;
738738

739-
sess.time("typeck_and_mir_analyses", || {
739+
sess.time("MIR_borrow_checking", || {
740740
tcx.hir().par_body_owners(|def_id| {
741-
let def_kind = tcx.def_kind(def_id);
742-
// FIXME: Remove this when we implement creating `DefId`s
743-
// for anon constants during their parents' typeck.
744-
// Typeck all body owners in parallel will produce queries
745-
// cycle errors because it may typeck on anon constants directly.
746-
if !matches!(def_kind, rustc_hir::def::DefKind::AnonConst) {
747-
tcx.ensure().typeck(def_id);
748-
}
749741
// Run unsafety check because it's responsible for stealing and
750742
// deallocating THIR.
751743
tcx.ensure().check_unsafety(def_id);
752-
tcx.ensure().mir_borrowck(def_id);
744+
tcx.ensure().mir_borrowck(def_id)
745+
});
746+
});
747+
748+
sess.time("MIR_effect_checking", || {
749+
for def_id in tcx.hir().body_owners() {
753750
if !tcx.sess.opts.unstable_opts.thir_unsafeck {
754751
rustc_mir_transform::check_unsafety::check_unsafety(tcx, def_id);
755752
}
@@ -764,15 +761,15 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
764761
tcx.ensure().mir_drops_elaborated_and_const_checked(def_id);
765762
tcx.ensure().unused_generic_params(ty::InstanceDef::Item(def_id.to_def_id()));
766763
}
767-
768-
if tcx.is_coroutine(def_id.to_def_id()) {
769-
tcx.ensure().mir_coroutine_witnesses(def_id);
770-
tcx.ensure().check_coroutine_obligations(def_id);
771-
}
772-
})
764+
}
773765
});
774766

775-
tcx.ensure().check_unused_traits(());
767+
tcx.hir().par_body_owners(|def_id| {
768+
if tcx.is_coroutine(def_id.to_def_id()) {
769+
tcx.ensure().mir_coroutine_witnesses(def_id);
770+
tcx.ensure().check_coroutine_obligations(def_id);
771+
}
772+
});
776773

777774
sess.time("layout_testing", || layout_test::test_layout(tcx));
778775
sess.time("abi_testing", || abi_test::test_abi(tcx));

tests/ui/binop/issue-77910-1.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
error[E0381]: used binding `xs` isn't initialized
2-
--> $DIR/issue-77910-1.rs:3:5
3-
|
4-
LL | let xs;
5-
| -- binding declared here but left uninitialized
6-
LL | xs
7-
| ^^ `xs` used here but it isn't initialized
8-
|
9-
help: consider assigning a value
10-
|
11-
LL | let xs = todo!();
12-
| +++++++++
13-
141
error[E0369]: binary operation `==` cannot be applied to type `for<'a> fn(&'a i32) -> &'a i32 {foo}`
152
--> $DIR/issue-77910-1.rs:8:5
163
|
@@ -35,6 +22,19 @@ LL | assert_eq!(foo, y);
3522
= help: use parentheses to call this function: `foo(/* &i32 */)`
3623
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
3724

25+
error[E0381]: used binding `xs` isn't initialized
26+
--> $DIR/issue-77910-1.rs:3:5
27+
|
28+
LL | let xs;
29+
| -- binding declared here but left uninitialized
30+
LL | xs
31+
| ^^ `xs` used here but it isn't initialized
32+
|
33+
help: consider assigning a value
34+
|
35+
LL | let xs = todo!();
36+
| +++++++++
37+
3838
error: aborting due to 3 previous errors
3939

4040
Some errors have detailed explanations: E0277, E0369, E0381.

tests/ui/binop/issue-77910-2.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
error[E0381]: used binding `xs` isn't initialized
2-
--> $DIR/issue-77910-2.rs:3:5
3-
|
4-
LL | let xs;
5-
| -- binding declared here but left uninitialized
6-
LL | xs
7-
| ^^ `xs` used here but it isn't initialized
8-
|
9-
help: consider assigning a value
10-
|
11-
LL | let xs = todo!();
12-
| +++++++++
13-
141
error[E0369]: binary operation `==` cannot be applied to type `for<'a> fn(&'a i32) -> &'a i32 {foo}`
152
--> $DIR/issue-77910-2.rs:7:12
163
|
@@ -24,6 +11,19 @@ help: use parentheses to call this function
2411
LL | if foo(/* &i32 */) == y {}
2512
| ++++++++++++
2613

14+
error[E0381]: used binding `xs` isn't initialized
15+
--> $DIR/issue-77910-2.rs:3:5
16+
|
17+
LL | let xs;
18+
| -- binding declared here but left uninitialized
19+
LL | xs
20+
| ^^ `xs` used here but it isn't initialized
21+
|
22+
help: consider assigning a value
23+
|
24+
LL | let xs = todo!();
25+
| +++++++++
26+
2727
error: aborting due to 2 previous errors
2828

2929
Some errors have detailed explanations: E0369, E0381.

tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr

+23-23
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ help: use `addr_of_mut!` instead to create a raw pointer
1313
LL | c1(addr_of_mut!(Y));
1414
| ~~~~~~~~~~~~~~~
1515

16-
error[E0594]: cannot assign to `x`, as it is not declared as mutable
17-
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:9:46
18-
|
19-
LL | pub fn e(x: &'static mut isize) {
20-
| - help: consider changing this to be mutable: `mut x`
21-
LL | static mut Y: isize = 3;
22-
LL | let mut c1 = |y: &'static mut isize| x = y;
23-
| ^^^^^ cannot assign
24-
2516
warning: creating a mutable reference to mutable static is discouraged
2617
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:27:16
2718
|
@@ -36,6 +27,29 @@ help: use `addr_of_mut!` instead to create a raw pointer
3627
LL | c1(addr_of_mut!(Z));
3728
| ~~~~~~~~~~~~~~~
3829

30+
warning: creating a mutable reference to mutable static is discouraged
31+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:64:37
32+
|
33+
LL | borrowck_closures_unique::e(&mut X);
34+
| ^^^^^^ mutable reference to mutable static
35+
|
36+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
37+
= note: this will be a hard error in the 2024 edition
38+
= note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
39+
help: use `addr_of_mut!` instead to create a raw pointer
40+
|
41+
LL | borrowck_closures_unique::e(addr_of_mut!(X));
42+
| ~~~~~~~~~~~~~~~
43+
44+
error[E0594]: cannot assign to `x`, as it is not declared as mutable
45+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:9:46
46+
|
47+
LL | pub fn e(x: &'static mut isize) {
48+
| - help: consider changing this to be mutable: `mut x`
49+
LL | static mut Y: isize = 3;
50+
LL | let mut c1 = |y: &'static mut isize| x = y;
51+
| ^^^^^ cannot assign
52+
3953
error[E0594]: cannot assign to `x`, as it is not declared as mutable
4054
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:22:50
4155
|
@@ -81,20 +95,6 @@ LL | || {
8195
LL | &mut x.0;
8296
| ^^^^^^^^ cannot borrow as mutable
8397

84-
warning: creating a mutable reference to mutable static is discouraged
85-
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:64:37
86-
|
87-
LL | borrowck_closures_unique::e(&mut X);
88-
| ^^^^^^ mutable reference to mutable static
89-
|
90-
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
91-
= note: this will be a hard error in the 2024 edition
92-
= note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
93-
help: use `addr_of_mut!` instead to create a raw pointer
94-
|
95-
LL | borrowck_closures_unique::e(addr_of_mut!(X));
96-
| ~~~~~~~~~~~~~~~
97-
9898
error: aborting due to 6 previous errors; 3 warnings emitted
9999

100100
Some errors have detailed explanations: E0594, E0596.

tests/ui/const-generics/generic_const_exprs/type_mismatch.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ LL | impl<const N: u64> Q for [u8; N] {}
2121
| |
2222
| unsatisfied trait bound introduced here
2323

24-
error[E0308]: mismatched types
25-
--> $DIR/type_mismatch.rs:8:31
26-
|
27-
LL | impl<const N: u64> Q for [u8; N] {}
28-
| ^ expected `usize`, found `u64`
29-
3024
error[E0308]: mismatched types
3125
--> $DIR/type_mismatch.rs:12:20
3226
|
@@ -35,6 +29,12 @@ LL | pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {}
3529
| |
3630
| implicitly returns `()` as its body has no tail or `return` expression
3731

32+
error[E0308]: mismatched types
33+
--> $DIR/type_mismatch.rs:8:31
34+
|
35+
LL | impl<const N: u64> Q for [u8; N] {}
36+
| ^ expected `usize`, found `u64`
37+
3838
error: aborting due to 4 previous errors
3939

4040
Some errors have detailed explanations: E0046, E0308.

0 commit comments

Comments
 (0)