Skip to content

Commit a91356a

Browse files
authored
Unrolled build for #153663
Rollup merge of #153663 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer Remove `TyCtxt::node_lint` method and `rustc_middle::lint_level` function Part of #153099. With this PR, we can finally get rid of `lint_level`. \o/ r? @JonathanBrouwer
2 parents d1c7945 + 2765e4a commit a91356a

7 files changed

Lines changed: 24 additions & 222 deletions

File tree

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,10 +1019,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10191019
if let Some(hir_id) =
10201020
terminator.source_info.scope.lint_root(&self.mir.source_scopes)
10211021
{
1022-
let msg = "tail calling a function marked with `#[track_caller]` has no special effect";
1023-
bx.tcx().node_lint(TAIL_CALL_TRACK_CALLER, hir_id, |d| {
1024-
_ = d.primary_message(msg).span(fn_span)
1025-
});
1022+
bx.tcx().emit_node_lint(TAIL_CALL_TRACK_CALLER, hir_id, rustc_errors::DiagDecorator(|d| {
1023+
_ = d.primary_message("tail calling a function marked with `#[track_caller]` has no special effect").span(fn_span)
1024+
}));
10261025
}
10271026

10281027
let instance = ty::Instance::resolve_for_fn_ptr(

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,12 +736,18 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
736736
let trait_name = self.tcx.item_name(pick.item.container_id(self.tcx));
737737
let import_span = self.tcx.hir_span_if_local(pick.import_ids[0].to_def_id()).unwrap();
738738

739-
self.tcx.node_lint(AMBIGUOUS_GLOB_IMPORTED_TRAITS, segment.hir_id, |diag| {
740-
diag.primary_message(format!("Use of ambiguously glob imported trait `{trait_name}`"))
739+
self.tcx.emit_node_lint(
740+
AMBIGUOUS_GLOB_IMPORTED_TRAITS,
741+
segment.hir_id,
742+
rustc_errors::DiagDecorator(|diag| {
743+
diag.primary_message(format!(
744+
"Use of ambiguously glob imported trait `{trait_name}`"
745+
))
741746
.span(segment.ident.span)
742747
.span_label(import_span, format!("`{trait_name}` imported ambiguously here"))
743748
.help(format!("Import `{trait_name}` explicitly"));
744-
});
749+
}),
750+
);
745751
}
746752

