Skip to content

Commit 939844a

Browse files
committed
Auto merge of #148686 - jhpratt:rollup-jlh9fj9, r=jhpratt
Rollup of 16 pull requests Successful merges: - #147534 (Implement SIMD funnel shifts in const-eval/Miri) - #147686 (update isolate_highest_one for NonZero<T>) - #148020 (Show backtrace on allocation failures when possible) - #148204 (Modify contributor email entries in .mailmap) - #148230 (rustdoc: Properly highlight shebang, frontmatter & weak keywords in source code pages and code blocks) - #148279 (rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names) - #148555 (Fix rust-by-example spanish translation) - #148556 (Fix suggestion for returning async closures) - #148585 ([rustdoc] Replace `print` methods with functions to improve code readability) - #148600 (re-use `self.get_all_attrs` result for pass indirectly attribute) - #148612 (Add note for identifier with attempted hygiene violation) - #148613 (Switch hexagon targets to rust-lld) - #148619 (Enable std locking functions on AIX) - #148644 ([bootstrap] Make `--open` option work with `doc src/tools/error_index_generator`) - #148649 (don't completely reset `HeadUsages`) - #148675 (Remove eslint-js from npm dependencies) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bbb6f68 + 896d190 commit 939844a

File tree

47 files changed

+1311
-644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1311
-644
lines changed

