Skip to content

'fail' exit from a constructor should be exempt from 'field is never initialized #2845

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

Closed
gwillen opened this issue Jul 8, 2012 · 3 comments

Comments

@gwillen
Copy link
Contributor

gwillen commented Jul 8, 2012

class foo {
    let x: ();
    new() {
        fail;
    }
}

This shouldn't error with 'field is never initialized'.

The real use case for this is of the form:

new() {
    res = some_operation();
    if res.is_err() {
        fail "This is a specific and helpful error message about the failure of some_operation().";
    } else {
        some_local = res.get();
    }
}

This can be worked around by initializing some_local to a placeholder value, but the type of some_local may not provide a convenient one. It can also be worked around in this specific case by not casing, and just setting some_local = res.get(), at the cost of a less useful error message.

@ghost ghost assigned catamorphism Jul 10, 2012
@catamorphism
Copy link
Contributor

Yes. Relabeling as "wrong" rather than "enhancement"... since the current behavior is wrong.

@Dretch
Copy link
Contributor

Dretch commented Sep 14, 2012

I think this can now be closed, since the inline constructor syntax no longer works, and the new struct initialization syntax does not have this problem.

@brson
Copy link
Contributor

brson commented Sep 14, 2012

Yes.

@brson brson closed this as completed Sep 14, 2012
RalfJung pushed a commit to RalfJung/rust that referenced this issue Apr 28, 2023
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
…in` (rust-lang#2845)

Adds a new workflow "Kani CI M1" that runs the regression suite on Apple
M1 runners (`macos-13-xlarge`), but only on pushes to `main`.

### Callouts
* Hasn't been tested since I don't have access to the `macos-13-xlarge`
runners in my fork.
* Added a new workflow to avoid making the "Kani CI" workflow more
complex. In particular, I first considered adding conditions to the
steps, but that would result in M1 runners being invoked only to skip
the job on PRs. Second, I tried adding a condition for the job itself,
but it's not possible to refer to `${{ os.matrix }}` at that stage.
* Similarly, I don't remove the `-xlarge` substring used for M1 runners.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants