Skip to content

Commit ec0e8a2

Browse files
authored
Unrolled build for rust-lang#134339
Rollup merge of rust-lang#134339 - Urgau:tcx-in-early-diag, r=jieyouxu Pass `TyCtxt` to early diagostics decoration This PR pass a `TyCtxt` to the early diagnostics decoration code so that diagnostics code that take advantage of (a very limited but still useful) `TyCtxt` in their note, help, suggestions, ... This is particulary useful for rust-lang#133221 which wants to get the crate name of a `DefId`, which is possible with `tcx.crate_name(...)`. I highly recommend reviewing this PR commit by commit. r? `@jieyouxu`
2 parents d185062 + 291c519 commit ec0e8a2

File tree

8 files changed

+84
-112
lines changed

8 files changed

+84
-112
lines changed

compiler/rustc_interface/src/passes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ fn pre_expansion_lint<'a>(
7676
|| {
7777
rustc_lint::check_ast_node(
7878
sess,
79+
None,
7980
features,
8081
true,
8182
lint_store,
@@ -310,6 +311,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
310311
let lint_store = unerased_lint_store(tcx.sess);
311312
rustc_lint::check_ast_node(
312313
sess,
314+
Some(tcx),
313315
tcx.features(),
314316
false,
315317
lint_store,

compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ lint_unexpected_cfg_add_build_rs_println = or consider adding `{$build_rs_printl
806806
lint_unexpected_cfg_add_cargo_feature = consider using a Cargo feature instead
807807
lint_unexpected_cfg_add_cargo_toml_lint_cfg = or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:{$cargo_toml_lint_cfg}
808808
lint_unexpected_cfg_add_cmdline_arg = to expect this configuration use `{$cmdline_arg}`
809-
lint_unexpected_cfg_cargo_update = the {$macro_kind} `{$macro_name}` may come from an old version of it's defining crate, try updating your dependencies with `cargo update`
809+
lint_unexpected_cfg_cargo_update = the {$macro_kind} `{$macro_name}` may come from an old version of the `{$crate_name}` crate, try updating your dependency with `cargo update -p {$crate_name}`
810810
811811
lint_unexpected_cfg_define_features = consider defining some features in `Cargo.toml`
812812
lint_unexpected_cfg_doc_cargo = see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration

compiler/rustc_lint/src/context.rs

+1-35
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
2020
use rustc_middle::ty::print::{PrintError, PrintTraitRefExt as _, Printer, with_no_trimmed_paths};
2121
use rustc_middle::ty::{self, GenericArg, RegisteredTools, Ty, TyCtxt, TypingEnv, TypingMode};
2222
use rustc_session::lint::{
23-
BuiltinLintDiag, FutureIncompatibleInfo, Level, Lint, LintBuffer, LintExpectationId, LintId,
23+
FutureIncompatibleInfo, Level, Lint, LintBuffer, LintExpectationId, LintId,
2424
};
2525
use rustc_session::{LintStoreMarker, Session};
2626
use rustc_span::Span;
@@ -33,8 +33,6 @@ use self::TargetLint::*;
3333
use crate::levels::LintLevelsBuilder;
3434
use crate::passes::{EarlyLintPassObject, LateLintPassObject};
3535

36-
mod diagnostics;
37-
3836
type EarlyLintPassFactory = dyn Fn() -> EarlyLintPassObject + sync::DynSend + sync::DynSync;
3937
type LateLintPassFactory =
4038
dyn for<'tcx> Fn(TyCtxt<'tcx>) -> LateLintPassObject<'tcx> + sync::DynSend + sync::DynSync;
@@ -511,38 +509,6 @@ pub struct EarlyContext<'a> {
511509
pub buffered: LintBuffer,
512510
}
513511

514-
impl EarlyContext<'_> {
515-
/// Emit a lint at the appropriate level, with an associated span and an existing
516-
/// diagnostic.
517-
///
518-
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
519-
#[rustc_lint_diagnostics]
520-
pub fn span_lint_with_diagnostics(
521-
&self,
522-
lint: &'static Lint,
523-
span: MultiSpan,
524-
diagnostic: BuiltinLintDiag,
525-
) {
526-
self.opt_span_lint_with_diagnostics(lint, Some(span), diagnostic);
527-
}
528-
529-
/// Emit a lint at the appropriate level, with an optional associated span and an existing
530-
/// diagnostic.
531-
///
532-
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
533-
#[rustc_lint_diagnostics]
534-
pub fn opt_span_lint_with_diagnostics(
535-
&self,
536-
lint: &'static Lint,
537-
span: Option<MultiSpan>,
538-
diagnostic: BuiltinLintDiag,
539-
) {
540-
self.opt_span_lint(lint, span, |diag| {
541-
diagnostics::decorate_lint(self.sess(), diagnostic, diag);
542-
});
543-
}
544-
}
545-
546512
pub trait LintContext {
547513
fn sess(&self) -> &Session;
548514

0 commit comments

Comments
 (0)