.mailmap

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Aaron Todd <github@opprobrio.us>
99
Abhishek Chanda <abhishek.becs@gmail.com> Abhishek Chanda <abhishek@cloudscaling.com>
1010
Abhijeet Bhagat <abhijeet.bhagat@gmx.com>
1111
Abroskin Alexander <arkweid@evilmartians.com>
12-
Adolfo Ochagavía <aochagavia92@gmail.com>
12+
Adolfo Ochagavía <aochagavia92@gmail.com> <github@adolfo.ochagavia.xyz>
1313
Adrian Heine né Lang <mail@adrianheine.de>
1414
Adrien Tétar <adri-from-59@hotmail.fr>
1515
Ahmed Charles <ahmedcharles@gmail.com> <acharles@outlook.com>
@@ -36,6 +36,7 @@ Amanda Stjerna <mail@amandastjerna.se> <albin.stjerna@gmail.com>
3636
Amanda Stjerna <mail@amandastjerna.se> <amanda.stjerna@it.uu.se>
3737
Amanieu d'Antras <amanieu@gmail.com> <amanieu.dantras@huawei.com>
3838
Amos Onn <amosonn@gmail.com>
39+
Amos Wenger <amoswenger@gmail.com> <fasterthanlime@users.noreply.github.com>
3940
Ana-Maria Mihalache <mihalacheana.maria@yahoo.com>
4041
Anatoly Ikorsky <aikorsky@gmail.com>
4142
Andre Bogus <bogusandre@gmail.com>
@@ -276,7 +277,8 @@ Irina Popa <irinagpopa@gmail.com>
276277
Ivan Ivaschenko <defuz.net@gmail.com>
277278
ivan tkachenko <me@ratijas.tk>
278279
J. J. Weber <jjweber@gmail.com>
279-
Jack Huey <jack.huey@umassmed.edu> <jackh726@gmail.com>
280+
Jack Huey <jackh726@gmail.com> <jack.huey@umassmed.edu>
281+
Jack Huey <jackh726@gmail.com> <31162821+jackh726@users.noreply.github.com>
280282
Jacob <jacob.macritchie@gmail.com>
281283
Jacob Hoffman-Andrews <rust@hoffman-andrews.com> <github@hoffman-andrews.com>
282284
Jacob Greenfield <xales@naveria.com>
@@ -292,6 +294,8 @@ Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com>
292294
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakub.bukaj@yahoo.com>
293295
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakub@jakub.cc>
294296
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakubw@jakubw.net>
297+
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <ja.wieczorek@student.uw.edu.pl>
298+
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <software@jacobadam.net>
295299
Jakub Beránek <berykubik@gmail.com> <jakub.beranek@vsb.cz>
296300
James [Undefined] <tpzker@thepuzzlemaker.info>
297301
James Deng <cnjamesdeng@gmail.com> <cnJamesDeng@gmail.com>
@@ -303,6 +307,7 @@ Jamie Hill-Daniel <jamie@hill-daniel.co.uk> <clubby789@gmail.com>
303307
Jana Dönszelmann <jana@donsz.nl>
304308
Jana Dönszelmann <jana@donsz.nl> <jonathan@donsz.nl>
305309
Jana Dönszelmann <jana@donsz.nl> <jonabent@gmail.com>
310+
Jane Lusby <jlusby42@gmail.com> <jlusby@yaah.dev>
306311
Jan-Erik Rediger <janerik@fnordig.de> <badboy@archlinux.us>
307312
Jaro Fietz <jaro.fietz@gmx.de>
308313
Jason Fager <jfager@gmail.com>
@@ -313,6 +318,7 @@ Jason Toffaletti <toffaletti@gmail.com> Jason Toffaletti <jason@topsy.com>
313318
Jauhien Piatlicki <jauhien@gentoo.org> Jauhien Piatlicki <jpiatlicki@zertisa.com>
314319
Jay True <glacjay@gmail.com>
315320
Jeremy Letang <letang.jeremy@gmail.com>
321+
Jeremy Soller <jackpot51@gmail.com> <jeremy@system76.com>
316322
Jeremy Sorensen <jeremy.a.sorensen@gmail.com>
317323
Jeremy Stucki <dev@jeremystucki.ch> <stucki.jeremy@gmail.com>
318324
Jeremy Stucki <dev@jeremystucki.ch> <jeremy@myelin.ch>
@@ -336,6 +342,7 @@ John Kåre Alsaker <john.kare.alsaker@gmail.com>
336342
John Kåre Alsaker <john.kare.alsaker@gmail.com> <zoxc32@gmail.com>
337343
John Talling <inrustwetrust@users.noreply.github.com>
338344
John Van Enk <vanenkj@gmail.com>
345+
Jon Gjengset <jon@thesquareplanet.com> <jongje@amazon.com>
339346
Jonas Tepe <jonasprogrammer@gmail.com>
340347
Jonathan Bailey <jbailey@mozilla.com> <jbailey@jbailey-20809.local>
341348
Jonathan Chan Kwan Yin <sofe2038@gmail.com>
@@ -424,7 +431,7 @@ Malo Jaffré <jaffre.malo@gmail.com>
424431
Manish Goregaokar <manishsmail@gmail.com>
425432
Mara Bos <m-ou.se@m-ou.se>
426433
Marcell Pardavi <marcell.pardavi@gmail.com>
427-
Marco Ieni <11428655+MarcoIeni@users.noreply.github.com>
434+
Marco Ieni <marcoieni@rustfoundation.org> <11428655+MarcoIeni@users.noreply.github.com>
428435
Marcus Klaas de Vries <mail@marcusklaas.nl>
429436
Margaret Meyerhofer <mmeyerho@andrew.cmu.edu> <mmeyerho@andrew>
430437
Marijn Schouten <mhkbst@gmail.com> <hkBst@users.noreply.github.com>
@@ -531,6 +538,7 @@ Oliver Scherer <oli-obk@users.noreply.github.com> <oliver.schneider@kit.edu>
531538
Oliver Scherer <oli-obk@users.noreply.github.com> <obk8176014uqher834@olio-obk.de>
532539
Oliver Scherer <oli-obk@users.noreply.github.com> <rustc-contact@oli-obk.de>
533540
Oliver Scherer <oli-obk@users.noreply.github.com>
541+
Onur Özkan <onurozkan.dev@outlook.com> <contact@onurozkan.dev>
534542
Onur Özkan <onurozkan.dev@outlook.com> <work@onurozkan.dev>
535543
Onur Özkan <onurozkan.dev@outlook.com>
536544
Ömer Sinan Ağacan <omeragacan@gmail.com>
@@ -591,6 +599,7 @@ Rusty Blitzerr <rusty.blitzerr@gmail.com>
591599
RustyYato <krishna.sd.2012@gmail.com>
592600
Ruud van Asseldonk <dev@veniogames.com> Ruud van Asseldonk <ruuda@google.com>
593601
Ryan Leung <rleungx@gmail.com>
602+
Ryan Levick <me@ryanlevick.com> <rylev@users.noreply.github.com>
594603
Ryan Scheel <ryan.havvy@gmail.com>
595604
Ryan Sullivant <rsulli55@gmail.com>
596605
Ryan Wiedemann <Ryan1729@gmail.com>
@@ -686,6 +695,8 @@ Weihang Lo <me@weihanglo.tw>
686695
Weihang Lo <me@weihanglo.tw> <weihanglo@users.noreply.github.com>
687696
Wesley Wiser <wwiser@gmail.com> <wesleywiser@microsoft.com>
688697
whitequark <whitequark@whitequark.org>
698+
Will Crichton <crichton.will@gmail.com> <wcrichto@stanford.edu>
699+
Will Crichton <crichton.will@gmail.com> <wcrichto@cs.stanford.edu>
689700
William Ting <io@williamting.com> <william.h.ting@gmail.com>
690701
Wim Looman <wim@nemo157.com> <rust-lang@nemo157.com>
691702
Wim Looman <wim@nemo157.com> <git@nemo157.com>
@@ -695,6 +706,8 @@ Xinye Tao <xy.tao@outlook.com>
695706
Xuefeng Wu <benewu@gmail.com> Xuefeng Wu <xfwu@thoughtworks.com>
696707
Xuefeng Wu <benewu@gmail.com> XuefengWu <benewu@gmail.com>
697708
York Xiang <bombless@126.com>
709+
Yoshua Wuyts <yoshuawuyts@gmail.com> <yoshuawuyts+github@gmail.com>
710+
Yoshua Wuyts <yoshuawuyts@gmail.com> <2467194+yoshuawuyts@users.noreply.github.com>
698711
Yotam Ofek <yotam.ofek@gmail.com> <yotamofek@microsoft.com>
699712
Youngsoo Son <ysson83@gmail.com> <ysoo.son@samsung.com>
700713
Youngsuk Kim <joseph942010@gmail.com>

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,30 +207,30 @@ pub(crate) fn expand_test_or_bench(
207207
};
208208

