Skip to content

Commit e59f2c5

Browse files
committed
Auto merge of #124388 - compiler-errors:rollup-v17b8fm, r=compiler-errors
Rollup of 4 pull requests Successful merges: - #124076 (Stablise io_error_downcast) - #124378 (Keep the LIB env var in the compiler-builtins test) - #124379 (Remove special-casing for `SimplifiedType` for next solver) - #124381 (Renamed `DerivedObligation` to `WellFormedDeriveObligation`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3a36386 + 88eae31 commit e59f2c5

File tree

9 files changed

+34
-73
lines changed

9 files changed

+34
-73
lines changed

compiler/rustc_middle/src/traits/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,16 @@ pub enum ObligationCauseCode<'tcx> {
328328
/// `static` items must have `Sync` type.
329329
SharedStatic,
330330

331+
/// Derived obligation (i.e. theoretical `where` clause) on a built-in
332+
/// implementation like `Copy` or `Sized`.
331333
BuiltinDerivedObligation(DerivedObligationCause<'tcx>),
332334

335+
/// Derived obligation (i.e. `where` clause) on an user-provided impl
336+
/// or a trait alias.
333337
ImplDerivedObligation(Box<ImplDerivedObligationCause<'tcx>>),
334338

335-
DerivedObligation(DerivedObligationCause<'tcx>),
339+
/// Derived obligation for WF goals.
340+
WellFormedDerivedObligation(DerivedObligationCause<'tcx>),
336341

337342
FunctionArgumentObligation {
338343
/// The node of the relevant argument in the function call.
@@ -534,7 +539,7 @@ impl<'tcx> ObligationCauseCode<'tcx> {
534539
match self {
535540
FunctionArgumentObligation { parent_code, .. } => Some((parent_code, None)),
536541
BuiltinDerivedObligation(derived)
537-
| DerivedObligation(derived)
542+
| WellFormedDerivedObligation(derived)
538543
| ImplDerivedObligation(box ImplDerivedObligationCause { derived, .. }) => {
539544
Some((&derived.parent_code, Some(derived.parent_trait_pred)))
540545
}

compiler/rustc_middle/src/ty/fast_reject.rs

+5-33
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,6 @@ pub enum TreatParams {
5858
/// This also treats projections with inference variables as infer vars
5959
/// since they could be further normalized.
6060
ForLookup,
61-
/// Treat parameters as placeholders in the given environment. This is the
62-
/// correct mode for *lookup*, as during candidate selection.
63-
///
64-
/// N.B. during deep rejection, this acts identically to `ForLookup`.
65-
///
66-
/// FIXME(-Znext-solver): Remove this variant and cleanup
67-
/// the code.
68-
NextSolverLookup,
69-
}
70-
71-
/// During fast-rejection, we have the choice of treating projection types
72-
/// as either simplifiable or not, depending on whether we expect the projection
73-
/// to be normalized/rigid.
74-
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
75-
pub enum TreatProjections {
76-
/// In the old solver we don't try to normalize projections
77-
/// when looking up impls and only access them by using the
78-
/// current self type. This means that if the self type is
79-
/// a projection which could later be normalized, we must not
80-
/// treat it as rigid.
81-
ForLookup,
82-
/// We can treat projections in the self type as opaque as
83-
/// we separately look up impls for the normalized self type.
84-
NextSolverLookup,
8561
}
8662

8763
/// Tries to simplify a type by only returning the outermost injective¹ layer, if one exists.
@@ -139,21 +115,17 @@ pub fn simplify_type<'tcx>(
139115
ty::FnPtr(f) => Some(SimplifiedType::Function(f.skip_binder().inputs().len())),
140116
ty::Placeholder(..) => Some(SimplifiedType::Placeholder),
141117
ty::Param(_) => match treat_params {
142-
TreatParams::ForLookup | TreatParams::NextSolverLookup => {
143-
Some(SimplifiedType::Placeholder)
144-
}
118+
TreatParams::ForLookup => Some(SimplifiedType::Placeholder),
145119
TreatParams::AsCandidateKey => None,
146120
},
147121
ty::Alias(..) => match treat_params {
148122
// When treating `ty::Param` as a placeholder, projections also
149123
// don't unify with anything else as long as they are fully normalized.
150-
//
151-
// We will have to be careful with lazy normalization here.
152-
// FIXME(lazy_normalization): This is probably not right...
124+
// FIXME(-Znext-solver): Can remove this `if` and always simplify to `Placeholder`
125+
// when the new solver is enabled by default.
153126
TreatParams::ForLookup if !ty.has_non_region_infer() => {
154127
Some(SimplifiedType::Placeholder)
155128
}
156-
TreatParams::NextSolverLookup => Some(SimplifiedType::Placeholder),
157129
TreatParams::ForLookup | TreatParams::AsCandidateKey => None,
158130
},
159131
ty::Foreign(def_id) => Some(SimplifiedType::Foreign(def_id)),
@@ -331,7 +303,7 @@ impl DeepRejectCtxt {
331303
// Depending on the value of `treat_obligation_params`, we either
332304
// treat generic parameters like placeholders or like inference variables.
333305
ty::Param(_) => match self.treat_obligation_params {
334-
TreatParams::ForLookup | TreatParams::NextSolverLookup => false,
306+
TreatParams::ForLookup => false,
335307
TreatParams::AsCandidateKey => true,
336308
},
337309

@@ -373,7 +345,7 @@ impl DeepRejectCtxt {
373345
let k = impl_ct.kind();
374346
match obligation_ct.kind() {
375347
ty::ConstKind::Param(_) => match self.treat_obligation_params {
376-
TreatParams::ForLookup | TreatParams::NextSolverLookup => false,
348+
TreatParams::ForLookup => false,
377349
TreatParams::AsCandidateKey => true,
378350
},
379351

compiler/rustc_middle/src/ty/trait_def.rs

+4-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::traits::specialization_graph;
2-
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams, TreatProjections};
2+
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams};
33
use crate::ty::{Ident, Ty, TyCtxt};
44
use hir::def_id::LOCAL_CRATE;
55
use rustc_hir as hir;
@@ -135,21 +135,6 @@ impl<'tcx> TyCtxt<'tcx> {
135135
self,
136136
trait_def_id: DefId,
137137
self_ty: Ty<'tcx>,
138-
f: impl FnMut(DefId),
139-
) {
140-
self.for_each_relevant_impl_treating_projections(
141-
trait_def_id,
142-
self_ty,
143-
TreatProjections::ForLookup,
144-
f,
145-
)
146-
}
147-
148-
pub fn for_each_relevant_impl_treating_projections(
149-
self,
150-
trait_def_id: DefId,
151-
self_ty: Ty<'tcx>,
152-
treat_projections: TreatProjections,
153138
mut f: impl FnMut(DefId),
154139
) {
155140
// FIXME: This depends on the set of all impls for the trait. That is
@@ -163,17 +148,13 @@ impl<'tcx> TyCtxt<'tcx> {
163148
f(impl_def_id);
164149
}
165150

166-
// Note that we're using `TreatParams::ForLookup` to query `non_blanket_impls` while using
167-
// `TreatParams::AsCandidateKey` while actually adding them.
168-
let treat_params = match treat_projections {
169-
TreatProjections::NextSolverLookup => TreatParams::NextSolverLookup,
170-
TreatProjections::ForLookup => TreatParams::ForLookup,
171-
};
172151
// This way, when searching for some impl for `T: Trait`, we do not look at any impls
173152
// whose outer level is not a parameter or projection. Especially for things like
174153
// `T: Clone` this is incredibly useful as we would otherwise look at all the impls
175154
// of `Clone` for `Option<T>`, `Vec<T>`, `ConcreteType` and so on.
176-
if let Some(simp) = fast_reject::simplify_type(self, self_ty, treat_params) {
155+
// Note that we're using `TreatParams::ForLookup` to query `non_blanket_impls` while using
156+
// `TreatParams::AsCandidateKey` while actually adding them.
157+
if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::ForLookup) {
177158
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
178159
for &impl_def_id in impls {
179160
f(impl_def_id);

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::traits::solve::{
1414
CandidateSource, CanonicalResponse, Certainty, Goal, QueryResult,
1515
};
1616
use rustc_middle::traits::{BuiltinImplSource, Reveal};
17-
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, TreatProjections};
17+
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
1818
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
1919
use rustc_middle::ty::{TraitPredicate, TypeVisitableExt};
2020
use rustc_span::{ErrorGuaranteed, DUMMY_SP};
@@ -1045,6 +1045,12 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
10451045
}
10461046
}
10471047

1048+
// If we still have an alias here, it must be rigid. For opaques, it's always
1049+
// okay to consider auto traits because that'll reveal its hidden type. For
1050+
// non-opaque aliases, we will not assemble any candidates since there's no way
1051+
// to further look into its type.
1052+
ty::Alias(..) => None,
1053+
10481054
// For rigid types, any possible implementation that could apply to
10491055
// the type (even if after unification and processing nested goals
10501056
// it does not hold) will disqualify the built-in auto impl.
@@ -1072,15 +1078,11 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
10721078
| ty::CoroutineWitness(..)
10731079
| ty::Never
10741080
| ty::Tuple(_)
1075-
| ty::Adt(_, _)
1076-
// FIXME: Handling opaques here is kinda sus. Especially because we
1077-
// simplify them to SimplifiedType::Placeholder.
1078-
| ty::Alias(ty::Opaque, _) => {
1081+
| ty::Adt(_, _) => {
10791082
let mut disqualifying_impl = None;
1080-
self.tcx().for_each_relevant_impl_treating_projections(
1083+
self.tcx().for_each_relevant_impl(
10811084
goal.predicate.def_id(),
10821085
goal.predicate.self_ty(),
1083-
TreatProjections::NextSolverLookup,
10841086
|impl_def_id| {
10851087
disqualifying_impl = Some(impl_def_id);
10861088
},

compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
128128
match obligation.cause.code() {
129129
ObligationCauseCode::BuiltinDerivedObligation(..)
130130
| ObligationCauseCode::ImplDerivedObligation(..)
131-
| ObligationCauseCode::DerivedObligation(..) => {}
131+
| ObligationCauseCode::WellFormedDerivedObligation(..) => {}
132132
_ => {
133133
// this is a "direct", user-specified, rather than derived,
134134
// obligation.

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22942294

22952295
next_code = Some(&cause.derived.parent_code);
22962296
}
2297-
ObligationCauseCode::DerivedObligation(derived_obligation)
2297+
ObligationCauseCode::WellFormedDerivedObligation(derived_obligation)
22982298
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation) => {
22992299
let ty = derived_obligation.parent_trait_pred.skip_binder().self_ty();
23002300
debug!(
@@ -3423,7 +3423,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
34233423
)
34243424
});
34253425
}
3426-
ObligationCauseCode::DerivedObligation(ref data) => {
3426+
ObligationCauseCode::WellFormedDerivedObligation(ref data) => {
34273427
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
34283428
let parent_predicate = parent_trait_ref;
34293429
// #74711: avoid a stack overflow

compiler/rustc_trait_selection/src/traits/wf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
381381
if let Some(parent_trait_pred) = predicate.to_opt_poly_trait_pred() {
382382
cause = cause.derived_cause(
383383
parent_trait_pred,
384-
traits::ObligationCauseCode::DerivedObligation,
384+
traits::ObligationCauseCode::WellFormedDerivedObligation,
385385
);
386386
}
387387
extend_cause_with_original_assoc_item_obligation(tcx, item, &mut cause, predicate);

library/std/src/io/error.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,6 @@ impl Error {
869869
/// # Examples
870870
///
871871
/// ```
872-
/// #![feature(io_error_downcast)]
873-
///
874872
/// use std::fmt;
875873
/// use std::io;
876874
/// use std::error::Error;
@@ -923,7 +921,7 @@ impl Error {
923921
/// assert!(io_error.raw_os_error().is_none());
924922
/// # }
925923
/// ```
926-
#[unstable(feature = "io_error_downcast", issue = "99262")]
924+
#[stable(feature = "io_error_downcast", since = "CURRENT_RUSTC_VERSION")]
927925
pub fn downcast<E>(self) -> result::Result<E, Self>
928926
where
929927
E: error::Error + Send + Sync + 'static,

tests/run-make/compiler-builtins/rmake.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ fn main() {
6363
.env("RUSTC", rustc)
6464
.env("RUSTFLAGS", "-Copt-level=0 -Cdebug-assertions=yes")
6565
.env("CARGO_TARGET_DIR", &target_dir)
66-
.env("RUSTC_BOOTSTRAP", "1");
66+
.env("RUSTC_BOOTSTRAP", "1")
67+
// Visual Studio 2022 requires that the LIB env var be set so it can
68+
// find the Windows SDK.
69+
.env("LIB", std::env::var("LIB").unwrap_or_default());
6770
set_host_rpath(&mut cmd);
6871

6972
let status = cmd.status().unwrap();

0 commit comments

Comments
 (0)