Skip to content

Commit 2dbb2f7

Browse files
authored
Rollup merge of #87178 - moxian:rd-use, r=jyn514
[rustdoc] Copy only item path to clipboard rather than full `use` statement. The (somewhat) recent addition of the "copy item import to clipboard" button is extremely nice. However, i tend to write my code with fully qualified paths wherever feasible and only resort to `use` statements as a refactoring pass. This makes the "copy to clipboard" workflow awkward to use, as i would be copy-pasting that as, say ```rust impl use std::ops::Add; for MyType { ``` and then go back and remove the `use ` and `;`. This PR removes the `use ;` decorations, making it much nicer to use for fully-qualified items. I argue, however, that this does not noticeably degrade experience for those who prefer to import items, since the hard part about those is getting the path right, and writing the `use ;` decoration can be done by hand with little effort.
2 parents 0035d9d + 81d792f commit 2dbb2f7

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/librustdoc/html/render/print_item.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer,
8585
write!(buf, "<a class=\"{}\" href=\"#\">{}</a>", item.type_(), item.name.as_ref().unwrap());
8686
write!(
8787
buf,
88-
"<button id=\"copy-path\" onclick=\"copy_path(this)\" title=\"copy path\">\
88+
"<button id=\"copy-path\" onclick=\"copy_path(this)\" title=\"Copy item path to clipboard\">\
8989
<img src=\"{static_root_path}clipboard{suffix}.svg\" \
9090
width=\"19\" height=\"18\" \
91-
alt=\"Copy item import\" \
92-
title=\"Copy item import to clipboard\">\
91+
alt=\"Copy item path\">\
9392
</button>",
9493
static_root_path = page.get_static_root_path(),
9594
suffix = page.resource_suffix,

src/librustdoc/html/static/js/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ function hideThemeButtonState() {
986986
});
987987

988988
var el = document.createElement('textarea');
989-
el.value = 'use ' + path.join('::') + ';';
989+
el.value = path.join('::');
990990
el.setAttribute('readonly', '');
991991
// To not make it appear on the screen.
992992
el.style.position = 'absolute';

0 commit comments

Comments
 (0)