209209
let test_fn = if is_bench {
210-
// A simple ident for a lambda
211-
let b = Ident::from_str_and_span("b", attr_sp);
212-
210+
// avoid name collisions by using the function name within the identifier, see bug #148275
211+
let bencher_param =
212+
Ident::from_str_and_span(&format!("__bench_{}", fn_.ident.name), attr_sp);
213213
cx.expr_call(
214214
sp,
215215
cx.expr_path(test_path("StaticBenchFn")),
216216
thin_vec![
217217
// #[coverage(off)]
218-
// |b| self::test::assert_test_result(
218+
// |__bench_fn_name| self::test::assert_test_result(
219219
coverage_off(cx.lambda1(
220220
sp,
221221
cx.expr_call(
222222
sp,
223223
cx.expr_path(test_path("assert_test_result")),
224224
thin_vec![
225-
// super::$test_fn(b)
225+
// super::$test_fn(__bench_fn_name)
226226
cx.expr_call(
227227
ret_ty_sp,
228228
cx.expr_path(cx.path(sp, vec![fn_.ident])),
229-
thin_vec![cx.expr_ident(sp, b)],
229+
thin_vec![cx.expr_ident(sp, bencher_param)],
230230
),
231231
],
232232
),
233-
b,
233+
bencher_param,
234234
)), // )
235235
],
236236
)

compiler/rustc_const_eval/src/interpret/intrinsics/simd.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_abi::{BackendRepr, Endian};
33
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
44
use rustc_apfloat::{Float, Round};
55
use rustc_middle::mir::interpret::{InterpErrorKind, Pointer, UndefinedBehaviorInfo};
6-
use rustc_middle::ty::{FloatTy, SimdAlign};
6+
use rustc_middle::ty::{FloatTy, ScalarInt, SimdAlign};
77
use rustc_middle::{bug, err_ub_format, mir, span_bug, throw_unsup_format, ty};
88
use rustc_span::{Symbol, sym};
99
use tracing::trace;
@@ -744,6 +744,58 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
744744
self.write_scalar(val, &dest)?;
745745
}
746746
}
747+
sym::simd_funnel_shl | sym::simd_funnel_shr => {
748+
let (left, _) = self.project_to_simd(&args[0])?;
749+
let (right, _) = self.project_to_simd(&args[1])?;
750+
let (shift, _) = self.project_to_simd(&args[2])?;
751+
let (dest, _) = self.project_to_simd(&dest)?;
752+
753+
let (len, elem_ty) = args[0].layout.ty.simd_size_and_type(*self.tcx);
754+
let (elem_size, _signed) = elem_ty.int_size_and_signed(*self.tcx);
755+
let elem_size_bits = u128::from(elem_size.bits());
756+
757+
let is_left = intrinsic_name == sym::simd_funnel_shl;
758+
759+
for i in 0..len {
760+
let left =
761+
self.read_scalar(&self.project_index(&left, i)?)?.to_bits(elem_size)?;
762+
let right =
763+
self.read_scalar(&self.project_index(&right, i)?)?.to_bits(elem_size)?;
764+
let shift_bits =
765+
self.read_scalar(&self.project_index(&shift, i)?)?.to_bits(elem_size)?;
766+
767+
if shift_bits >= elem_size_bits {
768+
throw_ub_format!(
769+
"overflowing shift by {shift_bits} in `{intrinsic_name}` in lane {i}"
770+
);
771+
}
772+
let inv_shift_bits = u32::try_from(elem_size_bits - shift_bits).unwrap();
773+
774+
// A funnel shift left by S can be implemented as `(x << S) | y.unbounded_shr(SIZE - S)`.
775+
// The `unbounded_shr` is needed because otherwise if `S = 0`, it would be `x | y`
776+
// when it should be `x`.
777+
//
778+
// This selects the least-significant `SIZE - S` bits of `x`, followed by the `S` most
779+
// significant bits of `y`. As `left` and `right` both occupy the lower `SIZE` bits,
780+
// we can treat the lower `SIZE` bits as an integer of the right width and use
781+
// the same implementation, but on a zero-extended `x` and `y`. This works because
782+
// `x << S` just pushes the `SIZE-S` MSBs out, and `y >> (SIZE - S)` shifts in
783+
// zeros, as it is zero-extended. To the lower `SIZE` bits, this looks just like a
784+
// funnel shift left.
785+
//
786+
// Note that the `unbounded_sh{l,r}`s are needed only in case we are using this on
787+
// `u128xN` and `inv_shift_bits == 128`.
788+
let result_bits = if is_left {
789+
(left << shift_bits) | right.unbounded_shr(inv_shift_bits)
790+
} else {
791+
left.unbounded_shl(inv_shift_bits) | (right >> shift_bits)
792+
};
793+
let (result, _overflow) = ScalarInt::truncate_from_uint(result_bits, elem_size);
794+
795+
let dest = self.project_index(&dest, i)?;
796+
self.write_scalar(result, &dest)?;
797+
}
798+
}
747799

