Skip to content

Commit ebd6847

Browse files
committed
Revert "Rollup merge of #113320 - oli-obk:eval_obligation_query, r=petrochenkov,BoxyUwU"
This reverts commit 0334b64, reversing changes made to 5c7a7d9.
1 parent e571544 commit ebd6847

File tree

18 files changed

+54
-442
lines changed

18 files changed

+54
-442
lines changed

compiler/rustc_middle/src/traits/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,6 @@ pub enum SelectionError<'tcx> {
588588
/// Signaling that an error has already been emitted, to avoid
589589
/// multiple errors being shown.
590590
ErrorReporting,
591-
/// Computing an opaque type's hidden type caused an error (e.g. a cycle error).
592-
/// We can thus not know whether the hidden type implements an auto trait, so
593-
/// we should not presume anything about it.
594-
OpaqueTypeAutoTraitLeakageUnknown(DefId),
595591
}
596592

597593
#[derive(Clone, Debug, TypeVisitable, Lift)]

compiler/rustc_query_system/src/query/plumbing.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,33 @@ where
126126

127127
#[cold]
128128
#[inline(never)]
129-
fn mk_cycle<Q, Qcx>(query: Q, qcx: Qcx, cycle_error: CycleError<Qcx::DepKind>) -> Q::Value
129+
fn mk_cycle<Q, Qcx>(
130+
query: Q,
131+
qcx: Qcx,
132+
cycle_error: CycleError<Qcx::DepKind>,
133+
handler: HandleCycleError,
134+
) -> Q::Value
130135
where
131136
Q: QueryConfig<Qcx>,
132137
Qcx: QueryContext,
133138
{
134139
let error = report_cycle(qcx.dep_context().sess(), &cycle_error);
135-
handle_cycle_error(query, qcx, &cycle_error, error)
140+
handle_cycle_error(query, qcx, &cycle_error, error, handler)
136141
}
137142

138143
fn handle_cycle_error<Q, Qcx>(
139144
query: Q,
140145
qcx: Qcx,
141146
cycle_error: &CycleError<Qcx::DepKind>,
142147
mut error: DiagnosticBuilder<'_, ErrorGuaranteed>,
148+
handler: HandleCycleError,
143149
) -> Q::Value
144150
where
145151
Q: QueryConfig<Qcx>,
146152
Qcx: QueryContext,
147153
{
148154
use HandleCycleError::*;
149-
match query.handle_cycle_error() {
155+
match handler {
150156
Error => {
151157
error.emit();
152158
query.value_from_cycle_error(*qcx.dep_context(), &cycle_error.cycle)
@@ -271,7 +277,7 @@ where
271277
&qcx.current_query_job(),
272278
span,
273279
);
274-
(mk_cycle(query, qcx, error), None)
280+
(mk_cycle(query, qcx, error, query.handle_cycle_error()), None)
275281
}
276282

277283
#[inline(always)]
@@ -308,7 +314,7 @@ where
308314

309315
(v, Some(index))
310316
}
311-
Err(cycle) => (mk_cycle(query, qcx, cycle), None),
317+
Err(cycle) => (mk_cycle(query, qcx, cycle, query.handle_cycle_error()), None),
312318
}
313319
}
314320

compiler/rustc_query_system/src/values.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ pub trait Value<Tcx: DepContext, D: DepKind>: Sized {
66
}
77

88
impl<Tcx: DepContext, T, D: DepKind> Value<Tcx, D> for T {
9-
default fn from_cycle_error(tcx: Tcx, cycle: &[QueryInfo<D>]) -> T {
9+
default fn from_cycle_error(tcx: Tcx, _: &[QueryInfo<D>]) -> T {
1010
tcx.sess().abort_if_errors();
1111
// Ideally we would use `bug!` here. But bug! is only defined in rustc_middle, and it's
1212
// non-trivial to define it earlier.
13-
panic!(
14-
"<{} as Value>::from_cycle_error called without errors: {cycle:#?}",
15-
std::any::type_name::<T>()
16-
);
13+
panic!("Value::from_cycle_error called without errors");
1714
}
1815
}

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

+10-48
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_infer::infer::error_reporting::TypeErrCtxt;
2929
use rustc_infer::infer::{InferOk, TypeTrace};
3030
use rustc_middle::traits::select::OverflowError;
3131
use rustc_middle::traits::solve::Goal;
32-
use rustc_middle::traits::{DefiningAnchor, SelectionOutputTypeParameterMismatch};
32+
use rustc_middle::traits::SelectionOutputTypeParameterMismatch;
3333
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
3434
use rustc_middle::ty::error::{ExpectedFound, TypeError};
3535
use rustc_middle::ty::fold::{BottomUpFolder, TypeFolder, TypeSuperFoldable};
@@ -1151,11 +1151,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
11511151
}
11521152
}
11531153

