Skip to content

Commit 40f6691

Browse files
committed
Auto merge of #121259 - GuillaumeGomez:rollup-yiksy0p, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #121067 (make "invalid fragment specifier" translatable) - #121079 (distribute tool documentations and avoid file conflicts on `x install`) - #121230 (Extend Level API) - #121241 (Implement `NonZero` traits generically.) - #121247 (Add help to `hir_analysis_unrecognized_intrinsic_function`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6f72620 + 8030435 commit 40f6691

21 files changed

+307
-226
lines changed

compiler/rustc_expand/messages.ftl

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ expand_invalid_cfg_multiple_predicates = multiple `cfg` predicates are specified
6161
expand_invalid_cfg_no_parens = `cfg` is not followed by parentheses
6262
expand_invalid_cfg_no_predicate = `cfg` predicate is not specified
6363
expand_invalid_cfg_predicate_literal = `cfg` predicate key cannot be a literal
64+
65+
expand_invalid_fragment_specifier =
66+
invalid fragment specifier `{$fragment}`
67+
.help = {$help}
68+
6469
expand_macro_body_stability =
6570
macros cannot have body stability attributes
6671
.label = invalid body stability attribute

compiler/rustc_expand/src/errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,13 @@ pub struct DuplicateMatcherBinding {
408408
#[label(expand_label2)]
409409
pub prev: Span,
410410
}
411+
412+
#[derive(Diagnostic)]
413+
#[diag(expand_invalid_fragment_specifier)]
414+
#[help]
415+
pub struct InvalidFragmentSpecifier {
416+
#[primary_span]
417+
pub span: Span,
418+
pub fragment: Ident,
419+
pub help: String,
420+
}

compiler/rustc_expand/src/mbe/quoted.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::errors;
12
use crate::mbe::macro_parser::count_metavar_decls;
23
use crate::mbe::{Delimited, KleeneOp, KleeneToken, MetaVarExpr, SequenceRepetition, TokenTree};
34

@@ -60,11 +61,11 @@ pub(super) fn parse(
6061
Some(&tokenstream::TokenTree::Token(Token { kind: token::Colon, span }, _)) => {
6162
match trees.next() {
6263
Some(tokenstream::TokenTree::Token(token, _)) => match token.ident() {
63-
Some((frag, _)) => {
64+
Some((fragment, _)) => {
6465
let span = token.span.with_lo(start_sp.lo());
6566

6667
let kind =
67-
token::NonterminalKind::from_symbol(frag.name, || {
68+
token::NonterminalKind::from_symbol(fragment.name, || {
6869
// FIXME(#85708) - once we properly decode a foreign
6970
// crate's `SyntaxContext::root`, then we can replace
7071
// this with just `span.edition()`. A
@@ -81,14 +82,13 @@ pub(super) fn parse(
8182
})
8283
.unwrap_or_else(
8384
|| {
84-
let msg = format!(
85-
"invalid fragment specifier `{}`",
86-
frag.name
85+
sess.dcx().emit_err(
86+
errors::InvalidFragmentSpecifier {
87+
span,
88+
fragment,
89+
help: VALID_FRAGMENT_NAMES_MSG.into(),
90+
},
8791
);
88-
sess.dcx()
89-
.struct_span_err(span, msg)
90-
.with_help(VALID_FRAGMENT_NAMES_MSG)
91-
.emit();
9292
token::NonterminalKind::Ident
9393
},
9494
);

compiler/rustc_hir_analysis/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ hir_analysis_unrecognized_atomic_operation =
469469
hir_analysis_unrecognized_intrinsic_function =
470470
unrecognized intrinsic function: `{$name}`
471471
.label = unrecognized intrinsic
472+
.help = if you're adding an intrinsic, be sure to update `check_intrinsic_type`
472473
473474
hir_analysis_unused_associated_type_bounds =
474475
unnecessary associated type bound for not object safe associated type

compiler/rustc_hir_analysis/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
143143

144144
#[derive(Diagnostic)]
145145
#[diag(hir_analysis_unrecognized_intrinsic_function, code = E0093)]
146+
#[help]
146147
pub struct UnrecognizedIntrinsicFunction {
147148
#[primary_span]
148149
#[label]

compiler/rustc_lint_defs/src/lib.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ impl Level {
227227
}
228228

229229
/// Converts a lower-case string to a level. This will never construct the expect
230-
/// level as that would require a [`LintExpectationId`]
231-
pub fn from_str(x: &str) -> Option<Level> {
230+
/// level as that would require a [`LintExpectationId`].
231+
pub fn from_str(x: &str) -> Option<Self> {
232232
match x {
233233
"allow" => Some(Level::Allow),
234234
"warn" => Some(Level::Warn),
@@ -238,17 +238,21 @@ impl Level {
238238
}
239239
}
240240

241-
/// Converts a symbol to a level.
242-
pub fn from_attr(attr: &Attribute) -> Option<Level> {
243-
match attr.name_or_empty() {
244-
sym::allow => Some(Level::Allow),
245-
sym::expect => Some(Level::Expect(LintExpectationId::Unstable {
246-
attr_id: attr.id,
247-
lint_index: None,
248-
})),
249-
sym::warn => Some(Level::Warn),
250-
sym::deny => Some(Level::Deny),
251-
sym::forbid => Some(Level::Forbid),
241+
/// Converts an `Attribute` to a level.
242+
pub fn from_attr(attr: &Attribute) -> Option<Self> {
243+
Self::from_symbol(attr.name_or_empty(), Some(attr.id))
244+
}
245+
246+
/// Converts a `Symbol` to a level.
247+
pub fn from_symbol(s: Symbol, id: Option<AttrId>) -> Option<Self> {
248+
match (s, id) {
249+
(sym::allow, _) => Some(Level::Allow),
250+
(sym::expect, Some(attr_id)) => {
251+
Some(Level::Expect(LintExpectationId::Unstable { attr_id, lint_index: None }))
252+
}
253+
(sym::warn, _) => Some(Level::Warn),
254+
(sym::deny, _) => Some(Level::Deny),
255+
(sym::forbid, _) => Some(Level::Forbid),
252256
_ => None,
253257
}
254258
}

0 commit comments

Comments
 (0)