748800
// Unsupported intrinsic: skip the return_to_block below.
749801
_ => return interp_ok(false),

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,21 @@ pub fn suggest_impl_trait<'tcx>(
12631263
infcx.tcx.lang_items().future_output(),
12641264
format_as_assoc,
12651265
),
1266+
(
1267+
infcx.tcx.lang_items().async_fn_trait(),
1268+
infcx.tcx.lang_items().async_fn_once_output(),
1269+
format_as_parenthesized,
1270+
),
1271+
(
1272+
infcx.tcx.lang_items().async_fn_mut_trait(),
1273+
infcx.tcx.lang_items().async_fn_once_output(),
1274+
format_as_parenthesized,
1275+
),
1276+
(
1277+
infcx.tcx.lang_items().async_fn_once_trait(),
1278+
infcx.tcx.lang_items().async_fn_once_output(),
1279+
format_as_parenthesized,
1280+
),
12661281
(
12671282
infcx.tcx.lang_items().fn_trait(),
12681283
infcx.tcx.lang_items().fn_once_output(),

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,9 +1512,8 @@ impl<'tcx> TyCtxt<'tcx> {
15121512
field_shuffle_seed ^= user_seed;
15131513
}
15141514

1515-
if let Some(reprs) =
1516-
find_attr!(self.get_all_attrs(did), AttributeKind::Repr { reprs, .. } => reprs)
1517-
{
1515+
let attributes = self.get_all_attrs(did);
1516+
if let Some(reprs) = find_attr!(attributes, AttributeKind::Repr { reprs, .. } => reprs) {
15181517
for (r, _) in reprs {
15191518
flags.insert(match *r {
15201519
attr::ReprRust => ReprFlags::empty(),
@@ -1574,10 +1573,7 @@ impl<'tcx> TyCtxt<'tcx> {
15741573
}
15751574

15761575
// See `TyAndLayout::pass_indirectly_in_non_rustic_abis` for details.
1577-
if find_attr!(
1578-
self.get_all_attrs(did),
1579-
AttributeKind::RustcPassIndirectlyInNonRusticAbis(..)
1580-
) {
1576+
if find_attr!(attributes, AttributeKind::RustcPassIndirectlyInNonRusticAbis(..)) {
15811577
flags.insert(ReprFlags::PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS);
15821578
}
15831579

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,8 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11251125
}
11261126
}
11271127
}
1128+
1129+
self.suggest_ident_hidden_by_hygiene(err, path, span);
11281130
} else if err_code == E0412 {
11291131
if let Some(correct) = Self::likely_rust_type(path) {
11301132
err.span_suggestion(
@@ -1138,6 +1140,28 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11381140
}
11391141
}
11401142

1143+
fn suggest_ident_hidden_by_hygiene(&self, err: &mut Diag<'_>, path: &[Segment], span: Span) {
1144+
let [segment] = path else { return };
1145+
1146+
let ident = segment.ident;
1147+
let callsite_span = span.source_callsite();
1148+
for rib in self.ribs[ValueNS].iter().rev() {
1149+
for (binding_ident, _) in &rib.bindings {
1150+
if binding_ident.name == ident.name
1151+
&& !binding_ident.span.eq_ctxt(span)
1152+
&& !binding_ident.span.from_expansion()
1153+
&& binding_ident.span.lo() < callsite_span.lo()
1154+
{
1155+
err.span_help(
1156+
binding_ident.span,
1157+
"an identifier with the same name exists, but is not accessible due to macro hygiene",
1158+
);
1159+
return;
1160+
}
1161+
}
1162+
}
1163+
}
1164+
11411165
/// Emit special messages for unresolved `Self` and `self`.
11421166
fn suggest_self_ty(
11431167
&self,

compiler/rustc_target/src/spec/targets/hexagon_unknown_linux_musl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) fn target() -> Target {
88
base.features = "-small-data,+hvx-length128b".into();
99

1010
base.has_rpath = true;
11+
base.linker = Some("rust-lld".into());
1112
base.linker_flavor = LinkerFlavor::Unix(Cc::Yes);
1213

1314
base.c_enum_min_bits = Some(8);

compiler/rustc_target/src/spec/targets/hexagon_unknown_none_elf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) fn target() -> Target {
2727
max_atomic_width: Some(32),
2828
emit_debug_gdb_scripts: false,
2929
c_enum_min_bits: Some(8),
30+
linker: Some("rust-lld".into()),
3031
..Default::default()
3132
},
3233
}

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use derive_where::derive_where;
2323
#[cfg(feature = "nightly")]
2424
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
2525
use rustc_type_ir::data_structures::HashMap;
26-
use tracing::{debug, instrument};
26+
use tracing::{debug, instrument, trace};
2727

2828
mod stack;
2929
use stack::{Stack, StackDepth, StackEntry};
@@ -916,6 +916,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
916916
/// heads from the stack. This may not necessarily mean that we've actually
917917
/// reached a fixpoint for that cycle head, which impacts the way we rebase
918918
/// provisional cache entries.
919+
#[derive_where(Debug; X: Cx)]
919920
enum RebaseReason<X: Cx> {
920921
NoCycleUsages,
921922
Ambiguity(X::AmbiguityInfo),
@@ -950,6 +951,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
950951
/// cache entries to also be ambiguous. This causes some undesirable ambiguity for nested
951952
/// goals whose result doesn't actually depend on this cycle head, but that's acceptable
952953
/// to me.
954+
#[instrument(level = "trace", skip(self, cx))]
953955
fn rebase_provisional_cache_entries(
954956
&mut self,
955957
cx: X,
@@ -969,6 +971,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
969971
let popped_head = if heads.highest_cycle_head_index() == popped_head_index {
970972
heads.remove_highest_cycle_head()
971973
} else {
974+
debug_assert!(heads.highest_cycle_head_index() < popped_head_index);
972975
return true;
973976
};
974977

@@ -1057,6 +1060,8 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
10571060
new_highest_head_index,
10581061
));
10591062

1063+
trace!(?input, ?entry, "rebased provisional cache entry");
1064+
10601065
true
10611066
});
10621067
!entries.is_empty()
@@ -1379,7 +1384,8 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
13791384
}
13801385