747753
fn upcast(

compiler/rustc_lint/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ pub trait LintContext {
514514
// set the span in their `decorate` function (preferably using set_span).
515515
/// Emit a lint at the appropriate level, with an optional associated span.
516516
///
517-
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
517+
/// [`diag_lint_level`]: rustc_middle::lint::diag_lint_level#decorate-signature
518518
#[track_caller]
519519
fn opt_span_diag_lint<S: Into<MultiSpan>>(
520520
&self,

compiler/rustc_middle/src/lint.rs

Lines changed: 0 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -293,201 +293,12 @@ fn explain_lint_level_source(
293293
}
294294
}
295295

296-
/// The innermost function for emitting lints.
297-
///
298-
/// If you are looking to implement a lint, look for higher level functions,
299-
/// for example:
300-
/// - [`TyCtxt::emit_node_span_lint`]
301-
/// - [`TyCtxt::node_lint`]
302-
/// - `LintContext::opt_span_lint`
303-
///
304-
/// ## `decorate`
305-
///
306-
/// It is not intended to call `emit`/`cancel` on the `Diag` passed in the `decorate` callback.
307-
#[track_caller]
308-
pub fn lint_level(
309-
sess: &Session,
310-
lint: &'static Lint,
311-
level: LevelAndSource,
312-
span: Option<MultiSpan>,
313-
decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
314-
) {
315-
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
316-
// the "real" work.
317-
#[track_caller]
318-
fn lint_level_impl(
319-
sess: &Session,
320-
lint: &'static Lint,
321-
level: LevelAndSource,
322-
span: Option<MultiSpan>,
323-
decorate: Box<dyn '_ + for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>)>,
324-
) {
325-
let LevelAndSource { level, lint_id, src } = level;
326-
327-
// Check for future incompatibility lints and issue a stronger warning.
328-
let future_incompatible = lint.future_incompatible;
329-
330-
let has_future_breakage = future_incompatible.map_or(
331-
// Default allow lints trigger too often for testing.
332-
sess.opts.unstable_opts.future_incompat_test && lint.default_level != Level::Allow,
333-
|incompat| incompat.report_in_deps,
334-
);
335-
336-
// Convert lint level to error level.
337-
let err_level = match level {
338-
Level::Allow => {
339-
if has_future_breakage {
340-
rustc_errors::Level::Allow
341-
} else {
342-
return;
343-
}
344-
}
345-
Level::Expect => {
346-
// This case is special as we actually allow the lint itself in this context, but
347-
// we can't return early like in the case for `Level::Allow` because we still
348-
// need the lint diagnostic to be emitted to `rustc_error::DiagCtxtInner`.
349-
//
350-
// We can also not mark the lint expectation as fulfilled here right away, as it
351-
// can still be cancelled in the decorate function. All of this means that we simply
352-
// create a `Diag` and continue as we would for warnings.
353-
rustc_errors::Level::Expect
354-
}
355-
Level::ForceWarn => rustc_errors::Level::ForceWarning,
356-
Level::Warn => rustc_errors::Level::Warning,
357-
Level::Deny | Level::Forbid => rustc_errors::Level::Error,
358-
};
359-
let mut err = Diag::new(sess.dcx(), err_level, "");
360-
if let Some(span) = span {
361-
err.span(span);
362-
}
363-
if let Some(lint_id) = lint_id {
364-
err.lint_id(lint_id);
365-
}
366-
367-
// If this code originates in a foreign macro, aka something that this crate
368-
// did not itself author, then it's likely that there's nothing this crate
369-
// can do about it. We probably want to skip the lint entirely.
370-
if err.span.primary_spans().iter().any(|s| s.in_external_macro(sess.source_map())) {
371-
// Any suggestions made here are likely to be incorrect, so anything we
372-
// emit shouldn't be automatically fixed by rustfix.
373-
err.disable_suggestions();
374-
375-
// If this is a future incompatible that is not an edition fixing lint
376-
// it'll become a hard error, so we have to emit *something*. Also,
377-
// if this lint occurs in the expansion of a macro from an external crate,
378-
// allow individual lints to opt-out from being reported.
379-
let incompatible = future_incompatible.is_some_and(|f| f.reason.edition().is_none());
380-
381-
// In rustc, for the find_attr macro, we want to always emit this.
382-
// This completely circumvents normal lint checking, which usually doesn't happen for macros from other crates.
383-
// However, we kind of want that when using find_attr from another rustc crate. So we cheat a little.
384-
let is_in_find_attr = sess.enable_internal_lints()
385-
&& err.span.primary_spans().iter().any(|s| {
386-
s.source_callee().is_some_and(
387-
|i| matches!(i.kind, ExpnKind::Macro(_, name) if name.as_str() == "find_attr")
388-
)
389-
});
390-
391-
if !incompatible && !lint.report_in_external_macro && !is_in_find_attr {
392-
err.cancel();
393-
394-
// Don't continue further, since we don't want to have
395-
// `diag_span_note_once` called for a diagnostic that isn't emitted.
396-
return;
397-
}
398-
}
399-
400-
err.is_lint(lint.name_lower(), has_future_breakage);
401-
402-
// Lint diagnostics that are covered by the expect level will not be emitted outside
403-
// the compiler. It is therefore not necessary to add any information for the user.
404-
// This will therefore directly call the decorate function which will in turn emit
405-
// the diagnostic.
406-
if let Level::Expect = level {
407-
decorate(&mut err);
408-
err.emit();
409-
return;
410-
}
411-
412-
if let Some(future_incompatible) = future_incompatible {
413-
let explanation = match future_incompatible.reason {
414-
FutureIncompatibilityReason::FutureReleaseError(_) => {
415-
"this was previously accepted by the compiler but is being phased out; \
416-
it will become a hard error in a future release!"
417-
.to_owned()
418-
}
419-
FutureIncompatibilityReason::FutureReleaseSemanticsChange(_) => {
420-
"this will change its meaning in a future release!".to_owned()
421-
}
422-
FutureIncompatibilityReason::EditionError(EditionFcw { edition, .. }) => {
423-
let current_edition = sess.edition();
424-
format!(
425-
"this is accepted in the current edition (Rust {current_edition}) but is a hard error in Rust {edition}!"
426-
)
427-
}
428-
FutureIncompatibilityReason::EditionSemanticsChange(EditionFcw {
429-
edition, ..
430-
}) => {
431-
format!("this changes meaning in Rust {edition}")
432-
}
433-
FutureIncompatibilityReason::EditionAndFutureReleaseError(EditionFcw {
434-
edition,
435-
..
436-
}) => {
437-
format!(
438-
"this was previously accepted by the compiler but is being phased out; \
439-
it will become a hard error in Rust {edition} and in a future release in all editions!"
440-
)
441-
}
442-
FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(
443-
EditionFcw { edition, .. },
444-
) => {
445-
format!(
446-
"this changes meaning in Rust {edition} and in a future release in all editions!"
447-
)
448-
}
449-
FutureIncompatibilityReason::Custom(reason, _) => reason.to_owned(),
450-
FutureIncompatibilityReason::Unreachable => unreachable!(),
451-
};
452-
453-
if future_incompatible.explain_reason {
454-
err.warn(explanation);
455-
}
456-
457-
let citation =
458-
format!("for more information, see {}", future_incompatible.reason.reference());
459-
err.note(citation);
460-
}
461-
462-
// Finally, run `decorate`. `decorate` can call `trimmed_path_str` (directly or indirectly),
463-
// so we need to make sure when we do call `decorate` that the diagnostic is eventually
464-
// emitted or we'll get a `must_produce_diag` ICE.
465-
//
466-
// When is a diagnostic *eventually* emitted? Well, that is determined by 2 factors:
467-
// 1. If the corresponding `rustc_errors::Level` is beyond warning, i.e. `ForceWarning(_)`
468-
// or `Error`, then the diagnostic will be emitted regardless of CLI options.
469-
// 2. If the corresponding `rustc_errors::Level` is warning, then that can be affected by
470-
// `-A warnings` or `--cap-lints=xxx` on the command line. In which case, the diagnostic
471-
// will be emitted if `can_emit_warnings` is true.
472-
let skip = err_level == rustc_errors::Level::Warning && !sess.dcx().can_emit_warnings();
473-
474-
if !skip {
475-
decorate(&mut err);
476-
}
477-
478-
explain_lint_level_source(sess, lint, level, src, &mut err);
479-
err.emit()
480-
}
481-
lint_level_impl(sess, lint, level, span, Box::new(decorate))
482-
}
483-
484296
/// The innermost function for emitting lints implementing the [`trait@Diagnostic`] trait.
485297
///
486298
/// If you are looking to implement a lint, look for higher level functions,
487299
/// for example:
488300
///
489301
/// - [`TyCtxt::emit_node_span_lint`]
490-
/// - [`TyCtxt::node_lint`]
491302
/// - `LintContext::opt_span_lint`
492303
///
493304
/// This function will replace `lint_level` once all its callers have been replaced

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use crate::dep_graph::dep_node::make_metadata;
5555
use crate::dep_graph::{DepGraph, DepKindVTable, DepNodeIndex};
5656
use crate::ich::StableHashingContext;
5757
use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarKind};
58-
use crate::lint::{diag_lint_level, lint_level};
58+
use crate::lint::diag_lint_level;
5959
use crate::metadata::ModChild;
6060
use crate::middle::codegen_fn_attrs::{CodegenFnAttrs, TargetFeature};
6161
use crate::middle::resolve_bound_vars;
@@ -2585,20 +2585,6 @@ impl<'tcx> TyCtxt<'tcx> {
25852585
diag_lint_level(self.sess, lint, level, None, decorator);
25862586
}
25872587

2588-
/// Emit a lint at the appropriate level for a hir node.
2589-
///
2590-
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
2591-
#[track_caller]
2592-
pub fn node_lint(
2593-
self,
2594-
lint: &'static Lint,
2595-
id: HirId,
2596-
decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
2597-
) {
2598-
let level = self.lint_level_at_node(lint, id);
2599-
lint_level(self.sess, lint, level, None, decorate);
2600-
}
2601-
26022588
pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate<'tcx>]> {
26032589
let map = self.in_scope_traits_map(id.owner)?;
26042590
let candidates = map.get(&id.local_id)?;

src/librustdoc/core.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,16 @@ pub(crate) fn run_global_ctxt(
400400
{}/rustdoc/how-to-write-documentation.html",
401401
crate::DOC_RUST_LANG_ORG_VERSION
402402
);
403-
tcx.node_lint(
403+
tcx.emit_node_lint(
404404
crate::lint::MISSING_CRATE_LEVEL_DOCS,
405405
DocContext::as_local_hir_id(tcx, krate.module.item_id).unwrap(),
406-
|lint| {
406+
rustc_errors::DiagDecorator(|lint| {
407407
if let Some(local_def_id) = krate.module.item_id.as_local_def_id() {
408408
lint.span(tcx.def_span(local_def_id));
409409
}
410410
lint.primary_message("no documentation found for this crate's top-level module");
411411
lint.help(help);
412-
},
412+
}),
413413
);
414414
}
415415

tests/ui/imports/ambiguous-trait-in-scope.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ LL | use m2::*;
77
LL | 0u8.method1();
88
| ^^^^^^^
99
|
10+
= help: Import `Trait` explicitly
1011
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1112
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
12-
= help: Import `Trait` explicitly
1313
= note: `#[warn(ambiguous_glob_imported_traits)]` (part of `#[warn(future_incompatible)]`) on by default
1414

1515
error[E0599]: no method named `method2` found for type `u8` in the current scope
@@ -49,9 +49,9 @@ LL | use m2::*;
4949
LL | 0u8.method2();
5050
| ^^^^^^^
5151
|
52+
= help: Import `Trait` explicitly
5253
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5354
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
54-
= help: Import `Trait` explicitly
5555

5656
warning: Use of ambiguously glob imported trait `Trait`
5757
--> $DIR/ambiguous-trait-in-scope.rs:49:9
@@ -62,9 +62,9 @@ LL | use m2_reexport::*;
6262
LL | 0u8.method1();
6363
| ^^^^^^^
6464
|
65+
= help: Import `Trait` explicitly
6566
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
6667
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
67-
= help: Import `Trait` explicitly
6868

6969
error[E0599]: no method named `method2` found for type `u8` in the current scope
7070
--> $DIR/ambiguous-trait-in-scope.rs:51:9
@@ -88,9 +88,9 @@ LL | use ambig_reexport::*;
8888
LL | 0u8.method1();
8989
| ^^^^^^^
9090
|
91+
= help: Import `Trait` explicitly
9192
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9293
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
93-
= help: Import `Trait` explicitly
9494

9595
error[E0599]: no method named `method2` found for type `u8` in the current scope
9696
--> $DIR/ambiguous-trait-in-scope.rs:58:9
@@ -115,9 +115,9 @@ LL | use external::m2::*;
115115
LL | 0u8.method1();
116116
| ^^^^^^^
117117
|
118+
= help: Import `Trait` explicitly
118119
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
119120
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
120-
= help: Import `Trait` explicitly
121121

122122
error[E0599]: no method named `method2` found for type `u8` in the current scope
123123
--> $DIR/ambiguous-trait-in-scope.rs:66:9
@@ -142,9 +142,9 @@ LL | use external::m2_reexport::*;
142142
LL | 0u8.method1();
143143
| ^^^^^^^
144144
|
145+
= help: Import `Trait` explicitly
145146
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
146147
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
147-
= help: Import `Trait` explicitly
148148

149149
error[E0599]: no method named `method2` found for type `u8` in the current scope
150150
--> $DIR/ambiguous-trait-in-scope.rs:74:9
@@ -168,9 +168,9 @@ LL | use external::ambig_reexport::*;
168168
LL | 0u8.method1();
169169
| ^^^^^^^
170170
|
171+
= help: Import `Trait` explicitly
171172
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
172173
= note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
173-
= help: Import `Trait` explicitly
174174

175175
error[E0599]: no method named `method2` found for type `u8` in the current scope
176176
--> $DIR/ambiguous-trait-in-scope.rs:81:9

0 commit comments

Comments
 (0)