Skip to content

Commit d933cf4

Browse files
committed
Auto merge of rust-lang#153377 - Zalathar:rollup-cWj10b1, r=Zalathar
Rollup of 8 pull requests Successful merges: - rust-lang#153280 (Add regression test for `doc(fake_variadic)` on reexports) - rust-lang#153302 (x86: reserve `bl` and `bh` registers to match `rbx`) - rust-lang#153358 (Boundary tests for various Duration-float operations) - rust-lang#153048 (Improve irrefutable let-else lint wording) - rust-lang#153258 (diag: Suppress `.clone()` suggestion inside derive macro expansions) - rust-lang#153272 (Add `Path::absolute` method as alias for `std::path::absolute`) - rust-lang#153295 (update panicking() docs for panic=abort) - rust-lang#153352 (Migration of `LintDiagnostic` - part 6)
2 parents d956393 + c4f239e commit d933cf4

73 files changed

Lines changed: 677 additions & 394 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_abi::ExternAbi;
44
use rustc_ast::ParamKindOrd;
55
use rustc_errors::codes::*;
66
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
7-
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
7+
use rustc_macros::{Diagnostic, Subdiagnostic};
88
use rustc_span::{Ident, Span, Symbol};
99

1010
#[derive(Diagnostic)]
@@ -671,7 +671,7 @@ pub(crate) struct MissingUnsafeOnExtern {
671671
pub span: Span,
672672
}
673673

674-
#[derive(LintDiagnostic)]
674+
#[derive(Diagnostic)]
675675
#[diag("extern blocks should be unsafe")]
676676
pub(crate) struct MissingUnsafeOnExternLint {
677677
#[suggestion(
@@ -1027,7 +1027,7 @@ pub(crate) struct MissingAbi {
10271027
pub span: Span,
10281028
}
10291029

1030-
#[derive(LintDiagnostic)]
1030+
#[derive(Diagnostic)]
10311031
#[diag("`extern` declarations without an explicit ABI are deprecated")]
10321032
pub(crate) struct MissingAbiSugg {
10331033
#[suggestion(

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_middle::ty::{
2828
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
2929
use rustc_span::def_id::{DefId, LocalDefId};
3030
use rustc_span::hygiene::DesugaringKind;
31-
use rustc_span::{BytePos, Ident, Span, Symbol, kw, sym};
31+
use rustc_span::{BytePos, ExpnKind, Ident, MacroKind, Span, Symbol, kw, sym};
3232
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
3333
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
3434
use rustc_trait_selection::error_reporting::traits::call_kind::CallKind;
@@ -1438,6 +1438,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
14381438
expr: &hir::Expr<'_>,
14391439
) -> bool {
14401440
let tcx = self.infcx.tcx;
1441+
1442+
// Don't suggest `.clone()` in a derive macro expansion.
1443+
if let ExpnKind::Macro(MacroKind::Derive, _) = self.body.span.ctxt().outer_expn_data().kind
1444+
{
1445+
return false;
1446+
}
14411447
if let Some(_) = self.clone_on_reference(expr) {
14421448
// Avoid redundant clone suggestion already suggested in `explain_captures`.
14431449
// See `tests/ui/moves/needs-clone-through-deref.rs`

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ use rustc_errors::{
33
Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans,
44
Subdiagnostic, msg,
55
};
6-
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
6+
use rustc_macros::{Diagnostic, Subdiagnostic};
77
use rustc_span::{Ident, Span, Symbol};
88

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

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

17-
#[derive(LintDiagnostic)]
17+
#[derive(Diagnostic)]
1818
#[diag("include macro expected single expression in source")]
1919
pub(crate) struct IncompleteInclude;
2020

21-
#[derive(LintDiagnostic)]
21+
#[derive(Diagnostic)]
2222
#[diag("cannot test inner items")]
2323
pub(crate) struct UnnameableTestItems;
2424

25-
#[derive(LintDiagnostic)]
25+
#[derive(Diagnostic)]
2626
#[diag("duplicated attribute")]
2727
pub(crate) struct DuplicateMacroAttribute;
2828

compiler/rustc_errors/src/decorate_diag.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
/// This module provides types and traits for buffering lints until later in compilation.
22
use rustc_ast::node_id::NodeId;
33
use rustc_data_structures::fx::FxIndexMap;
4+
use rustc_data_structures::sync::DynSend;
45
use rustc_error_messages::MultiSpan;
56
use rustc_lint_defs::{BuiltinLintDiag, Lint, LintId};
67

7-
use crate::{DynSend, LintDiagnostic, LintDiagnosticBox};
8+
use crate::{Diag, DiagCtxtHandle, Diagnostic, Level};
89

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

@@ -19,12 +20,10 @@ impl std::fmt::Debug for DecorateDiagCompat {
1920
}
2021
}
2122

22-
impl !LintDiagnostic<'_, ()> for BuiltinLintDiag {}
23-
24-
impl<D: for<'a> LintDiagnostic<'a, ()> + DynSend + 'static> From<D> for DecorateDiagCompat {
23+
impl<D: for<'a> Diagnostic<'a, ()> + DynSend + 'static> From<D> for DecorateDiagCompat {
2524
#[inline]
2625
fn from(d: D) -> Self {
27-
Self::Dynamic(Box::new(d))
26+
Self::Dynamic(Box::new(|dcx, level| d.into_diag(dcx, level)))
2827
}
2928
}
3029

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::panic;
77
use std::path::PathBuf;
88
use std::thread::panicking;
99

10+
use rustc_data_structures::sync::DynSend;
1011
use rustc_error_messages::{DiagArgMap, DiagArgName, DiagArgValue, IntoDiagArg};
1112
use rustc_lint_defs::{Applicability, LintExpectationId};
1213
use rustc_macros::{Decodable, Encodable};
@@ -118,6 +119,14 @@ where
118119
}
119120
}
120121

