Skip to content

Commit

Permalink
Auto merge of rust-lang#124026 - matthiaskrgr:rollup-an6s6gq, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#122632 (fetch submodule before checking llvm stamp)
 - rust-lang#123355 (Support type '/' to search)
 - rust-lang#123501 (Stabilize checking of cfgs at compile-time: `--check-cfg` option)
 - rust-lang#123535 (Match ergonomics 2024: `mut` doesn't reset binding mode)
 - rust-lang#123711 (drop `changelog-seen`)
 - rust-lang#123969 (The new solver ignores `DefineOpaqueTypes`, so switch it to `Yes`)
 - rust-lang#124007 (Miri subtree update)
 - rust-lang#124017 (Change a diagnostics-path-only `DefineOpaqueTypes` to `Yes`.)
 - rust-lang#124018 (interpret: pass MemoryKind to before_memory_deallocation)
 - rust-lang#124024 (interpret: remove outdated comment)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 16, 2024
2 parents 1dea922 + 4971d9f commit 468f115
Show file tree
Hide file tree
Showing 125 changed files with 819 additions and 423 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Expand Up @@ -3364,9 +3364,9 @@ dependencies = [

[[package]]
name = "rustc-build-sysroot"
version = "0.4.5"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26170e1d79ea32f7ccec3188dd13cfc1f18c82764a9cbc1071667c0f865a4ea"
checksum = "a9bf37423495cd3a6a9ef8c75fc4566de0d26de0ab75f36f67a426e58df5768c"
dependencies = [
"anyhow",
"rustc_version",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_const_eval/src/interpret/machine.rs
Expand Up @@ -347,8 +347,6 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
/// allocation (because a copy had to be done to adjust things), machine memory will
/// cache the result. (This relies on `AllocMap::get_or` being able to add the
/// owned allocation to the map even when the map is shared.)
///
/// This must only fail if `alloc` contains provenance.
fn adjust_allocation<'b>(
ecx: &InterpCx<'mir, 'tcx, Self>,
id: AllocId,
Expand Down Expand Up @@ -427,6 +425,7 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
_prov: (AllocId, Self::ProvenanceExtra),
_size: Size,
_align: Align,
_kind: MemoryKind<Self::MemoryKind>,
) -> InterpResult<'tcx> {
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/memory.rs
Expand Up @@ -227,7 +227,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.allocate_raw_ptr(alloc, kind)
}

/// This can fail only if `alloc` contains provenance.
pub fn allocate_raw_ptr(
&mut self,
alloc: Allocation,
Expand Down Expand Up @@ -355,6 +354,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
(alloc_id, prov),
size,
alloc.align,
kind,
)?;

// Don't forget to remember size and align of this now-dead allocation
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Expand Up @@ -533,6 +533,8 @@ declare_features! (
(unstable, more_qualified_paths, "1.54.0", Some(86935)),
/// Allows the `#[must_not_suspend]` attribute.
(unstable, must_not_suspend, "1.57.0", Some(83310)),
/// Make `mut` not reset the binding mode on edition >= 2024.
(incomplete, mut_preserve_binding_mode_2024, "CURRENT_RUSTC_VERSION", Some(123076)),
/// Allows `mut ref` and `mut ref mut` identifier patterns.
(incomplete, mut_ref, "CURRENT_RUSTC_VERSION", Some(123076)),
/// Allows using `#[naked]` on functions.
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_typeck/messages.ftl
Expand Up @@ -46,6 +46,10 @@ hir_typeck_ctor_is_private = tuple struct constructor `{$def}` is private
hir_typeck_deref_is_empty = this expression `Deref`s to `{$deref_ty}` which implements `is_empty`
hir_typeck_dereferencing_mut_binding = dereferencing `mut` binding
.label = `mut` dereferences the type of this binding
.help = this will change in edition 2024
hir_typeck_expected_default_return_type = expected `()` because of default return type
hir_typeck_expected_return_type = expected `{$expected}` because of return type
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_hir_typeck/src/errors.rs
Expand Up @@ -632,3 +632,11 @@ pub enum SuggestBoxingForReturnImplTrait {
ends: Vec<Span>,
},
}

