Skip to content

Commit f5a1ef7

Browse files
committed
Auto merge of rust-lang#138177 - matthiaskrgr:rollup-y0ikkzz, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#134797 (Ergonomic ref counting) - rust-lang#137549 (Clean up various LLVM FFI things in codegen_llvm) - rust-lang#137977 (Reduce `kw::Empty` usage, part 1) - rust-lang#138042 (Suggest struct or union to add generic that impls trait) - rust-lang#138141 (tests: fix some typos in comment) - rust-lang#138150 (Streamline HIR intravisit `visit_id` calls for items) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c53af1c + b772fa6 commit f5a1ef7

File tree

172 files changed

+2022
-572
lines changed

Some content is hidden

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

172 files changed

+2022
-572
lines changed

compiler/rustc_ast/src/ast.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,7 @@ impl Expr {
13991399
// Never need parens
14001400
ExprKind::Array(_)
14011401
| ExprKind::Await(..)
1402+
| ExprKind::Use(..)
14021403
| ExprKind::Block(..)
14031404
| ExprKind::Call(..)
14041405
| ExprKind::ConstBlock(_)
@@ -1588,6 +1589,8 @@ pub enum ExprKind {
15881589
Gen(CaptureBy, P<Block>, GenBlockKind, Span),
15891590
/// An await expression (`my_future.await`). Span is of await keyword.
15901591
Await(P<Expr>, Span),
1592+
/// A use expression (`x.use`). Span is of use keyword.
1593+
Use(P<Expr>, Span),
15911594

15921595
/// A try block (`try { ... }`).
15931596
TryBlock(P<Block>),
@@ -1757,8 +1760,17 @@ pub enum CaptureBy {
17571760
/// The span of the `move` keyword.
17581761
move_kw: Span,
17591762
},
1760-
/// `move` keyword was not specified.
1763+
/// `move` or `use` keywords were not specified.
17611764
Ref,
1765+
/// `use |x| y + x`.
1766+
///
1767+
/// Note that if you have a regular closure like `|| x.use`, this will *not* result
1768+
/// in a `Use` capture. Instead, the `ExprUseVisitor` will look at the type
1769+
/// of `x` and treat `x.use` as either a copy/clone/move as appropriate.
1770+
Use {
1771+
/// The span of the `use` keyword.
1772+
use_kw: Span,
1773+
},
17621774
}
17631775

17641776
/// Closure lifetime binder, `for<'a, 'b>` in `for<'a, 'b> |_: &'a (), _: &'b ()|`.

compiler/rustc_ast/src/mut_visit.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,10 @@ pub fn walk_expr<T: MutVisitor>(vis: &mut T, Expr { kind, id, span, attrs, token
17451745
vis.visit_expr(expr);
17461746
vis.visit_span(await_kw_span);
17471747
}
1748+
ExprKind::Use(expr, use_kw_span) => {
1749+
vis.visit_expr(expr);
1750+
vis.visit_span(use_kw_span);
1751+
}
17481752
ExprKind::Assign(el, er, span) => {
17491753
vis.visit_expr(el);
17501754
vis.visit_expr(er);
@@ -1895,6 +1899,9 @@ fn walk_capture_by<T: MutVisitor>(vis: &mut T, capture_by: &mut CaptureBy) {
18951899
CaptureBy::Value { move_kw } => {
18961900
vis.visit_span(move_kw);
18971901
}
1902+
CaptureBy::Use { use_kw } => {
1903+
vis.visit_span(use_kw);
1904+
}
18981905
}
18991906
}
19001907

compiler/rustc_ast/src/util/classify.rs

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub fn leading_labeled_expr(mut expr: &ast::Expr) -> bool {
108108
Assign(e, _, _)
109109
| AssignOp(_, e, _)
110110
| Await(e, _)
111+
| Use(e, _)
111112
| Binary(_, e, _)
112113
| Call(e, _)
113114
| Cast(e, _)
@@ -224,6 +225,7 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<TrailingBrace<'_>> {
224225
| Lit(_)
225226
| Type(_, _)
226227
| Await(_, _)
228+
| Use(_, _)
227229
| Field(_, _)
228230
| Index(_, _, _)
229231
| Underscore

compiler/rustc_ast/src/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
12111211
}
12121212
ExprKind::Gen(_capt, body, _kind, _decl_span) => try_visit!(visitor.visit_block(body)),
12131213
ExprKind::Await(expr, _span) => try_visit!(visitor.visit_expr(expr)),
1214+
ExprKind::Use(expr, _span) => try_visit!(visitor.visit_expr(expr)),
12141215
ExprKind::Assign(lhs, rhs, _span) => {
12151216
try_visit!(visitor.visit_expr(lhs));
12161217
try_visit!(visitor.visit_expr(rhs));

compiler/rustc_ast_lowering/src/expr.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, kw, sym};
16+
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -207,6 +207,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
207207
},
208208
),
209209
ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr),
210+
ExprKind::Use(expr, use_kw_span) => self.lower_expr_use(*use_kw_span, expr),
210211
ExprKind::Closure(box Closure {
211212
binder,
212213
capture_clause,
@@ -483,7 +484,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
483484
if legacy_args_idx.contains(&idx) {
484485
let parent_def_id = self.current_hir_id_owner.def_id;
485486
let node_id = self.next_node_id();
486-
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
487+
self.create_def(parent_def_id, node_id, None, DefKind::AnonConst, f.span);
487488
let mut visitor = WillCreateDefIdsVisitor {};
488489
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
489490
AstP(Expr {
@@ -1067,6 +1068,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
10671068
)
10681069
}
10691070

1071+
fn lower_expr_use(&mut self, use_kw_span: Span, expr: &Expr) -> hir::ExprKind<'hir> {
1072+
hir::ExprKind::Use(self.lower_expr(expr), use_kw_span)
1073+
}
1074+
10701075
fn lower_expr_closure(
10711076
&mut self,
10721077
binder: &ClosureBinder,

compiler/rustc_ast_lowering/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
494494
&mut self,
495495
parent: LocalDefId,
496496
node_id: ast::NodeId,
497-
name: Symbol,
497+
name: Option<Symbol>,
498498
def_kind: DefKind,
499499
span: Span,
500500
) -> LocalDefId {
@@ -774,7 +774,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
774774
let _def_id = self.create_def(
775775
self.current_hir_id_owner.def_id,
776776
param,
777-
kw::UnderscoreLifetime,
777+
Some(kw::UnderscoreLifetime),
778778
DefKind::LifetimeParam,
779779
ident.span,
780780
);
@@ -2089,8 +2089,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20892089
// We're lowering a const argument that was originally thought to be a type argument,
20902090
// so the def collector didn't create the def ahead of time. That's why we have to do
20912091
// it here.
2092-
let def_id =
2093-
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, span);
2092+
let def_id = self.create_def(parent_def_id, node_id, None, DefKind::AnonConst, span);
20942093
let hir_id = self.lower_node_id(node_id);
20952094

20962095
let path_expr = Expr {

compiler/rustc_ast_lowering/src/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res};
77
use rustc_hir::{self as hir, LangItem};
88
use rustc_middle::span_bug;
99
use rustc_span::source_map::{Spanned, respan};
10-
use rustc_span::{DesugaringKind, Ident, Span, kw};
10+
use rustc_span::{DesugaringKind, Ident, Span};
1111

1212
use super::errors::{
1313
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
@@ -523,7 +523,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
523523
// We're generating a range end that didn't exist in the AST,
524524
// so the def collector didn't create the def ahead of time. That's why we have to do
525525
// it here.
526-
let def_id = self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, span);
526+
let def_id = self.create_def(parent_def_id, node_id, None, DefKind::AnonConst, span);
527527
let hir_id = self.lower_node_id(node_id);
528528

529529
let unstable_span = self.mark_span_with_reason(

compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
489489
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
490490
gate_all!(const_closures, "const closures are experimental");
491491
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
492+
gate_all!(ergonomic_clones, "ergonomic clones are experimental");
492493
gate_all!(explicit_tail_calls, "`become` expression is experimental");
493494
gate_all!(generic_const_items, "generic const items are experimental");
494495
gate_all!(guard_patterns, "guard patterns are experimental", "consider using match arm guards");

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+9
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,14 @@ impl<'a> State<'a> {
574574
);
575575
self.word(".await");
576576
}
577+
ast::ExprKind::Use(expr, _) => {
578+
self.print_expr_cond_paren(
579+
expr,
580+
expr.precedence() < ExprPrecedence::Unambiguous,
581+
fixup,
582+
);
583+
self.word(".use");
584+
}
577585
ast::ExprKind::Assign(lhs, rhs, _) => {
578586
self.print_expr_cond_paren(
579587
lhs,
@@ -885,6 +893,7 @@ impl<'a> State<'a> {
885893
fn print_capture_clause(&mut self, capture_clause: ast::CaptureBy) {
886894
match capture_clause {
887895
ast::CaptureBy::Value { .. } => self.word_space("move"),
896+
ast::CaptureBy::Use { .. } => self.word_space("use"),
888897
ast::CaptureBy::Ref => {}
889898
}
890899
}

compiler/rustc_borrowck/src/borrowck_errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ impl<'infcx, 'tcx> crate::MirBorrowckCtxt<'_, 'infcx, 'tcx> {
403403
.expect_closure();
404404
let span = match capture_clause {
405405
rustc_hir::CaptureBy::Value { move_kw } => move_kw.shrink_to_lo(),
406+
rustc_hir::CaptureBy::Use { use_kw } => use_kw.shrink_to_lo(),
406407
rustc_hir::CaptureBy::Ref => fn_decl_span.shrink_to_lo(),
407408
};
408409
diag.span_suggestion_verbose(

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
823823
) => {
824824
capture_reason = format!("mutable borrow of `{upvar}`");
825825
}
826-
ty::UpvarCapture::ByValue => {
826+
ty::UpvarCapture::ByValue | ty::UpvarCapture::ByUse => {
827827
capture_reason = format!("possible mutation of `{upvar}`");
828828
}
829829
_ => bug!("upvar `{upvar}` borrowed, but not mutably"),

compiler/rustc_borrowck/src/lib.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1490,14 +1490,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
14901490
let stmt = &bbd.statements[loc.statement_index];
14911491
debug!("temporary assigned in: stmt={:?}", stmt);
14921492

1493-
if let StatementKind::Assign(box (_, Rvalue::Ref(_, _, source))) = stmt.kind
1494-
{
1495-
propagate_closure_used_mut_place(self, source);
1496-
} else {
1497-
bug!(
1498-
"closures should only capture user variables \
1493+
match stmt.kind {
1494+
StatementKind::Assign(box (
1495+
_,
1496+
Rvalue::Ref(_, _, source)
1497+
| Rvalue::Use(Operand::Copy(source) | Operand::Move(source)),
1498+
)) => {
1499+
propagate_closure_used_mut_place(self, source);
1500+
}
1501+
_ => {
1502+
bug!(
1503+
"closures should only capture user variables \
14991504
or references to user variables"
1500-
);
1505+
);
1506+
}
15011507
}
15021508
}
15031509
_ => propagate_closure_used_mut_place(self, place),

compiler/rustc_builtin_macros/src/assert/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
297297
| ExprKind::AssignOp(_, _, _)
298298
| ExprKind::Gen(_, _, _, _)
299299
| ExprKind::Await(_, _)
300+
| ExprKind::Use(_, _)
300301
| ExprKind::Block(_, _)
301302
| ExprKind::Break(_, _)
302303
| ExprKind::Closure(_)

compiler/rustc_codegen_gcc/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::context::CodegenCx;
1616
use crate::intrinsic::ArgAbiExt;
1717
use crate::type_of::LayoutGccExt;
1818

19-
impl<'a, 'gcc, 'tcx> AbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
19+
impl AbiBuilderMethods for Builder<'_, '_, '_> {
2020
fn get_param(&mut self, index: usize) -> Self::Value {
2121
let func = self.current_func();
2222
let param = func.get_param(index as i32);

compiler/rustc_codegen_gcc/src/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn type_is_pointer(typ: Type<'_>) -> bool {
5959
typ.get_pointee().is_some()
6060
}
6161

62-
impl<'gcc, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
62+
impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
6363
fn const_null(&self, typ: Type<'gcc>) -> RValue<'gcc> {
6464
if type_is_pointer(typ) { self.context.new_null(typ) } else { self.const_int(typ, 0) }
6565
}
@@ -257,7 +257,7 @@ impl<'gcc, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
257257
}
258258
}
259259

260-
fn const_data_from_alloc(&self, alloc: ConstAllocation<'tcx>) -> Self::Value {
260+
fn const_data_from_alloc(&self, alloc: ConstAllocation<'_>) -> Self::Value {
261261
const_alloc_to_gcc(self, alloc)
262262
}
263263

compiler/rustc_codegen_gcc/src/consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
302302
}
303303
}
304304

305-
pub fn const_alloc_to_gcc<'gcc, 'tcx>(
306-
cx: &CodegenCx<'gcc, 'tcx>,
307-
alloc: ConstAllocation<'tcx>,
305+
pub fn const_alloc_to_gcc<'gcc>(
306+
cx: &CodegenCx<'gcc, '_>,
307+
alloc: ConstAllocation<'_>,
308308
) -> RValue<'gcc> {
309309
let alloc = alloc.inner();
310310
let mut llvals = Vec::with_capacity(alloc.provenance().ptrs().len() + 1);

compiler/rustc_codegen_gcc/src/type_.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
123123
}
124124
}
125125

126-
impl<'gcc, 'tcx> BaseTypeCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
126+
impl<'gcc, 'tcx> BaseTypeCodegenMethods for CodegenCx<'gcc, 'tcx> {
127127
fn type_i8(&self) -> Type<'gcc> {
128128
self.i8_type
129129
}

compiler/rustc_codegen_llvm/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
654654
}
655655
}
656656

657-
impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
657+
impl AbiBuilderMethods for Builder<'_, '_, '_> {
658658
fn get_param(&mut self, index: usize) -> Self::Value {
659659
llvm::get_param(self.llfn(), index as c_uint)
660660
}

0 commit comments

Comments
 (0)