Skip to content

Commit 9bb1008

Browse files
committed
Avoid empty identifiers for delegate params and args.
Instead use `argN`. The empty identifiers could flow to `Liveness::should_warn`, where they would trigger a bounds error. Fixes rust-lang#139512.
1 parent 3cb9966 commit 9bb1008

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

compiler/rustc_ast_lowering/src/delegation.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use rustc_errors::ErrorGuaranteed;
4747
use rustc_hir::def_id::DefId;
4848
use rustc_middle::span_bug;
4949
use rustc_middle::ty::{Asyncness, ResolverAstLowering};
50-
use rustc_span::{Ident, Span};
50+
use rustc_span::{Ident, Span, Symbol};
5151
use {rustc_ast as ast, rustc_hir as hir};
5252

5353
use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
@@ -234,22 +234,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
234234
hir::FnSig { decl, header, span }
235235
}
236236

237-
fn generate_param(&mut self, span: Span) -> (hir::Param<'hir>, NodeId) {
237+
fn generate_param(&mut self, idx: usize, span: Span) -> (hir::Param<'hir>, NodeId) {
238238
let pat_node_id = self.next_node_id();
239239
let pat_id = self.lower_node_id(pat_node_id);
240+
let ident = Ident::with_dummy_span(Symbol::intern(&format!("arg{idx}")));
240241
let pat = self.arena.alloc(hir::Pat {
241242
hir_id: pat_id,
242-
kind: hir::PatKind::Binding(hir::BindingMode::NONE, pat_id, Ident::empty(), None),
243+
kind: hir::PatKind::Binding(hir::BindingMode::NONE, pat_id, ident, None),
243244
span,
244245
default_binding_modes: false,
245246
});
246247

247248
(hir::Param { hir_id: self.next_id(), pat, ty_span: span, span }, pat_node_id)
248249
}
249250

250-
fn generate_arg(&mut self, param_id: HirId, span: Span) -> hir::Expr<'hir> {
251+
fn generate_arg(&mut self, idx: usize, param_id: HirId, span: Span) -> hir::Expr<'hir> {
251252
let segments = self.arena.alloc_from_iter(iter::once(hir::PathSegment {
252-
ident: Ident::empty(),
253+
ident: Ident::with_dummy_span(Symbol::intern(&format!("arg{idx}"))),
253254
hir_id: self.next_id(),
254255
res: Res::Local(param_id),
255256
args: None,
@@ -273,7 +274,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
273274
let mut args: Vec<hir::Expr<'_>> = Vec::with_capacity(param_count);
274275

275276
for idx in 0..param_count {
276-
let (param, pat_node_id) = this.generate_param(span);
277+
let (param, pat_node_id) = this.generate_param(idx, span);
277278
parameters.push(param);
278279

279280
let arg = if let Some(block) = block
@@ -289,7 +290,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
289290
this.ident_and_label_to_local_id.insert(pat_node_id, param.pat.hir_id.local_id);
290291
this.lower_target_expr(&block)
291292
} else {
292-
this.generate_arg(param.pat.hir_id, span)
293+
this.generate_arg(idx, param.pat.hir_id, span)
293294
};
294295
args.push(arg);
295296
}

tests/pretty/hir-delegation.pp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
fn b<C>(e: C) { }
1212

1313
trait G {
14-
fn b(: _) -> _ { b({ }) }
14+
fn b(arg0: _) -> _ { b({ }) }
1515
}
1616

1717
mod m {
1818
fn add(a: u32, b: u32) -> u32 { a + b }
1919
}
2020

21-
fn add(: _, : _) -> _ { m::add(, ) }
21+
fn add(arg0: _, arg1: _) -> _ { m::add(arg0, arg1) }
2222

2323
fn main() { { let _ = add(1, 2); }; }

0 commit comments

Comments
 (0)