#[derive(LintDiagnostic)]
#[diag(hir_typeck_dereferencing_mut_binding)]
pub struct DereferencingMutBinding {
#[label]
#[help]
pub span: Span,
}
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Expand Up @@ -1696,7 +1696,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
if let ProbeResult::Match = result
&& self
.at(&ObligationCause::dummy(), self.param_env)
.sup(DefineOpaqueTypes::No, return_ty, xform_ret_ty)
.sup(DefineOpaqueTypes::Yes, return_ty, xform_ret_ty)
.is_err()
{
result = ProbeResult::BadReturnType;
Expand Down
23 changes: 19 additions & 4 deletions compiler/rustc_hir_typeck/src/pat.rs
Expand Up @@ -10,6 +10,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator;
use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Mutability, Pat, PatKind};
use rustc_infer::infer;
use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_lint as lint;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::{self, Adt, Ty, TypeVisitableExt};
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
Expand Down Expand Up @@ -629,12 +630,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Ty<'tcx>,
pat_info: PatInfo<'tcx, '_>,
) -> Ty<'tcx> {
let PatInfo { binding_mode: def_bm, top_info: ti, .. } = pat_info;
let PatInfo { binding_mode: BindingAnnotation(def_br, _), top_info: ti, .. } = pat_info;

// Determine the binding mode...
let bm = match ba {
BindingAnnotation(ByRef::No, Mutability::Not) => def_bm,
_ => ba,
BindingAnnotation(ByRef::No, Mutability::Mut)
if !(pat.span.at_least_rust_2024()
&& self.tcx.features().mut_preserve_binding_mode_2024)
&& matches!(def_br, ByRef::Yes(_)) =>
{
// `mut x` resets the binding mode in edition <= 2021.
self.tcx.emit_node_span_lint(
lint::builtin::DEREFERENCING_MUT_BINDING,
pat.hir_id,
pat.span,
errors::DereferencingMutBinding { span: pat.span },
);
BindingAnnotation(ByRef::No, Mutability::Mut)
}
BindingAnnotation(ByRef::No, mutbl) => BindingAnnotation(def_br, mutbl),
BindingAnnotation(ByRef::Yes(_), _) => ba,
};
// ...and store it in a side table:
self.typeck_results.borrow_mut().pat_binding_modes_mut().insert(pat.hir_id, bm);
Expand Down Expand Up @@ -743,7 +758,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

