Skip to content

Commit 80fd996

Browse files
committed
Auto merge of rust-lang#120654 - matthiaskrgr:rollup-ywlixr5, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#119481 (Clarify ambiguity in select_nth_unstable docs) - rust-lang#120384 (Use `<T, U>` for array/slice equality `impl`s) - rust-lang#120423 (update indirect structural match lints to match RFC and to show up for dependencies) - rust-lang#120458 (Document `&CStr` to `CString` conversion) - rust-lang#120558 (Stop bailing out from compilation just because there were incoherent traits) - rust-lang#120572 (Update libc to 0.2.153) - rust-lang#120641 (rustdoc: trait.impl, type.impl: sort impls to make it not depend on serialization order) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4d87c4a + 9252b87 commit 80fd996

File tree

86 files changed

+1159
-567
lines changed

Some content is hidden

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

86 files changed

+1159
-567
lines changed

Diff for: Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2169,9 +2169,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
21692169

21702170
[[package]]
21712171
name = "libc"
2172-
version = "0.2.150"
2172+
version = "0.2.153"
21732173
source = "registry+https://github.com/rust-lang/crates.io-index"
2174-
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
2174+
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
21752175
dependencies = [
21762176
"rustc-std-workspace-core",
21772177
]

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

+1-28
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::mem;
2020
use std::ops::{ControlFlow, Deref};
2121

2222
use super::ops::{self, NonConstOp, Status};
23-
use super::qualifs::{self, CustomEq, HasMutInterior, NeedsDrop, NeedsNonConstDrop};
23+
use super::qualifs::{self, HasMutInterior, NeedsDrop, NeedsNonConstDrop};
2424
use super::resolver::FlowSensitiveAnalysis;
2525
use super::{ConstCx, Qualif};
2626
use crate::const_eval::is_unstable_const_fn;
@@ -149,37 +149,10 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
149149

150150
let return_loc = ccx.body.terminator_loc(return_block);
151151

152-
let custom_eq = match ccx.const_kind() {
153-
// We don't care whether a `const fn` returns a value that is not structurally
154-
// matchable. Functions calls are opaque and always use type-based qualification, so
155-
// this value should never be used.
156-
hir::ConstContext::ConstFn => true,
157-
158-
// If we know that all values of the return type are structurally matchable, there's no
159-
// need to run dataflow.
160-
// Opaque types do not participate in const generics or pattern matching, so we can safely count them out.
161-
_ if ccx.body.return_ty().has_opaque_types()
162-
|| !CustomEq::in_any_value_of_ty(ccx, ccx.body.return_ty()) =>
163-
{
164-
false
165-
}
166-
167-
hir::ConstContext::Const { .. } | hir::ConstContext::Static(_) => {
168-
let mut cursor = FlowSensitiveAnalysis::new(CustomEq, ccx)
169-
.into_engine(ccx.tcx, ccx.body)
170-
.iterate_to_fixpoint()
171-
.into_results_cursor(ccx.body);
172-
173-
cursor.seek_after_primary_effect(return_loc);
174-
cursor.get().contains(RETURN_PLACE)
175-
}
176-
};
177-
178152
ConstQualifs {
179153
needs_drop: self.needs_drop(ccx, RETURN_PLACE, return_loc),
180154
needs_non_const_drop: self.needs_non_const_drop(ccx, RETURN_PLACE, return_loc),
181155
has_mut_interior: self.has_mut_interior(ccx, RETURN_PLACE, return_loc),
182-
custom_eq,
183156
tainted_by_errors,
184157
}
185158
}

Diff for: compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+1-31
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::mir::*;
1010
use rustc_middle::traits::BuiltinImplSource;
1111
use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty};
1212
use rustc_trait_selection::traits::{
13-
self, ImplSource, Obligation, ObligationCause, ObligationCtxt, SelectionContext,
13+
ImplSource, Obligation, ObligationCause, ObligationCtxt, SelectionContext,
1414
};
1515

1616
use super::ConstCx;
@@ -24,7 +24,6 @@ pub fn in_any_value_of_ty<'tcx>(
2424
has_mut_interior: HasMutInterior::in_any_value_of_ty(cx, ty),
2525
needs_drop: NeedsDrop::in_any_value_of_ty(cx, ty),
2626
needs_non_const_drop: NeedsNonConstDrop::in_any_value_of_ty(cx, ty),
27-
custom_eq: CustomEq::in_any_value_of_ty(cx, ty),
2827
tainted_by_errors,
2928
}
3029
}
@@ -213,35 +212,6 @@ impl Qualif for NeedsNonConstDrop {
213212
}
214213
}
215214

