Skip to content

Commit 3507a74

Browse files
committed
Auto merge of #145407 - Kobzol:rollup-g6yhx82, r=Kobzol
Rollup of 11 pull requests Successful merges: - #137872 (Include whitespace in "remove |" suggestion and make it hidden) - #144631 (Fix test intrinsic-raw_eq-const-bad for big-endian) - #145233 (cfg_select: Support unbraced expressions) - #145261 (Improve tracing in bootstrap) - #145324 (Rename and document `ONLY_HOSTS` in bootstrap) - #145353 (bootstrap: Fix jemalloc 64K page support for aarch64 tools) - #145379 (bootstrap: Support passing `--timings` to cargo) - #145397 (Rust documentation, use `rustc-dev-guide` :3) - #145398 (Use `default_field_values` in `Resolver`) - #145401 (cleanup: Remove useless `[T].iter().last()`) - #145403 (Adjust error message grammar to be less awkward) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 898aff7 + 0698921 commit 3507a74

File tree

70 files changed

+963
-800
lines changed

Some content is hidden

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

70 files changed

+963
-800
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ fn deny_equality_constraints(
17411741
.map(|segment| segment.ident.name)
17421742
.zip(poly.trait_ref.path.segments.iter().map(|segment| segment.ident.name))
17431743
.all(|(a, b)| a == b)
1744-
&& let Some(potential_assoc) = full_path.segments.iter().last()
1744+
&& let Some(potential_assoc) = full_path.segments.last()
17451745
{
17461746
suggest(poly, potential_assoc, predicate);
17471747
}

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
518518
.with_span_help(
519519
self.get_closure_bound_clause_span(*def_id),
520520
"`Fn` and `FnMut` closures require captured values to be able to be \
521-
consumed multiple times, but an `FnOnce` consume them only once",
521+
consumed multiple times, but `FnOnce` closures may consume them only once",
522522
)
523523
}
524524
_ => {

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11131113
.map(|snippet| {
11141114
debug_assert!(
11151115
!(sp.is_empty() && snippet.is_empty()),
1116-
"Span must not be empty and have no suggestion"
1116+
"Span `{sp:?}` must not be empty and have no suggestion"
11171117
);
11181118
Substitution { parts: vec![SubstitutionPart { snippet, span: sp }] }
11191119
})

compiler/rustc_macros/src/diagnostics/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'ty> FieldInnerTy<'ty> {
146146
};
147147

148148
let path = &ty_path.path;
149-
let ty = path.segments.iter().last().unwrap();
149+
let ty = path.segments.last().unwrap();
150150
let syn::PathArguments::AngleBracketed(bracketed) = &ty.arguments else {
151151
panic!("expected bracketed generic arguments");
152152
};

compiler/rustc_parse/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,8 @@ parse_too_many_hashes = too many `#` symbols: raw strings may be delimited by up
862862
863863
parse_too_short_hex_escape = numeric character escape is too short
864864
865-
parse_trailing_vert_not_allowed = a trailing `|` is not allowed in an or-pattern
866-
.suggestion = remove the `{$token}`
865+
parse_trailing_vert_not_allowed = a trailing `{$token}` is not allowed in an or-pattern
866+
parse_trailing_vert_not_allowed_suggestion = remove the `{$token}`
867867
868868
parse_trait_alias_cannot_be_auto = trait aliases cannot be `auto`
869869
parse_trait_alias_cannot_be_const = trait aliases cannot be `const`

compiler/rustc_parse/src/errors.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,7 +2661,7 @@ pub(crate) enum TopLevelOrPatternNotAllowedSugg {
26612661
parse_sugg_remove_leading_vert_in_pattern,
26622662
code = "",
26632663
applicability = "machine-applicable",
2664-
style = "verbose"
2664+
style = "tool-only"
26652665
)]
26662666
RemoveLeadingVert {
26672667
#[primary_span]
@@ -2694,12 +2694,25 @@ pub(crate) struct UnexpectedVertVertInPattern {
26942694
pub start: Option<Span>,
26952695
}
26962696

2697+
#[derive(Subdiagnostic)]
2698+
#[suggestion(
2699+
parse_trailing_vert_not_allowed,
2700+
code = "",
2701+
applicability = "machine-applicable",
2702+
style = "tool-only"
2703+
)]
2704+
pub(crate) struct TrailingVertSuggestion {
2705+
#[primary_span]
2706+
pub span: Span,
2707+
}
2708+
26972709
#[derive(Diagnostic)]
26982710
#[diag(parse_trailing_vert_not_allowed)]
26992711
pub(crate) struct TrailingVertNotAllowed {
27002712
#[primary_span]
2701-
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
27022713
pub span: Span,
2714+
#[subdiagnostic]
2715+
pub suggestion: TrailingVertSuggestion,
27032716
#[label(parse_label_while_parsing_or_pattern_here)]
27042717
pub start: Option<Span>,
27052718
pub token: Token,

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> {

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ use crate::errors::{
2424
GenericArgsInPatRequireTurbofishSyntax, InclusiveRangeExtraEquals, InclusiveRangeMatchArrow,
2525
InclusiveRangeNoEnd, InvalidMutInPattern, ParenRangeSuggestion, PatternOnWrongSideOfAt,
2626
RemoveLet, RepeatedMutInPattern, SwitchRefBoxOrder, TopLevelOrPatternNotAllowed,
27-
TopLevelOrPatternNotAllowedSugg, TrailingVertNotAllowed, UnexpectedExpressionInPattern,
28-
UnexpectedExpressionInPatternSugg, UnexpectedLifetimeInPattern, UnexpectedParenInRangePat,
29-
UnexpectedParenInRangePatSugg, UnexpectedVertVertBeforeFunctionParam,
30-
UnexpectedVertVertInPattern, WrapInParens,
27+
TopLevelOrPatternNotAllowedSugg, TrailingVertNotAllowed, TrailingVertSuggestion,
28+
UnexpectedExpressionInPattern, UnexpectedExpressionInPatternSugg, UnexpectedLifetimeInPattern,
29+
UnexpectedParenInRangePat, UnexpectedParenInRangePatSugg,
30+
UnexpectedVertVertBeforeFunctionParam, UnexpectedVertVertInPattern, WrapInParens,
3131
};
3232
use crate::parser::expr::{DestructuredFloat, could_be_unclosed_char_literal};
3333
use crate::{exp, maybe_recover_from_interpolated_ty_qpath};
@@ -267,10 +267,9 @@ impl<'a> Parser<'a> {
267267

268268
if let PatKind::Or(pats) = &pat.kind {
269269
let span = pat.span;
270-
let sub = if pats.len() == 1 {
271-
Some(TopLevelOrPatternNotAllowedSugg::RemoveLeadingVert {
272-
span: span.with_hi(span.lo() + BytePos(1)),
273-
})
270+
let sub = if let [_] = &pats[..] {
271+
let span = span.with_hi(span.lo() + BytePos(1));
272+
Some(TopLevelOrPatternNotAllowedSugg::RemoveLeadingVert { span })
274273
} else {
275274
Some(TopLevelOrPatternNotAllowedSugg::WrapInParens {
276275
span,
@@ -362,6 +361,9 @@ impl<'a> Parser<'a> {
362361
self.dcx().emit_err(TrailingVertNotAllowed {
363362
span: self.token.span,
364363
start: lo,
364+
suggestion: TrailingVertSuggestion {
365+
span: self.prev_token.span.shrink_to_hi().with_hi(self.token.span.hi()),
366+
},
365367
token: self.token,
366368
note_double_vert: self.token.kind == token::OrOr,
367369
});

compiler/rustc_resolve/src/lib.rs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![feature(assert_matches)]
1717
#![feature(box_patterns)]
1818
#![feature(decl_macro)]
19+
#![feature(default_field_values)]
1920
#![feature(if_let_guard)]
2021
#![feature(iter_intersperse)]
2122
#![feature(rustc_attrs)]
@@ -1075,7 +1076,7 @@ pub struct Resolver<'ra, 'tcx> {
10751076
/// Assert that we are in speculative resolution mode.
10761077
assert_speculative: bool,
10771078

1078-
prelude: Option<Module<'ra>>,
1079+
prelude: Option<Module<'ra>> = None,
10791080
extern_prelude: FxIndexMap<Macros20NormalizedIdent, ExternPreludeEntry<'ra>>,
10801081

10811082
/// N.B., this is used only for better diagnostics, not name resolution itself.
@@ -1087,10 +1088,10 @@ pub struct Resolver<'ra, 'tcx> {
10871088
field_visibility_spans: FxHashMap<DefId, Vec<Span>>,
10881089

10891090
/// All imports known to succeed or fail.
1090-
determined_imports: Vec<Import<'ra>>,
1091+
determined_imports: Vec<Import<'ra>> = Vec::new(),
10911092

10921093
/// All non-determined imports.
1093-
indeterminate_imports: Vec<Import<'ra>>,
1094+
indeterminate_imports: Vec<Import<'ra>> = Vec::new(),
10941095

10951096
// Spans for local variables found during pattern resolution.
10961097
// Used for suggestions during error reporting.
@@ -1141,19 +1142,19 @@ pub struct Resolver<'ra, 'tcx> {
11411142

11421143
/// Maps glob imports to the names of items actually imported.
11431144
glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
1144-
glob_error: Option<ErrorGuaranteed>,
1145-
visibilities_for_hashing: Vec<(LocalDefId, Visibility)>,
1145+
glob_error: Option<ErrorGuaranteed> = None,
1146+
visibilities_for_hashing: Vec<(LocalDefId, Visibility)> = Vec::new(),
11461147
used_imports: FxHashSet<NodeId>,
11471148
maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
11481149

11491150
/// Privacy errors are delayed until the end in order to deduplicate them.
1150-
privacy_errors: Vec<PrivacyError<'ra>>,
1151+
privacy_errors: Vec<PrivacyError<'ra>> = Vec::new(),
11511152
/// Ambiguity errors are delayed for deduplication.
1152-
ambiguity_errors: Vec<AmbiguityError<'ra>>,
1153+
ambiguity_errors: Vec<AmbiguityError<'ra>> = Vec::new(),
11531154
/// `use` injections are delayed for better placement and deduplication.
1154-
use_injections: Vec<UseError<'tcx>>,
1155+
use_injections: Vec<UseError<'tcx>> = Vec::new(),
11551156
/// Crate-local macro expanded `macro_export` referred to by a module-relative path.
1156-
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)>,
1157+
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)> = BTreeSet::new(),
11571158

11581159
arenas: &'ra ResolverArenas<'ra>,
11591160
dummy_binding: NameBinding<'ra>,
@@ -1205,9 +1206,9 @@ pub struct Resolver<'ra, 'tcx> {
12051206
/// Avoid duplicated errors for "name already defined".
12061207
name_already_seen: FxHashMap<Symbol, Span>,
12071208

1208-
potentially_unused_imports: Vec<Import<'ra>>,
1209+
potentially_unused_imports: Vec<Import<'ra>> = Vec::new(),
12091210

1210-
potentially_unnecessary_qualifications: Vec<UnnecessaryQualification<'ra>>,
1211+
potentially_unnecessary_qualifications: Vec<UnnecessaryQualification<'ra>> = Vec::new(),
12111212

12121213
/// Table for mapping struct IDs into struct constructor IDs,
12131214
/// it's not used during normal resolution, only for better error reporting.
@@ -1216,7 +1217,7 @@ pub struct Resolver<'ra, 'tcx> {
12161217

12171218
lint_buffer: LintBuffer,
12181219

1219-
next_node_id: NodeId,
1220+
next_node_id: NodeId = CRATE_NODE_ID,
12201221

12211222
node_id_to_def_id: NodeMap<Feed<'tcx, LocalDefId>>,
12221223

@@ -1234,17 +1235,17 @@ pub struct Resolver<'ra, 'tcx> {
12341235
item_generics_num_lifetimes: FxHashMap<LocalDefId, usize>,
12351236
delegation_fn_sigs: LocalDefIdMap<DelegationFnSig>,
12361237

1237-
main_def: Option<MainDefinition>,
1238+
main_def: Option<MainDefinition> = None,
12381239
trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
12391240
/// A list of proc macro LocalDefIds, written out in the order in which
12401241
/// they are declared in the static array generated by proc_macro_harness.
1241-
proc_macros: Vec<LocalDefId>,
1242+
proc_macros: Vec<LocalDefId> = Vec::new(),
12421243
confused_type_with_std_module: FxIndexMap<Span, Span>,
12431244
/// Whether lifetime elision was successful.
12441245
lifetime_elision_allowed: FxHashSet<NodeId>,
12451246

12461247
/// Names of items that were stripped out via cfg with their corresponding cfg meta item.
1247-
stripped_cfg_items: Vec<StrippedCfgItem<NodeId>>,
1248+
stripped_cfg_items: Vec<StrippedCfgItem<NodeId>> = Vec::new(),
12481249

12491250
effective_visibilities: EffectiveVisibilities,
12501251
doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
@@ -1558,9 +1559,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15581559
field_defaults: Default::default(),
15591560
field_visibility_spans: FxHashMap::default(),
15601561

1561-
determined_imports: Vec::new(),
1562-
indeterminate_imports: Vec::new(),
1563-
15641562
pat_span_map: Default::default(),
15651563
partial_res_map: Default::default(),
15661564
import_res_map: Default::default(),
@@ -1579,16 +1577,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15791577
ast_transform_scopes: FxHashMap::default(),
15801578

15811579
glob_map: Default::default(),
1582-
glob_error: None,
1583-
visibilities_for_hashing: Default::default(),
15841580
used_imports: FxHashSet::default(),
15851581
maybe_unused_trait_imports: Default::default(),
15861582

1587-
privacy_errors: Vec::new(),
1588-
ambiguity_errors: Vec::new(),
1589-
use_injections: Vec::new(),
1590-
macro_expanded_macro_export_errors: BTreeSet::new(),
1591-
15921583
arenas,
15931584
dummy_binding: arenas.new_pub_res_binding(Res::Err, DUMMY_SP, LocalExpnId::ROOT),
15941585
builtin_types_bindings: PrimTy::ALL
@@ -1632,8 +1623,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16321623
derive_data: Default::default(),
16331624
local_macro_def_scopes: FxHashMap::default(),
16341625
name_already_seen: FxHashMap::default(),
1635-
potentially_unused_imports: Vec::new(),
1636-
potentially_unnecessary_qualifications: Default::default(),
16371626
struct_constructors: Default::default(),
16381627
unused_macros: Default::default(),
16391628
unused_macro_rules: Default::default(),
@@ -1643,16 +1632,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16431632
builtin_attrs: Default::default(),
16441633
containers_deriving_copy: Default::default(),
16451634
lint_buffer: LintBuffer::default(),
1646-
next_node_id: CRATE_NODE_ID,
16471635
node_id_to_def_id,
16481636
disambiguator: DisambiguatorState::new(),
16491637
placeholder_field_indices: Default::default(),
16501638
invocation_parents,
16511639
legacy_const_generic_args: Default::default(),
16521640
item_generics_num_lifetimes: Default::default(),
1653-
main_def: Default::default(),
16541641
trait_impls: Default::default(),
1655-
proc_macros: Default::default(),
16561642
confused_type_with_std_module: Default::default(),
16571643
lifetime_elision_allowed: Default::default(),
16581644
stripped_cfg_items: Default::default(),
@@ -1667,6 +1653,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16671653
current_crate_outer_attr_insert_span,
16681654
mods_with_parse_errors: Default::default(),
16691655
impl_trait_names: Default::default(),
1656+
..
16701657
};
16711658

16721659
let root_parent_scope = ParentScope::module(graph_root, resolver.arenas);

library/core/src/macros/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,14 @@ pub macro assert_matches {
223223
/// }
224224
/// ```
225225
///
226-
/// The `cfg_select!` macro can also be used in expression position:
226+
/// The `cfg_select!` macro can also be used in expression position, with or without braces on the
227+
/// right-hand side:
227228
///
228229
/// ```
229230
/// #![feature(cfg_select)]
230231
///
231232
/// let _some_string = cfg_select! {
232-
/// unix => { "With great power comes great electricity bills" }
233+
/// unix => "With great power comes great electricity bills",
233234
/// _ => { "Behind every successful diet is an unwatched pizza" }
234235
/// };
235236
/// ```

0 commit comments

Comments
 (0)