Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Anonymous bound region BrAnon(0) in return but not args #47511

Closed

Description

@dtolnay

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.

fn f(_: X) -> X {
    unimplemented!()
}

type X<'a> = <&'a () as Trait>::Value;

trait Trait {
    type Value;
}

impl<'a> Trait for &'a () {
    type Value = ();
}

fn main() {}
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

Activity

  1. added
    I-ICE
    T-compiler
    regression-from-stable-to-stable
    C-bug
    on Jan 17, 2018
  2. eddyb commented on Jan 17, 2018

    @eddyb
    Contributor

    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).

  3. nikomatsakis commented on Jan 18, 2018

    @nikomatsakis
    Contributor

    triage: P-high

  4. topecongiro commented on Jan 20, 2018

    @topecongiro
    Contributor

    let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(&output);

    Is changing collect_referenced_late_bound_regions to collect_constrained_late_bound_regions ok?

    My understanding is that fn f<'a>(x: X<'a>) -> X<'a> is ok, whereas fn g<'a>(x: X<'a>) -> &'a X<'a> is not and rustc should produce an error.

  5. nikomatsakis commented on Jan 22, 2018

    @nikomatsakis
    Contributor

    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.

  6. nikomatsakis commented on Jan 22, 2018

    @nikomatsakis
    Contributor

    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.

  7. nikomatsakis commented on Jan 22, 2018

    @nikomatsakis
    Contributor

    Well, I opened a PR to fix the ICE, anyway.

  8. nikomatsakis commented on Jan 25, 2018

    @nikomatsakis
    Contributor

    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.

  9. 18 remaining items

  10. estebank commented on Jan 25, 2019

    @estebank
    Contributor

    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
    
  11. removed
    I-ICE
    on Dec 14, 2019
  12. Xiphoseer commented on Jan 23, 2020

    @Xiphoseer

    Is this issue the reason why in this playground, line 45 compiles but line 52 produces an error?

  13. marmeladema commented on Feb 28, 2022

    @marmeladema
    Contributor

    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

    impl ValueOperationWithGat for Box<dyn for<'e> Fn(&'e ExecutionContext<'e>) -> Value<'e>> {
        #[inline]
        // the 'e: 'e works around a compiler bug
        fn execute<'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`.
    

    Is there a path forward to fix it?

  14. added 3 commits that reference this issue on Mar 5, 2022
  15. added a commit that references this issue on Mar 5, 2022
  16. added
    S-bug-has-test
    on Mar 12, 2022
  17. added 3 commits that reference this issue on Nov 8, 2022
    254942c
    9d8ac54
    f162e3a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

C-bugP-mediumS-bug-has-testT-compilerregression-from-stable-to-stable

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions