Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2698,12 +2698,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {

let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);

tcx.emit_diag_node_span_lint(
UNUSED_MUT,
lint_root,
span,
VarNeedNotMut { span: mut_span },
)
tcx.emit_node_span_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span })
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub(crate) fn from_target_feature_attr(
// For "neon" specifically, we emit an FCW instead of a hard error.
// See <https://github.com/rust-lang/rust/issues/134375>.
if tcx.sess.target.arch == Arch::AArch64 && name.as_str() == "neon" {
tcx.emit_diag_node_span_lint(
tcx.emit_node_span_lint(
AARCH64_SOFTFLOAT_NEON,
tcx.local_def_id_to_hir_id(did),
feature_span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,5 @@ pub(super) fn lint<'tcx, L>(
{
let (span, frames) = get_span_and_frames(tcx, &machine.stack);

tcx.emit_diag_node_span_lint(lint, machine.best_lint_scope(*tcx), span, decorator(frames));
tcx.emit_node_span_lint(lint, machine.best_lint_scope(*tcx), span, decorator(frames));
}
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
.level
.is_error();
let span = ecx.cur_span();
ecx.tcx.emit_diag_node_span_lint(
ecx.tcx.emit_node_span_lint(
rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
hir_id,
span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ fn check_impl_items_against_trait<'tcx>(
}

if self_is_guaranteed_unsize_self && tcx.generics_require_sized_self(ty_trait_item.def_id) {
tcx.emit_diag_node_span_lint(
tcx.emit_node_span_lint(
rustc_lint_defs::builtin::DEAD_CODE,
tcx.local_def_id_to_hir_id(ty_impl_item.def_id.expect_local()),
tcx.def_span(ty_impl_item.def_id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
with_no_trimmed_paths!(with_types_for_signature!(format!("{return_ty}")));

let span = unmatched_bound.unwrap_or(span);
tcx.emit_diag_node_span_lint(
tcx.emit_node_span_lint(
if is_internal { REFINING_IMPL_TRAIT_INTERNAL } else { REFINING_IMPL_TRAIT_REACHABLE },
tcx.local_def_id_to_hir_id(impl_m_def_id.expect_local()),
span,
Expand Down Expand Up @@ -442,7 +442,7 @@ fn report_mismatched_rpitit_captures<'tcx>(
.sort_by_cached_key(|arg| !matches!(arg.kind(), ty::GenericArgKind::Lifetime(_)));
let suggestion = format!("use<{}>", trait_captured_args.iter().join(", "));

tcx.emit_diag_node_span_lint(
tcx.emit_node_span_lint(
if is_internal { REFINING_IMPL_TRAIT_INTERNAL } else { REFINING_IMPL_TRAIT_REACHABLE },
tcx.local_def_id_to_hir_id(impl_opaque_def_id),
use_bound_span,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ fn lint_item_shadowing_supertrait_item<'tcx>(tcx: TyCtxt<'tcx>, trait_item_def_i
errors::SupertraitItemShadowee::Several { traits: traits.into(), spans: spans.into() }
};

tcx.emit_diag_node_span_lint(
tcx.emit_node_span_lint(
SHADOWING_SUPERTRAIT_ITEMS,
tcx.local_def_id_to_hir_id(trait_item_def_id),
tcx.def_span(trait_item_def_id),
Expand Down Expand Up @@ -2458,7 +2458,7 @@ fn lint_redundant_lifetimes<'tcx>(
&& outlives_env.free_region_map().sub_free_regions(tcx, victim, candidate)
{
shadowed.insert(victim);
tcx.emit_diag_node_span_lint(
tcx.emit_node_span_lint(
rustc_lint_defs::builtin::REDUNDANT_LIFETIMES,
tcx.local_def_id_to_hir_id(def_id.expect_local()),
tcx.def_span(def_id),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,13 @@ fn lint_uncovered_ty_params<'tcx>(
let name = tcx.item_ident(param_def_id);

match local_ty {
Some(local_type) => tcx.emit_diag_node_span_lint(
Some(local_type) => tcx.emit_node_span_lint(
UNCOVERED_PARAM_IN_PROJECTION,
hir_id,
span,
errors::TyParamFirstLocalLint { span, note: (), param: name, local_type },
),
None => tcx.emit_diag_node_span_lint(
None => tcx.emit_node_span_lint(
UNCOVERED_PARAM_IN_PROJECTION,
hir_id,
span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// FIXME(mgca): Ideally we would generalize the name of this lint to sth. like
// `unused_associated_item_bindings` since this can now also trigger on *const*
// projections / assoc *const* bindings.
tcx.emit_diag_node_span_lint(
tcx.emit_node_span_lint(
UNUSED_ASSOCIATED_TYPE_BOUNDS,
hir_id,
span,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
};
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
fcx.tcx.emit_diag_node_span_lint(
fcx.tcx.emit_node_span_lint(
lint,
self.expr.hir_id,
self.span,
Expand Down Expand Up @@ -1125,7 +1125,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
};

let lint = errors::LossyProvenancePtr2Int { expr_ty, cast_ty, sugg };
fcx.tcx.emit_diag_node_span_lint(
fcx.tcx.emit_node_span_lint(
lint::builtin::LOSSY_PROVENANCE_CASTS,
self.expr.hir_id,
self.span,
Expand All @@ -1141,7 +1141,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
let lint = errors::LossyProvenanceInt2Ptr { expr_ty, cast_ty, sugg };
fcx.tcx.emit_diag_node_span_lint(
fcx.tcx.emit_node_span_lint(
lint::builtin::FUZZY_PROVENANCE_CASTS,
self.expr.hir_id,
self.span,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
let sugg = self.try_to_suggest_annotations(&[root_vid], coercion_graph);

for (hir_id, span, reason) in affected_unsafe_infer_vars {
self.tcx.emit_diag_node_span_lint(
self.tcx.emit_node_span_lint(
lint::builtin::NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
hir_id,
span,
Expand Down Expand Up @@ -304,7 +304,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
{
self.adjust_fulfillment_error_for_expr_obligation(never_error);
let sugg = self.try_to_suggest_annotations(diverging_vids, coercions);
self.tcx.emit_diag_node_span_lint(
self.tcx.emit_node_span_lint(
lint::builtin::DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
self.tcx.local_def_id_to_hir_id(self.body_id),
self.tcx.def_span(self.body_id),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});
return (Ty::new_error(self.tcx, guar), res);
} else {
self.tcx.emit_diag_node_span_lint(
self.tcx.emit_node_span_lint(
SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
hir_id,
path_span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
SupertraitItemShadowee::Several { traits: traits.into(), spans: spans.into() }
};

self.tcx.emit_diag_node_span_lint(
self.tcx.emit_node_span_lint(
RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
segment.hir_id,
segment.ident.span,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/async_closures.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_hir as hir;
use rustc_macros::{LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::Span;

Expand Down Expand Up @@ -107,7 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for AsyncClosureUsage {
}
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("closure returning async block can be made into an async closure")]
struct ClosureReturningAsyncBlock {
#[label(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/if_let_rescope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hir::intravisit::{self, Visitor};
use rustc_ast::Recovered;
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic, SuggestionStyle, msg};
use rustc_hir::{self as hir, HirIdSet};
use rustc_macros::{LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_middle::ty::adjustment::Adjust;
use rustc_middle::ty::significant_drop_order::{
extract_component_with_significant_dtor, ty_dtor_span,
Expand Down Expand Up @@ -302,7 +302,7 @@ impl<'tcx> LateLintPass<'tcx> for IfLetRescope {
}
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("`if let` assigns a shorter lifetime since Edition 2024")]
struct IfLetRescopeLint {
#[subdiagnostic]
Expand Down
25 changes: 16 additions & 9 deletions compiler/rustc_lint/src/impl_trait_overcaptures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::cell::LazyCell;
use rustc_data_structures::debug_assert_matches;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
use rustc_data_structures::unord::UnordSet;
use rustc_errors::{LintDiagnostic, Subdiagnostic, msg};
use rustc_errors::{Diagnostic, Subdiagnostic, msg};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_macros::LintDiagnostic;
use rustc_macros::Diagnostic;
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
use rustc_middle::ty::relate::{
Relate, RelateResult, TypeRelation, relate_args_with_variances, structurally_relate_consts,
Expand Down Expand Up @@ -433,11 +433,17 @@ struct ImplTraitOvercapturesLint<'tcx> {
suggestion: Option<AddPreciseCapturingForOvercapture>,
}

impl<'a> LintDiagnostic<'a, ()> for ImplTraitOvercapturesLint<'_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
diag.primary_message(msg!(
"`{$self_ty}` will capture more lifetimes than possibly intended in edition 2024"
));
impl<'a> Diagnostic<'a, ()> for ImplTraitOvercapturesLint<'_> {
fn into_diag(
self,
dcx: rustc_errors::DiagCtxtHandle<'a>,
level: rustc_errors::Level,
) -> rustc_errors::Diag<'a, ()> {
let mut diag = rustc_errors::Diag::new(
dcx,
level,
msg!("`{$self_ty}` will capture more lifetimes than possibly intended in edition 2024"),
);
diag.arg("self_ty", self.self_ty.to_string())
.arg("num_captured", self.num_captured)
.span_note(
Expand All @@ -451,12 +457,13 @@ impl<'a> LintDiagnostic<'a, ()> for ImplTraitOvercapturesLint<'_> {
)
.note(msg!("all lifetimes in scope will be captured by `impl Trait`s in edition 2024"));
if let Some(suggestion) = self.suggestion {
suggestion.add_to_diag(diag);
suggestion.add_to_diag(&mut diag);
}
diag
}
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("all possible in-scope parameters are already captured, so `use<...>` syntax is redundant")]
struct ImplTraitRedundantCapturesLint {
#[suggestion("remove the `use<...>` syntax", code = "", applicability = "machine-applicable")]
Expand Down
36 changes: 21 additions & 15 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use std::num::NonZero;

use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString, ElidedLifetimeInPathSubdiag,
EmissionGuarantee, LintDiagnostic, MultiSpan, Subdiagnostic, SuggestionStyle, msg,
Applicability, Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic,
ElidedLifetimeInPathSubdiag, EmissionGuarantee, Level, LintDiagnostic, MultiSpan,
Subdiagnostic, SuggestionStyle, msg,
};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::VisitorExt;
use rustc_macros::{LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::inhabitedness::InhabitedPredicate;
use rustc_middle::ty::{Clause, PolyExistentialTraitRef, Ty, TyCtxt};
use rustc_session::Session;
Expand Down Expand Up @@ -580,7 +581,7 @@ impl Subdiagnostic for BuiltinUnpermittedTypeInitSub {
}
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
pub(crate) enum BuiltinClashingExtern<'a> {
#[diag("`{$this}` redeclared with a different signature")]
SameName {
Expand Down Expand Up @@ -686,7 +687,7 @@ pub(crate) struct EnumIntrinsicsMemVariant<'a> {
}

// expect.rs
#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("this lint expectation is unfulfilled")]
pub(crate) struct Expectation {
#[subdiagnostic]
Expand Down Expand Up @@ -1341,7 +1342,7 @@ pub(crate) struct IgnoredUnlessCrateSpecified<'a> {
}

// dangling.rs
#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("this creates a dangling pointer because temporary `{$ty}` is dropped at end of statement")]
#[help("bind the `{$ty}` to a variable such that it outlives the pointer returned by `{$callee}`")]
#[note("a dangling pointer is safe, but dereferencing one is undefined behavior")]
Expand All @@ -1357,7 +1358,7 @@ pub(crate) struct DanglingPointersFromTemporaries<'tcx> {
pub temporary_span: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("{$fn_kind} returns a dangling pointer to dropped local variable `{$local_var_name}`")]
#[note("a dangling pointer is safe, but dereferencing one is undefined behavior")]
#[note("for more information, see <https://doc.rust-lang.org/reference/destructors.html>")]
Expand Down Expand Up @@ -1874,7 +1875,7 @@ impl<'a> LintDiagnostic<'a, ()> for DropGlue<'_> {
}

// transmute.rs
#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("transmuting an integer to a pointer creates a pointer without provenance")]
#[note("this is dangerous because dereferencing the resulting pointer is undefined behavior")]
#[note(
Expand Down Expand Up @@ -2324,7 +2325,7 @@ impl<'a> LintDiagnostic<'a, ()> for ImproperCTypes<'_> {
}
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("passing type `{$ty}` to a function with \"gpu-kernel\" ABI may have unexpected behavior")]
#[help("use primitive types and raw pointers to get reliable behavior")]
pub(crate) struct ImproperGpuKernelArg<'a> {
Expand Down Expand Up @@ -2564,13 +2565,18 @@ pub(crate) struct AsyncFnInTraitDiag {
pub sugg: Option<Vec<(Span, String)>>,
}

impl<'a> LintDiagnostic<'a, ()> for AsyncFnInTraitDiag {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.primary_message(msg!("use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified"));
diag.note(msg!("you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future`"));
impl<'a> Diagnostic<'a, ()> for AsyncFnInTraitDiag {
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
let mut diag = Diag::new(
dcx,
level,
"use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified",
);
diag.note("you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future`");
if let Some(sugg) = self.sugg {
diag.multipart_suggestion(msg!("you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`, but these cannot be relaxed without a breaking API change"), sugg, Applicability::MaybeIncorrect);
diag.multipart_suggestion("you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`, but these cannot be relaxed without a breaking API change", sugg, Applicability::MaybeIncorrect);
}
diag
}
}

Expand Down Expand Up @@ -3404,7 +3410,7 @@ pub(crate) struct ReservedMultihash {
pub suggestion: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("direct cast of function item into an integer")]
pub(crate) struct FunctionCastsAsIntegerDiag<'tcx> {
#[subdiagnostic]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/transmute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::LocalDefId;
use rustc_hir::{self as hir};
use rustc_macros::LintDiagnostic;
use rustc_macros::Diagnostic;
use rustc_middle::ty::{self, Ty};
use rustc_session::{declare_lint, impl_lint_pass};
use rustc_span::sym;
Expand Down Expand Up @@ -368,7 +368,7 @@ fn check_unnecessary_transmute<'tcx>(
});
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("pointers cannot be transmuted to integers during const eval")]
#[note("at compile-time, pointers do not have an integer value")]
#[note(
Expand Down
Loading
Loading