Skip to content

Rollup of 8 pull requests #145638

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

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1ddb4d0
Fix parameter order for `_by()` variants of `min` / `max`/ `minmax` i…
miried Apr 4, 2025
d78e762
scrape-examples.js: give each function a signature
lolbinarycat Apr 25, 2025
b4c77e1
rustdoc js: add ScrapedLoc type
lolbinarycat Apr 25, 2025
35ba7dd
rustdoc js: add rustdoc.ScrapedLoc type
lolbinarycat Apr 25, 2025
8799d3d
fix typo
lolbinarycat Apr 28, 2025
b06113d
scrape-examples.js: add another nonnull() invokation
lolbinarycat May 22, 2025
c021e7a
scrape-examples.js: fix typos
lolbinarycat May 27, 2025
36a3820
Use aarch64-apple-darwin as the fallback doc source for `-apple-`
shepmaster Aug 11, 2025
c574c91
Demote x86_64-apple-darwin to Tier 2 with host tools
shepmaster Aug 11, 2025
dc81d75
Add new `--test-codegen-backend` bootstrap option
GuillaumeGomez Aug 11, 2025
73d3d28
Implement feature `int_lowest_highest_one` for integer and NonZero types
Gnurou Aug 10, 2025
2d3ee01
Split compiletest `--codegen-backend` into two options `--default-cod…
GuillaumeGomez Aug 18, 2025
41d8d85
Remove hs_abs_cmp examples
miried Aug 19, 2025
36d309e
Merge remote-tracking branch 'upstream/master'
miried Aug 19, 2025
77d6ee0
Fix bug where `rustdoc-js` tester would not pick the right `search.js…
GuillaumeGomez Aug 13, 2025
2ebe679
Strenghten rustdoc js tester file macthing regex
GuillaumeGomez Aug 16, 2025
a971238
`std_detect`: Use `rustc-std-workspace-*` to pull in `compiler-builtins`
joshtriplett Aug 19, 2025
4c948bc
Update lockfile for changes to `std_detect`
joshtriplett Aug 19, 2025
9a29e16
mention lint group in default level lint note
karolzwolak Apr 28, 2025
d14b83e
bless tests with new lint messages
karolzwolak Apr 28, 2025
8105857
Rollup merge of #139357 - miried:master, r=Amanieu
jhpratt Aug 19, 2025
98ac6a9
Rollup merge of #140314 - lolbinarycat:rustdoc-js-scrape-examples-typ…
jhpratt Aug 19, 2025
b9f4ecc
Rollup merge of #140794 - karolzwolak:allow-unused-doc-65464, r=david…
jhpratt Aug 19, 2025
09af3e1
Rollup merge of #145252 - shepmaster:demote-x86_64-apple-darwin-to-ti…
jhpratt Aug 19, 2025
32d9fea
Rollup merge of #145256 - GuillaumeGomez:bootstrap-test-codegen-backe…
jhpratt Aug 19, 2025
c2e2e03
Rollup merge of #145359 - GuillaumeGomez:correctly-pick-search.js, r=…
jhpratt Aug 19, 2025
5b15bfd
Rollup merge of #145381 - Gnurou:int_lowest_highest_one, r=jhpratt
jhpratt Aug 19, 2025
870b1e2
Rollup merge of #145619 - joshtriplett:use-the-right-core, r=tgross35
jhpratt Aug 19, 2025
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
10 changes: 8 additions & 2 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
use rustc_middle::ty::print::{PrintError, PrintTraitRefExt as _, Printer, with_no_trimmed_paths};
use rustc_middle::ty::{self, GenericArg, RegisteredTools, Ty, TyCtxt, TypingEnv, TypingMode};
use rustc_session::lint::{FutureIncompatibleInfo, Lint, LintBuffer, LintExpectationId, LintId};
use rustc_session::{LintStoreMarker, Session};
use rustc_session::{DynLintStore, Session};
use rustc_span::edit_distance::find_best_match_for_names;
use rustc_span::{Ident, Span, Symbol, sym};
use tracing::debug;
Expand Down Expand Up @@ -62,7 +62,13 @@ pub struct LintStore {
lint_groups: FxIndexMap<&'static str, LintGroup>,
}

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

/// The target of the `by_name` map, which accounts for renaming/deprecation.
#[derive(Debug)]
Expand Down
29 changes: 27 additions & 2 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,28 @@ impl LintExpectation {
}

