diff options
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_const_eval/src/transform/check_consts/check.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/lib.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 26 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/lib.rs | 2 |
4 files changed, 12 insertions, 29 deletions
diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index a3c4734f0a3..26ef083219f 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -249,7 +249,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { let secondary_errors = mem::take(&mut self.secondary_errors); if self.error_emitted.is_none() { for error in secondary_errors { - error.emit(); + self.error_emitted = Some(error.emit()); } } else { assert!(self.tcx.dcx().has_errors().is_some()); diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index e53f922ad10..7cb103626da 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -198,6 +198,17 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { collect::test_opaque_hidden_types(tcx)?; } + // Make sure we evaluate all static and (non-associated) const items, even if unused. + // If any of these fail to evaluate, we do not want this crate to pass compilation. + tcx.hir().par_body_owners(|item_def_id| { + let def_kind = tcx.def_kind(item_def_id); + match def_kind { + DefKind::Static(_) => tcx.ensure().eval_static_initializer(item_def_id), + DefKind::Const => tcx.ensure().const_eval_poly(item_def_id.into()), + _ => (), + } + }); + // Freeze definitions as we don't add new ones at this point. This improves performance by // allowing lock-free access to them. tcx.untracked().definitions.freeze(); diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index faa35f51cd4..f9149f54e92 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1542,32 +1542,6 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds { } } -declare_lint_pass!( - /// Lint constants that are erroneous. - /// Without this lint, we might not get any diagnostic if the constant is - /// unused within this crate, even though downstream crates can't use it - /// without producing an error. - UnusedBrokenConst => [] -); - -impl<'tcx> LateLintPass<'tcx> for UnusedBrokenConst { - fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) { - match it.kind { - hir::ItemKind::Const(_, _, body_id) => { - let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id(); - // trigger the query once for all constants since that will already report the errors - // FIXME(generic_const_items): Does this work properly with generic const items? - cx.tcx.ensure().const_eval_poly(def_id); - } - hir::ItemKind::Static(_, _, body_id) => { - let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id(); - cx.tcx.ensure().eval_static_initializer(def_id); - } - _ => {} - } - } -} - declare_lint! { /// The `trivial_bounds` lint detects trait bounds that don't depend on /// any type parameters. diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index e50f4ca338b..bc5038a5b14 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -213,8 +213,6 @@ late_lint_methods!( ExplicitOutlivesRequirements: ExplicitOutlivesRequirements, InvalidValue: InvalidValue, DerefNullPtr: DerefNullPtr, - // May Depend on constants elsewhere - UnusedBrokenConst: UnusedBrokenConst, UnstableFeatures: UnstableFeatures, UngatedAsyncFnTrackCaller: UngatedAsyncFnTrackCaller, ArrayIntoIter: ArrayIntoIter::default(), |
