Skip to content

Commit 88bd39b

Browse files
committed
Auto merge of rust-lang#149410 - Zalathar:rollup-wke6axp, r=Zalathar
Rollup of 5 pull requests Successful merges: - rust-lang#149087 (Stabilize `unchecked_neg` and `unchecked_shifts`) - rust-lang#149107 (rustc_borrowck: Don't suggest changing closure param type not under user control) - rust-lang#149323 (Use cg_llvm's target_config in miri) - rust-lang#149380 (Run `eval_config_entry` on all branches so we always emit lints) - rust-lang#149394 (add regression test for guard patterns liveness ICE) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 10776a4 + 28fae11 commit 88bd39b

File tree

27 files changed

+299
-150
lines changed

27 files changed

+299
-150
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11981198
);
11991199
return;
12001200
}
1201+
1202+
// Do not suggest changing type if that is not under user control.
1203+
if self.is_closure_arg_with_non_locally_decided_type(local) {
1204+
return;
1205+
}
1206+
12011207
let decl_span = local_decl.source_info.span;
12021208

12031209
let (amp_mut_sugg, local_var_ty_info) = match *local_decl.local_info() {
@@ -1500,6 +1506,60 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
15001506
Applicability::HasPlaceholders,
15011507
);
15021508
}
1509+
1510+
/// Returns `true` if `local` is an argument in a closure passed to a
1511+
/// function defined in another crate.
1512+
///
1513+
/// For example, in the following code this function returns `true` for `x`
1514+
/// since `Option::inspect()` is not defined in the current crate:
1515+
///
1516+
/// ```text
1517+
/// some_option.as_mut().inspect(|x| {
1518+
/// ```
1519+
fn is_closure_arg_with_non_locally_decided_type(&self, local: Local) -> bool {
1520+
// We don't care about regular local variables, only args.
1521+
if self.body.local_kind(local) != LocalKind::Arg {
1522+
return false;
1523+
}
1524+
1525+
// Make sure we are inside a closure.
1526+
let InstanceKind::Item(body_def_id) = self.body.source.instance else {
1527+
return false;
1528+
};
1529+
let Some(Node::Expr(hir::Expr { hir_id: body_hir_id, kind, .. })) =
1530+
self.infcx.tcx.hir_get_if_local(body_def_id)
1531+
else {
1532+
return false;
1533+
};
1534+
let ExprKind::Closure(hir::Closure { kind: hir::ClosureKind::Closure, .. }) = kind else {
1535+
return false;
1536+
};
1537+
1538+
// Check if the method/function that our closure is passed to is defined
1539+
// in another crate.
1540+
let Node::Expr(closure_parent) = self.infcx.tcx.parent_hir_node(*body_hir_id) else {
1541+
return false;
1542+
};
1543+
match closure_parent.kind {
1544+
ExprKind::MethodCall(method, _, _, _) => self
1545+
.infcx
1546+
.tcx
1547+
.typeck(method.hir_id.owner.def_id)
1548+
.type_dependent_def_id(closure_parent.hir_id)
1549+
.is_some_and(|def_id| !def_id.is_local()),
1550+
ExprKind::Call(func, _) => self
1551+
.infcx
1552+
.tcx
1553+
.typeck(func.hir_id.owner.def_id)
1554+
.node_type_opt(func.hir_id)
1555+
.and_then(|ty| match ty.kind() {
1556+
ty::FnDef(def_id, _) => Some(def_id),
1557+
_ => None,
1558+
})
1559+
.is_some_and(|def_id| !def_id.is_local()),
1560+
_ => false,
1561+
}
1562+
}
15031563
}
15041564