fn explain_lint_level_source(
sess: &Session,
lint: &'static Lint,
level: Level,
src: LintLevelSource,
err: &mut Diag<'_, ()>,
) {
// Find the name of the lint group that contains the given lint.
// Assumes the lint only belongs to one group.
let lint_group_name = |lint| {
let lint_groups_iter = sess.lint_groups_iter();
let lint_id = LintId::of(lint);
lint_groups_iter
.filter(|lint_group| !lint_group.is_externally_loaded)
.find(|lint_group| {
lint_group
.lints
.iter()
.find(|lint_group_lint| **lint_group_lint == lint_id)
.is_some()
})
.map(|lint_group| lint_group.name)
};
let name = lint.name_lower();
if let Level::Allow = level {
// Do not point at `#[allow(compat_lint)]` as the reason for a compatibility lint
Expand All @@ -224,7 +241,15 @@ fn explain_lint_level_source(
}
match src {
LintLevelSource::Default => {
err.note_once(format!("`#[{}({})]` on by default", level.as_str(), name));
let level_str = level.as_str();
match lint_group_name(lint) {
Some(group_name) => {
err.note_once(format!("`#[{level_str}({name})]` (part of `#[{level_str}({group_name})]`) on by default"));
}
None => {
err.note_once(format!("`#[{level_str}({name})]` on by default"));
}
}
}
LintLevelSource::CommandLine(lint_flag_val, orig_level) => {
let flag = orig_level.to_cmd_flag();
Expand Down Expand Up @@ -427,7 +452,7 @@ pub fn lint_level(
decorate(&mut err);
}

explain_lint_level_source(lint, level, src, &mut err);
explain_lint_level_source(sess, lint, level, src, &mut err);
err.emit()
}
lint_level_impl(sess, lint, level, span, Box::new(decorate))
Expand Down
21 changes: 19 additions & 2 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use crate::config::{
SwitchWithOptPath,
};
use crate::filesearch::FileSearch;
use crate::lint::LintId;
use crate::parse::{ParseSess, add_feature_diagnostics};
use crate::search_paths::SearchPath;
use crate::{errors, filesearch, lint};
Expand Down Expand Up @@ -139,7 +140,10 @@ pub struct CompilerIO {
pub temps_dir: Option<PathBuf>,
}

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

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

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

/// Cap lint level specified by a driver specifically.
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
Expand Down Expand Up @@ -240,6 +244,12 @@ impl CodegenUnits {
}
}

pub struct LintGroup {
pub name: &'static str,
pub lints: Vec<LintId>,
pub is_externally_loaded: bool,
}

impl Session {
pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) {
self.miri_unleashed_features.lock().push((span, feature_gate));
Expand Down Expand Up @@ -596,6 +606,13 @@ impl Session {
(&*self.target.staticlib_prefix, &*self.target.staticlib_suffix)
}
}

pub fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = LintGroup> + '_> {
match self.lint_store {
Some(ref lint_store) => lint_store.lint_groups_iter(),
None => Box::new(std::iter::empty()),
}
}
}

// JUSTIFICATION: defn of the suggested wrapper fns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) fn target() -> Target {
llvm_target,
metadata: TargetMetadata {
description: Some("x86_64 Apple macOS (10.12+, Sierra+)".into()),
tier: Some(1),
tier: Some(2),
host_tools: Some(true),
std: Some(true),
},
Expand Down
4 changes: 2 additions & 2 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ dependencies = [
name = "std_detect"
version = "0.1.5"
dependencies = [
"alloc",
"core",
"libc",
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
]

[[package]]
Expand Down
15 changes: 12 additions & 3 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,9 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
///
/// Returns the first argument if the comparison determines them to be equal.
///
/// The parameter order is preserved when calling the `compare` function, i.e. `v1` is
/// always passed as the first argument and `v2` as the second.
///
/// # Examples
///
/// ```
Expand All @@ -1574,7 +1577,7 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
#[must_use]
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
if compare(&v2, &v1).is_lt() { v2 } else { v1 }
if compare(&v1, &v2).is_le() { v1 } else { v2 }
}

/// Returns the element that gives the minimum value from the specified function.
Expand Down Expand Up @@ -1646,6 +1649,9 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
///
/// Returns the second argument if the comparison determines them to be equal.
///
/// The parameter order is preserved when calling the `compare` function, i.e. `v1` is
/// always passed as the first argument and `v2` as the second.
///
/// # Examples
///
/// ```
Expand All @@ -1666,7 +1672,7 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
#[must_use]
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
if compare(&v2, &v1).is_lt() { v1 } else { v2 }
if compare(&v1, &v2).is_gt() { v1 } else { v2 }
}

