Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ae8890f
Add regression test for `doc(fake_variadic)` on reexports
GuillaumeGomez Mar 2, 2026
6696649
x86: reserve `bl` and `bh` registers to match `rbx`
CathalMullan Mar 2, 2026
a8d4eee
Improve irrefutable let-else lint wording
ozankenangungor Feb 24, 2026
3cecc8d
Suppress `.clone()` suggestion inside derive macro expansions
lapla-cogito Mar 1, 2026
9247487
Implement `Diagnostic` trait for `rustc_errors::DecorateDiagCompat`
GuillaumeGomez Mar 3, 2026
bd538f9
Remove unused `rustc_errors::LintDiagnosticBox` trait
GuillaumeGomez Mar 3, 2026
bde5b58
Add Path::absolute method as alias for path::absolute
wmmc88 Mar 2, 2026
d96ec37
Boundary tests for various Duration-float operations
eggyal Mar 3, 2026
014344b
update panicking() docs for panic=abort
biscuitrescue Mar 2, 2026
b5ff567
Migrate more types from `LintDiagnostic` to `Diagnostic`
GuillaumeGomez Mar 3, 2026
56d636a
Implement `Diagnostic` directly on `Box<FnOnce...>`
GuillaumeGomez Mar 3, 2026
d16ec85
Rollup merge of #153280 - GuillaumeGomez:add-test-reexport, r=lolbina…
Zalathar Mar 4, 2026
df44e39
Rollup merge of #153302 - CathalMullan:rbx, r=Amanieu
Zalathar Mar 4, 2026
54bb7b8
Rollup merge of #153358 - eggyal:duration-flop-boundary-tests, r=tgro…
Zalathar Mar 4, 2026
70287b9
Rollup merge of #153048 - ozankenangungor:fix-irrefutable-let-else-wo…
Zalathar Mar 4, 2026
010bca6
Rollup merge of #153258 - lapla-cogito:issue_153126, r=Kivooeo
Zalathar Mar 4, 2026
b5f3ca1
Rollup merge of #153272 - wmmc88:add-path-absolute-method, r=tgross35
Zalathar Mar 4, 2026
49966fe
Rollup merge of #153295 - biscuitrescue:fix-panicking-docs, r=tgross35
Zalathar Mar 4, 2026
c4f239e
Rollup merge of #153352 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer
Zalathar Mar 4, 2026
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
6 changes: 3 additions & 3 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_abi::ExternAbi;
use rustc_ast::ParamKindOrd;
use rustc_errors::codes::*;
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Ident, Span, Symbol};

#[derive(Diagnostic)]
Expand Down Expand Up @@ -671,7 +671,7 @@ pub(crate) struct MissingUnsafeOnExtern {
pub span: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("extern blocks should be unsafe")]
pub(crate) struct MissingUnsafeOnExternLint {
#[suggestion(
Expand Down Expand Up @@ -1027,7 +1027,7 @@ pub(crate) struct MissingAbi {
pub span: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("`extern` declarations without an explicit ABI are deprecated")]
pub(crate) struct MissingAbiSugg {
#[suggestion(
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use rustc_middle::ty::{
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::hygiene::DesugaringKind;
use rustc_span::{BytePos, Ident, Span, Symbol, kw, sym};
use rustc_span::{BytePos, ExpnKind, Ident, MacroKind, Span, Symbol, kw, sym};
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
use rustc_trait_selection::error_reporting::traits::call_kind::CallKind;
Expand Down Expand Up @@ -1438,6 +1438,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
expr: &hir::Expr<'_>,
) -> bool {
let tcx = self.infcx.tcx;

// Don't suggest `.clone()` in a derive macro expansion.
if let ExpnKind::Macro(MacroKind::Derive, _) = self.body.span.ctxt().outer_expn_data().kind
{
return false;
}
if let Some(_) = self.clone_on_reference(expr) {
// Avoid redundant clone suggestion already suggested in `explain_captures`.
// See `tests/ui/moves/needs-clone-through-deref.rs`
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_builtin_macros/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ use rustc_errors::{
Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans,
Subdiagnostic, msg,
};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Ident, Span, Symbol};

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("avoid using `.intel_syntax`, Intel syntax is the default")]
pub(crate) struct AvoidIntelSyntax;

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("avoid using `.att_syntax`, prefer using `options(att_syntax)` instead")]
pub(crate) struct AvoidAttSyntax;

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("include macro expected single expression in source")]
pub(crate) struct IncompleteInclude;

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("cannot test inner items")]
pub(crate) struct UnnameableTestItems;

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("duplicated attribute")]
pub(crate) struct DuplicateMacroAttribute;

Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_errors/src/decorate_diag.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/// This module provides types and traits for buffering lints until later in compilation.
use rustc_ast::node_id::NodeId;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync::DynSend;
use rustc_error_messages::MultiSpan;
use rustc_lint_defs::{BuiltinLintDiag, Lint, LintId};

