Skip to content

Commit 619f137

Browse files
Rollup merge of #148623 - trimmed-paths, r=davidtwco
Ignore `#[doc(hidden)]` items when computing trimmed paths for printing The `trimmed_def_paths` query examines all items in the current crate, and all pub items in immediate-dependency crates (including the standard library), to see which item names are unique and can therefore be printed unambiguously as a bare name without a module path. Currently that query has no special handling for `#[doc(hidden)]` items, which has two consequences: - Hidden names can be considered unique, and will therefore be printed without a path, making it hard to find where that name is defined (since it normally isn't listed in documentation). - Hidden names can conflict with visible names that would otherwise be considered unique, causing diagnostics to mysteriously become more verbose based on internal details of other crates. This PR therefore makes the `trimmed_def_paths` query ignore external-crate items that are `#[doc(hidden)]`, along with their descendants. As a result, hidden item names are never considered unique for trimming, and no longer interfere with visible item names being considered unique. --- - Fixes #148387.
2 parents d940e56 + 2df2c72 commit 619f137

File tree

91 files changed

+360
-193
lines changed

Some content is hidden

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

91 files changed

+360
-193
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,6 +3421,13 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
34213421
def::Res::Def(DefKind::AssocTy, _) => {}
34223422
def::Res::Def(DefKind::TyAlias, _) => {}
34233423
def::Res::Def(defkind, def_id) => {
3424+
// Ignore external `#[doc(hidden)]` items and their descendants.
3425+
// They shouldn't prevent other items from being considered
3426+
// unique, and should be printed with a full path if necessary.
3427+
if tcx.is_doc_hidden(def_id) {
3428+
continue;
3429+
}
3430+
34243431
if let Some(ns) = defkind.ns() {
34253432
collect_fn(&child.ident, ns, def_id);
34263433
}

tests/mir-opt/async_closure_fake_read_for_by_move.foo-{closure#0}-{closure#0}.built.after.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `foo::{closure#0}::{closure#0}` after built
22

3-
fn foo::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_fake_read_for_by_move.rs:12:27: 15:6}, _2: ResumeTy) -> ()
3+
fn foo::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_fake_read_for_by_move.rs:12:27: 15:6}, _2: std::future::ResumeTy) -> ()
44
yields ()
55
{
66
debug _task_context => _2;

tests/mir-opt/async_closure_fake_read_for_by_move.foo-{closure#0}-{synthetic#0}.built.after.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `foo::{closure#0}::{synthetic#0}` after built
22

3-
fn foo::{closure#0}::{synthetic#0}(_1: {async closure body@$DIR/async_closure_fake_read_for_by_move.rs:12:27: 15:6}, _2: ResumeTy) -> ()
3+
fn foo::{closure#0}::{synthetic#0}(_1: {async closure body@$DIR/async_closure_fake_read_for_by_move.rs:12:27: 15:6}, _2: std::future::ResumeTy) -> ()
44
yields ()
55
{
66
debug _task_context => _2;

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.built.after.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `main::{closure#0}::{closure#0}::{closure#0}` after built
22

3-
fn main::{closure#0}::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10}, _2: ResumeTy) -> ()
3+
fn main::{closure#0}::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10}, _2: std::future::ResumeTy) -> ()
44
yields ()
55
{
66
debug _task_context => _2;

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{synthetic#0}.built.after.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `main::{closure#0}::{closure#0}::{synthetic#0}` after built
22

3-
fn main::{closure#0}::{closure#0}::{synthetic#0}(_1: {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10}, _2: ResumeTy) -> ()
3+
fn main::{closure#0}::{closure#0}::{synthetic#0}(_1: {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10}, _2: std::future::ResumeTy) -> ()
44
yields ()
55
{
66
debug _task_context => _2;

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#1}-{closure#0}.built.after.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `main::{closure#0}::{closure#1}::{closure#0}` after built
22

3-
fn main::{closure#0}::{closure#1}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}, _2: ResumeTy) -> ()
3+
fn main::{closure#0}::{closure#1}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}, _2: std::future::ResumeTy) -> ()
44
yields ()
55
{
66
debug _task_context => _2;

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#1}-{synthetic#0}.built.after.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `main::{closure#0}::{closure#1}::{synthetic#0}` after built
22

3-
fn main::{closure#0}::{closure#1}::{synthetic#0}(_1: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}, _2: ResumeTy) -> ()
3+
fn main::{closure#0}::{closure#1}::{synthetic#0}(_1: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}, _2: std::future::ResumeTy) -> ()
44
yields ()
55
{
66
debug _task_context => _2;

tests/mir-opt/box_expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() {
88
// CHECK-LABEL: fn main(
99
// CHECK: [[ptr:_.*]] = move {{_.*}} as *const S (Transmute);
1010
// CHECK: [[nonnull:_.*]] = NonNull::<S> { pointer: move [[ptr]] };
11-
// CHECK: [[unique:_.*]] = Unique::<S> { pointer: move [[nonnull]], _marker: const PhantomData::<S> };
11+
// CHECK: [[unique:_.*]] = std::ptr::Unique::<S> { pointer: move [[nonnull]], _marker: const PhantomData::<S> };
1212
// CHECK: [[box:_.*]] = Box::<S>(move [[unique]], const std::alloc::Global);
1313
// CHECK: [[ptr:_.*]] = copy (([[box]].0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
1414
// CHECK: (*[[ptr]]) = S::new() -> [return: [[ret:bb.*]], unwind: [[unwind:bb.*]]];

tests/mir-opt/building/issue_101867.main.built.after.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() -> () {
3232
bb1: {
3333
StorageLive(_3);
3434
StorageLive(_4);
35-
_4 = begin_panic::<&str>(const "explicit panic") -> bb8;
35+
_4 = std::rt::begin_panic::<&str>(const "explicit panic") -> bb8;
3636
}
3737

3838
bb2: {

tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
StorageLive(_5);
3030
- _6 = move _4 as *const i32 (Transmute);
3131
- _7 = NonNull::<i32> { pointer: move _6 };
32-
- _8 = Unique::<i32> { pointer: move _7, _marker: const PhantomData::<i32> };
32+
- _8 = std::ptr::Unique::<i32> { pointer: move _7, _marker: const PhantomData::<i32> };
3333
+ _6 = copy _4 as *const i32 (PtrToPtr);
3434
+ _7 = NonNull::<i32> { pointer: copy _6 };
35-
+ _8 = Unique::<i32> { pointer: copy _7, _marker: const PhantomData::<i32> };
35+
+ _8 = std::ptr::Unique::<i32> { pointer: copy _7, _marker: const PhantomData::<i32> };
3636
_5 = Box::<i32>(move _8, const std::alloc::Global);
3737
- _9 = copy ((_5.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
3838
- (*_9) = const 42_i32;

0 commit comments

Comments
 (0)