Skip to content

Commit 7fbd7bd

Browse files
authored
Rollup merge of rust-lang#139614 - nnethercote:fix-139512, r=oli-obk
Avoid empty identifiers for delegate params and args. Details in individual commits. r? `@oli-obk`
2 parents 362c0f2 + 9bb1008 commit 7fbd7bd

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
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

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ pretty-compare-only
2+
//@ pretty-mode:hir
3+
//@ pp-exact:hir-delegation.pp
4+
5+
#![allow(incomplete_features)]#![feature(fn_delegation)]
6+
#[prelude_import]
7+
use ::std::prelude::rust_2015::*;
8+
#[macro_use]
9+
extern crate std;
10+
11+
fn b<C>(e: C) { }
12+
13+
trait G {
14+
fn b(arg0: _) -> _ { b({ }) }
15+
}
16+
17+
mod m {
18+
fn add(a: u32, b: u32) -> u32 { a + b }
19+
}
20+
21+
fn add(arg0: _, arg1: _) -> _ { m::add(arg0, arg1) }
22+
23+
fn main() { { let _ = add(1, 2); }; }

tests/pretty/hir-delegation.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ pretty-compare-only
2+
//@ pretty-mode:hir
3+
//@ pp-exact:hir-delegation.pp
4+
5+
#![allow(incomplete_features)]
6+
#![feature(fn_delegation)]
7+
8+
fn b<C>(e: C) {}
9+
10+
trait G {
11+
reuse b {}
12+
}
13+
14+
mod m {
15+
pub fn add(a: u32, b: u32) -> u32 { a + b }
16+
}
17+
18+
reuse m::add;
19+
20+
fn main() {
21+
_ = add(1, 2);
22+
}

0 commit comments

Comments
 (0)