Skip to content

Commit 657f246

Browse files
committed
Auto merge of #103344 - Dylan-DPC:rollup-d1rpfvx, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #102287 (Elaborate supertrait bounds when triggering `unused_must_use` on `impl Trait`) - #102922 (Filtering spans when emitting json) - #103051 (translation: doc comments with derives, subdiagnostic-less enum variants, more derive use) - #103111 (Account for hygiene in typo suggestions, and use them to point to shadowed names) - #103260 (Fixup a few tests needing asm support) - #103321 (rustdoc: improve appearance of source page navigation bar) Failed merges: - #103209 (Diagnostic derives: allow specifying multiple alternative suggestions) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0940040 + 325e920 commit 657f246

Some content is hidden

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

55 files changed

+617
-490
lines changed

compiler/rustc_ast_lowering/src/errors.rs

+18-41
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use rustc_errors::{
2-
fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay,
3-
SubdiagnosticMessage,
4-
};
1+
use rustc_errors::DiagnosticArgFromDisplay;
52
use rustc_macros::{Diagnostic, Subdiagnostic};
63
use rustc_span::{symbol::Ident, Span, Symbol};
74

@@ -15,25 +12,15 @@ pub struct GenericTypeWithParentheses {
1512
pub sub: Option<UseAngleBrackets>,
1613
}
1714

18-
#[derive(Clone, Copy)]
15+
#[derive(Clone, Copy, Subdiagnostic)]
16+
#[multipart_suggestion(ast_lowering::use_angle_brackets, applicability = "maybe-incorrect")]
1917
pub struct UseAngleBrackets {
18+
#[suggestion_part(code = "<")]
2019
pub open_param: Span,
20+
#[suggestion_part(code = ">")]
2121
pub close_param: Span,
2222
}
2323

24-
impl AddToDiagnostic for UseAngleBrackets {
25-
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
26-
where
27-
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
28-
{
29-
diag.multipart_suggestion(
30-
fluent::ast_lowering::use_angle_brackets,
31-
vec![(self.open_param, String::from("<")), (self.close_param, String::from(">"))],
32-
Applicability::MaybeIncorrect,
33-
);
34-
}
35-
}
36-
3724
#[derive(Diagnostic)]
3825
#[diag(ast_lowering::invalid_abi, code = "E0703")]
3926
#[note]
@@ -68,30 +55,20 @@ pub struct AssocTyParentheses {
6855
pub sub: AssocTyParenthesesSub,
6956
}
7057

71-
#[derive(Clone, Copy)]
58+
#[derive(Clone, Copy, Subdiagnostic)]
7259
pub enum AssocTyParenthesesSub {
73-
Empty { parentheses_span: Span },
74-
NotEmpty { open_param: Span, close_param: Span },
75-
}
76-
77-
impl AddToDiagnostic for AssocTyParenthesesSub {
78-
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
79-
where
80-
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
81-
{
82-
match self {
83-
Self::Empty { parentheses_span } => diag.multipart_suggestion(
84-
fluent::ast_lowering::remove_parentheses,
85-
vec![(parentheses_span, String::new())],
86-
Applicability::MaybeIncorrect,
87-
),
88-
Self::NotEmpty { open_param, close_param } => diag.multipart_suggestion(
89-
fluent::ast_lowering::use_angle_brackets,
90-
vec![(open_param, String::from("<")), (close_param, String::from(">"))],
91-
Applicability::MaybeIncorrect,
92-
),
93-
};
94-
}
60+
#[multipart_suggestion(ast_lowering::remove_parentheses)]
61+
Empty {
62+
#[suggestion_part(code = "")]
63+
parentheses_span: Span,
64+
},
65+
#[multipart_suggestion(ast_lowering::use_angle_brackets)]
66+
NotEmpty {
67+
#[suggestion_part(code = "<")]
68+
open_param: Span,
69+
#[suggestion_part(code = ">")]
70+
close_param: Span,
71+
},
9572
}
9673

9774
#[derive(Diagnostic)]

compiler/rustc_ast_passes/src/ast_validation.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_ast::*;
1414
use rustc_ast_pretty::pprust::{self, State};
1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_errors::{error_code, fluent, pluralize, struct_span_err, Applicability};
17+
use rustc_macros::Subdiagnostic;
1718
use rustc_parse::validate_attr;
1819
use rustc_session::lint::builtin::{
1920
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, PATTERNS_IN_FNS_WITHOUT_BODY,
@@ -1805,15 +1806,17 @@ pub fn check_crate(session: &Session, krate: &Crate, lints: &mut LintBuffer) ->
18051806
}
18061807

