Skip to content

Commit c602e9a

Browse files
committed
Auto merge of rust-lang#133160 - jhpratt:rollup-wzj9q15, r=jhpratt
Rollup of 4 pull requests Successful merges: - rust-lang#132934 (Overhaul the `-l` option parser (for linking to native libs)) - rust-lang#133142 (rename rustc_const_stable_intrinsic -> rustc_intrinsic_const_stable_indirect) - rust-lang#133145 (Document alternatives to `static mut`) - rust-lang#133158 (Subtree update of `rust-analyzer`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e83c45a + 194c76e commit c602e9a

25 files changed

+378
-217
lines changed

Diff for: compiler/rustc_const_eval/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ const_eval_uninhabited_enum_variant_written =
403403
const_eval_unmarked_const_fn_exposed = `{$def_path}` cannot be (indirectly) exposed to stable
404404
.help = either mark the callee as `#[rustc_const_stable_indirect]`, or the caller as `#[rustc_const_unstable]`
405405
const_eval_unmarked_intrinsic_exposed = intrinsic `{$def_path}` cannot be (indirectly) exposed to stable
406-
.help = mark the caller as `#[rustc_const_unstable]`, or mark the intrinsic `#[rustc_const_stable_intrinsic]` (but this requires team approval)
406+
.help = mark the caller as `#[rustc_const_unstable]`, or mark the intrinsic `#[rustc_intrinsic_const_stable_indirect]` (but this requires team approval)
407407
408408
const_eval_unreachable = entering unreachable code
409409
const_eval_unreachable_unwind =

Diff for: compiler/rustc_const_eval/src/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
760760
Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }) => {
761761
// All good. Note that a `#[rustc_const_stable]` intrinsic (meaning it
762762
// can be *directly* invoked from stable const code) does not always
763-
// have the `#[rustc_const_stable_intrinsic]` attribute (which controls
763+
// have the `#[rustc_intrinsic_const_stable_indirect]` attribute (which controls
764764
// exposing an intrinsic indirectly); we accept this call anyway.
765765
}
766766
}