// Precondition: pat is a Ref(_) pattern
/// Precondition: pat is a `Ref(_)` pattern
fn borrow_pat_suggestion(&self, err: &mut Diag<'_>, pat: &Pat<'_>) {
let tcx = self.tcx;
if let PatKind::Ref(inner, mutbl) = pat.kind
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/at.rs
Expand Up @@ -282,7 +282,7 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
{
let Trace { at, trace } = self;
debug_assert!(at.infcx.next_trait_solver());
let mut fields = at.infcx.combine_fields(trace, at.param_env, DefineOpaqueTypes::No);
let mut fields = at.infcx.combine_fields(trace, at.param_env, DefineOpaqueTypes::Yes);
fields
.equate(StructurallyRelateAliases::Yes)
.relate(a, b)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/context/diagnostics/check_cfg.rs
Expand Up @@ -168,7 +168,7 @@ pub(super) fn unexpected_cfg_name(
diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration");
} else {
diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration");
}
}

Expand Down Expand Up @@ -272,6 +272,6 @@ pub(super) fn unexpected_cfg_value(
if !is_cfg_a_well_know_name {
diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
}
diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration");
}
}
37 changes: 37 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Expand Up @@ -38,6 +38,7 @@ declare_lint_pass! {
DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
DEPRECATED_IN_FUTURE,
DEPRECATED_WHERE_CLAUSE_LOCATION,
DEREFERENCING_MUT_BINDING,
DUPLICATE_MACRO_ATTRIBUTES,
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
ELIDED_LIFETIMES_IN_PATHS,
Expand Down Expand Up @@ -1627,6 +1628,42 @@ declare_lint! {
"detect mut variables which don't need to be mutable"
}

declare_lint! {
/// The `dereferencing_mut_binding` lint detects a `mut x` pattern that resets the binding mode,
/// as this behavior will change in rust 2024.
///
/// ### Example
///
/// ```rust
/// # #![warn(dereferencing_mut_binding)]
/// let x = Some(123u32);
/// let _y = match &x {
/// Some(mut x) => {
/// x += 1;
/// x
/// }
/// None => 0,
/// };
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Without the `mut`, `x` would have type `&u32`. Pre-2024, adding `mut` makes `x` have type
/// `u32`, which was deemed surprising. After edition 2024, adding `mut` will not change the
/// type of `x`. This lint warns users of editions before 2024 to update their code.
pub DEREFERENCING_MUT_BINDING,
Allow,
"detects `mut x` bindings that change the type of `x`",
@feature_gate = sym::mut_preserve_binding_mode_2024;
// FIXME uncomment below upon stabilization
/*@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
reference: "123076",
};*/
}

declare_lint! {
/// The `unconditional_recursion` lint detects functions that cannot
/// return without calling themselves.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Expand Up @@ -1373,7 +1373,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
opt::flag_s("h", "help", "Display this message"),
opt::multi_s("", "cfg", "Configure the compilation environment.
SPEC supports the syntax `NAME[=\"VALUE\"]`.", "SPEC"),
opt::multi("", "check-cfg", "Provide list of valid cfg options for checking", "SPEC"),
opt::multi_s("", "check-cfg", "Provide list of expected cfgs for checking", "SPEC"),
opt::multi_s(
"L",
"",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config/cfg.rs
Expand Up @@ -257,7 +257,7 @@ impl CheckCfg {
// `tests/ui/check-cfg/well-known-values.rs` (in order to test the
// expected values of the new config) and bless the all directory.
//
// Don't forget to update `src/doc/unstable-book/src/compiler-flags/check-cfg.md`
// Don't forget to update `src/doc/rustc/src/check-cfg.md`
// in the unstable book as well!

ins!(sym::debug_assertions, no_values);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Expand Up @@ -1194,6 +1194,7 @@ symbols! {
multiple_supertrait_upcastable,
must_not_suspend,
must_use,
mut_preserve_binding_mode_2024,
mut_ref,
naked,
naked_functions,
Expand Down
4 changes: 0 additions & 4 deletions src/bootstrap/src/bin/main.rs
Expand Up @@ -131,10 +131,6 @@ fn main() {
fn check_version(config: &Config) -> Option<String> {
let mut msg = String::new();

if config.changelog_seen.is_some() {
msg.push_str("WARNING: The use of `changelog-seen` is deprecated. Please refer to `change-id` option in `config.example.toml` instead.\n");
}

let latest_change_id = CONFIG_CHANGE_HISTORY.last().unwrap().change_id;
let warned_id_path = config.out.join("bootstrap").join(".last-warned-change-id");

Expand Down
7 changes: 6 additions & 1 deletion src/bootstrap/src/core/build_steps/llvm.rs
Expand Up @@ -76,6 +76,9 @@ pub fn prebuilt_llvm_config(
builder: &Builder<'_>,
target: TargetSelection,
) -> Result<LlvmResult, Meta> {
// If we have llvm submodule initialized already, sync it.
builder.update_existing_submodule(&Path::new("src").join("llvm-project"));

builder.config.maybe_download_ci_llvm();

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

// Initialize the llvm submodule if not initialized already.
builder.update_submodule(&Path::new("src").join("llvm-project"));

let root = "src/llvm-project/llvm";
let out_dir = builder.llvm_out(target);

Expand Down Expand Up @@ -280,7 +286,6 @@ impl Step for Llvm {
Err(m) => m,
};

builder.update_submodule(&Path::new("src").join("llvm-project"));
if builder.llvm_link_shared() && target.is_windows() {
panic!("shared linking to LLVM is not currently supported on {}", target.triple);
}
Expand Down
16 changes: 1 addition & 15 deletions src/bootstrap/src/core/config/config.rs
Expand Up @@ -145,7 +145,6 @@ impl LldMode {
/// `config.example.toml`.
#[derive(Default, Clone)]
pub struct Config {
pub changelog_seen: Option<usize>, // FIXME: Deprecated field. Remove it at 2024.
pub change_id: Option<usize>,
pub bypass_bootstrap_lock: bool,
pub ccache: Option<String>,
Expand Down Expand Up @@ -605,7 +604,6 @@ impl Target {
#[derive(Deserialize, Default)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub(crate) struct TomlConfig {
changelog_seen: Option<usize>, // FIXME: Deprecated field. Remove it at 2024.
#[serde(flatten)]
change_id: ChangeIdWrapper,
build: Option<Build>,
Expand Down Expand Up @@ -645,17 +643,7 @@ trait Merge {
impl Merge for TomlConfig {
fn merge(
&mut self,
TomlConfig {
build,
install,
llvm,
rust,
dist,
target,
profile: _,
changelog_seen,
change_id,
}: Self,
TomlConfig { build, install, llvm, rust, dist, target, profile: _, change_id }: Self,
replace: ReplaceOpt,
) {
fn do_merge<T: Merge>(x: &mut Option<T>, y: Option<T>, replace: ReplaceOpt) {
Expand All @@ -667,7 +655,6 @@ impl Merge for TomlConfig {
}
}
}
self.changelog_seen.merge(changelog_seen, replace);
self.change_id.inner.merge(change_id.inner, replace);
do_merge(&mut self.build, build, replace);
do_merge(&mut self.install, install, replace);
Expand Down Expand Up @@ -1400,7 +1387,6 @@ impl Config {
}
toml.merge(override_toml, ReplaceOpt::Override);

config.changelog_seen = toml.changelog_seen;
config.change_id = toml.change_id.inner;

let Build {
Expand Down
12 changes: 12 additions & 0 deletions src/bootstrap/src/lib.rs
Expand Up @@ -630,6 +630,18 @@ impl Build {
}
}

/// Updates the given submodule only if it's initialized already; nothing happens otherwise.
pub fn update_existing_submodule(&self, submodule: &Path) {
// Avoid running git when there isn't a git checkout.
if !self.config.submodules(self.rust_info()) {
return;
}

if GitInfo::new(false, submodule).is_managed_git_subrepository() {
self.update_submodule(submodule);
}
}

/// Executes the entire build, as configured by the flags and configuration.
pub fn build(&mut self) {
unsafe {
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/change_tracker.rs
Expand Up @@ -170,4 +170,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Warning,
summary: "`rust.split-debuginfo` has been moved to `target.<triple>.split-debuginfo` and its default value is determined for each target individually.",
},
ChangeInfo {
change_id: 123711,
severity: ChangeSeverity::Warning,
summary: "The deprecated field `changelog-seen` has been removed. Using that field in `config.toml` from now on will result in breakage.",
},
];
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Expand Up @@ -77,6 +77,7 @@
- [Profile-guided Optimization](profile-guided-optimization.md)
- [Instrumentation-based Code Coverage](instrument-coverage.md)
- [Linker-plugin-based LTO](linker-plugin-lto.md)
- [Checking conditional configurations](check-cfg.md)
- [Exploit Mitigations](exploit-mitigations.md)
- [Symbol Mangling](symbol-mangling/index.md)
- [v0 Symbol Format](symbol-mangling/v0.md)
Expand Down
@@ -1,10 +1,4 @@
# `check-cfg`

The tracking issue for this feature is: [#82450](https://github.com/rust-lang/rust/issues/82450).

------------------------

This feature enables checking of conditional configuration.
# Checking conditional configurations

`rustc` accepts the `--check-cfg` option, which specifies whether to check conditions and how to
check them. The `--check-cfg` option takes a value, called the _check cfg specification_.
Expand Down
10 changes: 10 additions & 0 deletions src/doc/rustc/src/command-line-arguments.md
Expand Up @@ -18,6 +18,16 @@ The value can either be a single identifier or two identifiers separated by `=`.
For examples, `--cfg 'verbose'` or `--cfg 'feature="serde"'`. These correspond
to `#[cfg(verbose)]` and `#[cfg(feature = "serde")]` respectively.

<a id="option-check-cfg"></a>
## `--check-cfg`: enables checking conditional configurations

This flag will enable checking conditional configurations.
Refer to the [Checking conditional configurations](check-cfg.md) of this book
for further details and explanation.

For examples, `--check-cfg 'cfg(verbose)'` or `--check-cfg 'cfg(feature, values("serde"))'`.
These correspond to `#[cfg(verbose)]` and `#[cfg(feature = "serde")]` respectively.

<a id="option-l-search-path"></a>
## `-L`: add a directory to the library search path

Expand Down

0 comments on commit 468f115

Please sign in to comment.