Skip to content

Commit c0b64d9

Browse files
committed
Auto merge of rust-lang#81055 - matthewjasper:non-fatal-overflow, r=nikomatsakis
Make hitting the recursion limit in projection non-fatal This change was originally made in rust-lang#80246 to avoid future (effectively) infinite loop bugs in projections, but wundergraph relies on rustc recovering here. cc rust-lang#80953 r? `@nikomatsakis`
2 parents bf193d6 + 5db5d8f commit c0b64d9

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-13
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -736,14 +736,9 @@ fn project_type<'cx, 'tcx>(
736736

737737
if !selcx.tcx().sess.recursion_limit().value_within_limit(obligation.recursion_depth) {
738738
debug!("project: overflow!");
739-
match selcx.query_mode() {
740-
super::TraitQueryMode::Standard => {
741-
selcx.infcx().report_overflow_error(&obligation, true);
742-
}
743-
super::TraitQueryMode::Canonical => {
744-
return Err(ProjectionTyError::TraitSelectionError(SelectionError::Overflow));
745-
}
746-
}
739+
// This should really be an immediate error, but some existing code
740+
// relies on being able to recover from this.
741+
return Err(ProjectionTyError::TraitSelectionError(SelectionError::Overflow));
747742
}
748743

749744
let obligation_trait_ref = &obligation.predicate.trait_ref(selcx.tcx());

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

-4
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
291291
self.infcx.tcx
292292
}
293293

294-
pub(super) fn query_mode(&self) -> TraitQueryMode {
295-
self.query_mode
296-
}
297-
298294
///////////////////////////////////////////////////////////////////////////
299295
// Selection
300296
//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Regression test for #80953. Hitting the recursion limit in projection
2+
// is non-fatal. The above code, minimised from wundergraph shows a case
3+
// where this is relied on.
4+
5+
// check-pass
6+
7+
struct AlternateTable {}
8+
struct AlternateQuery {}
9+
10+
pub trait Query {}
11+
pub trait AsQuery {
12+
type Query;
13+
}
14+
impl<T: Query> AsQuery for T {
15+
type Query = Self;
16+
}
17+
impl AsQuery for AlternateTable {
18+
type Query = AlternateQuery;
19+
}
20+
21+
pub trait Table: AsQuery {
22+
type PrimaryKey;
23+
}
24+
impl Table for AlternateTable {
25+
type PrimaryKey = ();
26+
}
27+
28+
pub trait FilterDsl<Predicate> {
29+
type Output;
30+
}
31+
pub type Filter<Source, Predicate> = <Source as FilterDsl<Predicate>>::Output;
32+
impl<T, Predicate> FilterDsl<Predicate> for T
33+
where
34+
T: Table,
35+
T::Query: FilterDsl<Predicate>,
36+
{
37+
type Output = Filter<T::Query, Predicate>;
38+
}
39+
impl<Predicate> FilterDsl<Predicate> for AlternateQuery {
40+
type Output = &'static str;
41+
}
42+
43+
pub trait HandleDelete {
44+
type Filter;
45+
}
46+
impl<T> HandleDelete for T
47+
where
48+
T: Table,
49+
T::Query: FilterDsl<T::PrimaryKey>,
50+
Filter<T::Query, T::PrimaryKey>: ,
51+
{
52+
type Filter = Filter<T::Query, T::PrimaryKey>;
53+
}
54+
55+
fn main() {
56+
let x: <AlternateTable as HandleDelete>::Filter = "Hello, world";
57+
println!("{}", x);
58+
}

src/test/ui/issues/issue-23122-2.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
error[E0275]: overflow evaluating the requirement `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<T as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next`
1+
error[E0275]: overflow evaluating the requirement `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<T as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next: Sized`
22
--> $DIR/issue-23122-2.rs:9:5
33
|
44
LL | type Next = <GetNext<T::Next> as Next>::Next;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`issue_23122_2`)
8+
= note: required because of the requirements on the impl of `Next` for `GetNext<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<T as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next>`
89

910
error: aborting due to previous error
1011

0 commit comments

Comments
 (0)