use crate::{DynSend, LintDiagnostic, LintDiagnosticBox};
use crate::{Diag, DiagCtxtHandle, Diagnostic, Level};

/// We can't implement `LintDiagnostic` for `BuiltinLintDiag`, because decorating some of its
/// variants requires types we don't have yet. So, handle that case separately.
pub enum DecorateDiagCompat {
Dynamic(Box<dyn for<'a> LintDiagnosticBox<'a, ()> + DynSend + 'static>),
Dynamic(Box<dyn for<'a> FnOnce(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + 'static>),
Builtin(BuiltinLintDiag),
}

Expand All @@ -19,12 +20,10 @@ impl std::fmt::Debug for DecorateDiagCompat {
}
}

impl !LintDiagnostic<'_, ()> for BuiltinLintDiag {}

impl<D: for<'a> LintDiagnostic<'a, ()> + DynSend + 'static> From<D> for DecorateDiagCompat {
impl<D: for<'a> Diagnostic<'a, ()> + DynSend + 'static> From<D> for DecorateDiagCompat {
#[inline]
fn from(d: D) -> Self {
Self::Dynamic(Box::new(d))
Self::Dynamic(Box::new(|dcx, level| d.into_diag(dcx, level)))
}
}

Expand Down
19 changes: 9 additions & 10 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::panic;
use std::path::PathBuf;
use std::thread::panicking;

use rustc_data_structures::sync::DynSend;
use rustc_error_messages::{DiagArgMap, DiagArgName, DiagArgValue, IntoDiagArg};
use rustc_lint_defs::{Applicability, LintExpectationId};
use rustc_macros::{Decodable, Encodable};
Expand Down Expand Up @@ -118,6 +119,14 @@ where
}
}

impl<'a> Diagnostic<'a, ()>
for Box<dyn for<'b> FnOnce(DiagCtxtHandle<'b>, Level) -> Diag<'b, ()> + DynSend + 'static>
{
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
self(dcx, level)
}
}

/// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
#[rustc_diagnostic_item = "Subdiagnostic"]
Expand All @@ -137,16 +146,6 @@ pub trait LintDiagnostic<'a, G: EmissionGuarantee> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>);
}

pub trait LintDiagnosticBox<'a, G: EmissionGuarantee> {
fn decorate_lint_box<'b>(self: Box<Self>, diag: &'b mut Diag<'a, G>);
}

impl<'a, G: EmissionGuarantee, D: LintDiagnostic<'a, G>> LintDiagnosticBox<'a, G> for D {
fn decorate_lint_box<'b>(self: Box<Self>, diag: &'b mut Diag<'a, G>) {
self.decorate_lint(diag);
}
}

