Skip to content

Commit 3c5ecc5

Browse files
committed
Auto merge of #145394 - GuillaumeGomez:rollup-wrhcycn, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - #118087 (Add Ref/RefMut try_map method) - #140794 (Add information about group a lint belongs to) - #144947 (Fix description of unsigned `checked_exact_div`) - #145005 (strip prefix of temporary file names when it exceeds filesystem name length limit) - #145233 (cfg_select: Support unbraced expressions) - #145243 (take attr style into account in diagnostics) - #145353 (bootstrap: Fix jemalloc 64K page support for aarch64 tools) - #145379 (bootstrap: Support passing `--timings` to cargo) - #145389 ([rustdoc] Revert "rustdoc search: prefer stable items in search results") Failed merges: - #144983 (Rehome 37 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`) - #145065 (resolve: Introduce `RibKind::Block`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents be00ea1 + d105953 commit 3c5ecc5

File tree

284 files changed

+776
-506
lines changed

Some content is hidden

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

284 files changed

+776
-506
lines changed

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
4747
}
4848
}
4949
ArgParser::NameValue(_) => {
50-
let suggestions =
51-
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "inline");
50+
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
51+
.suggestions(cx.attr_style, "inline");
5252
let span = cx.attr_span;
5353
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
5454
return None;

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
9999
}
100100
}
101101
ArgParser::NameValue(_) => {
102-
let suggestions = MACRO_USE_TEMPLATE.suggestions(false, sym::macro_use);
102+
let suggestions = MACRO_USE_TEMPLATE.suggestions(cx.attr_style, sym::macro_use);
103103
cx.emit_err(session_diagnostics::IllFormedAttributeInputLint {
104104
num_suggestions: suggestions.len(),
105105
suggestions: DiagArgValue::StrListSepByAnd(

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
3535
Some(value_str)
3636
}
3737
ArgParser::List(_) => {
38-
let suggestions =
39-
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "must_use");
38+
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
39+
.suggestions(cx.attr_style, "must_use");
4040
cx.emit_err(session_diagnostics::IllFormedAttributeInputLint {
4141
num_suggestions: suggestions.len(),
4242
suggestions: DiagArgValue::StrListSepByAnd(

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
2626
ArgParser::NameValue(name_value) => {
2727
let Some(str_value) = name_value.value_as_str() else {
2828
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
29-
.suggestions(false, "ignore");
29+
.suggestions(cx.attr_style, "ignore");
3030
let span = cx.attr_span;
3131
cx.emit_lint(
3232
AttributeLintKind::IllFormedAttributeInput { suggestions },
@@ -37,8 +37,8 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
3737
Some(str_value)
3838
}
3939
ArgParser::List(_) => {
40-
let suggestions =
41-
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "ignore");
40+
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
41+
.suggestions(cx.attr_style, "ignore");
4242
let span = cx.attr_span;
4343
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
4444
return None;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::ops::{Deref, DerefMut};
44
use std::sync::LazyLock;
55

66
use private::Sealed;
7-
use rustc_ast::{self as ast, LitKind, MetaItemLit, NodeId};
7+
use rustc_ast::{self as ast, AttrStyle, LitKind, MetaItemLit, NodeId};
88
use rustc_errors::{DiagCtxtHandle, Diagnostic};
99
use rustc_feature::{AttributeTemplate, Features};
1010
use rustc_hir::attrs::AttributeKind;
@@ -305,6 +305,7 @@ pub struct AcceptContext<'f, 'sess, S: Stage> {
305305
/// The span of the attribute currently being parsed
306306
pub(crate) attr_span: Span,
307307

308+
pub(crate) attr_style: AttrStyle,
308309
/// The expected structure of the attribute.
309310
///
310311
/// Used in reporting errors to give a hint to users what the attribute *should* look like.
@@ -386,6 +387,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
386387
i.kind.is_bytestr().then(|| self.sess().source_map().start_point(i.span))
387388
}),
388389
},
390+
attr_style: self.attr_style,
389391
})
390392
}
391393

@@ -396,6 +398,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
396398
template: self.template.clone(),
397399
attribute: self.attr_path.clone(),
398400
reason: AttributeParseErrorReason::ExpectedIntegerLiteral,
401+
attr_style: self.attr_style,
399402
})
400403
}
401404

