Skip to content

Rollup of 8 pull requests #68861

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 29 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b0a9e94
Strip unnecessary subexpression
ForNeVeR Feb 2, 2020
0eb297d
Fix up `merge_from_succ`.
nnethercote Feb 3, 2020
d62b6f2
Pull out a special case in `merge_from_succ`.
nnethercote Feb 3, 2020
d9e3d2a
Make euclidean division `const`
ecstatic-morse Feb 3, 2020
37c1418
Make checked arithmetic besides division `const`
ecstatic-morse Feb 3, 2020
de52a54
Make overflowing arithmetic `const`
ecstatic-morse Feb 3, 2020
b422a19
Make `saturating_mul` a `const fn`
ecstatic-morse Feb 3, 2020
b46d1d2
Make wrapping arithmetic `const`
ecstatic-morse Feb 3, 2020
d4529be
Const-stabilize some arithmetic intrinsics
ecstatic-morse Feb 3, 2020
526304d
Make checked division `const`
ecstatic-morse Feb 3, 2020
dda015a
Make saturating arithmetic using intrinsics `const`
ecstatic-morse Feb 3, 2020
3e9fd80
Add tests for newly const arithmetic fns
ecstatic-morse Feb 3, 2020
11eee61
Clean up E0264, E0267 and E0268 explanations
GuillaumeGomez Feb 4, 2020
01dd376
`#![recursion_limit = "X"]`: note current crate name.
Centril Feb 5, 2020
09160d1
Use consistent feature naming
ecstatic-morse Feb 4, 2020
040d987
Fix test
ecstatic-morse Feb 4, 2020
78f8ad3
Implement remaining `unchecked` arithmetic intrinsics
ecstatic-morse Feb 5, 2020
9713b56
doc fix on doc attribute
king6cong Feb 5, 2020
df7d9f3
Fix issue number of `capacity` method
JohnTitor Feb 5, 2020
28b0ed0
merge item id stable hashing functions
ljedrz Feb 5, 2020
e8b72f4
move item reference comment
ljedrz Feb 5, 2020
d694f22
Rollup merge of #68762 - ForNeVeR:patch-1, r=alexcrichton
Dylan-DPC Feb 5, 2020
c177941
Rollup merge of #68790 - nnethercote:improve-merge_from_succ, r=nikom…
Dylan-DPC Feb 5, 2020
16555ac
Rollup merge of #68809 - ecstatic-morse:const-int-functions, r=oli-obk
Dylan-DPC Feb 5, 2020
ae0bb24
Rollup merge of #68832 - GuillaumeGomez:clean-up-3-err-codes, r=estebank
Dylan-DPC Feb 5, 2020
3096e13
Rollup merge of #68840 - Centril:rec-lim-curr-crate, r=estebank
Dylan-DPC Feb 5, 2020
c0fbac5
Rollup merge of #68846 - king6cong:doc-fix, r=GuillaumeGomez
Dylan-DPC Feb 5, 2020
cf32b71
Rollup merge of #68851 - JohnTitor:fix-issue-number, r=Centril
Dylan-DPC Feb 5, 2020
b37f968
Rollup merge of #68858 - ljedrz:collapse_stable_hash_foos, r=michaelw…
Dylan-DPC Feb 5, 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
2 changes: 1 addition & 1 deletion src/doc/rustdoc/src/the-doc-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ crate level, and ones that are useful at the item level.

## At the crate level

These options control how the docs look at a macro level.
These options control how the docs look at a crate level.

### `html_favicon_url`

Expand Down
5 changes: 5 additions & 0 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1305,9 +1305,11 @@ extern "rust-intrinsic" {

/// Performs an unchecked division, resulting in undefined behavior
/// where y = 0 or x = `T::min_value()` and y = -1
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
pub fn unchecked_div<T>(x: T, y: T) -> T;
/// Returns the remainder of an unchecked division, resulting in
/// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
pub fn unchecked_rem<T>(x: T, y: T) -> T;

/// Performs an unchecked left shift, resulting in undefined behavior when
Expand All @@ -1321,14 +1323,17 @@ extern "rust-intrinsic" {

/// Returns the result of an unchecked addition, resulting in
/// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
pub fn unchecked_add<T>(x: T, y: T) -> T;

/// Returns the result of an unchecked subtraction, resulting in
/// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
pub fn unchecked_sub<T>(x: T, y: T) -> T;

/// Returns the result of an unchecked multiplication, resulting in
/// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
pub fn unchecked_mul<T>(x: T, y: T) -> T;

/// Performs rotate left.
Expand Down
5 changes: 5 additions & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
#![feature(concat_idents)]
#![feature(const_alloc_layout)]
#![feature(const_if_match)]
#![feature(const_checked_int_methods)]
#![feature(const_euclidean_int_methods)]
#![feature(const_overflowing_int_methods)]
#![feature(const_saturating_int_methods)]
#![feature(const_int_unchecked_arith)]
#![feature(const_panic)]
#![feature(const_fn_union)]
#![feature(const_generics)]
Expand Down
147 changes: 98 additions & 49 deletions src/libcore/num/mod.rs

Large diffs are not rendered by default.

28 changes: 1 addition & 27 deletions src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,14 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
}
}