15051565
struct BindingFinder {

compiler/rustc_builtin_macros/src/cfg_select.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@ use crate::errors::{CfgSelectNoMatches, CfgSelectUnreachable};
1010

1111
/// Selects the first arm whose predicate evaluates to true.
1212
fn select_arm(ecx: &ExtCtxt<'_>, branches: CfgSelectBranches) -> Option<(TokenStream, Span)> {
13+
let mut result = None;
1314
for (cfg, tt, arm_span) in branches.reachable {
1415
if let EvalConfigResult::True = attr::eval_config_entry(
1516
&ecx.sess,
1617
&cfg,
1718
ecx.current_expansion.lint_node_id,
1819
ShouldEmit::ErrorsAndLints,
1920
) {
20-
return Some((tt, arm_span));
21+
// FIXME(#149215) Ideally we should short-circuit here, but `eval_config_entry` currently emits lints so we cannot do this yet.
22+
result.get_or_insert((tt, arm_span));
2123
}
2224
}
2325

24-
branches.wildcard.map(|(_, tt, span)| (tt, span))
26+
let wildcard = branches.wildcard.map(|(_, tt, span)| (tt, span));
27+
result.or(wildcard)
2528
}
2629

2730
pub(super) fn expand_cfg_select<'cx>(

compiler/rustc_interface/src/interface.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_session::parse::ParseSess;
2424
use rustc_session::{CompilerIO, EarlyDiagCtxt, Session, lint};
2525
use rustc_span::source_map::{FileLoader, RealFileLoader, SourceMapInputs};
2626
use rustc_span::{FileName, sym};
27+
use rustc_target::spec::Target;
2728
use tracing::trace;
2829

2930
use crate::util;
@@ -385,7 +386,7 @@ pub struct Config {
385386
/// custom driver where the custom codegen backend has arbitrary data."
386387
/// (See #102759.)
387388
pub make_codegen_backend:
388-
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
389+
Option<Box<dyn FnOnce(&config::Options, &Target) -> Box<dyn CodegenBackend> + Send>>,
389390

390391
/// Registry of diagnostics codes.
391392
pub registry: Registry,
@@ -453,7 +454,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
453454
Some(make_codegen_backend) => {
454455
// N.B. `make_codegen_backend` takes precedence over
455456
// `target.default_codegen_backend`, which is ignored in this case.
456-
make_codegen_backend(&config.opts)
457+
make_codegen_backend(&config.opts, &target)
457458
}
458459
};
459460

compiler/rustc_interface/src/util.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pub fn get_codegen_backend(
339339
filename if filename.contains('.') => {
340340
load_backend_from_dylib(early_dcx, filename.as_ref())
341341
}
342-
"dummy" => || Box::new(DummyCodegenBackend),
342+
"dummy" => || Box::new(DummyCodegenBackend { target_config_override: None }),
343343
#[cfg(feature = "llvm")]
344344
"llvm" => rustc_codegen_llvm::LlvmCodegenBackend::new,
345345
backend_name => get_codegen_sysroot(early_dcx, sysroot, backend_name),
@@ -352,7 +352,9 @@ pub fn get_codegen_backend(
352352
unsafe { load() }
353353
}
354354

355-
struct DummyCodegenBackend;
355+
pub struct DummyCodegenBackend {
356+
pub target_config_override: Option<Box<dyn Fn(&Session) -> TargetConfig>>,
357+
}
356358

357359
impl CodegenBackend for DummyCodegenBackend {
358360
fn locale_resource(&self) -> &'static str {
@@ -364,6 +366,10 @@ impl CodegenBackend for DummyCodegenBackend {
364366
}
365367

366368
fn target_config(&self, sess: &Session) -> TargetConfig {
369+
if let Some(target_config_override) = &self.target_config_override {
370+
return target_config_override(sess);
371+
}
372+
367373
let abi_required_features = sess.target.abi_required_features();
368374
let (target_features, unstable_target_features) = cfg_target_feature::<0>(
369375
sess,

library/core/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@
126126
#![feature(str_split_inclusive_remainder)]
127127
#![feature(str_split_remainder)]
128128
#![feature(ub_checks)]
129-
#![feature(unchecked_neg)]
130-
#![feature(unchecked_shifts)]
131129
#![feature(unsafe_pinned)]
132130
#![feature(utf16_extra)]
133131
#![feature(variant_count)]

library/core/src/num/int_macros.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,11 +1275,8 @@ macro_rules! int_impl {
12751275
/// i.e. when [`checked_neg`] would return `None`.
12761276
///
12771277
#[doc = concat!("[`checked_neg`]: ", stringify!($SelfT), "::checked_neg")]
1278-
#[unstable(
1279-
feature = "unchecked_neg",
1280-
reason = "niche optimization path",
1281-
issue = "85122",
1282-
)]
1278+
#[stable(feature = "unchecked_neg", since = "CURRENT_RUSTC_VERSION")]
1279+
#[rustc_const_stable(feature = "unchecked_neg", since = "CURRENT_RUSTC_VERSION")]
12831280
#[must_use = "this returns the result of the operation, \
12841281
without modifying the original"]
12851282
#[inline(always)]
@@ -1395,11 +1392,8 @@ macro_rules! int_impl {
13951392
/// i.e. when [`checked_shl`] would return `None`.
13961393
///
13971394
#[doc = concat!("[`checked_shl`]: ", stringify!($SelfT), "::checked_shl")]
1398-
#[unstable(
1399-
feature = "unchecked_shifts",
1400-
reason = "niche optimization path",
1401-
issue = "85122",
1402-
)]
1395+
#[stable(feature = "unchecked_shifts", since = "CURRENT_RUSTC_VERSION")]
1396+
#[rustc_const_stable(feature = "unchecked_shifts", since = "CURRENT_RUSTC_VERSION")]
14031397
#[must_use = "this returns the result of the operation, \
14041398
without modifying the original"]
14051399
#[inline(always)]
@@ -1570,11 +1564,8 @@ macro_rules! int_impl {
15701564
/// i.e. when [`checked_shr`] would return `None`.
15711565
///
15721566
#[doc = concat!("[`checked_shr`]: ", stringify!($SelfT), "::checked_shr")]
1573-
#[unstable(
1574-
feature = "unchecked_shifts",
1575-
reason = "niche optimization path",
1576-
issue = "85122",
1577-
)]
1567+
#[stable(feature = "unchecked_shifts", since = "CURRENT_RUSTC_VERSION")]
1568+
#[rustc_const_stable(feature = "unchecked_shifts", since = "CURRENT_RUSTC_VERSION")]
15781569
#[must_use = "this returns the result of the operation, \
15791570
without modifying the original"]
15801571
#[inline(always)]

library/core/src/num/uint_macros.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,11 +1851,8 @@ macro_rules! uint_impl {
18511851
/// i.e. when [`checked_shl`] would return `None`.
18521852
///
18531853
#[doc = concat!("[`checked_shl`]: ", stringify!($SelfT), "::checked_shl")]
1854-
#[unstable(
1855-
feature = "unchecked_shifts",
1856-
reason = "niche optimization path",
1857-
issue = "85122",
1858-
)]
1854+
#[stable(feature = "unchecked_shifts", since = "CURRENT_RUSTC_VERSION")]
1855+
#[rustc_const_stable(feature = "unchecked_shifts", since = "CURRENT_RUSTC_VERSION")]
18591856
#[must_use = "this returns the result of the operation, \
18601857
without modifying the original"]
18611858
#[inline(always)]
@@ -2023,11 +2020,8 @@ macro_rules! uint_impl {
20232020
/// i.e. when [`checked_shr`] would return `None`.
20242021
///
20252022
#[doc = concat!("[`checked_shr`]: ", stringify!($SelfT), "::checked_shr")]
2026-
#[unstable(
2027-
feature = "unchecked_shifts",
2028-
reason = "niche optimization path",
2029-
issue = "85122",
2030-
)]
2023+
#[stable(feature = "unchecked_shifts", since = "CURRENT_RUSTC_VERSION")]
2024+
#[rustc_const_stable(feature = "unchecked_shifts", since = "CURRENT_RUSTC_VERSION")]
20312025
#[must_use = "this returns the result of the operation, \
20322026
without modifying the original"]
20332027
#[inline(always)]

0 commit comments

Comments
 (0)