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

add missing ; to return () #156

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

kalmarek
Copy link

@kalmarek kalmarek commented Sep 23, 2024

Note that all other remaining test functions do suppress return value with an explicit semicolon. However these two don't and the following (I guess still valid?) solution

    pub fn set_title(&mut self, title: String) -> &Self {
        if title.is_empty() {
            panic!("Title cannot be empty");
        } else if title.len() > 50 {
            panic!("Title cannot be longer than 50 bytes");
        }
        self.title = title;
        return self
    }

throws an error:

   Compiling setters v0.1.0 (/home/kalmar/local/rust/100-exercises-to-learn-rust/exercises/03_ticket_v1/07_setters)
error[E0308]: mismatched types
   --> exercises/03_ticket_v1/07_setters/src/lib.rs:110:9
    |
110 | /         Ticket::new(valid_title(), valid_description(), "To-Do".into())
111 | |             .set_title(overly_long_title())
    | |___________________________________________^ expected `()`, found `&Ticket`
    |
help: consider using a semicolon here
    |
111 |             .set_title(overly_long_title());
    |                                            +
help: try adding a return type
    |
109 |     fn title_cannot_be_longer_than_fifty_chars() -> &Ticket {
    |                                                  ++++++++++

For more information about this error, try `rustc --explain E0308`.
error: could not compile `setters` (lib test) due to 1 previous error

Without these rustc complains:
```
   Compiling setters v0.1.0 (/home/kalmar/local/rust/100-exercises-to-learn-rust/exercises/03_ticket_v1/07_setters)
error[E0308]: mismatched types
   --> exercises/03_ticket_v1/07_setters/src/lib.rs:110:9
    |
110 | /         Ticket::new(valid_title(), valid_description(), "To-Do".into())
111 | |             .set_title(overly_long_title())
    | |___________________________________________^ expected `()`, found `&Ticket`
    |
help: consider using a semicolon here
    |
111 |             .set_title(overly_long_title());
    |                                            +
help: try adding a return type
    |
109 |     fn title_cannot_be_longer_than_fifty_chars() -> &Ticket {
    |                                                  ++++++++++

For more information about this error, try `rustc --explain E0308`.
error: could not compile `setters` (lib test) due to 1 previous error
```
Copy link

netlify bot commented Sep 23, 2024

Deploy Preview for taupe-lily-3539f6 ready!

Name Link
🔨 Latest commit 55896ab
🔍 Latest deploy log https://app.netlify.com/sites/taupe-lily-3539f6/deploys/66f170b59540640008be0e85
😎 Deploy Preview https://deploy-preview-156--taupe-lily-3539f6.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

Successfully merging this pull request may close these issues.

1 participant