// The following implementations of HashStable for `ItemId`, `TraitItemId`, and
// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
// the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
// are used when another item in the HIR is *referenced* and we certainly
// want to pick up on a reference changing its target, so we hash the NodeIds
// in "DefPath Mode".

fn hash_item_id(&mut self, id: hir::ItemId, hasher: &mut StableHasher) {
fn hash_reference_to_item(&mut self, id: hir::HirId, hasher: &mut StableHasher) {
let hcx = self;
let hir::ItemId { id } = id;

hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
id.hash_stable(hcx, hasher);
})
}

fn hash_impl_item_id(&mut self, id: hir::ImplItemId, hasher: &mut StableHasher) {
let hcx = self;
let hir::ImplItemId { hir_id } = id;

hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
hir_id.hash_stable(hcx, hasher);
})
}

fn hash_trait_item_id(&mut self, id: hir::TraitItemId, hasher: &mut StableHasher) {
let hcx = self;
let hir::TraitItemId { hir_id } = id;

hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
hir_id.hash_stable(hcx, hasher);
})
}

fn hash_hir_mod(&mut self, module: &hir::Mod<'_>, hasher: &mut StableHasher) {
let hcx = self;
let hir::Mod { inner: ref inner_span, ref item_ids } = *module;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/error_reporting/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,8 +1646,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let current_limit = self.tcx.sess.recursion_limit.get();
let suggested_limit = current_limit * 2;
err.help(&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
suggested_limit
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
suggested_limit, self.tcx.crate_name,
));
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_error_codes/error_codes/E0264.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
An unknown external lang item was used. Erroneous code example:
An unknown external lang item was used.

Erroneous code example:

```compile_fail,E0264
#![feature(lang_items)]
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_error_codes/error_codes/E0267.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
This error indicates the use of a loop keyword (`break` or `continue`) inside a
closure but outside of any loop. Erroneous code example:
A loop keyword (`break` or `continue`) was used inside a closure but outside of
any loop.

Erroneous code example:

```compile_fail,E0267
let w = || { break; }; // error: `break` inside of a closure
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_error_codes/error_codes/E0268.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
This error indicates the use of a loop keyword (`break` or `continue`) outside
of a loop. Without a loop to break out of or continue in, no sensible action can
be taken. Erroneous code example:
A loop keyword (`break` or `continue`) was used outside of a loop.

Erroneous code example:

```compile_fail,E0268
fn some_func() {
break; // error: `break` outside of a loop
}
```

Without a loop to break out of or continue in, no sensible action can be taken.
Please verify that you are using `break` and `continue` only in loops. Example:

