Skip to content

Commit 54ea8e1

Browse files
authored
Rollup merge of #81922 - magurotuna:issue81522, r=matthewjasper
Let `#[allow(unstable_name_collisions)]` work for things other than function Fixes #81522 In addition to the report in #81522, currently `#[allow(unstable_name_collisions)]` doesn't suppress the corresponding diagnostics even if this attribute is appended to an expression statement or a let statement. It seems like this is because the wrong `HirId` is passed to `struct_span_lint_hir`. It's fixed in this PR, and a regression test for it is also added.
2 parents 58e7189 + 06b3636 commit 54ea8e1

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

compiler/rustc_typeck/src/check/method/probe.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ struct ProbeContext<'a, 'tcx> {
8383
unsatisfied_predicates: Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>)>,
8484

8585
is_suggestion: IsSuggestion,
86+
87+
scope_expr_id: hir::HirId,
8688
}
8789

8890
impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
@@ -448,6 +450,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
448450
orig_values,
449451
steps.steps,
450452
is_suggestion,
453+
scope_expr_id,
451454
);
452455

453456
probe_cx.assemble_inherent_candidates();
@@ -547,6 +550,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
547550
orig_steps_var_values: OriginalQueryValues<'tcx>,
548551
steps: Lrc<Vec<CandidateStep<'tcx>>>,
549552
is_suggestion: IsSuggestion,
553+
scope_expr_id: hir::HirId,
550554
) -> ProbeContext<'a, 'tcx> {
551555
ProbeContext {
552556
fcx,
@@ -564,6 +568,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
564568
private_candidate: None,
565569
unsatisfied_predicates: Vec::new(),
566570
is_suggestion,
571+
scope_expr_id,
567572
}
568573
}
569574

@@ -1312,7 +1317,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
13121317
) {
13131318
self.tcx.struct_span_lint_hir(
13141319
lint::builtin::UNSTABLE_NAME_COLLISIONS,
1315-
self.fcx.body_id,
1320+
self.scope_expr_id,
13161321
self.span,
13171322
|lint| {
13181323
let def_kind = stable_pick.item.kind.as_def_kind();
@@ -1594,6 +1599,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15941599
self.orig_steps_var_values.clone(),
15951600
steps,
15961601
IsSuggestion(true),
1602+
self.scope_expr_id,
15971603
);
15981604
pcx.allow_similar_names = true;
15991605
pcx.assemble_inherent_candidates();

src/test/ui/inference/issue-81522.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Regression test for #81522.
2+
// Ensures that `#[allow(unstable_name_collisions)]` appended to things other than function
3+
// suppresses the corresponding diagnostics emitted from inside them.
4+
// But note that this attribute doesn't work for macro invocations if it is appended directly.
5+
6+
// aux-build:inference_unstable_iterator.rs
7+
// aux-build:inference_unstable_itertools.rs
8+
// run-pass
9+
10+
extern crate inference_unstable_iterator;
11+
extern crate inference_unstable_itertools;
12+
13+
#[allow(unused_imports)]
14+
use inference_unstable_iterator::IpuIterator;
15+
use inference_unstable_itertools::IpuItertools;
16+
17+
fn main() {
18+
// expression statement
19+
#[allow(unstable_name_collisions)]
20+
'x'.ipu_flatten();
21+
22+
// let statement
23+
#[allow(unstable_name_collisions)]
24+
let _ = 'x'.ipu_flatten();
25+
26+
// block expression
27+
#[allow(unstable_name_collisions)]
28+
{
29+
'x'.ipu_flatten();
30+
}
31+
}

0 commit comments

Comments
 (0)