122+
impl<'a> Diagnostic<'a, ()>
123+
for Box<dyn for<'b> FnOnce(DiagCtxtHandle<'b>, Level) -> Diag<'b, ()> + DynSend + 'static>
124+
{
125+
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
126+
self(dcx, level)
127+
}
128+
}
129+
121130
/// Trait implemented by error types. This should not be implemented manually. Instead, use
122131
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
123132
#[rustc_diagnostic_item = "Subdiagnostic"]
@@ -137,16 +146,6 @@ pub trait LintDiagnostic<'a, G: EmissionGuarantee> {
137146
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>);
138147
}
139148

140-
pub trait LintDiagnosticBox<'a, G: EmissionGuarantee> {
141-
fn decorate_lint_box<'b>(self: Box<Self>, diag: &'b mut Diag<'a, G>);
142-
}
143-
144-
impl<'a, G: EmissionGuarantee, D: LintDiagnostic<'a, G>> LintDiagnosticBox<'a, G> for D {
145-
fn decorate_lint_box<'b>(self: Box<Self>, diag: &'b mut Diag<'a, G>) {
146-
self.decorate_lint(diag);
147-
}
148-
}
149-
150149
#[derive(Clone, Debug, Encodable, Decodable)]
151150
pub(crate) struct DiagLocation {
152151
file: Cow<'static, str>,

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub use codes::*;
4040
pub use decorate_diag::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer};
4141
pub use diagnostic::{
4242
BugAbort, Diag, DiagInner, DiagStyledString, Diagnostic, EmissionGuarantee, FatalAbort,
43-
LintDiagnostic, LintDiagnosticBox, StringPart, Subdiag, Subdiagnostic,
43+
LintDiagnostic, StringPart, Subdiag, Subdiagnostic,
4444
};
4545
pub use diagnostic_impls::{
4646
DiagSymbolList, ElidedLifetimeInPathSubdiag, ExpectedLifetimeParameter,

compiler/rustc_expand/src/errors.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::borrow::Cow;
33
use rustc_ast::ast;
44
use rustc_errors::codes::*;
55
use rustc_hir::limit::Limit;
6-
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
6+
use rustc_macros::{Diagnostic, Subdiagnostic};
77
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol};
88

9-
#[derive(LintDiagnostic)]
9+
#[derive(Diagnostic)]
1010
#[diag("`#[cfg_attr]` does not expand to any attributes")]
1111
pub(crate) struct CfgAttrNoAttributes;
1212

@@ -94,15 +94,15 @@ pub(crate) struct MacroVarStillRepeating {
9494
pub ident: MacroRulesNormalizedIdent,
9595
}
9696

97-
#[derive(LintDiagnostic)]
97+
#[derive(Diagnostic)]
9898
#[diag("variable `{$ident}` is still repeating at this depth")]
9999
pub(crate) struct MetaVarStillRepeatingLint {
100100
#[label("expected repetition")]
101101
pub label: Span,
102102
pub ident: MacroRulesNormalizedIdent,
103103
}
104104

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

122-
#[derive(LintDiagnostic)]
122+
#[derive(Diagnostic)]
123123
#[diag("unknown macro variable `{$name}`")]
124124
pub(crate) struct UnknownMacroVariable {
125125
pub name: MacroRulesNormalizedIdent,
@@ -391,7 +391,7 @@ pub(crate) struct DuplicateMatcherBinding {
391391
pub prev: Span,
392392
}
393393

394-
#[derive(LintDiagnostic)]
394+
#[derive(Diagnostic)]
395395
#[diag("duplicate matcher binding")]
396396
pub(crate) struct DuplicateMatcherBindingLint {
397397
#[label("duplicate binding")]
@@ -569,7 +569,7 @@ pub(crate) struct MacroArgsBadDelimSugg {
569569
pub close: Span,
570570
}
571571

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

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

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

607-
#[derive(LintDiagnostic)]
607+
#[derive(Diagnostic)]
608608
#[diag("unused attribute `{$attr_name}`")]
609609
pub(crate) struct UnusedBuiltinAttribute {
610610
#[note(

compiler/rustc_lint/src/early.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
5050
);
5151
}
5252
DecorateDiagCompat::Dynamic(d) => {
53-
self.context
54-
.opt_span_lint(lint_id.lint, span, |diag| d.decorate_lint_box(diag));
53+
self.context.opt_span_diag_lint(lint_id.lint, span, d);
5554
}
5655
}
5756
}

