Skip to content

Commit e41e510

Browse files
authored
Rollup merge of #95085 - ouz-a:master5, r=jackh726
Return err instead of ICE Having `escaping_bound_vars` results in ICE when trying to create `ty::Binder::dummy`, to avoid it we return err like the line above. I think this requires a more sophisticated fix, I would love to investigate if mentorship is available 🤓 Fixes #95023 and #85350
2 parents e3557e2 + be566f1 commit e41e510

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

compiler/rustc_resolve/src/late/lifetimes.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-tidy-filelength
12
//! Name resolution for lifetimes.
23
//!
34
//! Name resolution for lifetimes follows *much* simpler rules than the
@@ -230,6 +231,10 @@ enum Scope<'a> {
230231
hir_id: hir::HirId,
231232

232233
s: ScopeRef<'a>,
234+
235+
/// In some cases not allowing late bounds allows us to avoid ICEs.
236+
/// This is almost ways set to true.
237+
allow_late_bound: bool,
233238
},
234239

235240
/// Lifetimes introduced by a fn are scoped to the call-site for that fn,
@@ -302,6 +307,7 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> {
302307
scope_type,
303308
hir_id,
304309
s: _,
310+
allow_late_bound,
305311
} => f
306312
.debug_struct("Binder")
307313
.field("lifetimes", lifetimes)
@@ -311,6 +317,7 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> {
311317
.field("scope_type", scope_type)
312318
.field("hir_id", hir_id)
313319
.field("s", &"..")
320+
.field("allow_late_bound", allow_late_bound)
314321
.finish(),
315322
Scope::Body { id, s: _ } => {
316323
f.debug_struct("Body").field("id", id).field("s", &"..").finish()
@@ -703,6 +710,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
703710
track_lifetime_uses: true,
704711
opaque_type_parent: false,
705712
scope_type: BinderScopeType::Normal,
713+
allow_late_bound: true,
706714
};
707715
self.with(scope, move |_old_scope, this| {
708716
intravisit::walk_fn(this, fk, fd, b, s, hir_id)
@@ -828,6 +836,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
828836
track_lifetime_uses,
829837
scope_type: BinderScopeType::Normal,
830838
s: ROOT_SCOPE,
839+
allow_late_bound: false,
831840
};
832841
self.with(scope, |old_scope, this| {
833842
this.check_lifetime_params(old_scope, &generics.params);
@@ -896,6 +905,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
896905
track_lifetime_uses: true,
897906
opaque_type_parent: false,
898907
scope_type: BinderScopeType::Normal,
908+
allow_late_bound: true,
899909
};
900910
self.with(scope, |old_scope, this| {
901911
// a bare fn has no bounds, so everything
@@ -1077,6 +1087,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
10771087
track_lifetime_uses: true,
10781088
opaque_type_parent: false,
10791089
scope_type: BinderScopeType::Normal,
1090+
allow_late_bound: false,
10801091
};
10811092
this.with(scope, |_old_scope, this| {
10821093
this.visit_generics(generics);
@@ -1097,6 +1108,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
10971108
track_lifetime_uses: true,
10981109
opaque_type_parent: false,
10991110
scope_type: BinderScopeType::Normal,
1111+
allow_late_bound: false,
11001112
};
11011113
self.with(scope, |_old_scope, this| {
11021114
let scope = Scope::TraitRefBoundary { s: this.scope };
@@ -1156,6 +1168,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
11561168
track_lifetime_uses: true,
11571169
opaque_type_parent: true,
11581170
scope_type: BinderScopeType::Normal,
1171+
allow_late_bound: false,
11591172
};
11601173
self.with(scope, |old_scope, this| {
11611174
this.check_lifetime_params(old_scope, &generics.params);
@@ -1225,6 +1238,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
12251238
track_lifetime_uses: true,
12261239
opaque_type_parent: true,
12271240
scope_type: BinderScopeType::Normal,
1241+
allow_late_bound: true,
12281242
};
12291243
self.with(scope, |old_scope, this| {
12301244
this.check_lifetime_params(old_scope, &generics.params);
@@ -1378,6 +1392,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
13781392
track_lifetime_uses: true,
13791393
opaque_type_parent: false,
13801394
scope_type: BinderScopeType::Normal,
1395+
allow_late_bound: true,
13811396
};
13821397
this.with(scope, |old_scope, this| {
13831398
this.check_lifetime_params(old_scope, &bound_generic_params);
@@ -1425,6 +1440,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
14251440
track_lifetime_uses: true,
14261441
opaque_type_parent: false,
14271442
scope_type,
1443+
allow_late_bound: true,
14281444
};
14291445
self.with(scope, |_, this| {
14301446
intravisit::walk_param_bound(this, bound);
@@ -1477,6 +1493,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
14771493
track_lifetime_uses: true,
14781494
opaque_type_parent: false,
14791495
scope_type,
1496+
allow_late_bound: true,
14801497
};
14811498
self.with(scope, |old_scope, this| {
14821499
this.check_lifetime_params(old_scope, &trait_ref.bound_generic_params);
@@ -2180,6 +2197,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
21802197
opaque_type_parent: true,
21812198
track_lifetime_uses: false,
21822199
scope_type: BinderScopeType::Normal,
2200+
allow_late_bound: true,
21832201
};
21842202
self.with(scope, move |old_scope, this| {
21852203
this.check_lifetime_params(old_scope, &generics.params);
@@ -2602,7 +2620,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26022620
let mut scope = &*self.scope;
26032621
let hir_id = loop {
26042622
match scope {
2605-
Scope::Binder { hir_id, .. } => {
2623+
Scope::Binder { hir_id, allow_late_bound: true, .. } => {
26062624
break *hir_id;
26072625
}
26082626
Scope::ObjectLifetimeDefault { ref s, .. }
@@ -2611,8 +2629,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26112629
| Scope::TraitRefBoundary { ref s, .. } => {
26122630
scope = *s;
26132631
}
2614-
Scope::Root | Scope::Body { .. } => {
2632+
Scope::Root
2633+
| Scope::Body { .. }
2634+
| Scope::Binder { allow_late_bound: false, .. } => {
26152635
// See issues #83907 and #83693. Just bail out from looking inside.
2636+
// See the issue #95023 for not allowing late bound
26162637
self.tcx.sess.delay_span_bug(
26172638
rustc_span::DUMMY_SP,
26182639
"In fn_like_elision without appropriate scope above",

src/test/ui/lifetimes/issue-95023.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct ErrorKind;
2+
struct Error(ErrorKind);
3+
impl Fn(&isize) for Error {
4+
//~^ ERROR manual implementations of `Fn` are experimental [E0183]
5+
//~^^ ERROR associated type bindings are not allowed here [E0229]
6+
fn foo<const N: usize>(&self) -> Self::B<{N}>;
7+
//~^ ERROR associated function in `impl` without body
8+
//~^^ ERROR method `foo` is not a member of trait `Fn` [E0407]
9+
//~^^^ ERROR associated type `B` not found for `Self` [E0220]
10+
}
11+
fn main() {}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: associated function in `impl` without body
2+
--> $DIR/issue-95023.rs:6:5
3+
|
4+
LL | fn foo<const N: usize>(&self) -> Self::B<{N}>;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
6+
| |
7+
| help: provide a definition for the function: `{ <body> }`
8+
9+
error[E0407]: method `foo` is not a member of trait `Fn`
10+
--> $DIR/issue-95023.rs:6:5
11+
|
12+
LL | fn foo<const N: usize>(&self) -> Self::B<{N}>;
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Fn`
14+
15+
error[E0183]: manual implementations of `Fn` are experimental
16+
--> $DIR/issue-95023.rs:3:6
17+
|
18+
LL | impl Fn(&isize) for Error {
19+
| ^^^^^^^^^^ manual implementations of `Fn` are experimental
20+
|
21+
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
22+
23+
error[E0229]: associated type bindings are not allowed here
24+
--> $DIR/issue-95023.rs:3:6
25+
|
26+
LL | impl Fn(&isize) for Error {
27+
| ^^^^^^^^^^ associated type not allowed here
28+
29+
error[E0220]: associated type `B` not found for `Self`
30+
--> $DIR/issue-95023.rs:6:44
31+
|
32+
LL | fn foo<const N: usize>(&self) -> Self::B<{N}>;
33+
| ^ associated type `B` not found
34+
35+
error: aborting due to 5 previous errors
36+
37+
Some errors have detailed explanations: E0183, E0220, E0229, E0407.
38+
For more information about an error, try `rustc --explain E0183`.

src/tools/tidy/src/ui_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::path::Path;
77

88
const ENTRY_LIMIT: usize = 1000;
99
// FIXME: The following limits should be reduced eventually.
10-
const ROOT_ENTRY_LIMIT: usize = 984;
10+
const ROOT_ENTRY_LIMIT: usize = 985;
1111
const ISSUES_ENTRY_LIMIT: usize = 2310;
1212

1313
fn check_entries(path: &Path, bad: &mut bool) {

0 commit comments

Comments
 (0)