Skip to content

Commit a84e060

Browse files
authored
Rollup merge of #107272 - compiler-errors:new-solver-more-predicates, r=lcnr
Implement ObjectSafe and WF in the new solver r? ``@lcnr``
2 parents a8b5e5d + 02b80d2 commit a84e060

File tree

3 files changed

+70
-13
lines changed

3 files changed

+70
-13
lines changed

Cargo.lock

+7-7
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ dependencies = [
351351
"cargo-test-macro",
352352
"cargo-test-support",
353353
"cargo-util",
354-
"clap 4.1.3",
354+
"clap 4.1.4",
355355
"crates-io",
356356
"curl",
357357
"curl-sys",
@@ -655,9 +655,9 @@ dependencies = [
655655

656656
[[package]]
657657
name = "clap"
658-
version = "4.1.3"
658+
version = "4.1.4"
659659
source = "registry+https://github.com/rust-lang/crates.io-index"
660-
checksum = "d8d93d855ce6a0aa87b8473ef9169482f40abaa2e9e0993024c35c902cbd5920"
660+
checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76"
661661
dependencies = [
662662
"bitflags",
663663
"clap_derive 4.1.0",
@@ -675,7 +675,7 @@ version = "4.0.7"
675675
source = "registry+https://github.com/rust-lang/crates.io-index"
676676
checksum = "10861370d2ba66b0f5989f83ebf35db6421713fd92351790e7fdd6c36774c56b"
677677
dependencies = [
678-
"clap 4.1.3",
678+
"clap 4.1.4",
679679
]
680680

681681
[[package]]
@@ -2294,7 +2294,7 @@ name = "jsondoclint"
22942294
version = "0.1.0"
22952295
dependencies = [
22962296
"anyhow",
2297-
"clap 4.1.3",
2297+
"clap 4.1.4",
22982298
"fs-err",
22992299
"rustdoc-json-types",
23002300
"serde",
@@ -2557,7 +2557,7 @@ dependencies = [
25572557
"ammonia",
25582558
"anyhow",
25592559
"chrono",
2560-
"clap 4.1.3",
2560+
"clap 4.1.4",
25612561
"clap_complete",
25622562
"elasticlunr-rs",
25632563
"env_logger 0.10.0",
@@ -3528,7 +3528,7 @@ dependencies = [
35283528
name = "rustbook"
35293529
version = "0.1.0"
35303530
dependencies = [
3531-
"clap 4.1.3",
3531+
"clap 4.1.4",
35323532
"env_logger 0.7.1",
35333533
"mdbook",
35343534
]

compiler/rustc_trait_selection/src/solve/mod.rs

+33-4
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,15 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
277277
param_env,
278278
predicate: (def_id, substs, kind),
279279
}),
280+
ty::PredicateKind::ObjectSafe(trait_def_id) => {
281+
self.compute_object_safe_goal(trait_def_id)
282+
}
283+
ty::PredicateKind::WellFormed(arg) => {
284+
self.compute_well_formed_goal(Goal { param_env, predicate: arg })
285+
}
280286
ty::PredicateKind::Ambiguous => self.make_canonical_response(Certainty::AMBIGUOUS),
281287
// FIXME: implement these predicates :)
282-
ty::PredicateKind::WellFormed(_)
283-
| ty::PredicateKind::ObjectSafe(_)
284-
| ty::PredicateKind::ConstEvaluatable(_)
285-
| ty::PredicateKind::ConstEquate(_, _) => {
288+
ty::PredicateKind::ConstEvaluatable(_) | ty::PredicateKind::ConstEquate(_, _) => {
286289
self.make_canonical_response(Certainty::Yes)
287290
}
288291
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
@@ -362,6 +365,32 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
362365
Err(NoSolution)
363366
}
364367
}
368+
369+
fn compute_object_safe_goal(&mut self, trait_def_id: DefId) -> QueryResult<'tcx> {
370+
if self.tcx().is_object_safe(trait_def_id) {
371+
self.make_canonical_response(Certainty::Yes)
372+
} else {
373+
Err(NoSolution)
374+
}
375+
}
376+
377+
fn compute_well_formed_goal(
378+
&mut self,
379+
goal: Goal<'tcx, ty::GenericArg<'tcx>>,
380+
) -> QueryResult<'tcx> {
381+
self.infcx.probe(|_| {
382+
match crate::traits::wf::unnormalized_obligations(
383+
self.infcx,
384+
goal.param_env,
385+
goal.predicate,
386+
) {
387+
Some(obligations) => self.evaluate_all_and_make_canonical_response(
388+
obligations.into_iter().map(|o| o.into()).collect(),
389+
),
390+
None => self.make_canonical_response(Certainty::AMBIGUOUS),
391+
}
392+
})
393+
}
365394
}
366395

367396
impl<'tcx> EvalCtxt<'_, 'tcx> {

compiler/rustc_trait_selection/src/traits/wf.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use rustc_hir as hir;
44
use rustc_hir::lang_items::LangItem;
55
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
66
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable};
7-
use rustc_span::def_id::{DefId, LocalDefId};
8-
use rustc_span::Span;
7+
use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
8+
use rustc_span::{Span, DUMMY_SP};
99

1010
use std::iter;
1111
/// Returns the set of obligations needed to make `arg` well-formed.
@@ -75,6 +75,34 @@ pub fn obligations<'tcx>(
7575
Some(result)
7676
}
7777

78+
/// Compute the predicates that are required for a type to be well-formed.
79+
///
80+
/// This is only intended to be used in the new solver, since it does not
81+
/// take into account recursion depth or proper error-reporting spans.
82+
pub fn unnormalized_obligations<'tcx>(
83+
infcx: &InferCtxt<'tcx>,
84+
param_env: ty::ParamEnv<'tcx>,
85+
arg: GenericArg<'tcx>,
86+
) -> Option<Vec<traits::PredicateObligation<'tcx>>> {
87+
if let ty::GenericArgKind::Lifetime(..) = arg.unpack() {
88+
return Some(vec![]);
89+
}
90+
91+
debug_assert_eq!(arg, infcx.resolve_vars_if_possible(arg));
92+
93+
let mut wf = WfPredicates {
94+
tcx: infcx.tcx,
95+
param_env,
96+
body_id: CRATE_DEF_ID,
97+
span: DUMMY_SP,
98+
out: vec![],
99+
recursion_depth: 0,
100+
item: None,
101+
};
102+
wf.compute(arg);
103+
Some(wf.out)
104+
}
105+
78106
/// Returns the obligations that make this trait reference
79107
/// well-formed. For example, if there is a trait `Set` defined like
80108
/// `trait Set<K:Eq>`, then the trait reference `Foo: Set<Bar>` is WF

0 commit comments

Comments
 (0)