Skip to content

Commit 6e4a9ab

Browse files
committed
Auto merge of rust-lang#101439 - Dylan-DPC:rollup-2wf1mtj, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#101142 (Improve HIR stats) - rust-lang#101367 (Suggest `{Option,Result}::{copied,clone}()` to satisfy type mismatch) - rust-lang#101391 (more clippy::perf fixes) - rust-lang#101409 (Don't fire `rust_2021_incompatible_closure_captures` in `edition = 2021` crates) - rust-lang#101420 (Fix `hir::Local` doc to match with the variable name used: `init`) - rust-lang#101429 (Don't suggest reborrow if usage is inside a closure) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5b4bd15 + d2fdb5d commit 6e4a9ab

File tree

34 files changed

+726
-287
lines changed

34 files changed

+726
-287
lines changed

compiler/rustc_ast/src/ast.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3045,13 +3045,16 @@ mod size_asserts {
30453045
static_assert_size!(Fn, 192);
30463046
static_assert_size!(ForeignItem, 96);
30473047
static_assert_size!(ForeignItemKind, 24);
3048+
static_assert_size!(GenericArg, 24);
30483049
static_assert_size!(GenericBound, 88);
30493050
static_assert_size!(Generics, 72);
30503051
static_assert_size!(Impl, 200);
30513052
static_assert_size!(Item, 184);
30523053
static_assert_size!(ItemKind, 112);
30533054
static_assert_size!(Lit, 48);
30543055
static_assert_size!(LitKind, 24);
3056+
static_assert_size!(Local, 72);
3057+
static_assert_size!(Param, 40);
30553058
static_assert_size!(Pat, 120);
30563059
static_assert_size!(PatKind, 96);
30573060
static_assert_size!(Path, 40);

compiler/rustc_ast_lowering/src/asm.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
155155
let op = match *op {
156156
InlineAsmOperand::In { reg, ref expr } => hir::InlineAsmOperand::In {
157157
reg: lower_reg(reg),
158-
expr: self.lower_expr_mut(expr),
158+
expr: self.lower_expr(expr),
159159
},
160160
InlineAsmOperand::Out { reg, late, ref expr } => hir::InlineAsmOperand::Out {
161161
reg: lower_reg(reg),
162162
late,
163-
expr: expr.as_ref().map(|expr| self.lower_expr_mut(expr)),
163+
expr: expr.as_ref().map(|expr| self.lower_expr(expr)),
164164
},
165165
InlineAsmOperand::InOut { reg, late, ref expr } => {
166166
hir::InlineAsmOperand::InOut {
167167
reg: lower_reg(reg),
168168
late,
169-
expr: self.lower_expr_mut(expr),
169+
expr: self.lower_expr(expr),
170170
}
171171
}
172172
InlineAsmOperand::SplitInOut { reg, late, ref in_expr, ref out_expr } => {
173173
hir::InlineAsmOperand::SplitInOut {
174174
reg: lower_reg(reg),
175175
late,
176-
in_expr: self.lower_expr_mut(in_expr),
177-
out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)),
176+
in_expr: self.lower_expr(in_expr),
177+
out_expr: out_expr.as_ref().map(|expr| self.lower_expr(expr)),
178178
}
179179
}
180180
InlineAsmOperand::Const { ref anon_const } => {

compiler/rustc_ast_lowering/src/item.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
120120
self.with_lctx(CRATE_NODE_ID, |lctx| {
121121
let module = lctx.lower_mod(&c.items, &c.spans);
122122
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
123-
hir::OwnerNode::Crate(lctx.arena.alloc(module))
123+
hir::OwnerNode::Crate(module)
124124
})
125125
}
126126

@@ -158,14 +158,18 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
158158
}
159159

