Skip to content

Commit b457170

Browse files
Auto merge of #145638 - jhpratt:rollup-ysjcbw0, r=<try>
Rollup of 8 pull requests try-job: test-various
2 parents 05f5a58 + 870b1e2 commit b457170

File tree

275 files changed

+968
-424
lines changed

Some content is hidden

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

275 files changed

+968
-424
lines changed

compiler/rustc_lint/src/context.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
2424
use rustc_middle::ty::print::{PrintError, PrintTraitRefExt as _, Printer, with_no_trimmed_paths};
2525
use rustc_middle::ty::{self, GenericArg, RegisteredTools, Ty, TyCtxt, TypingEnv, TypingMode};
2626
use rustc_session::lint::{FutureIncompatibleInfo, Lint, LintBuffer, LintExpectationId, LintId};
27-
use rustc_session::{LintStoreMarker, Session};
27+
use rustc_session::{DynLintStore, Session};
2828
use rustc_span::edit_distance::find_best_match_for_names;
2929
use rustc_span::{Ident, Span, Symbol, sym};
3030
use tracing::debug;
@@ -62,7 +62,13 @@ pub struct LintStore {
6262
lint_groups: FxIndexMap<&'static str, LintGroup>,
6363
}
6464

65-
impl LintStoreMarker for LintStore {}
65+
impl DynLintStore for LintStore {
66+
fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = rustc_session::LintGroup> + '_> {
67+
Box::new(self.get_lint_groups().map(|(name, lints, is_externally_loaded)| {
68+
rustc_session::LintGroup { name, lints, is_externally_loaded }
69+
}))
70+
}
71+
}
6672

6773
/// The target of the `by_name` map, which accounts for renaming/deprecation.
6874
#[derive(Debug)]

compiler/rustc_middle/src/lint.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,28 @@ impl LintExpectation {
211211
}
212212

