Skip to content

Commit 7c3c88f

Browse files
committed
Auto merge of rust-lang#156576 - GuillaumeGomez:rollup-3CJ0vjd, r=GuillaumeGomez
Rollup of 3 pull requests Successful merges: - rust-lang#146220 (feat(rustdoc): stabilize `--emit` flag) - rust-lang#153785 (Hand-written Debug implementation for `TypeTest`) - rust-lang#156564 (Lint level cleanups)
2 parents 480d852 + 1f5737c commit 7c3c88f

39 files changed

Lines changed: 396 additions & 315 deletions

File tree

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::VecDeque;
2+
use std::fmt;
23
use std::rc::Rc;
34

45
use rustc_data_structures::frozen::Frozen;
@@ -182,7 +183,7 @@ pub(crate) enum Cause {
182183
/// For more information about this translation, see
183184
/// `InferCtxt::process_registered_region_obligations` and
184185
/// `InferCtxt::type_must_outlive` in `rustc_infer::infer::InferCtxt`.
185-
#[derive(Clone, Debug)]
186+
#[derive(Clone)]
186187
pub(crate) struct TypeTest<'tcx> {
187188
/// The type `T` that must outlive the region.
188189
pub generic_kind: GenericKind<'tcx>,
@@ -198,6 +199,47 @@ pub(crate) struct TypeTest<'tcx> {
198199
pub verify_bound: VerifyBound<'tcx>,
199200
}
200201

202+
impl fmt::Debug for TypeTest<'_> {
203+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
204+
fn fmt_bound(
205+
f: &mut fmt::Formatter<'_>,
206+
generic_kind: GenericKind<'_>,
207+
lower: RegionVid,
208+
bound: &VerifyBound<'_>,
209+
) -> fmt::Result {
210+
let fmt_bounds =
211+
|f: &mut fmt::Formatter<'_>, bounds: &[VerifyBound<'_>]| -> fmt::Result {
212+
let mut it = bounds.iter().peekable();
213+
while let Some(bound) = it.next() {
214+
fmt_bound(f, generic_kind, lower, bound)?;
215+
if it.peek().is_some() {
216+
write!(f, ", ")?
217+
}
218+
}
219+
Ok(())
220+
};
221+
match bound {
222+
VerifyBound::IfEq(binder) => write!(f, "{:?} == {:?}", generic_kind, binder),
223+
VerifyBound::OutlivedBy(region) => write!(f, "{region:?}: {lower:?}"),
224+
VerifyBound::AnyBound(verify_bounds) => {
225+
write!(f, "Any[")?;
226+
fmt_bounds(f, verify_bounds)?;
227+
write!(f, "]")
228+
}
229+
VerifyBound::AllBounds(verify_bounds) => {
230+
write!(f, "All[")?;
231+
fmt_bounds(f, verify_bounds)?;
232+
write!(f, "]")
233+
}
234+
VerifyBound::IsEmpty => write!(f, "Empty({lower:?})"),
235+
}
236+
}
237+
write!(f, "TypeTest from {:?}[", self.span)?;
238+
fmt_bound(f, self.generic_kind, self.lower_bound, &self.verify_bound)?;
239+
write!(f, "] ⊢ {:?}: {:?}", self.generic_kind, self.lower_bound)
240+
}
241+
}
242+
201243
/// When we have an unmet lifetime constraint, we try to propagate it outward (e.g. to a closure
202244
/// environment). If we can't, it is an error.
203245
#[derive(Clone, Copy, Debug, Eq, PartialEq)]

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use super::metadata::{MetadataPosition, create_wrapper_file};
6060
use super::rpath::{self, RPathConfig};
6161
use super::{apple, rmeta_link, versioned_llvm_target};
6262
use crate::base::needs_allocator_shim_for_linking;
63-
use crate::{CodegenLintLevels, CompiledModule, CompiledModules, CrateInfo, NativeLib, errors};
63+
use crate::{CodegenLintLevelSpecs, CompiledModule, CompiledModules, CrateInfo, NativeLib, errors};
6464

