Skip to content

Commit fc42fb8

Browse files
committed
Auto merge of #77354 - ecstatic-morse:const-checking-moar-errors, r=oli-obk
Overhaul const-checking diagnostics The primary purpose of this PR was to remove `NonConstOp::STOPS_CONST_CHECKING`, which causes any additional errors found by the const-checker to be silenced. I used this flag to preserve diagnostic parity with `qualify_min_const_fn.rs`, which has since been removed. However, simply removing the flag caused a deluge of errors in some cases, since an error would be emitted any time a local or temporary had a wrong type. To remedy this, I added an alternative system (`DiagnosticImportance`) to silence additional error messages that were likely to distract the user from the underlying issue. When an error of the highest importance occurs, all less important errors are silenced. When no error of the highest importance occurs, all less important errors are emitted after checking is complete. Following the suggestions from the important error is usually enough to fix the less important errors, so this should lead to better UX most of the time. There's also some unrelated diagnostics improvements in this PR isolated in their own commits. Splitting them out would be possible, but a bit of a pain. This isn't as tidy as some of my other PRs, but it should *only* affect diagnostics, never whether or not something passes const-checking. Note that there are a few trivial exceptions to this, like banning `Yield` in all const-contexts, not just `const fn`. As always, meant to be reviewed commit-by-commit. r? `@oli-obk`
2 parents 00730fd + 1301f43 commit fc42fb8

File tree

58 files changed

+589
-602
lines changed

Some content is hidden

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

58 files changed

+589
-602
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ E0010: include_str!("./error_codes/E0010.md"),
1818
E0013: include_str!("./error_codes/E0013.md"),
1919
E0014: include_str!("./error_codes/E0014.md"),
2020
E0015: include_str!("./error_codes/E0015.md"),
21-
E0019: include_str!("./error_codes/E0019.md"),
2221
E0023: include_str!("./error_codes/E0023.md"),
2322
E0025: include_str!("./error_codes/E0025.md"),
2423
E0026: include_str!("./error_codes/E0026.md"),
@@ -463,6 +462,7 @@ E0776: include_str!("./error_codes/E0776.md"),
463462
;
464463
// E0006, // merged with E0005
465464
// E0008, // cannot bind by-move into a pattern guard
465+
// E0019, merged into E0015
466466
// E0035, merged into E0087/E0089
467467
// E0036, merged into E0087/E0089
468468
// E0068,

compiler/rustc_error_codes/src/error_codes/E0019.md

-36
This file was deleted.

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ impl Atom for Local {
670670
}
671671

672672
/// Classifies locals into categories. See `Body::local_kind`.
673-
#[derive(PartialEq, Eq, Debug, HashStable)]
673+
#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable)]
674674
pub enum LocalKind {
675675
/// User-declared variable binding.
676676
Var,

compiler/rustc_mir/src/transform/check_consts/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ impl ConstCx<'mir, 'tcx> {
5757
&& self.tcx.features().staged_api
5858
&& is_const_stable_const_fn(self.tcx, self.def_id.to_def_id())
5959
}
60+
61+
/// Returns the function signature of the item being const-checked if it is a `fn` or `const fn`.
62+
pub fn fn_sig(&self) -> Option<&'tcx hir::FnSig<'tcx>> {
63+
// Get this from the HIR map instead of a query to avoid cycle errors.
64+
//
65+
// FIXME: Is this still an issue?
66+
let hir_map = self.tcx.hir();
67+
let hir_id = hir_map.local_def_id_to_hir_id(self.def_id);
68+
hir_map.fn_sig_by_hir_id(hir_id)
69+
}
6070
}
6171

6272
/// Returns `true` if this `DefId` points to one of the official `panic` lang items.

0 commit comments

Comments
 (0)