Skip to content

Commit

Permalink
Auto merge of #96824 - matthiaskrgr:rollup-silw3ki, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - #96336 (Link to correct `as_mut` in docs for `pointer::as_ref`)
 - #96586 (Add aliases for std::fs::canonicalize)
 - #96667 (Add regression test)
 - #96671 (Remove hard links from `env::current_exe` security example)
 - #96726 (Add regression and bug tests)
 - #96756 (Enable compiler-docs by default for `compiler`, `codegen`, and `tools` profiles)
 - #96757 (Don't constantly rebuild clippy on `x test src/tools/clippy`.)
 - #96769 (Remove `adx_target_feature` feature from active features list)
 - #96777 (Make the test `check-pass` not to produce a JSON file)
 - #96822 (Enforce quote rule for JS source code)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 7, 2022
2 parents ea92b08 + 20ade86 commit e612ce9
Show file tree
Hide file tree
Showing 24 changed files with 237 additions and 87 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ declare_features! (

// Unstable `#[target_feature]` directives.
(active, aarch64_ver_target_feature, "1.27.0", Some(44839), None),
(active, adx_target_feature, "1.32.0", Some(44839), None),
(active, arm_target_feature, "1.27.0", Some(44839), None),
(active, avx512_target_feature, "1.27.0", Some(44839), None),
(active, bpf_target_feature, "1.54.0", Some(44839), None),
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<T: ?Sized> *mut T {
/// For the mutable counterpart see [`as_mut`].
///
/// [`as_uninit_ref`]: #method.as_uninit_ref-1
/// [`as_mut`]: #method.as_mut
/// [`as_mut`]: #method.as_mut-1
///
/// # Safety
///
Expand Down
47 changes: 17 additions & 30 deletions library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,36 +644,23 @@ pub fn temp_dir() -> PathBuf {
///
/// # Security
///
/// The output of this function should not be used in anything that might have
/// security implications. For example:
///
/// ```
/// fn main() {
/// println!("{:?}", std::env::current_exe());
/// }
/// ```
///
/// On Linux systems, if this is compiled as `foo`:
///
/// ```bash
/// $ rustc foo.rs
/// $ ./foo
/// Ok("/home/alex/foo")
/// ```
///
/// And you make a hard link of the program:
///
/// ```bash
/// $ ln foo bar
/// ```
///
/// When you run it, you won’t get the path of the original executable, you’ll
/// get the path of the hard link:
///
/// ```bash
/// $ ./bar
/// Ok("/home/alex/bar")
/// ```
/// The output of this function should not be trusted for anything
/// that might have security implications. Basically, if users can run
/// the executable, they can change the output arbitrarily.
///
/// As an example, you can easily introduce a race condition. It goes
/// like this:
///
/// 1. You get the path to the current executable using `current_exe()`, and
/// store it in a variable.
/// 2. Time passes. A malicious actor removes the current executable, and
/// replaces it with a malicious one.
/// 3. You then use the stored path to re-execute the current
/// executable.
///
/// You expected to safely execute the current executable, but you're
/// instead executing something completely different. The code you
/// just executed run with your privileges.
///
/// This sort of behavior has been known to [lead to privilege escalation] when
/// used incorrectly.
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,8 @@ pub fn read_link<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
/// Ok(())
/// }
/// ```
#[doc(alias = "realpath")]
#[doc(alias = "GetFinalPathNameByHandle")]
#[stable(feature = "fs_canonicalize", since = "1.5.0")]
pub fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
fs_imp::canonicalize(path.as_ref())
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/defaults/config.codegen.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# These defaults are meant for contributors to the compiler who modify codegen or LLVM
[build]
# Contributors working on the compiler will probably expect compiler docs to be generated.
compiler-docs = true

[llvm]
# This enables debug-assertions in LLVM,
# catching logic errors in codegen much earlier in the process.
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/defaults/config.compiler.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# These defaults are meant for contributors to the compiler who do not modify codegen or LLVM
[build]
# Contributors working on the compiler will probably expect compiler docs to be generated.
compiler-docs = true

[rust]
# This enables `RUSTC_LOG=debug`, avoiding confusing situations
# where adding `debug!()` appears to do nothing.
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/defaults/config.tools.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ download-rustc = "if-unchanged"
[build]
# Document with the in-tree rustdoc by default, since `download-rustc` makes it quick to compile.
doc-stage = 2
# Contributors working on tools will probably expect compiler docs to be generated, so they can figure out how to use the API.
compiler-docs = true

[llvm]
# Will download LLVM from CI if available on your platform.
Expand Down
2 changes: 0 additions & 2 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,6 @@ impl Step for Clippy {
&[],
);

// clippy tests need to know about the stage sysroot
cargo.env("SYSROOT", builder.sysroot(compiler));
cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ pub fn prepare_tool_cargo(
}
}

// clippy tests need to know about the stage sysroot. Set them consistently while building to
// avoid rebuilding when running tests.
cargo.env("SYSROOT", builder.sysroot(compiler));

// if tools are using lzma we want to force the build script to build its
// own copy
cargo.env("LZMA_API_STATIC", "1");
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/html/static/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ module.exports = {
"error",
"always"
],
"quotes": [
"error",
"double"
],
"no-var": ["error"],
"prefer-const": ["error"],
"prefer-arrow-callback": ["error"],
Expand Down
30 changes: 15 additions & 15 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function loadCss(cssFileName) {

(function() {
function loadScript(url) {
const script = document.createElement('script');
const script = document.createElement("script");
script.src = url;
document.head.append(script);
}
Expand Down Expand Up @@ -344,7 +344,7 @@ function loadCss(cssFileName) {
searchState.input.blur();
},
showResults: search => {
if (search === null || typeof search === 'undefined') {
if (search === null || typeof search === "undefined") {
search = searchState.outputElement();
}
switchDisplayedElement(search);
Expand Down Expand Up @@ -390,7 +390,7 @@ function loadCss(cssFileName) {
loadSearch();
});

if (search_input.value !== '') {
if (search_input.value !== "") {
loadSearch();
}

Expand Down Expand Up @@ -968,7 +968,7 @@ function loadCss(cssFileName) {

onEachLazy(document.getElementsByClassName("notable-traits"), e => {
e.onclick = function() {
this.getElementsByClassName('notable-traits-tooltiptext')[0]
this.getElementsByClassName("notable-traits-tooltiptext")[0]
.classList.toggle("force-tooltip");
};
});
Expand Down Expand Up @@ -1070,29 +1070,29 @@ function loadCss(cssFileName) {
const path = [];

onEach(parent.childNodes, child => {
if (child.tagName === 'A') {
if (child.tagName === "A") {
path.push(child.textContent);
}
});

const el = document.createElement('textarea');
el.value = path.join('::');
el.setAttribute('readonly', '');
const el = document.createElement("textarea");
el.value = path.join("::");
el.setAttribute("readonly", "");
// To not make it appear on the screen.
el.style.position = 'absolute';
el.style.left = '-9999px';
el.style.position = "absolute";
el.style.left = "-9999px";

document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.execCommand("copy");
document.body.removeChild(el);

// There is always one children, but multiple childNodes.
but.children[0].style.display = 'none';
but.children[0].style.display = "none";

let tmp;
if (but.childNodes.length < 2) {
tmp = document.createTextNode('✓');
tmp = document.createTextNode("✓");
but.appendChild(tmp);
} else {
onEachLazy(but.childNodes, e => {
Expand All @@ -1101,15 +1101,15 @@ function loadCss(cssFileName) {
return true;
}
});
tmp.textContent = '✓';
tmp.textContent = "✓";
}

if (reset_button_timeout !== null) {
window.clearTimeout(reset_button_timeout);
}

function reset_button() {
tmp.textContent = '';
tmp.textContent = "";
reset_button_timeout = null;
but.children[0].style.display = "";
}
Expand Down
34 changes: 17 additions & 17 deletions src/librustdoc/html/static/js/scrape-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// Scroll code block to the given code location
function scrollToLoc(elt, loc) {
const lines = elt.querySelector('.line-numbers');
const lines = elt.querySelector(".line-numbers");
let scrollOffset;

// If the block is greater than the size of the viewer,
Expand All @@ -32,16 +32,16 @@
function updateScrapedExample(example) {
const locs = JSON.parse(example.attributes.getNamedItem("data-locs").textContent);
let locIndex = 0;
const highlights = Array.prototype.slice.call(example.querySelectorAll('.highlight'));
const link = example.querySelector('.scraped-example-title a');
const highlights = Array.prototype.slice.call(example.querySelectorAll(".highlight"));
const link = example.querySelector(".scraped-example-title a");

if (locs.length > 1) {
// Toggle through list of examples in a given file
const onChangeLoc = changeIndex => {
removeClass(highlights[locIndex], 'focus');
removeClass(highlights[locIndex], "focus");
changeIndex();
scrollToLoc(example, locs[locIndex][0]);
addClass(highlights[locIndex], 'focus');
addClass(highlights[locIndex], "focus");

const url = locs[locIndex][1];
const title = locs[locIndex][2];
Expand All @@ -50,24 +50,24 @@
link.innerHTML = title;
};

example.querySelector('.prev')
.addEventListener('click', () => {
example.querySelector(".prev")
.addEventListener("click", () => {
onChangeLoc(() => {
locIndex = (locIndex - 1 + locs.length) % locs.length;
});
});

example.querySelector('.next')
.addEventListener('click', () => {
example.querySelector("next")
.addEventListener("click", () => {
onChangeLoc(() => {
locIndex = (locIndex + 1) % locs.length;
});
});
}

const expandButton = example.querySelector('.expand');
const expandButton = example.querySelector(".expand");
if (expandButton) {
expandButton.addEventListener('click', () => {
expandButton.addEventListener("click", () => {
if (hasClass(example, "expanded")) {
removeClass(example, "expanded");
scrollToLoc(example, locs[0][0]);
Expand All @@ -81,19 +81,19 @@
scrollToLoc(example, locs[0][0]);
}

const firstExamples = document.querySelectorAll('.scraped-example-list > .scraped-example');
const firstExamples = document.querySelectorAll(".scraped-example-list > .scraped-example");
onEachLazy(firstExamples, updateScrapedExample);
onEachLazy(document.querySelectorAll('.more-examples-toggle'), toggle => {
onEachLazy(document.querySelectorAll(".more-examples-toggle"), toggle => {
// Allow users to click the left border of the <details> section to close it,
// since the section can be large and finding the [+] button is annoying.
onEachLazy(toggle.querySelectorAll('.toggle-line, .hide-more'), button => {
button.addEventListener('click', () => {
onEachLazy(toggle.querySelectorAll(".toggle-line, .hide-more"), button => {
button.addEventListener("click", () => {
toggle.open = false;
});
});

const moreExamples = toggle.querySelectorAll('.scraped-example');
toggle.querySelector('summary').addEventListener('click', () => {
const moreExamples = toggle.querySelectorAll(".scraped-example");
toggle.querySelector("summary").addEventListener("click", () => {
// Wrapping in setTimeout ensures the update happens after the elements are actually
// visible. This is necessary since updateScrapedExample calls scrollToLoc which
// depends on offsetHeight, a property that requires an element to be visible to
Expand Down
Loading

0 comments on commit e612ce9

Please sign in to comment.