You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Anonymous bound region BrAnon(0) in return but not args #47511
C-bugCategory: This is a bug.P-mediumMedium priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
Looks just like #43567. Mentioning @petrochenkov and @eddyb who were involved in that issue. The following code compiles with 1.21.0 but ICE as of 1.22.0.
error: internal compiler error: librustc_typeck/astconv.rs:1212: anonymous bound region BrAnon(0) in return but not args
--> src/main.rs:1:15
|
1 | fn f(_: X) -> X {
| ^
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.25.0-nightly (da569fa9d 2018-01-16) running on x86_64-unknown-linux-gnu
cc @nikomatsakis Looks like astconv is eagerly normalizing, but not when checking the return. fn f<'a>(x: X<'a>) -> X<'a> { x } produces a non-ICE error which is also wrong (IMO).
OK, looked a bit closer. I think the code is correct, but the span_bug was just there to catch an edge-case in the error message formation that I didn't feel like handling (and thought was impossible) -- in particular, the case where a region is anonymous and yet somehow appears only in the return type.
I thought this was impossible because the elision code (which kicks in in such a case) ought to have detected that and repored an error. For example, fn foo() -> &u32 will error out in a different way.
But I overlooked the fact that there could be a lifetime which appeared in the parameters but was not constrained by the parameters. In particular, type and lifetime inputs to an associated type are not constrained (which is of course what we have here, though the use of a type-alias kind of hides it).
So I think we basically just want to tweak the error message code in this case.
Hmm, actually, while we can simply fix the error message, I'm now second guessing if this is the right place to detect an error, or if this should be an error at all. We could certainly handle it (alternatively) by treating the anonymous lifetime as an early-bound region.
Regarding the regression, it was caused by this bug fix #33685, for which we already underwent the warning cycle etc. I'm not sure why however things were working until 1.21. Seems like a bug.
Current output no longer ICEs but is still rejected:
error[E0581]: return type references an anonymous lifetime which is not constrained by the fn input types
--> src/main.rs:1:15
|
1 | fn f(_: X) -> X {
| ^
|
= note: lifetimes appearing in an associated type are not considered constrained
implValueOperationWithGatforBox<dynfor<'e>Fn(&'eExecutionContext<'e>) -> Value<'e>>{#[inline]// the 'e: 'e works around a compiler bugfnexecute<'e:'e>(&self,ctx:ExecutionContextOf<'e,Self>) -> Value<'e>{(self)(ctx)}}
We believe it's another instance of this bug! If you just introduce the <'e> lifetime, you get this error:
error[[E0581]](https://doc.rust-lang.org/stable/error-index.html#E0581): return type references lifetime `'e`, which is not constrained by the fn input types
[--> src/main.rs:73:65
](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a050229041bd8924c1891ab4756827d7#) |
73 | fn execute<'e>(&self, ctx: ExecutionContextOf<'e, Self>) -> Value<'e> {
| ^^^^^^^^^
For more information about this error, try `rustc --explain E0581`.
C-bugCategory: This is a bug.P-mediumMedium priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
Activity
eddyb commentedon Jan 17, 2018
cc @nikomatsakis Looks like
astconvis eagerly normalizing, but not when checking the return.fn f<'a>(x: X<'a>) -> X<'a> { x }produces a non-ICE error which is also wrong (IMO).nikomatsakis commentedon Jan 18, 2018
triage: P-high
topecongiro commentedon Jan 20, 2018
rust/src/librustc_typeck/astconv.rs
Line 1207 in ab7abfc
Is changing
collect_referenced_late_bound_regionstocollect_constrained_late_bound_regionsok?My understanding is that
fn f<'a>(x: X<'a>) -> X<'a>is ok, whereasfn g<'a>(x: X<'a>) -> &'a X<'a>is not and rustc should produce an error.nikomatsakis commentedon Jan 22, 2018
OK, looked a bit closer. I think the code is correct, but the
span_bugwas just there to catch an edge-case in the error message formation that I didn't feel like handling (and thought was impossible) -- in particular, the case where a region is anonymous and yet somehow appears only in the return type.I thought this was impossible because the elision code (which kicks in in such a case) ought to have detected that and repored an error. For example,
fn foo() -> &u32will error out in a different way.But I overlooked the fact that there could be a lifetime which appeared in the parameters but was not constrained by the parameters. In particular, type and lifetime inputs to an associated type are not constrained (which is of course what we have here, though the use of a type-alias kind of hides it).
So I think we basically just want to tweak the error message code in this case.
nikomatsakis commentedon Jan 22, 2018
Hmm, actually, while we can simply fix the error message, I'm now second guessing if this is the right place to detect an error, or if this should be an error at all. We could certainly handle it (alternatively) by treating the anonymous lifetime as an early-bound region.
nikomatsakis commentedon Jan 22, 2018
Well, I opened a PR to fix the ICE, anyway.
nikomatsakis commentedon Jan 25, 2018
Regarding the regression, it was caused by this bug fix #33685, for which we already underwent the warning cycle etc. I'm not sure why however things were working until 1.21. Seems like a bug.
18 remaining items
estebank commentedon Jan 25, 2019
Current output no longer ICEs but is still rejected:
Xiphoseer commentedon Jan 23, 2020
Is this issue the reason why in this playground, line 45 compiles but line 52 produces an error?
marmeladema commentedon Feb 28, 2022
Hi!
In a discussion around lifetime-only GAT not really requiring GAT, @steffahn ended up sharing this code: https://gist.github.com/rust-play/a050229041bd8924c1891ab4756827d7#file-playground-rs-L72
We believe it's another instance of this bug! If you just introduce the
<'e>lifetime, you get this error:Is there a path forward to fix it?
Add known-bug directive to issue rust-lang#47511 test case
Rollup merge of rust-lang#94626 - marmeladema:issue-47511-known-bug, …
Rollup merge of rust-lang#94626 - marmeladema:issue-47511-known-bug, …
Auto merge of rust-lang#94634 - Dylan-DPC:rollup-8wx1yrj, r=Dylan-DPC
Rollup merge of rust-lang#100508 - BoxyUwU:make_less_things_late_boun…
Rollup merge of rust-lang#100508 - BoxyUwU:make_less_things_late_boun…
Rollup merge of rust-lang#100508 - BoxyUwU:make_less_things_late_boun…