Skip to content

Commit 3f391b8

Browse files
committed
Auto merge of rust-lang#96087 - Dylan-DPC:rollup-k6yzk55, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - rust-lang#94457 (Stabilize `derive_default_enum`) - rust-lang#94461 (Create (unstable) 2024 edition) - rust-lang#94849 (Check var scope if it exist) - rust-lang#95194 (remove find_use_placement) - rust-lang#95749 (only downgrade selection Error -> Ambiguous if type error is in predicate) - rust-lang#96026 (couple of clippy::complexity fixes) - rust-lang#96027 (remove function parameters only used in recursion) - rust-lang#96034 ([test] Add test cases of untested functions for BTreeSet ) - rust-lang#96040 (Use u32 instead of i32 for futexes.) - rust-lang#96062 (docs: Update tests chapter for Termination stabilization) - rust-lang#96065 (Refactor: Use `format-args-capture` and remove unnecessary nested blocks in rustc_typeck) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1e6fe58 + fa281fd commit 3f391b8

File tree

94 files changed

+1020
-1064
lines changed

Some content is hidden

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

94 files changed

+1020
-1064
lines changed

compiler/rustc_ast/src/token.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ impl NonterminalKind {
722722
Edition::Edition2015 | Edition::Edition2018 => {
723723
NonterminalKind::PatParam { inferred: true }
724724
}
725-
Edition::Edition2021 => NonterminalKind::PatWithOr,
725+
Edition::Edition2021 | Edition::Edition2024 => NonterminalKind::PatWithOr,
726726
},
727727
sym::pat_param => NonterminalKind::PatParam { inferred: false },
728728
sym::expr => NonterminalKind::Expr,

compiler/rustc_ast_lowering/src/index.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ pub(super) fn index_hir<'hir>(
5252
};
5353

5454
match item {
55-
OwnerNode::Crate(citem) => collector.visit_mod(&citem, citem.inner, hir::CRATE_HIR_ID),
55+
OwnerNode::Crate(citem) => {
56+
collector.visit_mod(&citem, citem.spans.inner_span, hir::CRATE_HIR_ID)
57+
}
5658
OwnerNode::Item(item) => collector.visit_item(item),
5759
OwnerNode::TraitItem(item) => collector.visit_trait_item(item),
5860
OwnerNode::ImplItem(item) => collector.visit_impl_item(item),

compiler/rustc_ast_lowering/src/item.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
124124
debug_assert_eq!(self.resolver.local_def_id(CRATE_NODE_ID), CRATE_DEF_ID);
125125

126126
self.with_lctx(CRATE_NODE_ID, |lctx| {
127-
let module = lctx.lower_mod(&c.items, c.spans.inner_span);
127+
let module = lctx.lower_mod(&c.items, &c.spans);
128128
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
129129
hir::OwnerNode::Crate(lctx.arena.alloc(module))
130130
})
@@ -186,9 +186,12 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
186186
}
187187

188188
impl<'hir> LoweringContext<'_, 'hir> {
189-
pub(super) fn lower_mod(&mut self, items: &[P<Item>], inner: Span) -> hir::Mod<'hir> {
189+
pub(super) fn lower_mod(&mut self, items: &[P<Item>], spans: &ModSpans) -> hir::Mod<'hir> {
190190
hir::Mod {
191-
inner: self.lower_span(inner),
191+
spans: hir::ModSpans {
192+
inner_span: self.lower_span(spans.inner_span),
193+
inject_use_span: self.lower_span(spans.inject_use_span),
194+
},
192195
item_ids: self.arena.alloc_from_iter(items.iter().flat_map(|x| self.lower_item_ref(x))),
193196
}
194197
}
@@ -308,8 +311,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
308311
})
309312
}
310313
ItemKind::Mod(_, ref mod_kind) => match mod_kind {
311-
ModKind::Loaded(items, _, ModSpans { inner_span, inject_use_span: _ }) => {
312-
hir::ItemKind::Mod(self.lower_mod(items, *inner_span))
314+
ModKind::Loaded(items, _, spans) => {
315+
hir::ItemKind::Mod(self.lower_mod(items, spans))
313316
}
314317
ModKind::Unloaded => panic!("`mod` items should have been loaded by now"),
315318
},

compiler/rustc_builtin_macros/src/deriving/default.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,7 @@ pub fn expand_deriving_default(
4646
StaticStruct(_, fields) => {
4747
default_struct_substructure(cx, trait_span, substr, fields)
4848
}
49-
StaticEnum(enum_def, _) => {
50-
if !cx.sess.features_untracked().derive_default_enum {
51-
rustc_session::parse::feature_err(
52-
cx.parse_sess(),
53-
sym::derive_default_enum,
54-
span,
55-
"deriving `Default` on enums is experimental",
56-
)
57-
.emit();
58-
}
59-
default_enum_substructure(cx, trait_span, enum_def)
60-
}
49+
StaticEnum(enum_def, _) => default_enum_substructure(cx, trait_span, enum_def),
6150
_ => cx.span_bug(trait_span, "method in `derive(Default)`"),
6251
}
6352
})),