18071808
/// Used to forbid `let` expressions in certain syntactic locations.
1808-
#[derive(Clone, Copy)]
1809+
#[derive(Clone, Copy, Subdiagnostic)]
18091810
pub(crate) enum ForbiddenLetReason {
18101811
/// `let` is not valid and the source environment is not important
18111812
GenericForbidden,
18121813
/// A let chain with the `||` operator
1813-
NotSupportedOr(Span),
1814+
#[note(ast_passes::not_supported_or)]
1815+
NotSupportedOr(#[primary_span] Span),
18141816
/// A let chain with invalid parentheses
18151817
///
18161818
/// For example, `let 1 = 1 && (expr && expr)` is allowed
18171819
/// but `(let 1 = 1 && (let 1 = 1 && (let 1 = 1))) && let a = 1` is not
1818-
NotSupportedParentheses(Span),
1820+
#[note(ast_passes::not_supported_parentheses)]
1821+
NotSupportedParentheses(#[primary_span] Span),
18191822
}

compiler/rustc_ast_passes/src/errors.rs

-17
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@ pub struct ForbiddenLet {
1616
pub(crate) reason: ForbiddenLetReason,
1717
}
1818

19-
impl AddToDiagnostic for ForbiddenLetReason {
20-
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
21-
where
22-
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
23-
{
24-
match self {
25-
Self::GenericForbidden => {}
26-
Self::NotSupportedOr(span) => {
27-
diag.span_note(span, fluent::ast_passes::not_supported_or);
28-
}
29-
Self::NotSupportedParentheses(span) => {
30-
diag.span_note(span, fluent::ast_passes::not_supported_parentheses);
31-
}
32-
}
33-
}
34-
}
35-
3619
#[derive(Diagnostic)]
3720
#[diag(ast_passes::forbidden_let_stable)]
3821
#[note]

compiler/rustc_error_messages/locales/en-US/infer.ftl

+3-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ infer_region_explanation = {$pref_kind ->
164164
}
165165
166166
infer_mismatched_static_lifetime = incompatible lifetime on type
167-
infer_msl_impl_note = ...does not necessarily outlive the static lifetime introduced by the compatible `impl`
167+
infer_does_not_outlive_static_from_impl = ...does not necessarily outlive the static lifetime introduced by the compatible `impl`
168+
infer_implicit_static_lifetime_note = this has an implicit `'static` lifetime requirement
169+
infer_implicit_static_lifetime_suggestion = consider relaxing the implicit `'static` requirement
168170
infer_msl_introduces_static = introduces a `'static` lifetime requirement
169171
infer_msl_unmet_req = because this has an unmet lifetime requirement
170172
infer_msl_trait_note = this has an implicit `'static` lifetime requirement

compiler/rustc_error_messages/locales/en-US/session.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ session_crate_name_empty = crate name must not be empty
5454
session_invalid_character_in_create_name = invalid character `{$character}` in crate name: `{$crate_name}`
5555
5656
session_expr_parentheses_needed = parentheses are required to parse this as an expression
57+
58+
session_skipping_const_checks = skipping const checks
59+
session_unleashed_feature_help_named = skipping check for `{$gate}` feature
60+
session_unleashed_feature_help_unnamed = skipping check that does not even have a feature gate

compiler/rustc_errors/src/diagnostic.rs

+25
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,11 @@ impl Diagnostic {
567567
style: SuggestionStyle,
568568
) -> &mut Self {
569569
assert!(!suggestion.is_empty());
570+
debug_assert!(
571+
!(suggestion.iter().any(|(sp, text)| sp.is_empty() && text.is_empty())),
572+
"Span must not be empty and have no suggestion"
573+
);
574+
570575
self.push_suggestion(CodeSuggestion {
571576
substitutions: vec![Substitution {
572577
parts: suggestion
@@ -644,6 +649,10 @@ impl Diagnostic {
644649
applicability: Applicability,
645650
style: SuggestionStyle,
646651
) -> &mut Self {
652+
debug_assert!(
653+
!(sp.is_empty() && suggestion.to_string().is_empty()),
654+
"Span must not be empty and have no suggestion"
655+
);
647656
self.push_suggestion(CodeSuggestion {
648657
substitutions: vec![Substitution {
649658
parts: vec![SubstitutionPart { snippet: suggestion.to_string(), span: sp }],
@@ -684,6 +693,12 @@ impl Diagnostic {
684693
) -> &mut Self {
685694
let mut suggestions: Vec<_> = suggestions.collect();
686695
suggestions.sort();
696+
697+
debug_assert!(
698+
!(sp.is_empty() && suggestions.iter().any(|suggestion| suggestion.is_empty())),
699+
"Span must not be empty and have no suggestion"
700+
);
701+
687702
let substitutions = suggestions
688703
.into_iter()
689704
.map(|snippet| Substitution { parts: vec![SubstitutionPart { snippet, span: sp }] })
@@ -705,8 +720,18 @@ impl Diagnostic {
705720
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
706721
applicability: Applicability,
707722
) -> &mut Self {
723+
let suggestions: Vec<_> = suggestions.collect();
724+
debug_assert!(
725+
!(suggestions
726+
.iter()
727+
.flat_map(|suggs| suggs)
728+
.any(|(sp, suggestion)| sp.is_empty() && suggestion.is_empty())),
729+
"Span must not be empty and have no suggestion"
730+
);
731+
708732
self.push_suggestion(CodeSuggestion {
709733
substitutions: suggestions
734+
.into_iter()
710735
.map(|sugg| Substitution {
711736
parts: sugg
712737
.into_iter()

compiler/rustc_errors/src/diagnostic_impls.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use crate::{
22
fluent, DiagnosticArgValue, DiagnosticBuilder, Handler, IntoDiagnostic, IntoDiagnosticArg,
33
};
4-
use rustc_target::abi::TargetDataLayoutErrors;
5-
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
6-
74
use rustc_ast as ast;
85
use rustc_ast_pretty::pprust;
96
use rustc_hir as hir;
7+
use rustc_lint_defs::Level;
108
use rustc_span::edition::Edition;
119
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
10+
use rustc_target::abi::TargetDataLayoutErrors;
11+
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
1212
use std::borrow::Cow;
1313
use std::fmt;
1414
use std::num::ParseIntError;
@@ -155,6 +155,21 @@ impl IntoDiagnosticArg for ast::token::TokenKind {
155155
}
156156
}
157157

158+
impl IntoDiagnosticArg for Level {
159+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
160+
DiagnosticArgValue::Str(Cow::Borrowed(match self {
161+
Level::Allow => "-A",
162+
Level::Warn => "-W",
163+
Level::ForceWarn(_) => "--force-warn",
164+
Level::Deny => "-D",
165+
Level::Forbid => "-F",
166+
Level::Expect(_) => {
167+
unreachable!("lints with the level of `expect` should not run this code");
168+
}
169+
}))
170+
}
171+
}
172+
158173
impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
159174
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
160175
let mut diag;

compiler/rustc_expand/src/base.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_span::edition::Edition;
2222
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
2323
use rustc_span::source_map::SourceMap;
2424
use rustc_span::symbol::{kw, sym, Ident, Symbol};
25-
use rustc_span::{FileName, Span, DUMMY_SP};
25+
use rustc_span::{BytePos, FileName, Span, DUMMY_SP};
2626
use smallvec::{smallvec, SmallVec};
2727

2828
use std::default::Default;
@@ -1228,8 +1228,9 @@ pub fn expr_to_spanned_string<'a>(
12281228
ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)),
12291229
ast::LitKind::ByteStr(_) => {
12301230
let mut err = cx.struct_span_err(l.span, err_msg);
1231+
let span = expr.span.shrink_to_lo();
12311232
err.span_suggestion(
1232-
expr.span.shrink_to_lo(),
1233+
span.with_hi(span.lo() + BytePos(1)),
12331234
"consider removing the leading `b`",
12341235
"",
12351236
Applicability::MaybeIncorrect,

compiler/rustc_hir_analysis/src/astconv/mod.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -3051,24 +3051,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
30513051
.map_or(false, |s| s.trim_end().ends_with('<'));
30523052

30533053
let is_global = poly_trait_ref.trait_ref.path.is_global();
3054-
let sugg = Vec::from_iter([
3055-
(
3056-
self_ty.span.shrink_to_lo(),
3057-
format!(
3058-
"{}dyn {}",
3059-
if needs_bracket { "<" } else { "" },
3060-
if is_global { "(" } else { "" },
3061-
),
3054+
3055+
let mut sugg = Vec::from_iter([(
3056+
self_ty.span.shrink_to_lo(),
3057+
format!(
3058+
"{}dyn {}",
3059+
if needs_bracket { "<" } else { "" },
3060+
if is_global { "(" } else { "" },
30623061
),
3063-
(
3062+
)]);
3063+
3064+
if is_global || needs_bracket {
3065+
sugg.push((
30643066
self_ty.span.shrink_to_hi(),
30653067
format!(
30663068
"{}{}",
30673069
if is_global { ")" } else { "" },
30683070
if needs_bracket { ">" } else { "" },
30693071
),
3070-
),
3071-
]);
3072+
));
3073+
}
3074+
30723075
if self_ty.span.edition() >= Edition::Edition2021 {
30733076
let msg = "trait objects must include the `dyn` keyword";
30743077
let label = "add `dyn` keyword before this trait";

compiler/rustc_infer/src/errors/mod.rs

+29-42
Original file line numberDiff line numberDiff line change
@@ -459,47 +459,34 @@ impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
459459
}
460460
}
461461

462-
pub struct ImplNote {
463-
pub impl_span: Option<Span>,
464-
}
465-
466-
impl AddToDiagnostic for ImplNote {
467-
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
468-
where
469-
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
470-
{
471-
match self.impl_span {
472-
Some(span) => diag.span_note(span, fluent::infer::msl_impl_note),
473-
None => diag.note(fluent::infer::msl_impl_note),
474-
};
475-
}
476-
}
477-
478-
pub enum TraitSubdiag {
479-
Note { span: Span },
480-
Sugg { span: Span },
462+
// FIXME(#100717): replace with a `Option<Span>` when subdiagnostic supports that
463+
#[derive(Subdiagnostic)]
464+
pub enum DoesNotOutliveStaticFromImpl {
465+
#[note(infer::does_not_outlive_static_from_impl)]
466+
Spanned {
467+
#[primary_span]
468+
span: Span,
469+
},
470+
#[note(infer::does_not_outlive_static_from_impl)]
471+
Unspanned,
481472
}
482473

483-
// FIXME(#100717) used in `Vec<TraitSubdiag>` so requires eager translation/list support
484-
impl AddToDiagnostic for TraitSubdiag {
485-
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
486-
where
487-
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
488-
{
489-
match self {
490-
TraitSubdiag::Note { span } => {
491-
diag.span_note(span, "this has an implicit `'static` lifetime requirement");
492-
}
493-
TraitSubdiag::Sugg { span } => {
494-
diag.span_suggestion_verbose(
495-
span,
496-
"consider relaxing the implicit `'static` requirement",
497-
" + '_".to_owned(),
498-
rustc_errors::Applicability::MaybeIncorrect,
499-
);
500-
}
501-
}
502-
}
474+
#[derive(Subdiagnostic)]
475+
pub enum ImplicitStaticLifetimeSubdiag {
476+
#[note(infer::implicit_static_lifetime_note)]
477+
Note {
478+
#[primary_span]
479+
span: Span,
480+
},
481+
#[suggestion_verbose(
482+
infer::implicit_static_lifetime_suggestion,
483+
code = " + '_",
484+
applicability = "maybe-incorrect"
485+
)]
486+
Sugg {
487+
#[primary_span]
488+
span: Span,
489+
},
503490
}
504491

505492
#[derive(Diagnostic)]
@@ -512,7 +499,7 @@ pub struct MismatchedStaticLifetime<'a> {
512499
#[subdiagnostic]
513500
pub expl: Option<note_and_explain::RegionExplanation<'a>>,
514501
#[subdiagnostic]
515-
pub impl_note: ImplNote,
516-
#[subdiagnostic]
517-
pub trait_subdiags: Vec<TraitSubdiag>,
502+
pub does_not_outlive_static_from_impl: DoesNotOutliveStaticFromImpl,
503+
#[subdiagnostic(eager)]
504+
pub implicit_static_lifetimes: Vec<ImplicitStaticLifetimeSubdiag>,
518505
}

0 commit comments

Comments
 (0)