1154-
SelectionError::OpaqueTypeAutoTraitLeakageUnknown(def_id) => self.report_opaque_type_auto_trait_leakage(
1155-
&obligation,
1156-
def_id,
1157-
),
1158-
11591154
TraitNotObjectSafe(did) => {
11601155
let violations = self.tcx.object_safety_violations(did);
11611156
report_object_safety_error(self.tcx, span, did, violations)
@@ -1174,10 +1169,16 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
11741169
}
11751170

11761171
// Already reported in the query.
1177-
SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(_)) |
1172+
SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(_)) => {
1173+
// FIXME(eddyb) remove this once `ErrorGuaranteed` becomes a proof token.
1174+
self.tcx.sess.delay_span_bug(span, "`ErrorGuaranteed` without an error");
1175+
return;
1176+
}
11781177
// Already reported.
1179-
Overflow(OverflowError::Error(_)) => return,
1180-
1178+
Overflow(OverflowError::Error(_)) => {
1179+
self.tcx.sess.delay_span_bug(span, "`OverflowError` has been reported");
1180+
return;
1181+
}
11811182
Overflow(_) => {
11821183
bug!("overflow should be handled before the `report_selection_error` path");
11831184
}
@@ -1469,12 +1470,6 @@ trait InferCtxtPrivExt<'tcx> {
14691470
terr: TypeError<'tcx>,
14701471
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
14711472

1472-
fn report_opaque_type_auto_trait_leakage(
1473-
&self,
1474-
obligation: &PredicateObligation<'tcx>,
1475-
def_id: DefId,
1476-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
1477-
14781473
fn report_type_parameter_mismatch_error(
14791474
&self,
14801475
obligation: &PredicateObligation<'tcx>,
@@ -3203,39 +3198,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
32033198
)
32043199
}
32053200

3206-
fn report_opaque_type_auto_trait_leakage(
3207-
&self,
3208-
obligation: &PredicateObligation<'tcx>,
3209-
def_id: DefId,
3210-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
3211-
let name = match self.tcx.opaque_type_origin(def_id.expect_local()) {
3212-
hir::OpaqueTyOrigin::FnReturn(_) | hir::OpaqueTyOrigin::AsyncFn(_) => {
3213-
format!("opaque type")
3214-
}
3215-
hir::OpaqueTyOrigin::TyAlias { .. } => {
3216-
format!("`{}`", self.tcx.def_path_debug_str(def_id))
3217-
}
3218-
};
3219-
let mut err = self.tcx.sess.struct_span_err(
3220-
obligation.cause.span,
3221-
format!("cannot check whether the hidden type of {name} satisfies auto traits"),
3222-
);
3223-
err.span_note(self.tcx.def_span(def_id), "opaque type is declared here");
3224-
match self.defining_use_anchor {
3225-
DefiningAnchor::Bubble | DefiningAnchor::Error => {}
3226-
DefiningAnchor::Bind(bind) => {
3227-
err.span_note(
3228-
self.tcx.def_ident_span(bind).unwrap_or_else(|| self.tcx.def_span(bind)),
3229-
"this item depends on auto traits of the hidden type, \
3230-
but may also be registering the hidden type. \
3231-
This is not supported right now. \
3232-
You can try moving the opaque type and the item that actually registers a hidden type into a new submodule".to_string(),
3233-
);
3234-
}
3235-
};
3236-
err
3237-
}
3238-
32393201
fn report_type_parameter_mismatch_error(
32403202
&self,
32413203
obligation: &PredicateObligation<'tcx>,

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
6767
}
6868

6969
AutoImplCandidate => {
70-
let data = self.confirm_auto_impl_candidate(obligation)?;
70+
let data = self.confirm_auto_impl_candidate(obligation);
7171
ImplSource::Builtin(data)
7272
}
7373

@@ -376,12 +376,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
376376
fn confirm_auto_impl_candidate(
377377
&mut self,
378378
obligation: &PolyTraitObligation<'tcx>,
379-
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
379+
) -> Vec<PredicateObligation<'tcx>> {
380380
debug!(?obligation, "confirm_auto_impl_candidate");
381381

