Skip to content

Commit

Permalink
Auto merge of #68861 - Dylan-DPC:rollup-0m09hsg, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - #68762 (Strip unnecessary subexpression)
 - #68790 (Improve `merge_from_succ`)
 - #68809 (Make more arithmetic functions unstably const)
 - #68832 (Clean up E0264, E0267 and E0268 explanations)
 - #68840 (On suggesting `#![recursion_limit = "X"]`, note current crate name)
 - #68846 (doc fix on doc attribute)
 - #68851 (Fix issue number of `capacity` method)
 - #68858 (Merge item id stable hashing functions)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Feb 6, 2020
2 parents a25d58b + b37f968 commit ed853b8
Show file tree
Hide file tree
Showing 31 changed files with 320 additions and 120 deletions.
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

0 comments on commit ed853b8

Please sign in to comment.