Diff for: compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
838838
template!(Word), WarnFollowing, EncodeCrossCrate::No, IMPL_DETAIL,
839839
),
840840
rustc_attr!(
841-
rustc_const_stable_intrinsic, Normal,
841+
rustc_intrinsic_const_stable_indirect, Normal,
842842
template!(Word), WarnFollowing, EncodeCrossCrate::No, IMPL_DETAIL,
843843
),
844844
gated!(

Diff for: compiler/rustc_middle/src/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@ pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::Intrinsi
17931793
Some(ty::IntrinsicDef {
17941794
name: tcx.item_name(def_id.into()),
17951795
must_be_overridden: tcx.has_attr(def_id, sym::rustc_intrinsic_must_be_overridden),
1796-
const_stable: tcx.has_attr(def_id, sym::rustc_const_stable_intrinsic),
1796+
const_stable: tcx.has_attr(def_id, sym::rustc_intrinsic_const_stable_indirect),
17971797
})
17981798
} else {
17991799
None

Diff for: compiler/rustc_session/src/config.rs

+9-144
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ use rustc_target::spec::{
3030
};
3131
use tracing::debug;
3232

33+
pub use crate::config::cfg::{Cfg, CheckCfg, ExpectedValues};
34+
use crate::config::native_libs::parse_native_libs;
3335
use crate::errors::FileWriteFail;
3436
pub use crate::options::*;
3537
use crate::search_paths::SearchPath;
36-
use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
38+
use crate::utils::CanonicalizedPath;
3739
use crate::{EarlyDiagCtxt, HashStableContext, Session, filesearch, lint};
3840

3941
mod cfg;
42+
mod native_libs;
4043
pub mod sigpipe;
4144

42-
pub use cfg::{Cfg, CheckCfg, ExpectedValues};
43-
4445
/// The different settings that the `-C strip` flag can have.
4546
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
4647
pub enum Strip {
@@ -2134,143 +2135,6 @@ fn parse_assert_incr_state(
21342135
}
21352136
}
21362137

2137-
fn parse_native_lib_kind(
2138-
early_dcx: &EarlyDiagCtxt,
2139-
matches: &getopts::Matches,
2140-
kind: &str,
2141-
) -> (NativeLibKind, Option<bool>) {
2142-
let (kind, modifiers) = match kind.split_once(':') {
2143-
None => (kind, None),
2144-
Some((kind, modifiers)) => (kind, Some(modifiers)),
2145-
};
2146-
2147-
let kind = match kind {
2148-
"static" => NativeLibKind::Static { bundle: None, whole_archive: None },
2149-
"dylib" => NativeLibKind::Dylib { as_needed: None },
2150-
"framework" => NativeLibKind::Framework { as_needed: None },
2151-
"link-arg" => {
2152-
if !nightly_options::is_unstable_enabled(matches) {
2153-
let why = if nightly_options::match_is_nightly_build(matches) {
2154-
" and only accepted on the nightly compiler"
2155-
} else {
2156-
", the `-Z unstable-options` flag must also be passed to use it"
2157-
};
2158-
early_dcx.early_fatal(format!("library kind `link-arg` is unstable{why}"))
2159-
}
2160-
NativeLibKind::LinkArg
2161-
}
2162-
_ => early_dcx.early_fatal(format!(
2163-
"unknown library kind `{kind}`, expected one of: static, dylib, framework, link-arg"
2164-
)),
2165-
};
2166-
match modifiers {
2167-
None => (kind, None),
2168-
Some(modifiers) => parse_native_lib_modifiers(early_dcx, kind, modifiers, matches),
2169-
}
2170-
}
2171-
2172-
fn parse_native_lib_modifiers(
2173-
early_dcx: &EarlyDiagCtxt,
2174-
mut kind: NativeLibKind,
2175-
modifiers: &str,
2176-
matches: &getopts::Matches,
2177-
) -> (NativeLibKind, Option<bool>) {
2178-
let mut verbatim = None;
2179-
for modifier in modifiers.split(',') {
2180-
let (modifier, value) = match modifier.strip_prefix(['+', '-']) {
2181-
Some(m) => (m, modifier.starts_with('+')),
2182-
None => early_dcx.early_fatal(
2183-
"invalid linking modifier syntax, expected '+' or '-' prefix \
2184-
before one of: bundle, verbatim, whole-archive, as-needed",
2185-
),
2186-
};
2187-
2188-
let report_unstable_modifier = || {
2189-
if !nightly_options::is_unstable_enabled(matches) {
2190-
let why = if nightly_options::match_is_nightly_build(matches) {
2191-
" and only accepted on the nightly compiler"
2192-
} else {
2193-
", the `-Z unstable-options` flag must also be passed to use it"
2194-
};
2195-
early_dcx.early_fatal(format!("linking modifier `{modifier}` is unstable{why}"))
2196-
}
2197-
};
2198-
let assign_modifier = |dst: &mut Option<bool>| {
2199-
if dst.is_some() {
2200-
let msg = format!("multiple `{modifier}` modifiers in a single `-l` option");
2201-
early_dcx.early_fatal(msg)
2202-
} else {
2203-
*dst = Some(value);
2204-
}
2205-
};
2206-
match (modifier, &mut kind) {
2207-
("bundle", NativeLibKind::Static { bundle, .. }) => assign_modifier(bundle),
2208-
("bundle", _) => early_dcx.early_fatal(
2209-
"linking modifier `bundle` is only compatible with `static` linking kind",
2210-
),
2211-
2212-
("verbatim", _) => assign_modifier(&mut verbatim),
2213-
2214-
("whole-archive", NativeLibKind::Static { whole_archive, .. }) => {
2215-
assign_modifier(whole_archive)
2216-
}
2217-
("whole-archive", _) => early_dcx.early_fatal(
2218-
"linking modifier `whole-archive` is only compatible with `static` linking kind",
2219-
),
2220-
2221-
("as-needed", NativeLibKind::Dylib { as_needed })
2222-
| ("as-needed", NativeLibKind::Framework { as_needed }) => {
2223-
report_unstable_modifier();
2224-
assign_modifier(as_needed)
2225-
}
2226-
("as-needed", _) => early_dcx.early_fatal(
2227-
"linking modifier `as-needed` is only compatible with \
2228-
`dylib` and `framework` linking kinds",
2229-
),
2230-
2231-
// Note: this error also excludes the case with empty modifier
2232-
// string, like `modifiers = ""`.
2233-
_ => early_dcx.early_fatal(format!(
2234-
"unknown linking modifier `{modifier}`, expected one \
2235-
of: bundle, verbatim, whole-archive, as-needed"
2236-
)),
2237-
}
2238-
}
2239-
2240-
(kind, verbatim)
2241-
}
2242-
2243-
fn parse_libs(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Vec<NativeLib> {
2244-
matches
2245-
.opt_strs("l")
2246-
.into_iter()
2247-
.map(|s| {
2248-
// Parse string of the form "[KIND[:MODIFIERS]=]lib[:new_name]",
2249-
// where KIND is one of "dylib", "framework", "static", "link-arg" and
2250-
// where MODIFIERS are a comma separated list of supported modifiers
2251-
// (bundle, verbatim, whole-archive, as-needed). Each modifier is prefixed
2252-
// with either + or - to indicate whether it is enabled or disabled.
2253-
// The last value specified for a given modifier wins.
2254-
let (name, kind, verbatim) = match s.split_once('=') {
2255-
None => (s, NativeLibKind::Unspecified, None),
2256-
Some((kind, name)) => {
2257-
let (kind, verbatim) = parse_native_lib_kind(early_dcx, matches, kind);
2258-
(name.to_string(), kind, verbatim)
2259-
}
2260-
};
2261-
2262-
let (name, new_name) = match name.split_once(':') {
2263-
None => (name, None),
2264-
Some((name, new_name)) => (name.to_string(), Some(new_name.to_owned())),
2265-
};
2266-
if name.is_empty() {
2267-
early_dcx.early_fatal("library name must not be empty");
2268-
}
2269-
NativeLib { name, new_name, kind, verbatim }
2270-
})
2271-
.collect()
2272-
}
2273-
22742138
pub fn parse_externs(
22752139
early_dcx: &EarlyDiagCtxt,
22762140
matches: &getopts::Matches,
@@ -2644,7 +2508,10 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26442508
let debuginfo = select_debuginfo(matches, &cg);
26452509
let debuginfo_compression = unstable_opts.debuginfo_compression;
26462510

2647-
let libs = parse_libs(early_dcx, matches);
2511+
let crate_name = matches.opt_str("crate-name");
2512+
let unstable_features = UnstableFeatures::from_environment(crate_name.as_deref());
2513+
// Parse any `-l` flags, which link to native libraries.
2514+
let libs = parse_native_libs(early_dcx, &unstable_opts, unstable_features, matches);
26482515

26492516
let test = matches.opt_present("test");
26502517

@@ -2659,8 +2526,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26592526

26602527
let externs = parse_externs(early_dcx, matches, &unstable_opts);
26612528

2662-
let crate_name = matches.opt_str("crate-name");
2663-
26642529
let remap_path_prefix = parse_remap_path_prefix(early_dcx, matches, &unstable_opts);
26652530

26662531
let pretty = parse_pretty(early_dcx, &unstable_opts);
@@ -2734,7 +2599,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27342599
error_format,
27352600
diagnostic_width,
27362601
externs,
2737-
unstable_features: UnstableFeatures::from_environment(crate_name.as_deref()),
2602+
unstable_features,
27382603
crate_name,
27392604
libs,
27402605
debug_assertions,

0 commit comments

Comments
 (0)