compiler/rustc_builtin_macros/src/standard_library_imports.rs

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub fn inject(
7070
Edition2015 => sym::rust_2015,
7171
Edition2018 => sym::rust_2018,
7272
Edition2021 => sym::rust_2021,
73+
Edition2024 => sym::rust_2024,
7374
}])
7475
.map(|&symbol| Ident::new(symbol, span))
7576
.collect();

compiler/rustc_errors/src/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ impl Diagnostic {
832832
name: impl Into<Cow<'static, str>>,
833833
arg: DiagnosticArgValue<'static>,
834834
) -> &mut Self {
835-
self.args.push((name.into(), arg.into()));
835+
self.args.push((name.into(), arg));
836836
self
837837
}
838838

compiler/rustc_expand/src/mbe/macro_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn check_binders(
270270
MISSING_FRAGMENT_SPECIFIER,
271271
span,
272272
node_id,
273-
&format!("missing fragment specifier"),
273+
"missing fragment specifier",
274274
);
275275
}
276276
if !macros.is_empty() {

compiler/rustc_expand/src/mbe/macro_parser.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ use crate::mbe::{KleeneOp, TokenTree};
7777

7878
use rustc_ast::token::{self, DocComment, Nonterminal, NonterminalKind, Token};
7979
use rustc_parse::parser::{NtOrTt, Parser};
80-
use rustc_session::parse::ParseSess;
8180
use rustc_span::symbol::MacroRulesNormalizedIdent;
8281
use rustc_span::Span;
8382

@@ -128,9 +127,8 @@ pub(super) enum MatcherLoc {
128127
Eof,
129128
}
130129

131-
pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<MatcherLoc> {
130+
pub(super) fn compute_locs(matcher: &[TokenTree]) -> Vec<MatcherLoc> {
132131
fn inner(
133-
sess: &ParseSess,
134132
tts: &[TokenTree],
135133
locs: &mut Vec<MatcherLoc>,
136134
next_metavar: &mut usize,
@@ -147,7 +145,7 @@ pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<Match
147145

148146
locs.push(MatcherLoc::Delimited);
149147
locs.push(MatcherLoc::Token { token: open_token });
150-
inner(sess, &delimited.tts, locs, next_metavar, seq_depth);
148+
inner(&delimited.tts, locs, next_metavar, seq_depth);
151149
locs.push(MatcherLoc::Token { token: close_token });
152150
}
153151
TokenTree::Sequence(_, seq) => {
@@ -162,7 +160,7 @@ pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<Match
162160
let op = seq.kleene.op;
163161
let idx_first = locs.len();
164162
let idx_seq = idx_first - 1;
165-
inner(sess, &seq.tts, locs, next_metavar, seq_depth + 1);
163+
inner(&seq.tts, locs, next_metavar, seq_depth + 1);
166164

167165
if let Some(separator) = &seq.separator {
168166
locs.push(MatcherLoc::SequenceSep { separator: separator.clone() });
@@ -197,7 +195,7 @@ pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<Match
197195

198196
let mut locs = vec![];
199197
let mut next_metavar = 0;
200-
inner(sess, matcher, &mut locs, &mut next_metavar, /* seq_depth */ 0);
198+
inner(matcher, &mut locs, &mut next_metavar, /* seq_depth */ 0);
201199

202200
// A final entry is needed for eof.
203201
locs.push(MatcherLoc::Eof);

compiler/rustc_expand/src/mbe/macro_rules.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ pub fn compile_declarative_macro(
435435
),
436436
];
437437
// Convert it into `MatcherLoc` form.
438-
let argument_gram = mbe::macro_parser::compute_locs(&sess.parse_sess, &argument_gram);
438+
let argument_gram = mbe::macro_parser::compute_locs(&argument_gram);
439439

440440
let parser = Parser::new(&sess.parse_sess, body, true, rustc_parse::MACRO_ARGUMENTS);
441441
let mut tt_parser =
@@ -478,7 +478,7 @@ pub fn compile_declarative_macro(
478478
)
479479
.pop()
480480
.unwrap();
481-
valid &= check_lhs_nt_follows(&sess.parse_sess, features, &def, &tt);
481+
valid &= check_lhs_nt_follows(&sess.parse_sess, &def, &tt);
482482
return tt;
483483
}
484484
sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured lhs")
@@ -540,7 +540,7 @@ pub fn compile_declarative_macro(
540540
// Ignore the delimiters around the matcher.
541541
match lhs {
542542
mbe::TokenTree::Delimited(_, delimited) => {
543-
mbe::macro_parser::compute_locs(&sess.parse_sess, &delimited.tts)
543+
mbe::macro_parser::compute_locs(&delimited.tts)
544544
}
545545
_ => sess.parse_sess.span_diagnostic.span_bug(def.span, "malformed macro lhs"),
546546
}
@@ -563,16 +563,11 @@ pub fn compile_declarative_macro(
563563
}))
564564
}
565565

566-
fn check_lhs_nt_follows(
567-
sess: &ParseSess,
568-
features: &Features,
569-
def: &ast::Item,
570-
lhs: &mbe::TokenTree,
571-
) -> bool {
566+
fn check_lhs_nt_follows(sess: &ParseSess, def: &ast::Item, lhs: &mbe::TokenTree) -> bool {
572567
// lhs is going to be like TokenTree::Delimited(...), where the
573568
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
574569
if let mbe::TokenTree::Delimited(_, delimited) = lhs {
575-
check_matcher(sess, features, def, &delimited.tts)
570+
check_matcher(sess, def, &delimited.tts)
576571
} else {
577572
let msg = "invalid macro matcher; matchers must be contained in balanced delimiters";
578573
sess.span_diagnostic.span_err(lhs.span(), msg);
@@ -632,16 +627,11 @@ fn check_rhs(sess: &ParseSess, rhs: &mbe::TokenTree) -> bool {
632627
false
633628
}
634629

635-
fn check_matcher(
636-
sess: &ParseSess,
637-
features: &Features,
638-
def: &ast::Item,
639-
matcher: &[mbe::TokenTree],
640-
) -> bool {
630+
fn check_matcher(sess: &ParseSess, def: &ast::Item, matcher: &[mbe::TokenTree]) -> bool {
641631
let first_sets = FirstSets::new(matcher);
642632
let empty_suffix = TokenSet::empty();
643633
let err = sess.span_diagnostic.err_count();
644-
check_matcher_core(sess, features, def, &first_sets, matcher, &empty_suffix);
634+
check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix);
645635
err == sess.span_diagnostic.err_count()
646636
}
647637

@@ -955,7 +945,6 @@ impl<'tt> TokenSet<'tt> {
955945
// see `FirstSets::new`.
956946
fn check_matcher_core<'tt>(
957947
sess: &ParseSess,
958-
features: &Features,
959948
def: &ast::Item,
960949
first_sets: &FirstSets<'tt>,
961950
matcher: &'tt [mbe::TokenTree],
@@ -1008,7 +997,7 @@ fn check_matcher_core<'tt>(
1008997
token::CloseDelim(d.delim),
1009998
span.close,
1010999
));
1011-
check_matcher_core(sess, features, def, first_sets, &d.tts, &my_suffix);
1000+
check_matcher_core(sess, def, first_sets, &d.tts, &my_suffix);
10121001
// don't track non NT tokens
10131002
last.replace_with_irrelevant();
10141003

@@ -1040,8 +1029,7 @@ fn check_matcher_core<'tt>(
10401029
// At this point, `suffix_first` is built, and
10411030
// `my_suffix` is some TokenSet that we can use
10421031
// for checking the interior of `seq_rep`.
1043-
let next =
1044-
check_matcher_core(sess, features, def, first_sets, &seq_rep.tts, my_suffix);
1032+
let next = check_matcher_core(sess, def, first_sets, &seq_rep.tts, my_suffix);
10451033
if next.maybe_empty {
10461034
last.add_all(&next);
10471035
} else {
@@ -1114,7 +1102,7 @@ fn check_matcher_core<'tt>(
11141102
err.span_label(sp, format!("not allowed after `{}` fragments", kind));
11151103

11161104
if kind == NonterminalKind::PatWithOr
1117-
&& sess.edition == Edition::Edition2021
1105+
&& sess.edition.rust_2021()
11181106
&& next_token.is_token(&BinOp(token::BinOpToken::Or))
11191107
{
11201108
let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl(

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ declare_features! (
126126
(accepted, default_type_params, "1.0.0", None, None),
127127
/// Allows `#[deprecated]` attribute.
128128
(accepted, deprecated, "1.9.0", Some(29935), None),
129+
/// Allows `#[derive(Default)]` and `#[default]` on enums.
130+
(accepted, derive_default_enum, "1.62.0", Some(86985), None),
129131
/// Allows the use of destructuring assignments.
130132
(accepted, destructuring_assignment, "1.59.0", Some(71126), None),
131133
/// Allows `#[doc(alias = "...")]`.

compiler/rustc_feature/src/active.rs

-2
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,6 @@ declare_features! (
368368
(active, deprecated_safe, "1.61.0", Some(94978), None),
369369
/// Allows having using `suggestion` in the `#[deprecated]` attribute.
370370
(active, deprecated_suggestion, "1.61.0", Some(94785), None),
371-
/// Allows `#[derive(Default)]` and `#[default]` on enums.
372-
(active, derive_default_enum, "1.56.0", Some(86985), None),
373371
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
374372
(active, doc_auto_cfg, "1.58.0", Some(43781), None),
375373
/// Allows `#[doc(cfg(...))]`.

compiler/rustc_feature/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! even if it is stabilized or removed, *do not remove it*. Instead, move the
1212
//! symbol to the `accepted` or `removed` modules respectively.
1313
14-
#![feature(derive_default_enum)]
14+
#![cfg_attr(bootstrap, feature(derive_default_enum))]
1515
#![feature(once_cell)]
1616

1717
mod accepted;

compiler/rustc_hir/src/hir.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -2557,11 +2557,17 @@ impl FnRetTy<'_> {
25572557

25582558
#[derive(Encodable, Debug, HashStable_Generic)]
25592559
pub struct Mod<'hir> {
2560+
pub spans: ModSpans,
2561+
pub item_ids: &'hir [ItemId],
2562+
}
2563+
2564+
#[derive(Copy, Clone, Debug, HashStable_Generic, Encodable)]
2565+
pub struct ModSpans {
25602566
/// A span from the first token past `{` to the last token until `}`.
25612567
/// For `mod foo;`, the inner span ranges from the first token
25622568
/// to the last token in the external file.
2563-
pub inner: Span,
2564-
pub item_ids: &'hir [ItemId],
2569+
pub inner_span: Span,
2570+
pub inject_use_span: Span,
25652571
}
25662572

25672573
#[derive(Debug, HashStable_Generic)]
@@ -3059,8 +3065,8 @@ impl<'hir> OwnerNode<'hir> {
30593065
OwnerNode::Item(Item { span, .. })
30603066
| OwnerNode::ForeignItem(ForeignItem { span, .. })
30613067
| OwnerNode::ImplItem(ImplItem { span, .. })
3062-
| OwnerNode::TraitItem(TraitItem { span, .. })
3063-
| OwnerNode::Crate(Mod { inner: span, .. }) => *span,
3068+
| OwnerNode::TraitItem(TraitItem { span, .. }) => *span,
3069+
OwnerNode::Crate(Mod { spans: ModSpans { inner_span, .. }, .. }) => *inner_span,
30643070
}
30653071
}
30663072

compiler/rustc_infer/src/infer/at.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
6363
/// common state. Used in coherence.
6464
pub fn fork(&self) -> Self {
6565
Self {
66-
tcx: self.tcx.clone(),
67-
defining_use_anchor: self.defining_use_anchor.clone(),
68-
in_progress_typeck_results: self.in_progress_typeck_results.clone(),
66+
tcx: self.tcx,
67+
defining_use_anchor: self.defining_use_anchor,
68+
in_progress_typeck_results: self.in_progress_typeck_results,
6969
inner: self.inner.clone(),
7070
skip_leak_check: self.skip_leak_check.clone(),
7171
lexical_region_resolutions: self.lexical_region_resolutions.clone(),

compiler/rustc_infer/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#![feature(bool_to_option)]
1818
#![feature(box_patterns)]
1919
#![feature(control_flow_enum)]
20-
#![feature(derive_default_enum)]
20+
#![cfg_attr(bootstrap, feature(derive_default_enum))]
2121
#![feature(extend_one)]
2222
#![feature(label_break_value)]
2323
#![feature(let_chains)]

compiler/rustc_macros/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn symbols(input: TokenStream) -> TokenStream {
4444
#[proc_macro]
4545
#[allow_internal_unstable(step_trait, rustc_attrs, trusted_step)]
4646
pub fn newtype_index(input: TokenStream) -> TokenStream {
47-
newtype::newtype(input).into()
47+
newtype::newtype(input)
4848
}
4949

5050
decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);

compiler/rustc_middle/src/hir/map/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ impl<'hir> Map<'hir> {
584584
Some(OwnerNode::Item(&Item { span, kind: ItemKind::Mod(ref m), .. })) => {
585585
(m, span, hir_id)
586586
}
587-
Some(OwnerNode::Crate(item)) => (item, item.inner, hir_id),
587+
Some(OwnerNode::Crate(item)) => (item, item.spans.inner_span, hir_id),
588588
node => panic!("not a module: {:?}", node),
589589
}
590590
}
@@ -1012,7 +1012,7 @@ impl<'hir> Map<'hir> {
10121012
Node::Infer(i) => i.span,
10131013
Node::Visibility(v) => bug!("unexpected Visibility {:?}", v),
10141014
Node::Local(local) => local.span,
1015-
Node::Crate(item) => item.inner,
1015+
Node::Crate(item) => item.spans.inner_span,
10161016
};
10171017
Some(span)
10181018
}

compiler/rustc_middle/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#![feature(bool_to_option)]
3131
#![feature(box_patterns)]
3232
#![feature(core_intrinsics)]
33-
#![feature(derive_default_enum)]
33+
#![cfg_attr(bootstrap, feature(derive_default_enum))]
3434
#![feature(discriminant_kind)]
3535
#![feature(exhaustive_patterns)]
3636
#![feature(get_mut_unchecked)]

compiler/rustc_middle/src/middle/region.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,9 @@ impl ScopeTree {
362362
self.parent_map.get(&id).cloned().map(|(p, _)| p)
363363
}
364364

365-
/// Returns the lifetime of the local variable `var_id`
366-
pub fn var_scope(&self, var_id: hir::ItemLocalId) -> Scope {
367-
self.var_map
368-
.get(&var_id)
369-
.cloned()
370-
.unwrap_or_else(|| bug!("no enclosing scope for id {:?}", var_id))
365+
/// Returns the lifetime of the local variable `var_id`, if any.
366+
pub fn var_scope(&self, var_id: hir::ItemLocalId) -> Option<Scope> {
367+
self.var_map.get(&var_id).cloned()
371368
}
372369

373370
/// Returns the scope when the temp created by `expr_id` will be cleaned up.

compiler/rustc_middle/src/ty/inhabitedness/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'tcx> Ty<'tcx> {
191191
tcx: TyCtxt<'tcx>,
192192
param_env: ty::ParamEnv<'tcx>,
193193
) -> DefIdForest<'tcx> {
194-
tcx.type_uninhabited_from(param_env.and(self)).clone()
194+
tcx.type_uninhabited_from(param_env.and(self))
195195
}
196196
}
197197

compiler/rustc_mir_build/src/build/expr/as_constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3939
}
4040
};
4141

42-
Constant { span, user_ty: None, literal: literal.into() }
42+
Constant { span, user_ty: None, literal }
4343
}
4444
ExprKind::NonHirLiteral { lit, user_ty } => {
4545
let user_ty = user_ty.map(|user_ty| {

0 commit comments

Comments
 (0)