/// Returns the element that gives the maximum value from the specified function.
Expand Down Expand Up @@ -1745,6 +1751,9 @@ where
///
/// Returns `[v1, v2]` if the comparison determines them to be equal.
///
/// The parameter order is preserved when calling the `compare` function, i.e. `v1` is
/// always passed as the first argument and `v2` as the second.
///
/// # Examples
///
/// ```
Expand All @@ -1769,7 +1778,7 @@ pub fn minmax_by<T, F>(v1: T, v2: T, compare: F) -> [T; 2]
where
F: FnOnce(&T, &T) -> Ordering,
{
if compare(&v2, &v1).is_lt() { [v2, v1] } else { [v1, v2] }
if compare(&v1, &v2).is_le() { [v1, v2] } else { [v2, v1] }
}

/// Returns minimum and maximum values with respect to the specified key function.
Expand Down
42 changes: 42 additions & 0 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,48 @@ macro_rules! int_impl {
self & self.wrapping_neg()
}

/// Returns the index of the highest bit set to one in `self`, or `None`
/// if `self` is `0`.
///
/// # Examples
///
/// ```
/// #![feature(int_lowest_highest_one)]
///
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".highest_one(), None);")]
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".highest_one(), Some(0));")]
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".highest_one(), Some(4));")]
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".highest_one(), Some(4));")]
/// ```
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
pub const fn highest_one(self) -> Option<u32> {
(self as $UnsignedT).highest_one()
}

/// Returns the index of the lowest bit set to one in `self`, or `None`
/// if `self` is `0`.
///
/// # Examples
///
/// ```
/// #![feature(int_lowest_highest_one)]
///
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".lowest_one(), None);")]
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".lowest_one(), Some(0));")]
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".lowest_one(), Some(4));")]
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".lowest_one(), Some(0));")]
/// ```
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
pub const fn lowest_one(self) -> Option<u32> {
(self as $UnsignedT).lowest_one()
}

/// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size.
///
/// This produces the same result as an `as` cast, but ensures that the bit-width remains
Expand Down
48 changes: 48 additions & 0 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,54 @@ macro_rules! nonzero_integer {
unsafe { NonZero::new_unchecked(n) }
}

/// Returns the index of the highest bit set to one in `self`.
///
/// # Examples
///
/// ```
/// #![feature(int_lowest_highest_one)]
///
/// # use core::num::NonZero;
/// # fn main() { test().unwrap(); }
/// # fn test() -> Option<()> {
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1)?.highest_one(), 0);")]
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x10)?.highest_one(), 4);")]
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1f)?.highest_one(), 4);")]
/// # Some(())
/// # }
/// ```
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
pub const fn highest_one(self) -> u32 {
Self::BITS - 1 - self.leading_zeros()
}

/// Returns the index of the lowest bit set to one in `self`.
///
/// # Examples
///
/// ```
/// #![feature(int_lowest_highest_one)]
///
/// # use core::num::NonZero;
/// # fn main() { test().unwrap(); }
/// # fn test() -> Option<()> {
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1)?.lowest_one(), 0);")]
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x10)?.lowest_one(), 4);")]
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1f)?.lowest_one(), 0);")]
/// # Some(())
/// # }
/// ```
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
pub const fn lowest_one(self) -> u32 {
self.trailing_zeros()
}

/// Returns the number of ones in the binary representation of `self`.
///
/// # Examples
Expand Down
48 changes: 48 additions & 0 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,54 @@ macro_rules! uint_impl {
self & self.wrapping_neg()
}

/// Returns the index of the highest bit set to one in `self`, or `None`
/// if `self` is `0`.
///
/// # Examples
///
/// ```
/// #![feature(int_lowest_highest_one)]
///
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".highest_one(), None);")]
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".highest_one(), Some(0));")]
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".highest_one(), Some(4));")]
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".highest_one(), Some(4));")]
/// ```
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
pub const fn highest_one(self) -> Option<u32> {
match NonZero::new(self) {
Some(v) => Some(v.highest_one()),
None => None,
}
}

/// Returns the index of the lowest bit set to one in `self`, or `None`
/// if `self` is `0`.
///
/// # Examples
///
/// ```
/// #![feature(int_lowest_highest_one)]
///
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".lowest_one(), None);")]
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".lowest_one(), Some(0));")]
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".lowest_one(), Some(4));")]
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".lowest_one(), Some(0));")]
/// ```
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
pub const fn lowest_one(self) -> Option<u32> {
match NonZero::new(self) {
Some(v) => Some(v.lowest_one()),
None => None,
}
}

/// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
///
/// This produces the same result as an `as` cast, but ensures that the bit-width remains
Expand Down
1 change: 1 addition & 0 deletions library/coretests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#![feature(generic_assert_internals)]
#![feature(hasher_prefixfree_extras)]
#![feature(hashmap_internals)]
#![feature(int_lowest_highest_one)]
#![feature(int_roundings)]
#![feature(ip)]
#![feature(is_ascii_octdigit)]
Expand Down
Loading
Loading