216-
/// A constant that cannot be used as part of a pattern in a `match` expression.
217-
pub struct CustomEq;
218-
219-
impl Qualif for CustomEq {
220-
const ANALYSIS_NAME: &'static str = "flow_custom_eq";
221-
222-
fn in_qualifs(qualifs: &ConstQualifs) -> bool {
223-
qualifs.custom_eq
224-
}
225-
226-
fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
227-
// If *any* component of a composite data type does not implement `Structural{Partial,}Eq`,
228-
// we know that at least some values of that type are not structural-match. I say "some"
229-
// because that component may be part of an enum variant (e.g.,
230-
// `Option::<NonStructuralMatchTy>::Some`), in which case some values of this type may be
231-
// structural-match (`Option::None`).
232-
traits::search_for_structural_match_violation(cx.body.span, cx.tcx, ty).is_some()
233-
}
234-
235-
fn in_adt_inherently<'tcx>(
236-
cx: &ConstCx<'_, 'tcx>,
237-
def: AdtDef<'tcx>,
238-
args: GenericArgsRef<'tcx>,
239-
) -> bool {
240-
let ty = Ty::new_adt(cx.tcx, def, args);
241-
!ty.is_structural_eq_shallow(cx.tcx)
242-
}
243-
}
244-
245215
// FIXME: Use `mir::visit::Visitor` for the `in_*` functions if/when it supports early return.
246216