13811386
// Clear all provisional cache entries which depend on a previous provisional
1382-
// result of this goal and rerun.
1387+
// result of this goal and rerun. This does not remove goals which accessed this
1388+
// goal without depending on its result.
13831389
self.clear_dependent_provisional_results_for_rerun();
13841390

13851391
debug!(?result, "fixpoint changed provisional results");
@@ -1399,7 +1405,12 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
13991405
// similar to the previous iterations when reevaluating, it's better
14001406
// for caching if the reevaluation also starts out with `false`.
14011407
encountered_overflow: false,
1402-
usages: None,
1408+
// We keep provisional cache entries around if they used this goal
1409+
// without depending on its result.
1410+
//
1411+
// We still need to drop or rebase these cache entries once we've
1412+
// finished evaluating this goal.
1413+
usages: Some(HeadUsages::default()),
14031414
candidate_usages: None,
14041415
});
14051416
}

library/core/src/num/nonzero.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,15 @@ macro_rules! nonzero_integer {
660660
without modifying the original"]
661661
#[inline(always)]
662662
pub const fn isolate_highest_one(self) -> Self {
663-
let n = self.get() & (((1 as $Int) << (<$Int>::BITS - 1)).wrapping_shr(self.leading_zeros()));
664-
665663
// SAFETY:
666664
// `self` is non-zero, so masking to preserve only the most
667665
// significant set bit will result in a non-zero `n`.
668-
unsafe { NonZero::new_unchecked(n) }
666+
// and self.leading_zeros() is always < $INT::BITS since
667+
// at least one of the bits in the number is not zero
668+
unsafe {
669+
let bit = (((1 as $Uint) << (<$Uint>::BITS - 1)).unchecked_shr(self.leading_zeros()));
670+
NonZero::new_unchecked(bit as $Int)
671+
}
669672
}
670673

671674
/// Returns `self` with only the least significant bit set.

0 commit comments

Comments
 (0)