382382
let self_ty = self.infcx.shallow_resolve(obligation.predicate.self_ty());
383-
let types = self.constituent_types_for_ty(self_ty)?;
384-
Ok(self.vtable_auto_impl(obligation, obligation.predicate.def_id(), types))
383+
let types = self.constituent_types_for_ty(self_ty);
384+
self.vtable_auto_impl(obligation, obligation.predicate.def_id(), types)
385385
}
386386

387387
/// See `confirm_auto_impl_candidate`.

compiler/rustc_trait_selection/src/traits/select/mod.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -2284,8 +2284,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
22842284
fn constituent_types_for_ty(
22852285
&self,
22862286
t: ty::Binder<'tcx, Ty<'tcx>>,
2287-
) -> Result<ty::Binder<'tcx, Vec<Ty<'tcx>>>, SelectionError<'tcx>> {
2288-
Ok(match *t.skip_binder().kind() {
2287+
) -> ty::Binder<'tcx, Vec<Ty<'tcx>>> {
2288+
match *t.skip_binder().kind() {
22892289
ty::Uint(_)
22902290
| ty::Int(_)
22912291
| ty::Bool
@@ -2349,16 +2349,12 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
23492349
}
23502350

23512351
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
2352-
let ty = self.tcx().type_of(def_id);
2353-
if ty.skip_binder().references_error() {
2354-
return Err(SelectionError::OpaqueTypeAutoTraitLeakageUnknown(def_id));
2355-
}
23562352
// We can resolve the `impl Trait` to its concrete type,
23572353
// which enforces a DAG between the functions requiring
23582354
// the auto trait bounds in question.
2359-
t.rebind(vec![ty.subst(self.tcx(), substs)])
2355+
t.rebind(vec![self.tcx().type_of(def_id).subst(self.tcx(), substs)])
23602356
}
2361-
})
2357+
}
23622358
}
23632359

23642360
fn collect_predicates_for_types(

tests/ui/generator/layout-error.rs

-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ fn main() {
2424
type F = impl Future;
2525
// Check that statics are inhabited computes they layout.
2626
static POOL: Task<F> = Task::new();
27-
//~^ ERROR: cannot check whether the hidden type of `layout_error[b009]::main::F::{opaque#0}` satisfies auto traits
2827
Task::spawn(&POOL, || cb());
2928
}

tests/ui/generator/layout-error.stderr

+1-19
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,6 @@ error[E0425]: cannot find value `Foo` in this scope
44
LL | let a = Foo;
55
| ^^^ not found in this scope
66

7-
error: cannot check whether the hidden type of `layout_error[b009]::main::F::{opaque#0}` satisfies auto traits
8-
--> $DIR/layout-error.rs:26:18
9-
|
10-
LL | static POOL: Task<F> = Task::new();
11-
| ^^^^^^^
12-
|
13-
note: opaque type is declared here
14-
--> $DIR/layout-error.rs:24:14
15-
|
16-
LL | type F = impl Future;
17-
| ^^^^^^^^^^^
18-
note: required because it appears within the type `Task<F>`
19-
--> $DIR/layout-error.rs:9:12
20-
|
21-
LL | pub struct Task<F: Future>(F);
22-
| ^^^^
23-
= note: shared static variables must have a type that implements `Sync`
24-
25-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
268

279
For more information about this error, try `rustc --explain E0425`.

tests/ui/impl-trait/auto-trait-leak.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ use std::rc::Rc;
33

44
fn send<T: Send>(_: T) {}
55

6-
fn main() {}
6+
fn main() {
7+
}
78

89
// Cycles should work as the deferred obligations are
910
// independently resolved and only require the concrete
1011
// return type, which can't depend on the obligation.
1112
fn cycle1() -> impl Clone {
1213
//~^ ERROR cycle detected
13-
//~| ERROR cycle detected
1414
send(cycle2().clone());
15-
//~^ ERROR: cannot check whether the hidden type of opaque type satisfies auto traits
1615

1716
Rc::new(Cell::new(5))
1817
}
1918

2019
fn cycle2() -> impl Clone {
2120
send(cycle1().clone());
22-
//~^ ERROR: cannot check whether the hidden type of opaque type satisfies auto traits
2321

2422
Rc::new(String::from("foo"))
2523
}

0 commit comments

Comments
 (0)