213213
fn explain_lint_level_source(
214+
sess: &Session,
214215
lint: &'static Lint,
215216
level: Level,
216217
src: LintLevelSource,
217218
err: &mut Diag<'_, ()>,
218219
) {
220+
// Find the name of the lint group that contains the given lint.
221+
// Assumes the lint only belongs to one group.
222+
let lint_group_name = |lint| {
223+
let lint_groups_iter = sess.lint_groups_iter();
224+
let lint_id = LintId::of(lint);
225+
lint_groups_iter
226+
.filter(|lint_group| !lint_group.is_externally_loaded)
227+
.find(|lint_group| {
228+
lint_group
229+
.lints
230+
.iter()
231+
.find(|lint_group_lint| **lint_group_lint == lint_id)
232+
.is_some()
233+
})
234+
.map(|lint_group| lint_group.name)
235+
};
219236
let name = lint.name_lower();
220237
if let Level::Allow = level {
221238
// Do not point at `#[allow(compat_lint)]` as the reason for a compatibility lint
@@ -224,7 +241,15 @@ fn explain_lint_level_source(
224241
}
225242
match src {
226243
LintLevelSource::Default => {
227-
err.note_once(format!("`#[{}({})]` on by default", level.as_str(), name));
244+
let level_str = level.as_str();
245+
match lint_group_name(lint) {
246+
Some(group_name) => {
247+
err.note_once(format!("`#[{level_str}({name})]` (part of `#[{level_str}({group_name})]`) on by default"));
248+
}
249+
None => {
250+
err.note_once(format!("`#[{level_str}({name})]` on by default"));
251+
}
252+
}
228253
}
229254
LintLevelSource::CommandLine(lint_flag_val, orig_level) => {
230255
let flag = orig_level.to_cmd_flag();
@@ -427,7 +452,7 @@ pub fn lint_level(
427452
decorate(&mut err);
428453
}
429454

430-
explain_lint_level_source(lint, level, src, &mut err);
455+
explain_lint_level_source(sess, lint, level, src, &mut err);
431456
err.emit()
432457
}
433458
lint_level_impl(sess, lint, level, span, Box::new(decorate))

compiler/rustc_session/src/session.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use crate::config::{
4444
SwitchWithOptPath,
4545
};
4646
use crate::filesearch::FileSearch;
47+
use crate::lint::LintId;
4748
use crate::parse::{ParseSess, add_feature_diagnostics};
4849
use crate::search_paths::SearchPath;
4950
use crate::{errors, filesearch, lint};
@@ -139,7 +140,10 @@ pub struct CompilerIO {
139140
pub temps_dir: Option<PathBuf>,
140141
}
141142

142-
pub trait LintStoreMarker: Any + DynSync + DynSend {}
143+
pub trait DynLintStore: Any + DynSync + DynSend {
144+
/// Provides a way to access lint groups without depending on `rustc_lint`
145+
fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = LintGroup> + '_>;
146+
}
143147

144148
/// Represents the data associated with a compilation
145149
/// session for a single crate.
@@ -164,7 +168,7 @@ pub struct Session {
164168
pub code_stats: CodeStats,
165169

166170
/// This only ever stores a `LintStore` but we don't want a dependency on that type here.
167-
pub lint_store: Option<Arc<dyn LintStoreMarker>>,
171+
pub lint_store: Option<Arc<dyn DynLintStore>>,
168172

169173
/// Cap lint level specified by a driver specifically.
170174
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
@@ -240,6 +244,12 @@ impl CodegenUnits {
240244
}
241245
}
242246

247+
pub struct LintGroup {
248+
pub name: &'static str,
249+
pub lints: Vec<LintId>,
250+
pub is_externally_loaded: bool,
251+
}
252+
243253
impl Session {
244254
pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) {
245255
self.miri_unleashed_features.lock().push((span, feature_gate));
@@ -596,6 +606,13 @@ impl Session {
596606
(&*self.target.staticlib_prefix, &*self.target.staticlib_suffix)
597607
}
598608
}
609+
610+
pub fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = LintGroup> + '_> {
611+
match self.lint_store {
612+
Some(ref lint_store) => lint_store.lint_groups_iter(),
613+
None => Box::new(std::iter::empty()),
614+
}
615+
}
599616
}
600617

601618
// JUSTIFICATION: defn of the suggested wrapper fns

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) fn target() -> Target {
77
llvm_target,
88
metadata: TargetMetadata {
99
description: Some("x86_64 Apple macOS (10.12+, Sierra+)".into()),
10-
tier: Some(1),
10+
tier: Some(2),
1111
host_tools: Some(true),
1212
std: Some(true),
1313
},

library/Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ dependencies = [
336336
name = "std_detect"
337337
version = "0.1.5"
338338
dependencies = [
339-
"alloc",
340-
"core",
341339
"libc",
340+
"rustc-std-workspace-alloc",
341+
"rustc-std-workspace-core",
342342
]
343343

344344
[[package]]

library/core/src/cmp.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,9 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
15541554
///
15551555
/// Returns the first argument if the comparison determines them to be equal.
15561556
///
1557+
/// The parameter order is preserved when calling the `compare` function, i.e. `v1` is
1558+
/// always passed as the first argument and `v2` as the second.
1559+
///
15571560
/// # Examples
15581561
///
15591562
/// ```
@@ -1574,7 +1577,7 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
15741577
#[must_use]
15751578
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
15761579
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
1577-
if compare(&v2, &v1).is_lt() { v2 } else { v1 }
1580+
if compare(&v1, &v2).is_le() { v1 } else { v2 }
15781581
}
15791582

15801583
/// Returns the element that gives the minimum value from the specified function.
@@ -1646,6 +1649,9 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
16461649
///
16471650
/// Returns the second argument if the comparison determines them to be equal.
16481651
///
1652+
/// The parameter order is preserved when calling the `compare` function, i.e. `v1` is
1653+
/// always passed as the first argument and `v2` as the second.
1654+
///
16491655
/// # Examples
16501656
///
16511657
/// ```
@@ -1666,7 +1672,7 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
16661672
#[must_use]
16671673
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
16681674
pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
1669-
if compare(&v2, &v1).is_lt() { v1 } else { v2 }
1675+
if compare(&v1, &v2).is_gt() { v1 } else { v2 }
16701676
}
16711677

16721678
/// Returns the element that gives the maximum value from the specified function.
@@ -1745,6 +1751,9 @@ where
17451751
///
17461752
/// Returns `[v1, v2]` if the comparison determines them to be equal.
17471753
///
1754+
/// The parameter order is preserved when calling the `compare` function, i.e. `v1` is
1755+
/// always passed as the first argument and `v2` as the second.
1756+
///
17481757
/// # Examples
17491758
///
17501759
/// ```
@@ -1769,7 +1778,7 @@ pub fn minmax_by<T, F>(v1: T, v2: T, compare: F) -> [T; 2]
17691778
where
17701779
F: FnOnce(&T, &T) -> Ordering,
17711780
{
1772-
if compare(&v2, &v1).is_lt() { [v2, v1] } else { [v1, v2] }
1781+
if compare(&v1, &v2).is_le() { [v1, v2] } else { [v2, v1] }
17731782
}
17741783

17751784
/// Returns minimum and maximum values with respect to the specified key function.

library/core/src/num/int_macros.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,48 @@ macro_rules! int_impl {
209209
self & self.wrapping_neg()
210210
}
211211