#[derive(Clone, Debug, Encodable, Decodable)]
pub(crate) struct DiagLocation {
file: Cow<'static, str>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub use codes::*;
pub use decorate_diag::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer};
pub use diagnostic::{
BugAbort, Diag, DiagInner, DiagStyledString, Diagnostic, EmissionGuarantee, FatalAbort,
LintDiagnostic, LintDiagnosticBox, StringPart, Subdiag, Subdiagnostic,
LintDiagnostic, StringPart, Subdiag, Subdiagnostic,
};
pub use diagnostic_impls::{
DiagSymbolList, ElidedLifetimeInPathSubdiag, ExpectedLifetimeParameter,
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::borrow::Cow;
use rustc_ast::ast;
use rustc_errors::codes::*;
use rustc_hir::limit::Limit;
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol};

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("`#[cfg_attr]` does not expand to any attributes")]
pub(crate) struct CfgAttrNoAttributes;

Expand Down Expand Up @@ -94,15 +94,15 @@ pub(crate) struct MacroVarStillRepeating {
pub ident: MacroRulesNormalizedIdent,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("variable `{$ident}` is still repeating at this depth")]
pub(crate) struct MetaVarStillRepeatingLint {
#[label("expected repetition")]
pub label: Span,
pub ident: MacroRulesNormalizedIdent,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("meta-variable repeats with different Kleene operator")]
pub(crate) struct MetaVariableWrongOperator {
#[label("expected repetition")]
Expand All @@ -119,7 +119,7 @@ pub(crate) struct MetaVarsDifSeqMatchers {
pub msg: String,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("unknown macro variable `{$name}`")]
pub(crate) struct UnknownMacroVariable {
pub name: MacroRulesNormalizedIdent,
Expand Down Expand Up @@ -391,7 +391,7 @@ pub(crate) struct DuplicateMatcherBinding {
pub prev: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("duplicate matcher binding")]
pub(crate) struct DuplicateMatcherBindingLint {
#[label("duplicate binding")]
Expand Down Expand Up @@ -569,7 +569,7 @@ pub(crate) struct MacroArgsBadDelimSugg {
pub close: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("unused doc comment")]
#[help(
"to document an item produced by a macro, the macro must produce the documentation as part of its expansion"
Expand All @@ -579,7 +579,7 @@ pub(crate) struct MacroCallUnusedDocComment {
pub span: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag(
"the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro"
)]
Expand All @@ -593,7 +593,7 @@ pub(crate) struct OrPatternsBackCompat {
pub suggestion: String,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("trailing semicolon in macro used in expression position")]
pub(crate) struct TrailingMacro {
#[note("macro invocations at the end of a block are treated as expressions")]
Expand All @@ -604,7 +604,7 @@ pub(crate) struct TrailingMacro {
pub name: Ident,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("unused attribute `{$attr_name}`")]
pub(crate) struct UnusedBuiltinAttribute {
#[note(
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
);
}
DecorateDiagCompat::Dynamic(d) => {
self.context
.opt_span_lint(lint_id.lint, span, |diag| d.decorate_lint_box(diag));
self.context.opt_span_diag_lint(lint_id.lint, span, d);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_mir_build/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,13 +932,14 @@ pub(crate) struct IrrefutableLetPatternsIfLetGuard {
)]
#[note(
"{$count ->
[one] this pattern
*[other] these patterns
} will always match, so the `else` clause is useless"
[one] this pattern always matches, so the else clause is unreachable
*[other] these patterns always match, so the else clause is unreachable
}"
)]
#[help("consider removing the `else` clause")]
pub(crate) struct IrrefutableLetPatternsLetElse {
pub(crate) count: usize,
#[help("remove this `else` block")]
pub(crate) else_span: Option<Span>,
}

