Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly handle anonymous regions appearing in return type - anon-anon conflicts #44018

Closed
gaurikholkar-zz opened this issue Aug 21, 2017 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@gaurikholkar-zz
Copy link

gaurikholkar-zz commented Aug 21, 2017

For the following example, currently E0623 is disabled right now. This is how the error message will now look like.

fn foo<'a>(&self, x: &i32) -> &i32 {
    //               -----    ---- these references must have the same lifetime
    if true { &self.field } else { x }
    //                             ^ data from `x` is returned here
}

cc @nikomatsakis

@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Aug 22, 2017
@gaurikholkar-zz
Copy link
Author

@nikomatsakis this is the output I get

  --> $DIR/ex3-both-anon-regions-return-type-is-anon.rs:17:5
   |
16 |   fn foo<'a>(&self, x: &i32) -> &i32 {
   |              -----     ---- this parameter and the return type are
                            declared with different lifetimes...
17 |     x
   |     ^ ...but data from `x` flows into `self` here

error: aborting due to previous error

How do we want this?

@gaurikholkar-zz
Copy link
Author

gaurikholkar-zz commented Aug 27, 2017

@nikomatsakis @arielb1 @estebank @GuillaumeGomez I needed some help to extract the span of the return type. I was thinking of getting it from the fndecl.output.span. Is there a better way?

@arielb1
Copy link
Contributor

arielb1 commented Aug 27, 2017

There isn't.

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Sep 29, 2017
adding E0623 for return types - both parameters are anonymous

This is a fix for rust-lang#44018
```
error[E0621]: explicit lifetime required in the type of `self`
  --> $DIR/ex3-both-anon-regions-return-type-is-anon.rs:17:5
   |
16 |   fn foo<'a>(&self, x: &i32) -> &i32 {
   |                        ----     ----
   |                        |
   |                        this parameter and the return type are
                            declared with different lifetimes...
17 |     x
   |     ^ ...but data from `x` is returned here

error: aborting due to previous error
```
It also works for the below case where we have self as anonymous

```
error[E0623]: lifetime mismatch
  --> src/test/ui/lifetime-errors/ex3-both-anon-regions-self-is-anon.rs:17:19
   |
16 |     fn foo<'a>(&self, x: &Foo) -> &Foo {
   |                          ----     ----
   |                          |
   |                          this parameter and the return type are
                            declared with different lifetimes...
17 |         if true { x } else { self }
   |                   ^ ...but data from `x` is returned here

error: aborting due to previous error
```
r? @nikomatsakis

Currently, I have enabled E0621 where return type and self are anonymous, hence WIP.
@estebank estebank closed this as completed Apr 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants