Skip to content

Commit

Permalink
Auto merge of rust-lang#96759 - compiler-errors:rollup-p4jtm92, r=com…
Browse files Browse the repository at this point in the history
…piler-errors

Rollup of 7 pull requests

Successful merges:

 - rust-lang#96174 (mark ptr-int-transmute test as no_run)
 - rust-lang#96639 (Fix typo in `offset_from` documentation)
 - rust-lang#96704 (Add rotation animation on settings button when loading)
 - rust-lang#96730 (Add a regression test for rust-lang#64173 and rust-lang#66152)
 - rust-lang#96741 (Improve settings loading strategy)
 - rust-lang#96744 (Implement [OsStr]::join)
 - rust-lang#96747 (Add `track_caller` to `DefId::expect_local()`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 6, 2022
2 parents 74cea9f + b8c829b commit 9714e13
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 7 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_span/src/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ impl DefId {
}

#[inline]
#[track_caller]
pub fn expect_local(self) -> LocalDefId {
self.as_local().unwrap_or_else(|| panic!("DefId::expect_local: `{:?}` isn't local", self))
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ extern "rust-intrinsic" {
///
/// Turning a pointer into a `usize`:
///
/// ```
/// ```no_run
/// let ptr = &0;
/// let ptr_num_transmute = unsafe {
/// std::mem::transmute::<&i32, usize>(ptr)
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl<T: ?Sized> *const T {
}

/// Calculates the distance between two pointers. The returned value is in
/// units of T: the distance in bytes is divided by `mem::size_of::<T>()`.
/// units of T: the distance in bytes divided by `mem::size_of::<T>()`.
///
/// This function is the inverse of [`offset`].
///
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 @@ -696,7 +696,7 @@ impl<T: ?Sized> *mut T {
}

/// Calculates the distance between two pointers. The returned value is in
/// units of T: the distance in bytes is divided by `mem::size_of::<T>()`.
/// units of T: the distance in bytes divided by `mem::size_of::<T>()`.
///
/// This function is the inverse of [`offset`].
///
Expand Down
17 changes: 17 additions & 0 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,23 @@ impl OsStr {
}
}

#[unstable(feature = "slice_concat_ext", issue = "27747")]
impl<S: Borrow<OsStr>> alloc::slice::Join<&OsStr> for [S] {
type Output = OsString;

fn join(slice: &Self, sep: &OsStr) -> OsString {
let Some(first) = slice.first() else {
return OsString::new();
};
let first = first.borrow().to_owned();
slice[1..].iter().fold(first, |mut a, b| {
a.push(sep);
a.push(b.borrow());
a
})
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl Borrow<OsStr> for OsString {
#[inline]
Expand Down
14 changes: 14 additions & 0 deletions library/std/src/ffi/os_str/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ fn test_os_string_reserve_exact() {
assert!(os_string.capacity() >= 33)
}

#[test]
fn test_os_string_join() {
let strings = [OsStr::new("hello"), OsStr::new("dear"), OsStr::new("world")];
assert_eq!("hello", strings[..1].join(OsStr::new(" ")));
assert_eq!("hello dear world", strings.join(OsStr::new(" ")));
assert_eq!("hellodearworld", strings.join(OsStr::new("")));
assert_eq!("hello.\n dear.\n world", strings.join(OsStr::new(".\n ")));

assert_eq!("dear world", strings[1..].join(&OsString::from(" ")));

let strings_abc = [OsString::from("a"), OsString::from("b"), OsString::from("c")];
assert_eq!("a b c", strings_abc.join(OsStr::new(" ")));
}

#[test]
fn test_os_string_default() {
let os_string: OsString = Default::default();
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
#![feature(intra_doc_pointers)]
#![feature(lang_items)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(linkage)]
#![feature(min_specialization)]
#![feature(must_not_suspend)]
Expand Down Expand Up @@ -300,6 +301,7 @@
#![feature(toowned_clone_into)]
#![feature(try_reserve_kind)]
#![feature(vec_into_raw_parts)]
#![feature(slice_concat_trait)]
//
// Library features (unwind):
#![feature(panic_unwind)]
Expand Down
12 changes: 12 additions & 0 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,18 @@ pre.rust {
cursor: pointer;
}

@keyframes rotating {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
#settings-menu.rotate img {
animation: rotating 2s linear infinite;
}

#help-button {
font-family: "Fira Sans", Arial, sans-serif;
text-align: center;
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,11 @@ function loadCss(cssFileName) {
}

getSettingsButton().onclick = event => {
addClass(getSettingsButton(), "rotate");
event.preventDefault();
// Sending request for the CSS and the JS files at the same time so it will
// hopefully be loaded when the JS will generate the settings content.
loadCss("settings");
loadScript(window.settingsJS);
};

Expand Down
6 changes: 2 additions & 4 deletions src/librustdoc/html/static/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint prefer-const: "error" */
/* eslint prefer-arrow-callback: "error" */
// Local js definitions:
/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme, loadCss */
/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme */
/* global addClass, removeClass, onEach, onEachLazy, NOT_DISPLAYED_ID */
/* global MAIN_ID, getVar, getSettingsButton, switchDisplayedElement, getNotDisplayedElem */

Expand Down Expand Up @@ -209,9 +209,6 @@
},
];

// First, we add the settings.css file.
loadCss("settings");

// Then we build the DOM.
const el = document.createElement("section");
el.id = "settings";
Expand Down Expand Up @@ -274,5 +271,6 @@
if (!isSettingsPage) {
switchDisplayedElement(settingsMenu);
}
removeClass(getSettingsButton(), "rotate");
}, 0);
})();
19 changes: 19 additions & 0 deletions src/test/ui/lifetimes/issue-64173-unused-lifetimes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::mem::size_of;

struct Foo<'s> { //~ ERROR: parameter `'s` is never used
array: [(); size_of::<&Self>()],
//~^ ERROR: generic `Self` types are currently not permitted in anonymous constants
}

// The below is taken from https://github.com/rust-lang/rust/issues/66152#issuecomment-550275017
// as the root cause seems the same.

const fn foo<T>() -> usize {
0
}

struct Bar<'a> { //~ ERROR: parameter `'a` is never used
beta: [(); foo::<&'a ()>()], //~ ERROR: a non-static lifetime is not allowed in a `const`
}

fn main() {}
35 changes: 35 additions & 0 deletions src/test/ui/lifetimes/issue-64173-unused-lifetimes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error[E0658]: a non-static lifetime is not allowed in a `const`
--> $DIR/issue-64173-unused-lifetimes.rs:16:23
|
LL | beta: [(); foo::<&'a ()>()],
| ^^
|
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
= help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable

error: generic `Self` types are currently not permitted in anonymous constants
--> $DIR/issue-64173-unused-lifetimes.rs:4:28
|
LL | array: [(); size_of::<&Self>()],
| ^^^^

error[E0392]: parameter `'s` is never used
--> $DIR/issue-64173-unused-lifetimes.rs:3:12
|
LL | struct Foo<'s> {
| ^^ unused parameter
|
= help: consider removing `'s`, referring to it in a field, or using a marker such as `PhantomData`

error[E0392]: parameter `'a` is never used
--> $DIR/issue-64173-unused-lifetimes.rs:15:12
|
LL | struct Bar<'a> {
| ^^ unused parameter
|
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0392, E0658.
For more information about an error, try `rustc --explain E0392`.

0 comments on commit 9714e13

Please sign in to comment.