compiler/rustc_mir_build/src/errors.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -932,13 +932,14 @@ pub(crate) struct IrrefutableLetPatternsIfLetGuard {
932932
)]
933933
#[note(
934934
"{$count ->
935-
[one] this pattern
936-
*[other] these patterns
937-
} will always match, so the `else` clause is useless"
935+
[one] this pattern always matches, so the else clause is unreachable
936+
*[other] these patterns always match, so the else clause is unreachable
937+
}"
938938
)]
939-
#[help("consider removing the `else` clause")]
940939
pub(crate) struct IrrefutableLetPatternsLetElse {
941940
pub(crate) count: usize,
941+
#[help("remove this `else` block")]
942+
pub(crate) else_span: Option<Span>,
942943
}
943944

944945
#[derive(Diagnostic)]

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> {
160160
self.check_match(scrutinee, arms, MatchSource::Normal, span);
161161
}
162162
ExprKind::Let { box ref pat, expr } => {
163-
self.check_let(pat, Some(expr), ex.span);
163+
self.check_let(pat, Some(expr), ex.span, None);
164164
}
165165
ExprKind::LogicalOp { op: LogicalOp::And, .. }
166166
if !matches!(self.let_source, LetSource::None) =>
@@ -169,7 +169,7 @@ impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> {
169169
let Ok(()) = self.visit_land(ex, &mut chain_refutabilities) else { return };
170170
// Lint only single irrefutable let binding.
171171
if let [Some((_, Irrefutable))] = chain_refutabilities[..] {
172-
self.lint_single_let(ex.span);
172+
self.lint_single_let(ex.span, None);
173173
}
174174
return;
175175
}
@@ -184,8 +184,9 @@ impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> {
184184
self.with_hir_source(hir_id, |this| {
185185
let let_source =
186186
if else_block.is_some() { LetSource::LetElse } else { LetSource::PlainLet };
187+
let else_span = else_block.map(|bid| this.thir.blocks[bid].span);
187188
this.with_let_source(let_source, |this| {
188-
this.check_let(pattern, initializer, span)
189+
this.check_let(pattern, initializer, span, else_span)
189190
});
190191
visit::walk_stmt(this, stmt);
191192
});
@@ -426,13 +427,19 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
426427
}
427428

428429
#[instrument(level = "trace", skip(self))]
429-
fn check_let(&mut self, pat: &'p Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
430+
fn check_let(
431+
&mut self,
432+
pat: &'p Pat<'tcx>,
433+
scrutinee: Option<ExprId>,
434+
span: Span,
435+
else_span: Option<Span>,
436+
) {
430437
assert!(self.let_source != LetSource::None);
431438
let scrut = scrutinee.map(|id| &self.thir[id]);
432439
if let LetSource::PlainLet = self.let_source {
433440
self.check_binding_is_irrefutable(pat, "local binding", scrut, Some(span));
434441
} else if let Ok(Irrefutable) = self.is_let_irrefutable(pat, scrut) {
435-
self.lint_single_let(span);
442+
self.lint_single_let(span, else_span);
436443
}
437444
}
438445

@@ -540,8 +547,15 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
540547
}
541548

542549
#[instrument(level = "trace", skip(self))]
543-
fn lint_single_let(&mut self, let_span: Span) {
544-
report_irrefutable_let_patterns(self.tcx, self.hir_source, self.let_source, 1, let_span);
550+
fn lint_single_let(&mut self, let_span: Span, else_span: Option<Span>) {
551+
report_irrefutable_let_patterns(
552+
self.tcx,
553+
self.hir_source,
554+
self.let_source,
555+
1,
556+
let_span,
557+
else_span,
558+
);
545559
}
546560

547561
fn analyze_binding(
@@ -836,6 +850,7 @@ fn report_irrefutable_let_patterns(
836850
source: LetSource,
837851
count: usize,
838852
span: Span,
853+
else_span: Option<Span>,
839854
) {
840855
macro_rules! emit_diag {
841856
($lint:tt) => {{
@@ -847,7 +862,14 @@ fn report_irrefutable_let_patterns(
847862
LetSource::None | LetSource::PlainLet | LetSource::Else => bug!(),
848863
LetSource::IfLet | LetSource::ElseIfLet => emit_diag!(IrrefutableLetPatternsIfLet),
849864
LetSource::IfLetGuard => emit_diag!(IrrefutableLetPatternsIfLetGuard),
850-
LetSource::LetElse => emit_diag!(IrrefutableLetPatternsLetElse),
865+
LetSource::LetElse => {
866+
tcx.emit_node_span_lint(
867+
IRREFUTABLE_LET_PATTERNS,
868+
id,
869+
span,
870+
IrrefutableLetPatternsLetElse { count, else_span },
871+
);
872+
}
851873
LetSource::WhileLet => emit_diag!(IrrefutableLetPatternsWhileLet),
852874
}
853875
}

0 commit comments

Comments
 (0)