Skip to content

Commit 468f115

Browse files
committed
Auto merge of #124026 - matthiaskrgr:rollup-an6s6gq, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #122632 (fetch submodule before checking llvm stamp) - #123355 (Support type '/' to search) - #123501 (Stabilize checking of cfgs at compile-time: `--check-cfg` option) - #123535 (Match ergonomics 2024: `mut` doesn't reset binding mode) - #123711 (drop `changelog-seen`) - #123969 (The new solver ignores `DefineOpaqueTypes`, so switch it to `Yes`) - #124007 (Miri subtree update) - #124017 (Change a diagnostics-path-only `DefineOpaqueTypes` to `Yes`.) - #124018 (interpret: pass MemoryKind to before_memory_deallocation) - #124024 (interpret: remove outdated comment) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1dea922 + 4971d9f commit 468f115

File tree

125 files changed

+819
-423
lines changed

Some content is hidden

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

125 files changed

+819
-423
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -3364,9 +3364,9 @@ dependencies = [
33643364

33653365
[[package]]
33663366
name = "rustc-build-sysroot"
3367-
version = "0.4.5"
3367+
version = "0.4.6"
33683368
source = "registry+https://github.com/rust-lang/crates.io-index"
3369-
checksum = "a26170e1d79ea32f7ccec3188dd13cfc1f18c82764a9cbc1071667c0f865a4ea"
3369+
checksum = "a9bf37423495cd3a6a9ef8c75fc4566de0d26de0ab75f36f67a426e58df5768c"
33703370
dependencies = [
33713371
"anyhow",
33723372
"rustc_version",

compiler/rustc_const_eval/src/interpret/machine.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,6 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
347347
/// allocation (because a copy had to be done to adjust things), machine memory will
348348
/// cache the result. (This relies on `AllocMap::get_or` being able to add the
349349
/// owned allocation to the map even when the map is shared.)
350-
///
351-
/// This must only fail if `alloc` contains provenance.
352350
fn adjust_allocation<'b>(
353351
ecx: &InterpCx<'mir, 'tcx, Self>,
354352
id: AllocId,
@@ -427,6 +425,7 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
427425
_prov: (AllocId, Self::ProvenanceExtra),
428426
_size: Size,
429427
_align: Align,
428+
_kind: MemoryKind<Self::MemoryKind>,
430429
) -> InterpResult<'tcx> {
431430
Ok(())
432431
}

compiler/rustc_const_eval/src/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
227227
self.allocate_raw_ptr(alloc, kind)
228228
}
229229

230-
/// This can fail only if `alloc` contains provenance.
231230
pub fn allocate_raw_ptr(
232231
&mut self,
233232
alloc: Allocation,
@@ -355,6 +354,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
355354
(alloc_id, prov),
356355
size,
357356
alloc.align,
357+
kind,
358358
)?;
359359

360360
// Don't forget to remember size and align of this now-dead allocation

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,8 @@ declare_features! (
533533
(unstable, more_qualified_paths, "1.54.0", Some(86935)),
534534
/// Allows the `#[must_not_suspend]` attribute.
535535
(unstable, must_not_suspend, "1.57.0", Some(83310)),
536+
/// Make `mut` not reset the binding mode on edition >= 2024.
537+
(incomplete, mut_preserve_binding_mode_2024, "CURRENT_RUSTC_VERSION", Some(123076)),
536538
/// Allows `mut ref` and `mut ref mut` identifier patterns.
537539
(incomplete, mut_ref, "CURRENT_RUSTC_VERSION", Some(123076)),
538540
/// Allows using `#[naked]` on functions.

compiler/rustc_hir_typeck/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ hir_typeck_ctor_is_private = tuple struct constructor `{$def}` is private
4646
4747
hir_typeck_deref_is_empty = this expression `Deref`s to `{$deref_ty}` which implements `is_empty`
4848
49+
hir_typeck_dereferencing_mut_binding = dereferencing `mut` binding
50+
.label = `mut` dereferences the type of this binding
51+
.help = this will change in edition 2024
52+
4953
hir_typeck_expected_default_return_type = expected `()` because of default return type
5054
5155
hir_typeck_expected_return_type = expected `{$expected}` because of return type

compiler/rustc_hir_typeck/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,11 @@ pub enum SuggestBoxingForReturnImplTrait {
632632
ends: Vec<Span>,
633633
},
634634
}
635+
636+
#[derive(LintDiagnostic)]
637+
#[diag(hir_typeck_dereferencing_mut_binding)]
638+
pub struct DereferencingMutBinding {
639+
#[label]
640+
#[help]
641+
pub span: Span,
642+
}

compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16961696
if let ProbeResult::Match = result
16971697
&& self
16981698
.at(&ObligationCause::dummy(), self.param_env)
1699-
.sup(DefineOpaqueTypes::No, return_ty, xform_ret_ty)
1699+
.sup(DefineOpaqueTypes::Yes, return_ty, xform_ret_ty)
17001700
.is_err()
17011701
{
17021702
result = ProbeResult::BadReturnType;

compiler/rustc_hir_typeck/src/pat.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator;
1010
use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Mutability, Pat, PatKind};
1111
use rustc_infer::infer;
1212
use rustc_infer::infer::type_variable::TypeVariableOrigin;
13+
use rustc_lint as lint;
1314
use rustc_middle::mir::interpret::ErrorHandled;
1415
use rustc_middle::ty::{self, Adt, Ty, TypeVisitableExt};
1516
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
@@ -629,12 +630,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
629630
expected: Ty<'tcx>,
630631
pat_info: PatInfo<'tcx, '_>,
631632
) -> Ty<'tcx> {
632-
let PatInfo { binding_mode: def_bm, top_info: ti, .. } = pat_info;
633+
let PatInfo { binding_mode: BindingAnnotation(def_br, _), top_info: ti, .. } = pat_info;
633634

634635
// Determine the binding mode...
635636
let bm = match ba {
636-
BindingAnnotation(ByRef::No, Mutability::Not) => def_bm,
637-
_ => ba,
637+
BindingAnnotation(ByRef::No, Mutability::Mut)
638+
if !(pat.span.at_least_rust_2024()
639+
&& self.tcx.features().mut_preserve_binding_mode_2024)
640+
&& matches!(def_br, ByRef::Yes(_)) =>
641+
{
642+
// `mut x` resets the binding mode in edition <= 2021.
643+
self.tcx.emit_node_span_lint(
644+
lint::builtin::DEREFERENCING_MUT_BINDING,
645+
pat.hir_id,
646+
pat.span,
647+
errors::DereferencingMutBinding { span: pat.span },
648+
);
649+
BindingAnnotation(ByRef::No, Mutability::Mut)
650+
}
651+
BindingAnnotation(ByRef::No, mutbl) => BindingAnnotation(def_br, mutbl),
652+
BindingAnnotation(ByRef::Yes(_), _) => ba,
638653
};
639654
// ...and store it in a side table:
640655
self.typeck_results.borrow_mut().pat_binding_modes_mut().insert(pat.hir_id, bm);
@@ -743,7 +758,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
743758
}
744759
}
745760

746-
// Precondition: pat is a Ref(_) pattern
761+
/// Precondition: pat is a `Ref(_)` pattern
747762
fn borrow_pat_suggestion(&self, err: &mut Diag<'_>, pat: &Pat<'_>) {
748763
let tcx = self.tcx;
749764
if let PatKind::Ref(inner, mutbl) = pat.kind

compiler/rustc_infer/src/infer/at.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
282282
{
283283
let Trace { at, trace } = self;
284284
debug_assert!(at.infcx.next_trait_solver());
285-
let mut fields = at.infcx.combine_fields(trace, at.param_env, DefineOpaqueTypes::No);
285+
let mut fields = at.infcx.combine_fields(trace, at.param_env, DefineOpaqueTypes::Yes);
286286
fields
287287
.equate(StructurallyRelateAliases::Yes)
288288
.relate(a, b)

compiler/rustc_lint/src/context/diagnostics/check_cfg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub(super) fn unexpected_cfg_name(
168168
diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration");
169169
} else {
170170
diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
171-
diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
171+
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration");
172172
}
173173
}
174174

@@ -272,6 +272,6 @@ pub(super) fn unexpected_cfg_value(
272272
if !is_cfg_a_well_know_name {
273273
diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
274274
}
275-
diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
275+
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration");
276276
}
277277
}

compiler/rustc_lint_defs/src/builtin.rs

