Skip to content

forbid cast as bool + forbid surrogate chars in strings #8980

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
wants to merge 2 commits into from
Closed

forbid cast as bool + forbid surrogate chars in strings #8980

wants to merge 2 commits into from

Conversation

thestinger
Copy link
Contributor

This is currently unsound since bool is represented as i8. It will
become sound when bool is stored as i8 but always used as i1.

However, the current behaviour will always be identical to x & 1 != 0,
so there's no need for it. It's also surprising, since x != 0 is the
expected behaviour.

Closes #7311

d0a1176 r=huonw
e4a76e6 r=thestinger

@@ -2710,6 +2711,9 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
fmt!("only `u8` can be cast as `char`, not `%s`", actual)
}, t_e, None);
}
} else if ty::get(t1).sty == ty::ty_bool {
fcx.tcx().sess.span_err(expr.span,
"cannot cast as `bool`, compare with zero instead");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Cannot cast to bool"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure if to or as sounds nicer here, but I'm still leaning towards as.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, if someone feels strongly about it, they can come and change it later.

thestinger and others added 2 commits September 4, 2013 23:09
This is currently unsound since `bool` is represented as `i8`. It will
become sound when `bool` is stored as `i8` but always used as `i1`.

However, the current behaviour will always be identical to `x & 1 != 0`,
so there's no need for it. It's also surprising, since `x != 0` is the
expected behaviour.

Closes #7311
Reject codepoints \uD800 to \uDFFF which are the surrogates
(reserved/unused codepoints that are invalid to encode into UTF-8)

The surrogates is the only hole of invalid codepoints in the range from
\u0 to \u10FFFF.
bors added a commit that referenced this pull request Sep 5, 2013
This is currently unsound since `bool` is represented as `i8`. It will
become sound when `bool` is stored as `i8` but always used as `i1`.

However, the current behaviour will always be identical to `x & 1 != 0`,
so there's no need for it. It's also surprising, since `x != 0` is the
expected behaviour.

Closes #7311

d0a1176 r=huonw
e4a76e6 r=thestinger
@bors bors closed this Sep 5, 2013
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.

"as bool" does not properly convert its argument.
3 participants