160160
impl<'hir> LoweringContext<'_, 'hir> {
161-
pub(super) fn lower_mod(&mut self, items: &[P<Item>], spans: &ModSpans) -> hir::Mod<'hir> {
162-
hir::Mod {
161+
pub(super) fn lower_mod(
162+
&mut self,
163+
items: &[P<Item>],
164+
spans: &ModSpans,
165+
) -> &'hir hir::Mod<'hir> {
166+
self.arena.alloc(hir::Mod {
163167
spans: hir::ModSpans {
164168
inner_span: self.lower_span(spans.inner_span),
165169
inject_use_span: self.lower_span(spans.inject_use_span),
166170
},
167171
item_ids: self.arena.alloc_from_iter(items.iter().flat_map(|x| self.lower_item_ref(x))),
168-
}
172+
})
169173
}
170174

171175
pub(super) fn lower_item_ref(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> {
@@ -947,7 +951,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
947951
params: &'hir [hir::Param<'hir>],
948952
value: hir::Expr<'hir>,
949953
) -> hir::BodyId {
950-
let body = hir::Body { generator_kind: self.generator_kind, params, value };
954+
let body = hir::Body {
955+
generator_kind: self.generator_kind,
956+
params,
957+
value: self.arena.alloc(value),
958+
};
951959
let id = body.id();
952960
debug_assert_eq!(id.hir_id.owner, self.current_hir_id_owner);
953961
self.bodies.push((id.hir_id.local_id, self.arena.alloc(body)));

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11551155
}
11561156
_ => {}
11571157
}
1158-
GenericArg::Type(self.lower_ty_direct(&ty, itctx))
1158+
GenericArg::Type(self.lower_ty(&ty, itctx))
11591159
}
11601160
ast::GenericArg::Const(ct) => GenericArg::Const(ConstArg {
11611161
value: self.lower_anon_const(&ct),

compiler/rustc_ast_lowering/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
358358
}
359359
FnRetTy::Default(_) => self.arena.alloc(self.ty_tup(*span, &[])),
360360
};
361-
let args = smallvec![GenericArg::Type(self.ty_tup(*inputs_span, inputs))];
361+
let args = smallvec![GenericArg::Type(self.arena.alloc(self.ty_tup(*inputs_span, inputs)))];
362362
let binding = self.output_ty_binding(output_ty.span, output_ty);
363363
(
364364
GenericArgsCtor {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
258258
let ty = place.ty(self.body, self.infcx.tcx).ty;
259259

260260
// If we're in pattern, we do nothing in favor of the previous suggestion (#80913).
261-
if is_loop_move & !in_pattern {
261+
// Same for if we're in a loop, see #101119.
262+
if is_loop_move & !in_pattern && !matches!(use_spans, UseSpans::ClosureUse { .. }) {
262263
if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() {
263264
// We have a `&mut` ref, we need to reborrow on each iteration (#62112).
264265
err.span_suggestion_verbose(

compiler/rustc_hir/src/hir.rs

+37-21
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl InferArg {
265265
#[derive(Debug, HashStable_Generic)]
266266
pub enum GenericArg<'hir> {
267267
Lifetime(Lifetime),
268-
Type(Ty<'hir>),
268+
Type(&'hir Ty<'hir>),
269269
Const(ConstArg),
270270
Infer(InferArg),
271271
}
@@ -280,7 +280,7 @@ impl GenericArg<'_> {
280280
}
281281
}
282282

283-
pub fn id(&self) -> HirId {
283+
pub fn hir_id(&self) -> HirId {
284284
match self {
285285
GenericArg::Lifetime(l) => l.hir_id,
286286
GenericArg::Type(t) => t.hir_id,
@@ -1321,7 +1321,7 @@ pub enum StmtKind<'hir> {
13211321
Semi(&'hir Expr<'hir>),
13221322
}
13231323

1324-
/// Represents a `let` statement (i.e., `let <pat>:<ty> = <expr>;`).
1324+
/// Represents a `let` statement (i.e., `let <pat>:<ty> = <init>;`).
13251325
#[derive(Debug, HashStable_Generic)]
13261326
pub struct Local<'hir> {
13271327
pub pat: &'hir Pat<'hir>,
@@ -1438,7 +1438,7 @@ pub struct BodyId {
14381438
#[derive(Debug, HashStable_Generic)]
14391439
pub struct Body<'hir> {
14401440
pub params: &'hir [Param<'hir>],
1441-
pub value: Expr<'hir>,
1441+
pub value: &'hir Expr<'hir>,
14421442
pub generator_kind: Option<GeneratorKind>,
14431443
}
14441444

@@ -2561,23 +2561,23 @@ pub enum TyKind<'hir> {
25612561
pub enum InlineAsmOperand<'hir> {
25622562
In {
25632563
reg: InlineAsmRegOrRegClass,
2564-
expr: Expr<'hir>,
2564+
expr: &'hir Expr<'hir>,
25652565
},
25662566
Out {
25672567
reg: InlineAsmRegOrRegClass,
25682568
late: bool,
2569-
expr: Option<Expr<'hir>>,
2569+
expr: Option<&'hir Expr<'hir>>,
25702570
},
25712571
InOut {
25722572
reg: InlineAsmRegOrRegClass,
25732573
late: bool,
2574-
expr: Expr<'hir>,
2574+
expr: &'hir Expr<'hir>,
25752575
},
25762576
SplitInOut {
25772577
reg: InlineAsmRegOrRegClass,
25782578
late: bool,
2579-
in_expr: Expr<'hir>,
2580-
out_expr: Option<Expr<'hir>>,
2579+
in_expr: &'hir Expr<'hir>,
2580+
out_expr: Option<&'hir Expr<'hir>>,
25812581
},
25822582
Const {
25832583
anon_const: AnonConst,
@@ -2991,7 +2991,7 @@ pub enum ItemKind<'hir> {
29912991
/// A MBE macro definition (`macro_rules!` or `macro`).
29922992
Macro(ast::MacroDef, MacroKind),
29932993
/// A module.
2994-
Mod(Mod<'hir>),
2994+
Mod(&'hir Mod<'hir>),
29952995
/// An external module, e.g. `extern { .. }`.
29962996
ForeignMod { abi: Abi, items: &'hir [ForeignItemRef] },
29972997
/// Module-level inline assembly (from `global_asm!`).
@@ -3495,16 +3495,32 @@ impl<'hir> Node<'hir> {
34953495
mod size_asserts {
34963496
use super::*;
34973497
// These are in alphabetical order, which is easy to maintain.
3498-
static_assert_size!(Block<'static>, 48);
3499-
static_assert_size!(Expr<'static>, 56);
3500-
static_assert_size!(ForeignItem<'static>, 72);
3498+
static_assert_size!(Block<'_>, 48);
3499+
static_assert_size!(Body<'_>, 32);
3500+
static_assert_size!(Expr<'_>, 56);
3501+
static_assert_size!(ExprKind<'_>, 40);
3502+
static_assert_size!(FnDecl<'_>, 40);
3503+
static_assert_size!(ForeignItem<'_>, 72);
3504+
static_assert_size!(ForeignItemKind<'_>, 40);
3505+
static_assert_size!(GenericArg<'_>, 40);
35013506
static_assert_size!(GenericBound<'_>, 48);
3502-
static_assert_size!(Generics<'static>, 56);
3503-
static_assert_size!(ImplItem<'static>, 88);
3504-
static_assert_size!(Impl<'static>, 80);
3505-
static_assert_size!(Item<'static>, 80);
3506-
static_assert_size!(Pat<'static>, 88);
3507-
static_assert_size!(QPath<'static>, 24);
3508-
static_assert_size!(TraitItem<'static>, 96);
3509-
static_assert_size!(Ty<'static>, 72);
3507+
static_assert_size!(Generics<'_>, 56);
3508+
static_assert_size!(Impl<'_>, 80);
3509+
static_assert_size!(ImplItem<'_>, 88);
3510+
static_assert_size!(ImplItemKind<'_>, 40);
3511+
static_assert_size!(Item<'_>, 80);
3512+
static_assert_size!(ItemKind<'_>, 48);
3513+
static_assert_size!(Local<'_>, 64);
3514+
static_assert_size!(Param<'_>, 32);
3515+
static_assert_size!(Pat<'_>, 88);
3516+
static_assert_size!(PatKind<'_>, 64);
3517+
static_assert_size!(Path<'_>, 48);
3518+
static_assert_size!(PathSegment<'_>, 56);
3519+
static_assert_size!(QPath<'_>, 24);
3520+
static_assert_size!(Stmt<'_>, 32);
3521+
static_assert_size!(StmtKind<'_>, 16);
3522+
static_assert_size!(TraitItem<'_>, 96);
3523+
static_assert_size!(TraitItemKind<'_>, 56);
3524+
static_assert_size!(Ty<'_>, 72);
3525+
static_assert_size!(TyKind<'_>, 56);
35103526
}

compiler/rustc_interface/src/passes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
6868
}
6969

7070
if sess.opts.unstable_opts.hir_stats {
71-
hir_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS");
71+
hir_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS", "ast-stats-1");
7272
}
7373

7474
Ok(krate)
@@ -415,7 +415,7 @@ pub fn configure_and_expand(
415415
}
416416

417417
if sess.opts.unstable_opts.hir_stats {
418-
hir_stats::print_ast_stats(&krate, "POST EXPANSION AST STATS");
418+
hir_stats::print_ast_stats(&krate, "POST EXPANSION AST STATS", "ast-stats-2");
419419
}
420420

421421
resolver.resolve_crate(&krate);

compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ pub trait LintContext: Sized {
842842
if let Some(positional_arg_to_replace) = position_sp_to_replace {
843843
let name = if is_formatting_arg { named_arg_name + "$" } else { named_arg_name };
844844
let span_to_replace = if let Ok(positional_arg_content) =
845-
self.sess().source_map().span_to_snippet(positional_arg_to_replace) && positional_arg_content.starts_with(":") {
845+
self.sess().source_map().span_to_snippet(positional_arg_to_replace) && positional_arg_content.starts_with(':') {
846846
positional_arg_to_replace.shrink_to_lo()
847847
} else {
848848
positional_arg_to_replace

compiler/rustc_lint_defs/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3407,7 +3407,7 @@ declare_lint! {
34073407
///
34083408
/// ### Example of drop reorder
34093409
///
3410-
/// ```rust,compile_fail
3410+
/// ```rust,edition2018,compile_fail
34113411
/// #![deny(rust_2021_incompatible_closure_captures)]
34123412
/// # #![allow(unused)]
34133413
///
@@ -3443,7 +3443,7 @@ declare_lint! {
34433443
///
34443444
/// ### Example of auto-trait
34453445
///
3446-
/// ```rust,compile_fail
3446+
/// ```rust,edition2018,compile_fail
34473447
/// #![deny(rust_2021_incompatible_closure_captures)]
34483448
/// use std::thread;
34493449
///

compiler/rustc_metadata/src/rmeta/encoder.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -1377,19 +1377,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13771377

13781378
let tcx = self.tcx;
13791379

1380-
let keys_and_jobs = tcx
1381-
.mir_keys(())
1382-
.iter()
1383-
.filter_map(|&def_id| {
1384-
let (encode_const, encode_opt) = should_encode_mir(tcx, def_id);
1385-
if encode_const || encode_opt {
1386-
Some((def_id, encode_const, encode_opt))
1387-
} else {
1388-
None
1389-
}
1390-
})
1391-
.collect::<Vec<_>>();
1392-
for (def_id, encode_const, encode_opt) in keys_and_jobs.into_iter() {
1380+
let keys_and_jobs = tcx.mir_keys(()).iter().filter_map(|&def_id| {
1381+
let (encode_const, encode_opt) = should_encode_mir(tcx, def_id);
1382+
if encode_const || encode_opt { Some((def_id, encode_const, encode_opt)) } else { None }
1383+
});
1384+
for (def_id, encode_const, encode_opt) in keys_and_jobs {
13931385
debug_assert!(encode_const || encode_opt);
13941386

13951387
debug!("EntryBuilder::encode_mir({:?})", def_id);

0 commit comments

Comments
 (0)