Skip to content

Commit 337b2d4

Browse files
committed
Auto merge of #68861 - Dylan-DPC:rollup-0m09hsg, r=Dylan-DPC
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
2 parents eda1a7a + b37f968 commit 337b2d4

31 files changed

+320
-120
lines changed

src/doc/rustdoc/src/the-doc-attribute.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ crate level, and ones that are useful at the item level.
3939

4040
## At the crate level
4141

42-
These options control how the docs look at a macro level.
42+
These options control how the docs look at a crate level.
4343

4444
### `html_favicon_url`
4545

src/libcore/intrinsics.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1305,9 +1305,11 @@ extern "rust-intrinsic" {
13051305

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

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

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

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

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

13341339
/// Performs rotate left.

src/libcore/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
#![feature(concat_idents)]
7373
#![feature(const_alloc_layout)]
7474
#![feature(const_if_match)]
75+
#![feature(const_checked_int_methods)]
76+
#![feature(const_euclidean_int_methods)]
77+
#![feature(const_overflowing_int_methods)]
78+
#![feature(const_saturating_int_methods)]
79+
#![feature(const_int_unchecked_arith)]
7580
#![feature(const_panic)]
7681
#![feature(const_fn_union)]
7782
#![feature(const_generics)]

src/libcore/num/mod.rs

+98-49
Large diffs are not rendered by default.

src/librustc/ich/impls_hir.rs

+1-27
Original file line numberDiff line numberDiff line change
@@ -40,40 +40,14 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
4040
}
4141
}
4242

43-
// The following implementations of HashStable for `ItemId`, `TraitItemId`, and
44-
// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
45-
// the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
46-
// are used when another item in the HIR is *referenced* and we certainly
47-
// want to pick up on a reference changing its target, so we hash the NodeIds
48-
// in "DefPath Mode".
49-
50-
fn hash_item_id(&mut self, id: hir::ItemId, hasher: &mut StableHasher) {
43+
fn hash_reference_to_item(&mut self, id: hir::HirId, hasher: &mut StableHasher) {
5144
let hcx = self;
52-
let hir::ItemId { id } = id;
5345

5446
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
5547
id.hash_stable(hcx, hasher);
5648
})
5749
}
5850

59-
fn hash_impl_item_id(&mut self, id: hir::ImplItemId, hasher: &mut StableHasher) {
60-
let hcx = self;
61-
let hir::ImplItemId { hir_id } = id;
62-
63-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
64-
hir_id.hash_stable(hcx, hasher);
65-
})
66-
}
67-
68-
fn hash_trait_item_id(&mut self, id: hir::TraitItemId, hasher: &mut StableHasher) {
69-
let hcx = self;
70-
let hir::TraitItemId { hir_id } = id;
71-
72-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
73-
hir_id.hash_stable(hcx, hasher);
74-
})
75-
}
76-
7751
fn hash_hir_mod(&mut self, module: &hir::Mod<'_>, hasher: &mut StableHasher) {
7852
let hcx = self;
7953
let hir::Mod { inner: ref inner_span, ref item_ids } = *module;

src/librustc/traits/error_reporting/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1646,8 +1646,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16461646
let current_limit = self.tcx.sess.recursion_limit.get();
16471647
let suggested_limit = current_limit * 2;
16481648
err.help(&format!(
1649-
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
1650-
suggested_limit
1649+
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
1650+
suggested_limit, self.tcx.crate_name,
16511651
));
16521652
}
16531653
}

src/librustc_error_codes/error_codes/E0264.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
An unknown external lang item was used. Erroneous code example:
1+
An unknown external lang item was used.
2+
3+
Erroneous code example:
24

35
```compile_fail,E0264
46
#![feature(lang_items)]

src/librustc_error_codes/error_codes/E0267.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
This error indicates the use of a loop keyword (`break` or `continue`) inside a
2-
closure but outside of any loop. Erroneous code example:
1+
A loop keyword (`break` or `continue`) was used inside a closure but outside of
2+
any loop.
3+
4+
Erroneous code example:
35

46
```compile_fail,E0267
57
let w = || { break; }; // error: `break` inside of a closure

