about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2021-04-05 13:03:36 +0200
committerGitHub <noreply@github.com>2021-04-05 13:03:36 +0200
commit54ea8e1b82a67202e64f8aac1ed57bc7b987e508 (patch)
tree3a58fc584780565d66b1f88196aed568f651c358
parent58e71896506edb701f276158bd2f47e8788a1133 (diff)
parent06b3636f4ed23c1ad0ed18ecc1408147ec862c1a (diff)
downloadrust-54ea8e1b82a67202e64f8aac1ed57bc7b987e508.tar.gz
rust-54ea8e1b82a67202e64f8aac1ed57bc7b987e508.zip
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.
-rw-r--r--compiler/rustc_typeck/src/check/method/probe.rs8
-rw-r--r--src/test/ui/inference/issue-81522.rs31
2 files changed, 38 insertions, 1 deletions
diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs
index bfaf36e702f..d83b74f4ce9 100644
--- a/compiler/rustc_typeck/src/check/method/probe.rs
+++ b/compiler/rustc_typeck/src/check/method/probe.rs
@@ -83,6 +83,8 @@ struct ProbeContext<'a, 'tcx> {
     unsatisfied_predicates: Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>)>,
 
     is_suggestion: IsSuggestion,
+
+    scope_expr_id: hir::HirId,
 }
 
 impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
@@ -448,6 +450,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 orig_values,
                 steps.steps,
                 is_suggestion,
+                scope_expr_id,
             );
 
             probe_cx.assemble_inherent_candidates();
@@ -547,6 +550,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         orig_steps_var_values: OriginalQueryValues<'tcx>,
         steps: Lrc<Vec<CandidateStep<'tcx>>>,
         is_suggestion: IsSuggestion,
+        scope_expr_id: hir::HirId,
     ) -> ProbeContext<'a, 'tcx> {
         ProbeContext {
             fcx,
@@ -564,6 +568,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
             private_candidate: None,
             unsatisfied_predicates: Vec::new(),
             is_suggestion,
+            scope_expr_id,
         }
     }
 
@@ -1312,7 +1317,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
     ) {
         self.tcx.struct_span_lint_hir(
             lint::builtin::UNSTABLE_NAME_COLLISIONS,
-            self.fcx.body_id,
+            self.scope_expr_id,
             self.span,
             |lint| {
                 let def_kind = stable_pick.item.kind.as_def_kind();
@@ -1594,6 +1599,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
                 self.orig_steps_var_values.clone(),
                 steps,
                 IsSuggestion(true),
+                self.scope_expr_id,
             );
             pcx.allow_similar_names = true;
             pcx.assemble_inherent_candidates();
diff --git a/src/test/ui/inference/issue-81522.rs b/src/test/ui/inference/issue-81522.rs
new file mode 100644
index 00000000000..902f8fdde58
--- /dev/null
+++ b/src/test/ui/inference/issue-81522.rs
@@ -0,0 +1,31 @@
+// Regression test for #81522.
+// Ensures that `#[allow(unstable_name_collisions)]` appended to things other than function
+// suppresses the corresponding diagnostics emitted from inside them.
+// But note that this attribute doesn't work for macro invocations if it is appended directly.
+
+// aux-build:inference_unstable_iterator.rs
+// aux-build:inference_unstable_itertools.rs
+// run-pass
+
+extern crate inference_unstable_iterator;
+extern crate inference_unstable_itertools;
+
+#[allow(unused_imports)]
+use inference_unstable_iterator::IpuIterator;
+use inference_unstable_itertools::IpuItertools;
+
+fn main() {
+    // expression statement
+    #[allow(unstable_name_collisions)]
+    'x'.ipu_flatten();
+
+    // let statement
+    #[allow(unstable_name_collisions)]
+    let _ = 'x'.ipu_flatten();
+
+    // block expression
+    #[allow(unstable_name_collisions)]
+    {
+        'x'.ipu_flatten();
+    }
+}