247217
/// Returns `true` if this `Rvalue` contains qualif `Q`.

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,10 @@ pub(super) fn check_type_bounds<'tcx>(
19901990
impl_ty: ty::AssocItem,
19911991
impl_trait_ref: ty::TraitRef<'tcx>,
19921992
) -> Result<(), ErrorGuaranteed> {
1993+
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
1994+
// other `Foo` impls are incoherent.
1995+
tcx.ensure().coherent_trait(impl_trait_ref.def_id)?;
1996+
19931997
let param_env = tcx.param_env(impl_ty.def_id);
19941998
debug!(?param_env);
19951999

Diff for: compiler/rustc_hir_analysis/src/check/wfcheck.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,10 @@ fn check_associated_item(
10051005
enter_wf_checking_ctxt(tcx, span, item_id, |wfcx| {
10061006
let item = tcx.associated_item(item_id);
10071007

1008+
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
1009+
// other `Foo` impls are incoherent.
1010+
tcx.ensure().coherent_trait(tcx.local_parent(item_id))?;
1011+
10081012
let self_ty = match item.container {
10091013
ty::TraitContainer => tcx.types.self_param,
10101014
ty::ImplContainer => tcx.type_of(item.container_id(tcx)).instantiate_identity(),
@@ -1291,6 +1295,9 @@ fn check_impl<'tcx>(
12911295
// therefore don't need to be WF (the trait's `Self: Trait` predicate
12921296
// won't hold).
12931297
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity();
1298+
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
1299+
// other `Foo` impls are incoherent.
1300+
tcx.ensure().coherent_trait(trait_ref.def_id)?;
12941301
let trait_ref = wfcx.normalize(
12951302
ast_trait_ref.path.span,
12961303
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),

Diff for: compiler/rustc_hir_analysis/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
169169

170170
tcx.sess.time("coherence_checking", || {
171171
// Check impls constrain their parameters
172-
let mut res =
172+
let res =
173173
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_impl_wf(module));
174174

175175
for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
176-
res = res.and(tcx.ensure().coherent_trait(trait_def_id));
176+
let _ = tcx.ensure().coherent_trait(trait_def_id);
177177
}
178178
// these queries are executed for side-effects (error reporting):
179179
res.and(tcx.ensure().crate_inherent_impls(()))

Diff for: compiler/rustc_lint/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,11 @@ fn register_builtins(store: &mut LintStore) {
516516
"converted into hard error, see PR #118649 \
517517
<https://github.com/rust-lang/rust/pull/118649> for more information",
518518
);
519+
store.register_removed(
520+
"nontrivial_structural_match",
521+
"no longer needed, see RFC #3535 \
522+
<https://rust-lang.github.io/rfcs/3535-constants-in-patterns.html> for more information",
523+
);
519524
}
520525

521526
fn register_internals(store: &mut LintStore) {

Diff for: compiler/rustc_lint_defs/src/builtin.rs

+7-44
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
//! These are the built-in lints that are emitted direct in the main
44
//! compiler code, rather than using their own custom pass. Those
55
//! lints are all available in `rustc_lint::builtin`.
6+
//!
7+
//! When removing a lint, make sure to also add a call to `register_removed` in
8+
//! compiler/rustc_lint/src/lib.rs.
69
710
use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};
811
use rustc_span::edition::Edition;
@@ -67,7 +70,6 @@ declare_lint_pass! {
6770
MUST_NOT_SUSPEND,
6871
NAMED_ARGUMENTS_USED_POSITIONALLY,
6972
NON_EXHAUSTIVE_OMITTED_PATTERNS,
70-
NONTRIVIAL_STRUCTURAL_MATCH,
7173
ORDER_DEPENDENT_TRAIT_OBJECTS,
7274
OVERLAPPING_RANGE_ENDPOINTS,
7375
PATTERNS_IN_FNS_WITHOUT_BODY,
@@ -2330,8 +2332,8 @@ declare_lint! {
23302332
Warn,
23312333
"constant used in pattern contains value of non-structural-match type in a field or a variant",
23322334
@future_incompatible = FutureIncompatibleInfo {
2333-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
2334-
reference: "issue #62411 <https://github.com/rust-lang/rust/issues/62411>",
2335+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
2336+
reference: "issue #120362 <https://github.com/rust-lang/rust/issues/120362>",
23352337
};
23362338
}
23372339

@@ -2386,47 +2388,8 @@ declare_lint! {
23862388
Warn,
23872389
"pointers are not structural-match",
23882390
@future_incompatible = FutureIncompatibleInfo {
2389-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
2390-
reference: "issue #62411 <https://github.com/rust-lang/rust/issues/70861>",
2391-
};
2392-
}
2393-
2394-
declare_lint! {
2395-
/// The `nontrivial_structural_match` lint detects constants that are used in patterns,
2396-
/// whose type is not structural-match and whose initializer body actually uses values
2397-
/// that are not structural-match. So `Option<NotStructuralMatch>` is ok if the constant
2398-
/// is just `None`.
2399-
///
2400-
/// ### Example
2401-
///
2402-
/// ```rust,compile_fail
2403-
/// #![deny(nontrivial_structural_match)]
2404-
///
2405-
/// #[derive(Copy, Clone, Debug)]
2406-
/// struct NoDerive(u32);
2407-
/// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
2408-
/// impl Eq for NoDerive { }
2409-
/// fn main() {
2410-
/// const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0];
2411-
/// match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
2412-
/// }
2413-
/// ```
2414-
///
2415-
/// {{produces}}
2416-
///
2417-
/// ### Explanation
2418-
///
2419-
/// Previous versions of Rust accepted constants in patterns, even if those constants' types
2420-
/// did not have `PartialEq` derived. Thus the compiler falls back to runtime execution of
2421-
/// `PartialEq`, which can report that two constants are not equal even if they are
2422-
/// bit-equivalent.
2423-
pub NONTRIVIAL_STRUCTURAL_MATCH,
2424-
Warn,
2425-
"constant used in pattern of non-structural-match type and the constant's initializer \
2426-
expression contains values of non-structural-match types",
2427-
@future_incompatible = FutureIncompatibleInfo {
2428-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
2429-
reference: "issue #73448 <https://github.com/rust-lang/rust/issues/73448>",
2391+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
2392+
reference: "issue #120362 <https://github.com/rust-lang/rust/issues/120362>",
24302393
};
24312394
}
24322395

Diff for: compiler/rustc_middle/src/mir/query.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,14 @@ pub struct BorrowCheckResult<'tcx> {
189189

190190
/// The result of the `mir_const_qualif` query.
191191
///
192-
/// Each field (except `error_occurred`) corresponds to an implementer of the `Qualif` trait in
192+
/// Each field (except `tainted_by_errors`) corresponds to an implementer of the `Qualif` trait in
193193
/// `rustc_const_eval/src/transform/check_consts/qualifs.rs`. See that file for more information on each
194194
/// `Qualif`.
195195
#[derive(Clone, Copy, Debug, Default, TyEncodable, TyDecodable, HashStable)]
196196
pub struct ConstQualifs {
197197
pub has_mut_interior: bool,
198198
pub needs_drop: bool,
199199
pub needs_non_const_drop: bool,
200-
pub custom_eq: bool,
201200
pub tainted_by_errors: Option<ErrorGuaranteed>,
202201
}
203202

0 commit comments

Comments
 (0)