src/librustc_error_codes/error_codes/E0268.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
This error indicates the use of a loop keyword (`break` or `continue`) outside
2-
of a loop. Without a loop to break out of or continue in, no sensible action can
3-
be taken. Erroneous code example:
1+
A loop keyword (`break` or `continue`) was used outside of a loop.
2+
3+
Erroneous code example:
44

55
```compile_fail,E0268
66
fn some_func() {
77
break; // error: `break` outside of a loop
88
}
99
```
1010

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

1314
```

src/librustc_expand/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
609609
&format!("recursion limit reached while expanding `{}`", expn_data.kind.descr()),
610610
);
611611
err.help(&format!(
612-
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
613-
suggested_limit
612+
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
613+
suggested_limit, self.cx.ecfg.crate_name,
614614
));
615615
err.emit();
616616
self.cx.trace_macros_diag();

src/librustc_hir/stable_hash_impls.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ pub trait HashStableContext: syntax::HashStableContext + rustc_target::HashStabl
1111
fn hash_def_id(&mut self, _: DefId, hasher: &mut StableHasher);
1212
fn hash_hir_id(&mut self, _: HirId, hasher: &mut StableHasher);
1313
fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher);
14-
fn hash_item_id(&mut self, _: ItemId, hasher: &mut StableHasher);
15-
fn hash_impl_item_id(&mut self, _: ImplItemId, hasher: &mut StableHasher);
16-
fn hash_trait_item_id(&mut self, _: TraitItemId, hasher: &mut StableHasher);
14+
fn hash_reference_to_item(&mut self, _: HirId, hasher: &mut StableHasher);
1715
fn hash_hir_mod(&mut self, _: &Mod<'_>, hasher: &mut StableHasher);
1816
fn hash_hir_expr(&mut self, _: &Expr<'_>, hasher: &mut StableHasher);
1917
fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
@@ -38,21 +36,28 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
3836
}
3937
}
4038

39+
// The following implementations of HashStable for `ItemId`, `TraitItemId`, and
40+
// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
41+
// the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
42+
// are used when another item in the HIR is *referenced* and we certainly
43+
// want to pick up on a reference changing its target, so we hash the NodeIds
44+
// in "DefPath Mode".
45+
4146
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ItemId {
4247
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
43-
hcx.hash_item_id(*self, hasher)
48+
hcx.hash_reference_to_item(self.id, hasher)
4449
}
4550
}
4651

4752
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId {
4853
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
49-
hcx.hash_impl_item_id(*self, hasher)
54+
hcx.hash_reference_to_item(self.hir_id, hasher)
5055
}
5156
}
5257

5358
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItemId {
5459
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
55-
hcx.hash_trait_item_id(*self, hasher)
60+
hcx.hash_reference_to_item(self.hir_id, hasher)
5661
}
5762
}
5863

src/librustc_mir/interpret/intrinsics.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,34 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
218218
};
219219
self.write_scalar(val, dest)?;
220220
}
221-
sym::unchecked_shl | sym::unchecked_shr => {
221+
sym::unchecked_shl
222+
| sym::unchecked_shr
223+
| sym::unchecked_add
224+
| sym::unchecked_sub
225+
| sym::unchecked_mul
226+
| sym::unchecked_div
227+
| sym::unchecked_rem => {
222228
let l = self.read_immediate(args[0])?;
223229
let r = self.read_immediate(args[1])?;
224230
let bin_op = match intrinsic_name {
225231
sym::unchecked_shl => BinOp::Shl,
226232
sym::unchecked_shr => BinOp::Shr,
233+
sym::unchecked_add => BinOp::Add,
234+
sym::unchecked_sub => BinOp::Sub,
235+
sym::unchecked_mul => BinOp::Mul,
236+
sym::unchecked_div => BinOp::Div,
237+
sym::unchecked_rem => BinOp::Rem,
227238
_ => bug!("Already checked for int ops"),
228239
};
229240
let (val, overflowed, _ty) = self.overflowing_binary_op(bin_op, l, r)?;
230241
if overflowed {
231242
let layout = self.layout_of(substs.type_at(0))?;
232243
let r_val = self.force_bits(r.to_scalar()?, layout.size)?;
233-
throw_ub_format!("Overflowing shift by {} in `{}`", r_val, intrinsic_name);
244+
if let sym::unchecked_shl | sym::unchecked_shr = intrinsic_name {
245+
throw_ub_format!("Overflowing shift by {} in `{}`", r_val, intrinsic_name);
246+
} else {
247+
throw_ub_format!("Overflow executing `{}`", intrinsic_name);
248+
}
234249
}
235250
self.write_scalar(val, dest)?;
236251
}

src/librustc_passes/liveness.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,15 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
822822
return false;
823823
}
824824

825-
let mut changed = false;
825+
let mut any_changed = false;
826826
self.indices2(ln, succ_ln, |this, idx, succ_idx| {
827+
// This is a special case, pulled out from the code below, where we
828+
// don't have to do anything. It occurs about 60-70% of the time.
829+
if this.rwu_table.packed_rwus[succ_idx] == INV_INV_FALSE {
830+
return;
831+
}
832+
833+
let mut changed = false;
827834
let mut rwu = this.rwu_table.get(idx);
828835
let succ_rwu = this.rwu_table.get(succ_idx);
829836
if succ_rwu.reader.is_valid() && !rwu.reader.is_valid() {
@@ -843,6 +850,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
843850

844851
if changed {
845852
this.rwu_table.assign_unpacked(idx, rwu);
853+
any_changed = true;
846854
}
847855
});
848856

@@ -851,9 +859,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
851859
ln,
852860
self.ln_str(succ_ln),
853861
first_merge,
854-
changed
862+
any_changed
855863
);
856-
return changed;
864+
return any_changed;
857865
}
858866

859867
// Indicates that a local variable was *defined*; we know that no

src/librustc_span/symbol.rs

+5
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,13 @@ symbols! {
755755
u64,
756756
u8,
757757
unboxed_closures,
758+
unchecked_add,
759+
unchecked_div,
760+
unchecked_mul,
761+
unchecked_rem,
758762
unchecked_shl,
759763
unchecked_shr,
764+
unchecked_sub,
760765
underscore_const_names,
761766
underscore_imports,
762767
underscore_lifetimes,

src/librustc_typeck/check/autoderef.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Spa
250250
)
251251
.span_label(span, "deref recursion limit reached")
252252
.help(&format!(
253-
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
254-
suggested_limit
253+
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
254+
suggested_limit, tcx.crate_name,
255255
))
256256
.emit();
257257
}

src/libstd/io/buffered.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<R> BufReader<R> {
198198
/// Ok(())
199199
/// }
200200
/// ```
201-
#[unstable(feature = "buffered_io_capacity", issue = "68558")]
201+
#[unstable(feature = "buffered_io_capacity", issue = "68833")]
202202
pub fn capacity(&self) -> usize {
203203
self.buf.len()
204204
}
@@ -616,7 +616,7 @@ impl<W: Write> BufWriter<W> {
616616
/// // Calculate how many bytes can be written without flushing
617617
/// let without_flush = capacity - buf_writer.buffer().len();
618618
/// ```
619-
#[unstable(feature = "buffered_io_capacity", issue = "68558")]
619+
#[unstable(feature = "buffered_io_capacity", issue = "68833")]
620620
pub fn capacity(&self) -> usize {
621621
self.buf.capacity()
622622
}

src/libstd/sys/unix/time.rs

-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ mod inner {
282282
(cfg!(target_os = "linux") && cfg!(target_arch = "x86_64"))
283283
|| (cfg!(target_os = "linux") && cfg!(target_arch = "x86"))
284284
|| cfg!(target_os = "fuchsia")
285-
|| false // last clause, used so `||` is always trailing above
286285
}
287286

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

0 commit comments

Comments
 (0)