+37
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ declare_lint_pass! {
3838
DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
3939
DEPRECATED_IN_FUTURE,
4040
DEPRECATED_WHERE_CLAUSE_LOCATION,
41+
DEREFERENCING_MUT_BINDING,
4142
DUPLICATE_MACRO_ATTRIBUTES,
4243
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
4344
ELIDED_LIFETIMES_IN_PATHS,
@@ -1627,6 +1628,42 @@ declare_lint! {
16271628
"detect mut variables which don't need to be mutable"
16281629
}
16291630

1631+
declare_lint! {
1632+
/// The `dereferencing_mut_binding` lint detects a `mut x` pattern that resets the binding mode,
1633+
/// as this behavior will change in rust 2024.
1634+
///
1635+
/// ### Example
1636+
///
1637+
/// ```rust
1638+
/// # #![warn(dereferencing_mut_binding)]
1639+
/// let x = Some(123u32);
1640+
/// let _y = match &x {
1641+
/// Some(mut x) => {
1642+
/// x += 1;
1643+
/// x
1644+
/// }
1645+
/// None => 0,
1646+
/// };
1647+
/// ```
1648+
///
1649+
/// {{produces}}
1650+
///
1651+
/// ### Explanation
1652+
///
1653+
/// Without the `mut`, `x` would have type `&u32`. Pre-2024, adding `mut` makes `x` have type
1654+
/// `u32`, which was deemed surprising. After edition 2024, adding `mut` will not change the
1655+
/// type of `x`. This lint warns users of editions before 2024 to update their code.
1656+
pub DEREFERENCING_MUT_BINDING,
1657+
Allow,
1658+
"detects `mut x` bindings that change the type of `x`",
1659+
@feature_gate = sym::mut_preserve_binding_mode_2024;
1660+
// FIXME uncomment below upon stabilization
1661+
/*@future_incompatible = FutureIncompatibleInfo {
1662+
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
1663+
reference: "123076",
1664+
};*/
1665+
}
1666+
16301667
declare_lint! {
16311668
/// The `unconditional_recursion` lint detects functions that cannot
16321669
/// return without calling themselves.

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
13731373
opt::flag_s("h", "help", "Display this message"),
13741374
opt::multi_s("", "cfg", "Configure the compilation environment.
13751375
SPEC supports the syntax `NAME[=\"VALUE\"]`.", "SPEC"),
1376-
opt::multi("", "check-cfg", "Provide list of valid cfg options for checking", "SPEC"),
1376+
opt::multi_s("", "check-cfg", "Provide list of expected cfgs for checking", "SPEC"),
13771377
opt::multi_s(
13781378
"L",
13791379
"",

compiler/rustc_session/src/config/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl CheckCfg {
257257
// `tests/ui/check-cfg/well-known-values.rs` (in order to test the
258258
// expected values of the new config) and bless the all directory.
259259
//
260-
// Don't forget to update `src/doc/unstable-book/src/compiler-flags/check-cfg.md`
260+
// Don't forget to update `src/doc/rustc/src/check-cfg.md`
261261
// in the unstable book as well!
262262

263263
ins!(sym::debug_assertions, no_values);

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ symbols! {
11941194
multiple_supertrait_upcastable,
11951195
must_not_suspend,
11961196
must_use,
1197+
mut_preserve_binding_mode_2024,
11971198
mut_ref,
11981199
naked,
11991200
naked_functions,

src/bootstrap/src/bin/main.rs

-4
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ fn main() {
131131
fn check_version(config: &Config) -> Option<String> {
132132
let mut msg = String::new();
133133

134-
if config.changelog_seen.is_some() {
135-
msg.push_str("WARNING: The use of `changelog-seen` is deprecated. Please refer to `change-id` option in `config.example.toml` instead.\n");
136-
}
137-
138134
let latest_change_id = CONFIG_CHANGE_HISTORY.last().unwrap().change_id;
139135
let warned_id_path = config.out.join("bootstrap").join(".last-warned-change-id");
140136

src/bootstrap/src/core/build_steps/llvm.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ pub fn prebuilt_llvm_config(
7676
builder: &Builder<'_>,
7777
target: TargetSelection,
7878
) -> Result<LlvmResult, Meta> {
79+
// If we have llvm submodule initialized already, sync it.
80+
builder.update_existing_submodule(&Path::new("src").join("llvm-project"));
81+
7982
builder.config.maybe_download_ci_llvm();
8083

8184
// If we're using a custom LLVM bail out here, but we can only use a
@@ -94,6 +97,9 @@ pub fn prebuilt_llvm_config(
9497
}
9598
}
9699

100+
// Initialize the llvm submodule if not initialized already.
101+
builder.update_submodule(&Path::new("src").join("llvm-project"));
102+
97103
let root = "src/llvm-project/llvm";
98104
let out_dir = builder.llvm_out(target);
99105

@@ -280,7 +286,6 @@ impl Step for Llvm {
280286
Err(m) => m,
281287
};
282288

283-
builder.update_submodule(&Path::new("src").join("llvm-project"));
284289
if builder.llvm_link_shared() && target.is_windows() {
285290
panic!("shared linking to LLVM is not currently supported on {}", target.triple);
286291
}

src/bootstrap/src/core/config/config.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ impl LldMode {
145145
/// `config.example.toml`.
146146
#[derive(Default, Clone)]
147147
pub struct Config {
148-
pub changelog_seen: Option<usize>, // FIXME: Deprecated field. Remove it at 2024.
149148
pub change_id: Option<usize>,
150149
pub bypass_bootstrap_lock: bool,
151150
pub ccache: Option<String>,
@@ -605,7 +604,6 @@ impl Target {
605604
#[derive(Deserialize, Default)]
606605
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
607606
pub(crate) struct TomlConfig {
608-
changelog_seen: Option<usize>, // FIXME: Deprecated field. Remove it at 2024.
609607
#[serde(flatten)]
610608
change_id: ChangeIdWrapper,
611609
build: Option<Build>,
@@ -645,17 +643,7 @@ trait Merge {
645643
impl Merge for TomlConfig {
646644
fn merge(
647645
&mut self,
648-
TomlConfig {
649-
build,
650-
install,
651-
llvm,
652-
rust,
653-
dist,
654-
target,
655-
profile: _,
656-
changelog_seen,
657-
change_id,
658-
}: Self,
646+
TomlConfig { build, install, llvm, rust, dist, target, profile: _, change_id }: Self,
659647
replace: ReplaceOpt,
660648
) {
661649
fn do_merge<T: Merge>(x: &mut Option<T>, y: Option<T>, replace: ReplaceOpt) {
@@ -667,7 +655,6 @@ impl Merge for TomlConfig {
667655
}
668656
}
669657
}
670-
self.changelog_seen.merge(changelog_seen, replace);
671658
self.change_id.inner.merge(change_id.inner, replace);
672659
do_merge(&mut self.build, build, replace);
673660
do_merge(&mut self.install, install, replace);
@@ -1400,7 +1387,6 @@ impl Config {
14001387
}
14011388
toml.merge(override_toml, ReplaceOpt::Override);
14021389

1403-
config.changelog_seen = toml.changelog_seen;
14041390
config.change_id = toml.change_id.inner;
14051391

14061392
let Build {

src/bootstrap/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,18 @@ impl Build {
630630
}
631631
}
632632

633+
/// Updates the given submodule only if it's initialized already; nothing happens otherwise.
634+
pub fn update_existing_submodule(&self, submodule: &Path) {
635+
// Avoid running git when there isn't a git checkout.
636+
if !self.config.submodules(self.rust_info()) {
637+
return;
638+
}
639+
640+
if GitInfo::new(false, submodule).is_managed_git_subrepository() {
641+
self.update_submodule(submodule);
642+
}
643+
}
644+
633645
/// Executes the entire build, as configured by the flags and configuration.
634646
pub fn build(&mut self) {
635647
unsafe {

src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
170170
severity: ChangeSeverity::Warning,
171171
summary: "`rust.split-debuginfo` has been moved to `target.<triple>.split-debuginfo` and its default value is determined for each target individually.",
172172
},
173+
ChangeInfo {
174+
change_id: 123711,
175+
severity: ChangeSeverity::Warning,
176+
summary: "The deprecated field `changelog-seen` has been removed. Using that field in `config.toml` from now on will result in breakage.",
177+
},
173178
];

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
- [Profile-guided Optimization](profile-guided-optimization.md)
7878
- [Instrumentation-based Code Coverage](instrument-coverage.md)
7979
- [Linker-plugin-based LTO](linker-plugin-lto.md)
80+
- [Checking conditional configurations](check-cfg.md)
8081
- [Exploit Mitigations](exploit-mitigations.md)
8182
- [Symbol Mangling](symbol-mangling/index.md)
8283
- [v0 Symbol Format](symbol-mangling/v0.md)

src/doc/unstable-book/src/compiler-flags/check-cfg.md src/doc/rustc/src/check-cfg.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
# `check-cfg`
2-
3-
The tracking issue for this feature is: [#82450](https://github.com/rust-lang/rust/issues/82450).
4-
5-
------------------------
6-
7-
This feature enables checking of conditional configuration.
1+
# Checking conditional configurations
82

93
`rustc` accepts the `--check-cfg` option, which specifies whether to check conditions and how to
104
check them. The `--check-cfg` option takes a value, called the _check cfg specification_.

src/doc/rustc/src/command-line-arguments.md

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ The value can either be a single identifier or two identifiers separated by `=`.
1818
For examples, `--cfg 'verbose'` or `--cfg 'feature="serde"'`. These correspond
1919
to `#[cfg(verbose)]` and `#[cfg(feature = "serde")]` respectively.
2020

21+
<a id="option-check-cfg"></a>
22+
## `--check-cfg`: enables checking conditional configurations
23+
24+
This flag will enable checking conditional configurations.
25+
Refer to the [Checking conditional configurations](check-cfg.md) of this book
26+
for further details and explanation.
27+
28+
For examples, `--check-cfg 'cfg(verbose)'` or `--check-cfg 'cfg(feature, values("serde"))'`.
29+
These correspond to `#[cfg(verbose)]` and `#[cfg(feature = "serde")]` respectively.
30+
2131
<a id="option-l-search-path"></a>
2232
## `-L`: add a directory to the library search path
2333

0 commit comments

Comments
 (0)