Skip to content

Rollup of 8 pull requests #75351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
82ccdab
Disallow missing unsafe blocks in unsafe fn in panicking.rs
poliorcetics Jul 29, 2020
e7e41a8
Add additonal case for Path starts with
pickfire Aug 8, 2020
4dbe0ac
Detect likely `for foo of bar` JS syntax
estebank Aug 9, 2020
cc54a1f
Clean up E0749 explanation
GuillaumeGomez Aug 9, 2020
4e78760
Remove E0749 from untested error codes
GuillaumeGomez Aug 9, 2020
b11e2f2
Give precedence to primitives over modules
jyn514 Aug 9, 2020
4b549fa
show multiple slashes starts_with Path example
pickfire Aug 9, 2020
f3cc957
Rename "Important traits" to "Notable traits"
camelid Aug 9, 2020
e9e319c
Use intra-doc links
denisvasilik Aug 9, 2020
ce24421
Remove liNone as it is in the prelude
denisvasilik Aug 9, 2020
9e71c13
Add link for Duration
denisvasilik Aug 9, 2020
bdf426a
Do not ICE when lowering invalid extern fn with bodies
estebank Aug 9, 2020
62e5488
Rollup merge of #74200 - poliorcetics:std-panicking-unsafe-block-in-u…
JohnTitor Aug 10, 2020
df2da46
Rollup merge of #75286 - pickfire:patch-9, r=jyn514
JohnTitor Aug 10, 2020
968740a
Rollup merge of #75318 - jyn514:primitive, r=manishearth
JohnTitor Aug 10, 2020
d8ac403
Rollup merge of #75320 - estebank:js-for-i-of-x, r=davidtwco
JohnTitor Aug 10, 2020
f6c41fb
Rollup merge of #75328 - GuillaumeGomez:cleanup-e0749, r=Dylan-DPC
JohnTitor Aug 10, 2020
8176240
Rollup merge of #75344 - camelid:rename-important-to-notable-traits, …
JohnTitor Aug 10, 2020
64d7109
Rollup merge of #75348 - denisvasilik:intra-doc-links-core-time, r=jy…
JohnTitor Aug 10, 2020
5369619
Rollup merge of #75350 - estebank:foreign-fn-with-body-ice, r=davidtwco
JohnTitor Aug 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ const MICROS_PER_SEC: u64 = 1_000_000;
/// nanosecond-level precision, APIs binding a system timeout will typically round up
/// the number of nanoseconds.
///
/// `Duration`s implement many common traits, including [`Add`], [`Sub`], and other
/// [`ops`] traits. It implements `Default` by returning a zero-length `Duration`.
/// [`Duration`]s implement many common traits, including [`Add`], [`Sub`], and other
/// [`ops`] traits. It implements [`Default`] by returning a zero-length `Duration`.
///
/// [`Add`]: ../../std/ops/trait.Add.html
/// [`Sub`]: ../../std/ops/trait.Sub.html
/// [`ops`]: ../../std/ops/index.html
/// [`ops`]: crate::ops
///
/// # Examples
///
Expand Down Expand Up @@ -293,7 +291,7 @@ impl Duration {
/// + duration.subsec_nanos() as f64 * 1e-9);
/// ```
///
/// [`subsec_nanos`]: #method.subsec_nanos
/// [`subsec_nanos`]: Duration::subsec_nanos
#[stable(feature = "duration", since = "1.3.0")]
#[rustc_const_stable(feature = "duration", since = "1.32.0")]
#[inline]
Expand Down Expand Up @@ -421,8 +419,6 @@ impl Duration {
/// Checked `Duration` addition. Computes `self + other`, returning [`None`]
/// if overflow occurred.
///
/// [`None`]: ../../std/option/enum.Option.html#variant.None
///
/// # Examples
///
/// Basic usage:
Expand Down Expand Up @@ -457,8 +453,6 @@ impl Duration {
/// Checked `Duration` subtraction. Computes `self - other`, returning [`None`]
/// if the result would be negative or if overflow occurred.
///
/// [`None`]: ../../std/option/enum.Option.html#variant.None
///
/// # Examples
///
/// Basic usage:
Expand Down Expand Up @@ -494,8 +488,6 @@ impl Duration {
/// Checked `Duration` multiplication. Computes `self * other`, returning
/// [`None`] if overflow occurred.
///
/// [`None`]: ../../std/option/enum.Option.html#variant.None
///
/// # Examples
///
/// Basic usage:
Expand Down Expand Up @@ -526,8 +518,6 @@ impl Duration {
/// Checked `Duration` division. Computes `self / other`, returning [`None`]
/// if `other == 0`.
///
/// [`None`]: ../../std/option/enum.Option.html#variant.None
///
/// # Examples
///
/// Basic usage:
Expand Down
50 changes: 44 additions & 6 deletions library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//! * Executing a panic up to doing the actual implementation
//! * Shims around "try"

#![deny(unsafe_op_in_unsafe_fn)]

use core::panic::{BoxMeUp, Location, PanicInfo};

use crate::any::Any;
Expand Down Expand Up @@ -322,25 +324,48 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
let mut data = Data { f: ManuallyDrop::new(f) };

let data_ptr = &mut data as *mut _ as *mut u8;
return if intrinsics::r#try(do_call::<F, R>, data_ptr, do_catch::<F, R>) == 0 {
Ok(ManuallyDrop::into_inner(data.r))
} else {
Err(ManuallyDrop::into_inner(data.p))
};
// SAFETY:
//
// Access to the union's fields: this is `std` and we know that the `r#try`
// intrinsic fills in the `r` or `p` union field based on its return value.
//
// The call to `intrinsics::r#try` is made safe by:
// - `do_call`, the first argument, can be called with the initial `data_ptr`.
// - `do_catch`, the second argument, can be called with the `data_ptr` as well.
// See their safety preconditions for more informations
unsafe {
return if intrinsics::r#try(do_call::<F, R>, data_ptr, do_catch::<F, R>) == 0 {
Ok(ManuallyDrop::into_inner(data.r))
} else {
Err(ManuallyDrop::into_inner(data.p))
};
}

// We consider unwinding to be rare, so mark this function as cold. However,
// do not mark it no-inline -- that decision is best to leave to the
// optimizer (in most cases this function is not inlined even as a normal,
// non-cold function, though, as of the writing of this comment).
#[cold]
unsafe fn cleanup(payload: *mut u8) -> Box<dyn Any + Send + 'static> {
let obj = Box::from_raw(__rust_panic_cleanup(payload));
// SAFETY: The whole unsafe block hinges on a correct implementation of
// the panic handler `__rust_panic_cleanup`. As such we can only
// assume it returns the correct thing for `Box::from_raw` to work
// without undefined behavior.
let obj = unsafe { Box::from_raw(__rust_panic_cleanup(payload)) };
panic_count::decrease();
obj
}

// SAFETY:
// data must be non-NUL, correctly aligned, and a pointer to a `Data<F, R>`
// Its must contains a valid `f` (type: F) value that can be use to fill
// `data.r`.
//
// This function cannot be marked as `unsafe` because `intrinsics::r#try`
// expects normal function pointers.
#[inline]
fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
// SAFETY: this is the responsibilty of the caller, see above.
unsafe {
let data = data as *mut Data<F, R>;
let data = &mut (*data);
Expand All @@ -352,8 +377,21 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
// We *do* want this part of the catch to be inlined: this allows the
// compiler to properly track accesses to the Data union and optimize it
// away most of the time.
//
// SAFETY:
// data must be non-NUL, correctly aligned, and a pointer to a `Data<F, R>`
// Since this uses `cleanup` it also hinges on a correct implementation of
// `__rustc_panic_cleanup`.
//
// This function cannot be marked as `unsafe` because `intrinsics::r#try`
// expects normal function pointers.
#[inline]
fn do_catch<F: FnOnce() -> R, R>(data: *mut u8, payload: *mut u8) {
// SAFETY: this is the responsibilty of the caller, see above.
//
// When `__rustc_panic_cleaner` is correctly implemented we can rely
// on `obj` being the correct thing to pass to `data.p` (after wrapping
// in `ManuallyDrop`).
unsafe {
let data = data as *mut Data<F, R>;
let data = &mut (*data);
Expand Down
6 changes: 5 additions & 1 deletion library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2031,9 +2031,13 @@ impl Path {
/// assert!(path.starts_with("/etc"));
/// assert!(path.starts_with("/etc/"));
/// assert!(path.starts_with("/etc/passwd"));
/// assert!(path.starts_with("/etc/passwd/"));
/// assert!(path.starts_with("/etc/passwd/")); // extra slash is okay
/// assert!(path.starts_with("/etc/passwd///")); // multiple extra slashes are okay
///
/// assert!(!path.starts_with("/e"));
/// assert!(!path.starts_with("/etc/passwd.txt"));
///
/// assert!(!Path::new("/etc/foo.rs").starts_with("/etc/foo"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool {
Expand Down
6 changes: 5 additions & 1 deletion library/std/src/thread/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ macro_rules! __thread_local_inner {
static __KEY: $crate::thread::__OsLocalKeyInner<$t> =
$crate::thread::__OsLocalKeyInner::new();

__KEY.get(__init)
// FIXME: remove the #[allow(...)] marker when macros don't
// raise warning for missing/extraneous unsafe blocks anymore.
// See https://github.com/rust-lang/rust/issues/74838.
#[allow(unused_unsafe)]
unsafe { __KEY.get(__init) }
}

unsafe {
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
.resolver
.trait_map()
.iter()
.map(|(&k, v)| (self.node_id_to_hir_id[k].unwrap(), v.clone()))
.filter_map(|(&k, v)| {
self.node_id_to_hir_id.get(k).and_then(|id| id.as_ref()).map(|id| (*id, v.clone()))
})
.collect();

let mut def_id_to_hir_id = IndexVec::default();
Expand Down
23 changes: 19 additions & 4 deletions src/librustc_error_codes/error_codes/E0749.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
Negative impls are not allowed to have any items. Negative impls
declare that a trait is **not** implemented (and never will be) and
hence there is no need to specify the values for trait methods or
other items.
An item was added on a negative impl.

Erroneous code example:

```compile_fail,E0749
# #![feature(negative_impls)]
trait MyTrait {
type Foo;
}

impl !MyTrait for u32 {
type Foo = i32; // error!
}
# fn main() {}
```

Negative impls are not allowed to have any items. Negative impls declare that a
trait is **not** implemented (and never will be) and hence there is no need to
specify the values for trait methods or other items.
19 changes: 13 additions & 6 deletions src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1733,13 +1733,20 @@ impl<'a> Parser<'a> {
Ok(self.mk_expr(lo.to(self.prev_token.span), kind, attrs))
}

fn error_missing_in_for_loop(&self) {
let in_span = self.prev_token.span.between(self.token.span);
self.struct_span_err(in_span, "missing `in` in `for` loop")
fn error_missing_in_for_loop(&mut self) {
let (span, msg, sugg) = if self.token.is_ident_named(sym::of) {
// Possibly using JS syntax (#75311).
let span = self.token.span;
self.bump();
(span, "try using `in` here instead", "in")
} else {
(self.prev_token.span.between(self.token.span), "try adding `in` here", " in ")
};
self.struct_span_err(span, "missing `in` in `for` loop")
.span_suggestion_short(
in_span,
"try adding `in` here",
" in ".into(),
span,
msg,
sugg.into(),
// Has been misleading, at least in the past (closed Issue #48492).
Applicability::MaybeIncorrect,
)
Expand Down
1 change: 1 addition & 0 deletions src/librustc_span/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ symbols! {
not,
note,
object_safe_for_dispatch,
of,
offset,
omit_gdb_pretty_printer_section,
on,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3450,7 +3450,7 @@ fn spotlight_decl(decl: &clean::FnDecl) -> String {
if impl_.trait_.def_id().map_or(false, |d| c.traits[&d].is_spotlight) {
if out.is_empty() {
out.push_str(&format!(
"<h3 class=\"important\">Important traits for {}</h3>\
"<h3 class=\"notable\">Notable traits for {}</h3>\
<code class=\"content\">",
impl_.for_.print()
));
Expand Down Expand Up @@ -3485,7 +3485,7 @@ fn spotlight_decl(decl: &clean::FnDecl) -> String {
if !out.is_empty() {
out.insert_str(
0,
"<span class=\"important-traits\"><span class=\"important-traits-tooltip\">ⓘ<div class='important-traits-tooltiptext'><span class=\"docblock\">"
"<span class=\"notable-traits\"><span class=\"notable-traits-tooltip\">ⓘ<div class='notable-traits-tooltiptext'><span class=\"docblock\">"

);
out.push_str("</code></span></div></span></span>");
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2636,9 +2636,9 @@ function defocusSearchBar() {
});
}());

onEachLazy(document.getElementsByClassName("important-traits"), function(e) {
onEachLazy(document.getElementsByClassName("notable-traits"), function(e) {
e.onclick = function() {
this.getElementsByClassName('important-traits-tooltiptext')[0]
this.getElementsByClassName('notable-traits-tooltiptext')[0]
.classList.toggle("force-tooltip");
};
});
Expand Down
28 changes: 14 additions & 14 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ h2 {
h3 {
font-size: 1.3em;
}
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod):not(.important),
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod):not(.notable),
h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant) {
font-weight: 500;
margin: 20px 0 15px 0;
Expand Down Expand Up @@ -528,7 +528,7 @@ h4 > code, h3 > code, .invisible > code {
font-size: 0.8em;
}

.content .methods > div:not(.important-traits) {
.content .methods > div:not(.notable-traits) {
margin-left: 40px;
margin-bottom: 15px;
}
Expand Down Expand Up @@ -1099,17 +1099,17 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
font-size: 20px;
}

.important-traits-tooltip {
.notable-traits-tooltip {
display: inline-block;
cursor: pointer;
}

.important-traits:hover .important-traits-tooltiptext,
.important-traits .important-traits-tooltiptext.force-tooltip {
.notable-traits:hover .notable-traits-tooltiptext,
.notable-traits .notable-traits-tooltiptext.force-tooltip {
display: inline-block;
}

.important-traits .important-traits-tooltiptext {
.notable-traits .notable-traits-tooltiptext {
display: none;
padding: 5px 3px 3px 3px;
border-radius: 6px;
Expand All @@ -1121,18 +1121,18 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
border: 1px solid;
}

.important-traits-tooltip::after {
.notable-traits-tooltip::after {
/* The margin on the tooltip does not capture hover events,
this extends the area of hover enough so that mouse hover is not
lost when moving the mouse to the tooltip */
content: "\00a0\00a0\00a0";
}

.important-traits .important, .important-traits .docblock {
.notable-traits .notable, .notable-traits .docblock {
margin: 0;
}

.important-traits .docblock code.content{
.notable-traits .docblock code.content{
margin: 0;
padding: 0;
font-size: 20px;
Expand Down Expand Up @@ -1183,13 +1183,13 @@ pre.rust {
font-size: 16px;
}

.important-traits {
.notable-traits {
cursor: pointer;
z-index: 2;
margin-left: 5px;
}

h4 > .important-traits {
h4 > .notable-traits {
position: absolute;
left: -44px;
top: 2px;
Expand Down Expand Up @@ -1431,7 +1431,7 @@ h4 > .important-traits {
z-index: 1;
}

h4 > .important-traits {
h4 > .notable-traits {
position: absolute;
left: -22px;
top: 24px;
Expand Down Expand Up @@ -1522,7 +1522,7 @@ h4 > .important-traits {
margin-top: 0;
}

.important-traits .important-traits-tooltiptext {
.notable-traits .notable-traits-tooltiptext {
left: 0;
top: 100%;
}
Expand All @@ -1544,7 +1544,7 @@ h4 > .important-traits {
}
}

h3.important {
h3.notable {
margin: 0;
margin-bottom: 13px;
font-size: 19px;
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ pre.ignore:hover, .information:hover + pre.ignore {
border-color: transparent #314559 transparent transparent;
}

.important-traits-tooltiptext {
.notable-traits-tooltiptext {
background-color: #314559;
border-color: #5c6773;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ pre.ignore:hover, .information:hover + pre.ignore {
border-color: transparent black transparent transparent;
}

.important-traits-tooltiptext {
.notable-traits-tooltiptext {
background-color: #111;
border-color: #777;
}
Expand Down
Loading