@@ -406,6 +409,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
406409
template: self.template.clone(),
407410
attribute: self.attr_path.clone(),
408411
reason: AttributeParseErrorReason::ExpectedList,
412+
attr_style: self.attr_style,
409413
})
410414
}
411415

@@ -416,6 +420,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
416420
template: self.template.clone(),
417421
attribute: self.attr_path.clone(),
418422
reason: AttributeParseErrorReason::ExpectedNoArgs,
423+
attr_style: self.attr_style,
419424
})
420425
}
421426

@@ -427,6 +432,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
427432
template: self.template.clone(),
428433
attribute: self.attr_path.clone(),
429434
reason: AttributeParseErrorReason::ExpectedIdentifier,
435+
attr_style: self.attr_style,
430436
})
431437
}
432438

@@ -439,6 +445,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
439445
template: self.template.clone(),
440446
attribute: self.attr_path.clone(),
441447
reason: AttributeParseErrorReason::ExpectedNameValue(name),
448+
attr_style: self.attr_style,
442449
})
443450
}
444451

@@ -450,6 +457,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
450457
template: self.template.clone(),
451458
attribute: self.attr_path.clone(),
452459
reason: AttributeParseErrorReason::DuplicateKey(key),
460+
attr_style: self.attr_style,
453461
})
454462
}
455463

@@ -462,6 +470,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
462470
template: self.template.clone(),
463471
attribute: self.attr_path.clone(),
464472
reason: AttributeParseErrorReason::UnexpectedLiteral,
473+
attr_style: self.attr_style,
465474
})
466475
}
467476

@@ -472,6 +481,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
472481
template: self.template.clone(),
473482
attribute: self.attr_path.clone(),
474483
reason: AttributeParseErrorReason::ExpectedSingleArgument,
484+
attr_style: self.attr_style,
475485
})
476486
}
477487

@@ -482,6 +492,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
482492
template: self.template.clone(),
483493
attribute: self.attr_path.clone(),
484494
reason: AttributeParseErrorReason::ExpectedAtLeastOneArgument,
495+
attr_style: self.attr_style,
485496
})
486497
}
487498

@@ -500,6 +511,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
500511
strings: false,
501512
list: false,
502513
},
514+
attr_style: self.attr_style,
503515
})
504516
}
505517

@@ -518,6 +530,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
518530
strings: false,
519531
list: true,
520532
},
533+
attr_style: self.attr_style,
521534
})
522535
}
523536

@@ -536,6 +549,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
536549
strings: true,
537550
list: false,
538551
},
552+
attr_style: self.attr_style,
539553
})
540554
}
541555

@@ -735,6 +749,7 @@ impl<'sess> AttributeParser<'sess, Early> {
735749
},
736750
},
737751
attr_span: attr.span,
752+
attr_style: attr.style,
738753
template,
739754
attr_path: path.get_attribute_path(),
740755
};
@@ -844,6 +859,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
844859
emit_lint: &mut emit_lint,
845860
},
846861
attr_span: lower_span(attr.span),
862+
attr_style: attr.style,
847863
template: &accept.template,
848864
attr_path: path.get_attribute_path(),
849865
};

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::num::IntErrorKind;
22