#[derive(Diagnostic)]
Expand Down
38 changes: 30 additions & 8 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> {
self.check_match(scrutinee, arms, MatchSource::Normal, span);
}
ExprKind::Let { box ref pat, expr } => {
self.check_let(pat, Some(expr), ex.span);
self.check_let(pat, Some(expr), ex.span, None);
}
ExprKind::LogicalOp { op: LogicalOp::And, .. }
if !matches!(self.let_source, LetSource::None) =>
Expand All @@ -169,7 +169,7 @@ impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> {
let Ok(()) = self.visit_land(ex, &mut chain_refutabilities) else { return };
// Lint only single irrefutable let binding.
if let [Some((_, Irrefutable))] = chain_refutabilities[..] {
self.lint_single_let(ex.span);
self.lint_single_let(ex.span, None);
}
return;
}
Expand All @@ -184,8 +184,9 @@ impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> {
self.with_hir_source(hir_id, |this| {
let let_source =
if else_block.is_some() { LetSource::LetElse } else { LetSource::PlainLet };
let else_span = else_block.map(|bid| this.thir.blocks[bid].span);
this.with_let_source(let_source, |this| {
this.check_let(pattern, initializer, span)
this.check_let(pattern, initializer, span, else_span)
});
visit::walk_stmt(this, stmt);
});
Expand Down Expand Up @@ -426,13 +427,19 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
}

#[instrument(level = "trace", skip(self))]
fn check_let(&mut self, pat: &'p Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
fn check_let(
&mut self,
pat: &'p Pat<'tcx>,
scrutinee: Option<ExprId>,
span: Span,
else_span: Option<Span>,
) {
assert!(self.let_source != LetSource::None);
let scrut = scrutinee.map(|id| &self.thir[id]);
if let LetSource::PlainLet = self.let_source {
self.check_binding_is_irrefutable(pat, "local binding", scrut, Some(span));
} else if let Ok(Irrefutable) = self.is_let_irrefutable(pat, scrut) {
self.lint_single_let(span);
self.lint_single_let(span, else_span);
}
}

Expand Down Expand Up @@ -540,8 +547,15 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
}

#[instrument(level = "trace", skip(self))]
fn lint_single_let(&mut self, let_span: Span) {
report_irrefutable_let_patterns(self.tcx, self.hir_source, self.let_source, 1, let_span);
fn lint_single_let(&mut self, let_span: Span, else_span: Option<Span>) {
report_irrefutable_let_patterns(
self.tcx,
self.hir_source,
self.let_source,
1,
let_span,
else_span,
);
}

fn analyze_binding(
Expand Down Expand Up @@ -836,6 +850,7 @@ fn report_irrefutable_let_patterns(
source: LetSource,
count: usize,
span: Span,
else_span: Option<Span>,
) {
macro_rules! emit_diag {
($lint:tt) => {{
Expand All @@ -847,7 +862,14 @@ fn report_irrefutable_let_patterns(
LetSource::None | LetSource::PlainLet | LetSource::Else => bug!(),
LetSource::IfLet | LetSource::ElseIfLet => emit_diag!(IrrefutableLetPatternsIfLet),
LetSource::IfLetGuard => emit_diag!(IrrefutableLetPatternsIfLetGuard),
LetSource::LetElse => emit_diag!(IrrefutableLetPatternsLetElse),
LetSource::LetElse => {
tcx.emit_node_span_lint(
IRREFUTABLE_LET_PATTERNS,
id,
span,
IrrefutableLetPatternsLetElse { count, else_span },
);
}
LetSource::WhileLet => emit_diag!(IrrefutableLetPatternsWhileLet),
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_errors::{
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg,
Level, Subdiagnostic, SuggestionStyle, msg,
};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
use rustc_span::{Ident, Span, Symbol};
Expand Down Expand Up @@ -4305,7 +4305,7 @@ pub(crate) struct ExpectedRegisterClassOrExplicitRegister {
pub(crate) span: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("unicode codepoint changing visible direction of text present in {$label}")]
#[note(
"these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen"
Expand Down Expand Up @@ -4388,7 +4388,7 @@ impl Subdiagnostic for HiddenUnicodeCodepointsDiagSub {
}
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("missing pattern for `...` argument")]
pub(crate) struct VarargsWithoutPattern {
#[suggestion(
Expand Down
Loading
Loading