6565
pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
6666
if let Err(e) = fs::remove_file(path) {
@@ -728,7 +728,12 @@ fn is_windows_gnu_clang(sess: &Session) -> bool {
728728
&& sess.target.options.cfg_abi == CfgAbi::Llvm
729729
}
730730

731-
fn report_linker_output(sess: &Session, levels: CodegenLintLevels, stdout: &[u8], stderr: &[u8]) {
731+
fn report_linker_output(
732+
sess: &Session,
733+
levels: CodegenLintLevelSpecs,
734+
stdout: &[u8],
735+
stderr: &[u8],
736+
) {
732737
let mut escaped_stderr = escape_string(&stderr);
733738
let mut escaped_stdout = escape_string(&stdout);
734739
let mut linker_info = String::new();
@@ -1106,7 +1111,7 @@ fn link_natively(
11061111
}
11071112

11081113
info!("reporting linker output: flavor={flavor:?}");
1109-
report_linker_output(sess, crate_info.lint_levels, &prog.stdout, &prog.stderr);
1114+
report_linker_output(sess, crate_info.lint_level_specs, &prog.stdout, &prog.stderr);
11101115
}
11111116
Err(e) => {
11121117
let linker_not_found = e.kind() == io::ErrorKind::NotFound;

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ use crate::meth::load_vtable;
4949
use crate::mir::operand::OperandValue;
5050
use crate::mir::place::PlaceRef;
5151
use crate::traits::*;
52-
use crate::{CachedModuleCodegen, CodegenLintLevels, CrateInfo, ModuleCodegen, errors, meth, mir};
52+
use crate::{
53+
CachedModuleCodegen, CodegenLintLevelSpecs, CrateInfo, ModuleCodegen, errors, meth, mir,
54+
};
5355

5456
pub(crate) fn bin_op_to_icmp_predicate(op: BinOp, signed: bool) -> IntPredicate {
5557
match (op, signed) {
@@ -953,7 +955,7 @@ impl CrateInfo {
953955
dependency_formats: Arc::clone(tcx.dependency_formats(())),
954956
windows_subsystem,
955957
natvis_debugger_visualizers: Default::default(),
956-
lint_levels: CodegenLintLevels::from_tcx(tcx),
958+
lint_level_specs: CodegenLintLevelSpecs::from_tcx(tcx),
957959
metadata_symbol: exported_symbols::metadata_symbol_name(tcx),
958960
each_linked_rlib_file_for_lto: Default::default(),
959961
exported_symbols_for_lto: Default::default(),

compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_lint_defs::builtin::LINKER_INFO;
2626
use rustc_macros::{Decodable, Encodable};
2727
use rustc_metadata::EncodedMetadata;
2828
use rustc_middle::dep_graph::WorkProduct;
29-
use rustc_middle::lint::LevelAndSource;
29+
use rustc_middle::lint::LevelSpec;
3030
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
3131
use rustc_middle::middle::dependency_format::Dependencies;
3232
use rustc_middle::middle::exported_symbols::SymbolExportKind;
@@ -223,7 +223,7 @@ pub struct CrateInfo {
223223
pub dependency_formats: Arc<Dependencies>,
224224
pub windows_subsystem: Option<WindowsSubsystemKind>,
225225
pub natvis_debugger_visualizers: BTreeSet<DebuggerVisualizerFile>,
226-
pub lint_levels: CodegenLintLevels,
226+
pub lint_level_specs: CodegenLintLevelSpecs,
227227
pub metadata_symbol: String,
228228
pub each_linked_rlib_file_for_lto: Vec<PathBuf>,
229229
pub exported_symbols_for_lto: Vec<String>,
@@ -341,16 +341,16 @@ impl CompiledModules {
341341
/// solely from the `.rlink` file. `Lint`s are defined too early to be encodeable.
342342
/// Instead, encode exactly the information we need.
343343
#[derive(Copy, Clone, Debug, Encodable, Decodable)]
344-
pub struct CodegenLintLevels {
345-
linker_messages: LevelAndSource,
346-
linker_info: LevelAndSource,
344+
pub struct CodegenLintLevelSpecs {
345+
linker_messages: LevelSpec,
346+
linker_info: LevelSpec,
347347
}
348348

349-
impl CodegenLintLevels {
349+
impl CodegenLintLevelSpecs {
350350
pub fn from_tcx(tcx: TyCtxt<'_>) -> Self {
351351
Self {
352-
linker_messages: tcx.lint_level_at_node(LINKER_MESSAGES, CRATE_HIR_ID),
353-
linker_info: tcx.lint_level_at_node(LINKER_INFO, CRATE_HIR_ID),
352+
linker_messages: tcx.lint_level_spec_at_node(LINKER_MESSAGES, CRATE_HIR_ID),
353+
linker_info: tcx.lint_level_spec_at_node(LINKER_INFO, CRATE_HIR_ID),
354354
}
355355
}
356356
}

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,11 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
735735
let hir_id = ecx.machine.best_lint_scope(*ecx.tcx);
736736
let is_error = ecx
737737
.tcx
738-
.lint_level_at_node(
738+
.lint_level_spec_at_node(
739739
rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
740740
hir_id,
741741
)
742-
.level
742+
.level()
743743
.is_error();
744744
let span = ecx.cur_span();
745745
ecx.tcx.emit_node_span_lint(

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ fn print_crate_info(
714714
let lint_store = crate::unerased_lint_store(sess);
715715
let features = rustc_expand::config::features(sess, attrs, crate_name);
716716
let registered_tools = rustc_resolve::registered_tools_ast(sess.dcx(), attrs, sess);
717-
let lint_levels = rustc_lint::LintLevelsBuilder::crate_root(
717+
let builder = rustc_lint::LintLevelsBuilder::crate_root(
718718
sess,
719719
&features,
720720
true,
@@ -729,7 +729,7 @@ fn print_crate_info(
729729
// lint is unstable and feature gate isn't active, don't print
730730
continue;
731731
}
732-
let level = lint_levels.lint_level(lint).level;
732+
let level = builder.lint_level_spec(lint).level();
733733
println_info!("{}={}", lint.name_lower(), level.as_str());
734734
}
735735
}

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,11 +2415,8 @@ fn should_do_rust_2021_incompatible_closure_captures_analysis(
24152415
return false;
24162416
}
24172417

2418-
let level = tcx
2419-
.lint_level_at_node(lint::builtin::RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES, closure_id)
2420-
.level;
2421-
2422-
!matches!(level, lint::Level::Allow)
2418+
!tcx.lint_level_spec_at_node(lint::builtin::RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES, closure_id)
2419+
.is_allow()
24232420
}
24242421

24252422
/// Return a two string tuple (s1, s2)

compiler/rustc_lint/src/builtin.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
3030
use rustc_hir::intravisit::FnKind as HirFnKind;
3131
use rustc_hir::{self as hir, Body, FnDecl, ImplItemImplKind, PatKind, PredicateOrigin, find_attr};
3232
use rustc_middle::bug;
33-
use rustc_middle::lint::LevelAndSource;
3433
use rustc_middle::ty::layout::LayoutOf;
3534
use rustc_middle::ty::print::with_no_trimmed_paths;
3635
use rustc_middle::ty::{
@@ -61,7 +60,8 @@ use crate::lints::{
6160
BuiltinUnreachablePub, BuiltinUnsafe, BuiltinUnstableFeatures, BuiltinUnusedDocComment,
6261
BuiltinUnusedDocCommentSub, BuiltinWhileTrue, EqInternalMethodImplemented, InvalidAsmLabel,
6362
};
64-
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext};
63+
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
64+
6565
declare_lint! {
6666
/// The `while_true` lint detects `while true { }`.
6767
///
@@ -695,9 +695,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
695695
}
696696

697697
// Avoid listing trait impls if the trait is allowed.
698-
let LevelAndSource { level, .. } =
699-
cx.tcx.lint_level_at_node(MISSING_DEBUG_IMPLEMENTATIONS, item.hir_id());
700-
if level == Level::Allow {
698+
if cx.tcx.lint_level_spec_at_node(MISSING_DEBUG_IMPLEMENTATIONS, item.hir_id()).is_allow() {
701699
return;
702700
}
703701

compiler/rustc_lint/src/context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_hir::def_id::{CrateNum, DefId};
2020
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
2121
use rustc_hir::{Pat, PatKind};
2222
use rustc_middle::bug;
23-
use rustc_middle::lint::LevelAndSource;
23+
use rustc_middle::lint::LevelSpec;
2424
use rustc_middle::middle::privacy::EffectiveVisibilities;
2525
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
2626
use rustc_middle::ty::print::{PrintError, PrintTraitRefExt as _, Printer, with_no_trimmed_paths};
@@ -537,8 +537,8 @@ pub trait LintContext {
537537
self.opt_span_lint(lint, Some(span), decorator);
538538
}
539539

540-
/// This returns the lint level for the given lint at the current location.
541-
fn get_lint_level(&self, lint: &'static Lint) -> LevelAndSource;
540+
/// This returns the lint level spec for the given lint at the current location.
541+
fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec;
542542

543543
/// This function can be used to manually fulfill an expectation. This can
544544
/// be used for lints which contain several spans, and should be suppressed,
@@ -604,8 +604,8 @@ impl<'tcx> LintContext for LateContext<'tcx> {
604604
}
605605
}
606606

607-
fn get_lint_level(&self, lint: &'static Lint) -> LevelAndSource {
608-
self.tcx.lint_level_at_node(lint, self.last_node_with_lint_attrs)
607+
fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec {
608+
self.tcx.lint_level_spec_at_node(lint, self.last_node_with_lint_attrs)
609609
}
610610
}
611611

@@ -624,8 +624,8 @@ impl LintContext for EarlyContext<'_> {
624624
self.builder.opt_span_lint(lint, span.map(|s| s.into()), decorator)
625625
}
626626

627-
fn get_lint_level(&self, lint: &'static Lint) -> LevelAndSource {
628-
self.builder.lint_level(lint)
627+
fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec {
628+
self.builder.lint_level_spec(lint)
629629
}
630630
}
631631

0 commit comments

Comments
 (0)