3-
use rustc_ast as ast;
3+
use rustc_ast::{self as ast, AttrStyle};
44
use rustc_errors::codes::*;
55
use rustc_errors::{
66
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level,
@@ -556,6 +556,7 @@ pub(crate) enum AttributeParseErrorReason {
556556
pub(crate) struct AttributeParseError {
557557
pub(crate) span: Span,
558558
pub(crate) attr_span: Span,
559+
pub(crate) attr_style: AttrStyle,
559560
pub(crate) template: AttributeTemplate,
560561
pub(crate) attribute: AttrPath,
561562
pub(crate) reason: AttributeParseErrorReason,
@@ -694,7 +695,8 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
694695
if let Some(link) = self.template.docs {
695696
diag.note(format!("for more information, visit <{link}>"));
696697
}
697-
let suggestions = self.template.suggestions(false, &name);
698+
let suggestions = self.template.suggestions(self.attr_style, &name);
699+
698700
diag.span_suggestions(
699701
self.attr_span,
700702
if suggestions.len() == 1 {

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use AttributeDuplicates::*;
66
use AttributeGate::*;
77
use AttributeType::*;
88
use rustc_data_structures::fx::FxHashMap;
9+
use rustc_hir::AttrStyle;
910
use rustc_hir::attrs::EncodeCrossCrate;
1011
use rustc_span::edition::Edition;
1112
use rustc_span::{Symbol, sym};
@@ -132,9 +133,12 @@ pub struct AttributeTemplate {
132133
}
133134

134135
impl AttributeTemplate {
135-
pub fn suggestions(&self, inner: bool, name: impl std::fmt::Display) -> Vec<String> {
136+
pub fn suggestions(&self, style: AttrStyle, name: impl std::fmt::Display) -> Vec<String> {
136137
let mut suggestions = vec![];
137-
let inner = if inner { "!" } else { "" };
138+
let inner = match style {
139+
AttrStyle::Outer => "",
140+
AttrStyle::Inner => "!",
141+
};
138142
if self.word {
139143
suggestions.push(format!("#{inner}[{name}]"));
140144
}

compiler/rustc_lint/src/context.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
2424
use rustc_middle::ty::print::{PrintError, PrintTraitRefExt as _, Printer, with_no_trimmed_paths};
2525
use rustc_middle::ty::{self, GenericArg, RegisteredTools, Ty, TyCtxt, TypingEnv, TypingMode};
2626
use rustc_session::lint::{FutureIncompatibleInfo, Lint, LintBuffer, LintExpectationId, LintId};
27-
use rustc_session::{LintStoreMarker, Session};
27+
use rustc_session::{DynLintStore, Session};
2828
use rustc_span::edit_distance::find_best_match_for_names;
2929
use rustc_span::{Ident, Span, Symbol, sym};
3030
use tracing::debug;
@@ -62,7 +62,13 @@ pub struct LintStore {
6262
lint_groups: FxIndexMap<&'static str, LintGroup>,
6363
}
6464

65-
impl LintStoreMarker for LintStore {}
65+
impl DynLintStore for LintStore {
66+
fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = rustc_session::LintGroup> + '_> {
67+
Box::new(self.get_lint_groups().map(|(name, lints, is_externally_loaded)| {
68+
rustc_session::LintGroup { name, lints, is_externally_loaded }
69+
}))
70+
}
71+
}
6672

6773
/// The target of the `by_name` map, which accounts for renaming/deprecation.
6874
#[derive(Debug)]

compiler/rustc_middle/src/lint.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,28 @@ impl LintExpectation {
211211
}
212212

213213
fn explain_lint_level_source(
214+
sess: &Session,
214215
lint: &'static Lint,
215216
level: Level,
216217
src: LintLevelSource,
217218
err: &mut Diag<'_, ()>,
218219
) {
220+
// Find the name of the lint group that contains the given lint.
221+
// Assumes the lint only belongs to one group.
222+
let lint_group_name = |lint| {
223+
let lint_groups_iter = sess.lint_groups_iter();
224+
let lint_id = LintId::of(lint);
225+
lint_groups_iter
226+
.filter(|lint_group| !lint_group.is_externally_loaded)
227+
.find(|lint_group| {
228+
lint_group
229+
.lints
230+
.iter()
231+
.find(|lint_group_lint| **lint_group_lint == lint_id)
232+
.is_some()
233+
})
234+
.map(|lint_group| lint_group.name)
235+
};
219236
let name = lint.name_lower();
220237
if let Level::Allow = level {
221238
// Do not point at `#[allow(compat_lint)]` as the reason for a compatibility lint
@@ -224,7 +241,15 @@ fn explain_lint_level_source(
224241
}
225242
match src {
226243
LintLevelSource::Default => {
227-
err.note_once(format!("`#[{}({})]` on by default", level.as_str(), name));
244+
let level_str = level.as_str();
245+
match lint_group_name(lint) {
246+
Some(group_name) => {
247+
err.note_once(format!("`#[{level_str}({name})]` (part of `#[{level_str}({group_name})]`) on by default"));
248+
}
249+
None => {
250+
err.note_once(format!("`#[{level_str}({name})]` on by default"));
251+
}
252+
}
228253
}
229254
LintLevelSource::CommandLine(lint_flag_val, orig_level) => {
230255
let flag = orig_level.to_cmd_flag();
@@ -427,7 +452,7 @@ pub fn lint_level(
427452
decorate(&mut err);
428453
}
429454

430-
explain_lint_level_source(lint, level, src, &mut err);
455+
explain_lint_level_source(sess, lint, level, src, &mut err);
431456
err.emit()
432457
}
433458
lint_level_impl(sess, lint, level, span, Box::new(decorate))

compiler/rustc_parse/src/parser/cfg_select.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use rustc_ast::token::Token;
22
use rustc_ast::tokenstream::{TokenStream, TokenTree};
3+
use rustc_ast::util::classify;
34
use rustc_ast::{MetaItemInner, token};
45
use rustc_errors::PResult;
56
use rustc_span::Span;
67

78
use crate::exp;
8-
use crate::parser::Parser;
9+
use crate::parser::{AttrWrapper, ForceCollect, Parser, Restrictions, Trailing, UsePreAttrPos};
910

1011
pub enum CfgSelectPredicate {
1112
Cfg(MetaItemInner),
@@ -23,19 +24,26 @@ pub struct CfgSelectBranches {
2324
pub unreachable: Vec<(CfgSelectPredicate, TokenStream, Span)>,
2425
}
2526

26-
/// Parses a `TokenTree` that must be of the form `{ /* ... */ }`, and returns a `TokenStream` where
27-
/// the surrounding braces are stripped.
27+
/// Parses a `TokenTree` consisting either of `{ /* ... */ }` (and strip the braces) or an
28+
/// expression followed by a comma (and strip the comma).
2829
fn parse_token_tree<'a>(p: &mut Parser<'a>) -> PResult<'a, TokenStream> {
29-
// Generate an error if the `=>` is not followed by `{`.
30-
if p.token != token::OpenBrace {
31-
p.expect(exp!(OpenBrace))?;
30+
if p.token == token::OpenBrace {
31+
// Strip the outer '{' and '}'.
32+
match p.parse_token_tree() {
33+
TokenTree::Token(..) => unreachable!("because of the expect above"),
34+
TokenTree::Delimited(.., tts) => return Ok(tts),
35+
}
3236
}
33-
34-
// Strip the outer '{' and '}'.
35-
match p.parse_token_tree() {
36-
TokenTree::Token(..) => unreachable!("because of the expect above"),
37-
TokenTree::Delimited(.., tts) => Ok(tts),
37+
let expr = p.collect_tokens(None, AttrWrapper::empty(), ForceCollect::Yes, |p, _| {
38+
p.parse_expr_res(Restrictions::STMT_EXPR, AttrWrapper::empty())
39+
.map(|(expr, _)| (expr, Trailing::No, UsePreAttrPos::No))
40+
})?;
41+
if !classify::expr_is_complete(&expr) && p.token != token::CloseBrace && p.token != token::Eof {
42+
p.expect(exp!(Comma))?;
43+
} else {
44+
let _ = p.eat(exp!(Comma));
3845
}
46+
Ok(TokenStream::from_ast(&expr))
3947
}
4048

4149
pub fn parse_cfg_select<'a>(p: &mut Parser<'a>) -> PResult<'a, CfgSelectBranches> {

0 commit comments

Comments
 (0)