212+
/// Returns the index of the highest bit set to one in `self`, or `None`
213+
/// if `self` is `0`.
214+
///
215+
/// # Examples
216+
///
217+
/// ```
218+
/// #![feature(int_lowest_highest_one)]
219+
///
220+
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".highest_one(), None);")]
221+
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".highest_one(), Some(0));")]
222+
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".highest_one(), Some(4));")]
223+
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".highest_one(), Some(4));")]
224+
/// ```
225+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
226+
#[must_use = "this returns the result of the operation, \
227+
without modifying the original"]
228+
#[inline(always)]
229+
pub const fn highest_one(self) -> Option<u32> {
230+
(self as $UnsignedT).highest_one()
231+
}
232+
233+
/// Returns the index of the lowest bit set to one in `self`, or `None`
234+
/// if `self` is `0`.
235+
///
236+
/// # Examples
237+
///
238+
/// ```
239+
/// #![feature(int_lowest_highest_one)]
240+
///
241+
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".lowest_one(), None);")]
242+
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".lowest_one(), Some(0));")]
243+
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".lowest_one(), Some(4));")]
244+
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".lowest_one(), Some(0));")]
245+
/// ```
246+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
247+
#[must_use = "this returns the result of the operation, \
248+
without modifying the original"]
249+
#[inline(always)]
250+
pub const fn lowest_one(self) -> Option<u32> {
251+
(self as $UnsignedT).lowest_one()
252+
}
253+
212254
/// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size.
213255
///
214256
/// This produces the same result as an `as` cast, but ensures that the bit-width remains

library/core/src/num/nonzero.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,54 @@ macro_rules! nonzero_integer {
681681
unsafe { NonZero::new_unchecked(n) }
682682
}
683683

684+
/// Returns the index of the highest bit set to one in `self`.
685+
///
686+
/// # Examples
687+
///
688+
/// ```
689+
/// #![feature(int_lowest_highest_one)]
690+
///
691+
/// # use core::num::NonZero;
692+
/// # fn main() { test().unwrap(); }
693+
/// # fn test() -> Option<()> {
694+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1)?.highest_one(), 0);")]
695+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x10)?.highest_one(), 4);")]
696+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1f)?.highest_one(), 4);")]
697+
/// # Some(())
698+
/// # }
699+
/// ```
700+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
701+
#[must_use = "this returns the result of the operation, \
702+
without modifying the original"]
703+
#[inline(always)]
704+
pub const fn highest_one(self) -> u32 {
705+
Self::BITS - 1 - self.leading_zeros()
706+
}
707+
708+
/// Returns the index of the lowest bit set to one in `self`.
709+
///
710+
/// # Examples
711+
///
712+
/// ```
713+
/// #![feature(int_lowest_highest_one)]
714+
///
715+
/// # use core::num::NonZero;
716+
/// # fn main() { test().unwrap(); }
717+
/// # fn test() -> Option<()> {
718+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1)?.lowest_one(), 0);")]
719+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x10)?.lowest_one(), 4);")]
720+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1f)?.lowest_one(), 0);")]
721+
/// # Some(())
722+
/// # }
723+
/// ```
724+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
725+
#[must_use = "this returns the result of the operation, \
726+
without modifying the original"]
727+
#[inline(always)]
728+
pub const fn lowest_one(self) -> u32 {
729+
self.trailing_zeros()
730+
}
731+
684732
/// Returns the number of ones in the binary representation of `self`.
685733
///
686734
/// # Examples

library/core/src/num/uint_macros.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,54 @@ macro_rules! uint_impl {
261261
self & self.wrapping_neg()
262262
}
263263

264+
/// Returns the index of the highest bit set to one in `self`, or `None`
265+
/// if `self` is `0`.
266+
///
267+
/// # Examples
268+
///
269+
/// ```
270+
/// #![feature(int_lowest_highest_one)]
271+
///
272+
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".highest_one(), None);")]
273+
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".highest_one(), Some(0));")]
274+
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".highest_one(), Some(4));")]
275+
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".highest_one(), Some(4));")]
276+
/// ```
277+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
278+
#[must_use = "this returns the result of the operation, \
279+
without modifying the original"]
280+
#[inline(always)]
281+
pub const fn highest_one(self) -> Option<u32> {
282+
match NonZero::new(self) {
283+
Some(v) => Some(v.highest_one()),
284+
None => None,
285+
}
286+
}
287+
288+
/// Returns the index of the lowest bit set to one in `self`, or `None`
289+
/// if `self` is `0`.
290+
///
291+
/// # Examples
292+
///
293+
/// ```
294+
/// #![feature(int_lowest_highest_one)]
295+
///
296+
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".lowest_one(), None);")]
297+
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".lowest_one(), Some(0));")]
298+
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".lowest_one(), Some(4));")]
299+
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".lowest_one(), Some(0));")]
300+
/// ```
301+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
302+
#[must_use = "this returns the result of the operation, \
303+
without modifying the original"]
304+
#[inline(always)]
305+
pub const fn lowest_one(self) -> Option<u32> {
306+
match NonZero::new(self) {
307+
Some(v) => Some(v.lowest_one()),
308+
None => None,
309+
}
310+
}
311+
264312
/// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
265313
///
266314
/// This produces the same result as an `as` cast, but ensures that the bit-width remains

library/coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#![feature(generic_assert_internals)]
5555
#![feature(hasher_prefixfree_extras)]
5656
#![feature(hashmap_internals)]
57+
#![feature(int_lowest_highest_one)]
5758
#![feature(int_roundings)]
5859
#![feature(ip)]
5960
#![feature(is_ascii_octdigit)]

0 commit comments

Comments
 (0)