```
error[E0317]: if may be missing an else clause
--> $DIR/if-without-else-as-fn-expr.rs:2:5
|
LL | fn foo(bar: usize) -> usize {
| ----- found `usize` because of this return type
LL | / if bar % 5 == 0 {
LL | | return 3;
LL | | }
| |_____^ expected (), found usize
|
= note: expected type `()`
found type `usize`
= note: `if` expressions without `else` must evaluate to `()`
```
`va_start` and `va_end` must be called to initialize/cleanup the
"spoofed" `VaList` in a Rust defined C-variadic function even if
the `VaList` is not used.
`-Z treat-err-as-bug=0` will cause `rustc` to panic after the first
error is reported. `-Z treat-err-as-bug=2` will cause `rustc` to
panic after 3 errors have been reported.
Add const generics to ty (and transitive dependencies)
Split out from #53645. This work is a collaborative effort with @yodaldevoid.
There are a number of stubs. Some I plan to leave for the next PRs (e.g. `infer` and `rustdoc`). Others I can either fix up in this PR, or as follow ups (which would avoid the time-consuming rebasing).
It was a little hard to split this up, as so much depends on ty and friends. Apologies for the large diff.
r? @eddyb
There are two moments when a BufRead object needs to empty it's internal
buffer:
- In a seek call;
- In a read call when all data in the internal buffer had been already
consumed and the output buffer has a greater or equal size than the
internal buffer.
In both cases, the buffer was not being properly emptied, but only
marked as consumed (self.pos = self.cap). That should be no problem if
the inner reader is only Read, but if it is Seek as well, then it's
possible to access the data in the buffer by using the seek_relative
method. In order to prevent this from happening, both self.pos and
self.cap should be set to 0.
Two test cases were added to detect that failure:
- test_buffered_reader_invalidated_after_read
- test_buffered_reader_invalidated_after_seek
Both tests are very similar to each other. The inner reader contains the
following data: [5, 6, 7, 0, 1, 2, 3, 4]. The buffer capacity is 3
bytes.
- First, we call fill_buffer, which loads [5, 6, 7] into the internal
buffer, and then consume those 3 bytes.
- Then we either read the 5 remaining bytes in a single read call or we
move to the end of the stream by calling seek. In both cases the
buffer should be emptied to prevent the previous data [5, 6, 7] from
being read.
- We now call seek_relative(-2) and read two bytes, which should give us
the last 2 bytes of the stream: [3, 4].
Before this commit, the the seek_relative method would consider that
we're still in the range of the internal buffer, so instead of fetching
data from the inner reader, it would return the two last bytes that were
incorrectly still in the buffer: [6, 7]. Therefore, the test would fail.
Now, when seek_relative is called the buffer is empty. So the expected
data [3, 4] is fetched from the inner reader and the test passes.
(It is possible that there is a more fundamental invariant being
violated, in terms of the `check_type_defn` code assuming that lifting
to tcx will always succeed. But I am unaware of any test input that
hits this that isn't already type-incorrect in some fashion.)