```
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_expand/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
&format!("recursion limit reached while expanding `{}`", expn_data.kind.descr()),
);
err.help(&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
suggested_limit
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
suggested_limit, self.cx.ecfg.crate_name,
));
err.emit();
self.cx.trace_macros_diag();
Expand Down
17 changes: 11 additions & 6 deletions src/librustc_hir/stable_hash_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ pub trait HashStableContext: syntax::HashStableContext + rustc_target::HashStabl
fn hash_def_id(&mut self, _: DefId, hasher: &mut StableHasher);
fn hash_hir_id(&mut self, _: HirId, hasher: &mut StableHasher);
fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher);
fn hash_item_id(&mut self, _: ItemId, hasher: &mut StableHasher);
fn hash_impl_item_id(&mut self, _: ImplItemId, hasher: &mut StableHasher);
fn hash_trait_item_id(&mut self, _: TraitItemId, hasher: &mut StableHasher);
fn hash_reference_to_item(&mut self, _: HirId, hasher: &mut StableHasher);
fn hash_hir_mod(&mut self, _: &Mod<'_>, hasher: &mut StableHasher);
fn hash_hir_expr(&mut self, _: &Expr<'_>, hasher: &mut StableHasher);
fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
Expand All @@ -38,21 +36,28 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
}
}

// The following implementations of HashStable for `ItemId`, `TraitItemId`, and
// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
// the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
// are used when another item in the HIR is *referenced* and we certainly
// want to pick up on a reference changing its target, so we hash the NodeIds
// in "DefPath Mode".

impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_item_id(*self, hasher)
hcx.hash_reference_to_item(self.id, hasher)
}
}

impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_impl_item_id(*self, hasher)
hcx.hash_reference_to_item(self.hir_id, hasher)
}
}

impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItemId {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
hcx.hash_trait_item_id(*self, hasher)
hcx.hash_reference_to_item(self.hir_id, hasher)
}
}

Expand Down
19 changes: 17 additions & 2 deletions src/librustc_mir/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,34 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
};
self.write_scalar(val, dest)?;
}
sym::unchecked_shl | sym::unchecked_shr => {
sym::unchecked_shl
| sym::unchecked_shr
| sym::unchecked_add
| sym::unchecked_sub
| sym::unchecked_mul
| sym::unchecked_div
| sym::unchecked_rem => {
let l = self.read_immediate(args[0])?;
let r = self.read_immediate(args[1])?;
let bin_op = match intrinsic_name {
sym::unchecked_shl => BinOp::Shl,
sym::unchecked_shr => BinOp::Shr,
sym::unchecked_add => BinOp::Add,
sym::unchecked_sub => BinOp::Sub,
sym::unchecked_mul => BinOp::Mul,
sym::unchecked_div => BinOp::Div,
sym::unchecked_rem => BinOp::Rem,
_ => bug!("Already checked for int ops"),
};
let (val, overflowed, _ty) = self.overflowing_binary_op(bin_op, l, r)?;
if overflowed {
let layout = self.layout_of(substs.type_at(0))?;
let r_val = self.force_bits(r.to_scalar()?, layout.size)?;
throw_ub_format!("Overflowing shift by {} in `{}`", r_val, intrinsic_name);
if let sym::unchecked_shl | sym::unchecked_shr = intrinsic_name {
throw_ub_format!("Overflowing shift by {} in `{}`", r_val, intrinsic_name);
} else {
throw_ub_format!("Overflow executing `{}`", intrinsic_name);
}
}
self.write_scalar(val, dest)?;
}
Expand Down
14 changes: 11 additions & 3 deletions src/librustc_passes/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,15 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
return false;
}

let mut changed = false;
let mut any_changed = false;
self.indices2(ln, succ_ln, |this, idx, succ_idx| {
// This is a special case, pulled out from the code below, where we
// don't have to do anything. It occurs about 60-70% of the time.
if this.rwu_table.packed_rwus[succ_idx] == INV_INV_FALSE {
return;
}

let mut changed = false;
let mut rwu = this.rwu_table.get(idx);
let succ_rwu = this.rwu_table.get(succ_idx);
if succ_rwu.reader.is_valid() && !rwu.reader.is_valid() {
Expand All @@ -843,6 +850,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {

if changed {
this.rwu_table.assign_unpacked(idx, rwu);
any_changed = true;
}
});

Expand All @@ -851,9 +859,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
ln,
self.ln_str(succ_ln),
first_merge,
changed
any_changed
);
return changed;
return any_changed;
}

// Indicates that a local variable was *defined*; we know that no
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_span/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,13 @@ symbols! {
u64,
u8,
unboxed_closures,
unchecked_add,
unchecked_div,
unchecked_mul,
unchecked_rem,
unchecked_shl,
unchecked_shr,
unchecked_sub,
underscore_const_names,
underscore_imports,
underscore_lifetimes,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Spa
)
.span_label(span, "deref recursion limit reached")
.help(&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
suggested_limit
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
suggested_limit, tcx.crate_name,
))
.emit();
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl<R> BufReader<R> {
/// Ok(())
/// }
/// ```
#[unstable(feature = "buffered_io_capacity", issue = "68558")]
#[unstable(feature = "buffered_io_capacity", issue = "68833")]
pub fn capacity(&self) -> usize {
self.buf.len()
}
Expand Down Expand Up @@ -616,7 +616,7 @@ impl<W: Write> BufWriter<W> {
/// // Calculate how many bytes can be written without flushing
/// let without_flush = capacity - buf_writer.buffer().len();
/// ```
#[unstable(feature = "buffered_io_capacity", issue = "68558")]
#[unstable(feature = "buffered_io_capacity", issue = "68833")]
pub fn capacity(&self) -> usize {
self.buf.capacity()
}
Expand Down
1 change: 0 additions & 1 deletion src/libstd/sys/unix/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ mod inner {
(cfg!(target_os = "linux") && cfg!(target_arch = "x86_64"))
|| (cfg!(target_os = "linux") && cfg!(target_arch = "x86"))
|| cfg!(target_os = "fuchsia")
|| false // last clause, used so `||` is always trailing above
}

pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> {
Expand Down
Loading