This does not update the use sites or delete the now unnecessary
SourceMapper trait, to allow git to interpret the file move as a rename
rather than a new file.
This is a bit unfortunate, but code needs to be able to fatally error
early on (in particular, syntax_pos after we move SourceMap there). It's
also a tiny bit of code, which means it's ultimately not that bad.
Move error codes
Works towards #66210.
r? @Centril
Oh btw, for the ones interested, I used this python script to get all error codes content sorted into one final file:
<details>
```python
from os import listdir
from os.path import isdir, isfile, join
def get_error_codes(error_codes, f_path):
with open(f_path) as f:
short_mode = False
lines = f.read().split("\n")
i = 0
while i < len(lines):
line = lines[i]
if not short_mode and line.startswith("E0") and line.endswith(": r##\""):
error = line
error += "\n"
i += 1
while i < len(lines):
line = lines[i]
error += line
if line.endswith("\"##,"):
break
error += "\n"
i += 1
error_codes["long"].append(error)
elif line == ';':
short_mode = True
elif short_mode is True and len(line) > 0 and line != "}":
error_codes["short"].append(line)
while i + 1 < len(lines):
line = lines[i + 1].strip()
if not line.startswith("//"):
break
parts = line.split("//")
if len(parts) < 2:
break
if parts[1].strip().startswith("E0"):
break
error_codes["short"][-1] += "\n"
error_codes["short"][-1] += lines[i + 1]
i += 1
i += 1
def loop_dirs(error_codes, cur_dir):
for entry in listdir(cur_dir):
f = join(cur_dir, entry)
if isfile(f) and entry == "error_codes.rs":
get_error_codes(error_codes, f)
elif isdir(f) and not entry.startswith("librustc_error_codes"):
loop_dirs(error_codes, f)
def get_error_code(err):
x = err.split(",")
if len(x) < 2:
return err
x = x[0]
if x.strip().startswith("//"):
x = x.split("//")[1].strip()
return x.strip()
def write_into_file(error_codes, f_path):
with open(f_path, "w") as f:
f.write("// Error messages for EXXXX errors. Each message should start and end with a\n")
f.write("// new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and\n")
f.write("// use `gq` to wrap paragraphs. Use `:set tw=0` to disable.\n\n")
f.write("syntax::register_diagnostics! {\n\n")
error_codes["long"].sort()
for i in error_codes["long"]:
f.write(i)
f.write("\n\n")
f.write(";\n")
error_codes["short"] = sorted(error_codes["short"], key=lambda err: get_error_code(err))
for i in error_codes["short"]:
f.write(i)
f.write("\n")
f.write("}\n")
error_codes = {
"long": [],
"short": []
}
loop_dirs(error_codes, "src")
write_into_file(error_codes, "src/librustc_error_codes/src/error_codes.rs")
```
</details>
And to move the error codes into their own files:
<details>
```python
import os
try:
os.mkdir("src/librustc_error_codes/error_codes")
except OSError:
print("Seems like folder already exist, moving on!")
data = ''
with open("src/librustc_error_codes/error_codes.rs") as f:
x = f.read().split('\n')
i = 0
short_part = False
while i < len(x):
line = x[i]
if short_part is False and line.startswith('E0') and line.endswith(': r##"'):
err_code = line.split(':')[0]
i += 1
content = ''
while i < len(x):
if x[i] == '"##,':
break
content += x[i]
content += '\n'
i += 1
f_path = "src/librustc_error_codes/error_codes/{}.md".format(err_code)
with open(f_path, "w") as ff:
ff.write(content)
data += '{}: include_str!("./error_codes/{}.md"),'.format(err_code, err_code)
elif short_part is False and line == ';':
short_part is True
data += ';\n'
else:
data += line
data += '\n'
i += 1
with open("src/librustc_error_codes/error_codes.rs", "w") as f:
f.write(data)
```
</details>
Rollup of 9 pull requests
Successful merges:
- #66253 (Improve errors after re rebalance coherence)
- #66264 (fix an ICE in macro's diagnostic message)
- #66349 (expand source_util macros with def-site context)
- #66351 (Tweak non-char/numeric in range pattern diagnostic)
- #66360 (Fix link to Exten in Vec::set_len)
- #66361 (parser: don't use `unreachable!()` in `fn unexpected`.)
- #66363 (Improve error message in make_tests)
- #66369 (compiletest: Obtain timestamps for common inputs only once)
- #66372 (Fix broken links in Ipv4Addr::is_benchmarking docs)
Failed merges:
r? @ghost
Fix broken links in Ipv4Addr::is_benchmarking docs
[The documentation for `Ipv4Addr::is_benchmarking`](https://doc.rust-lang.org/nightly/std/net/struct.Ipv4Addr.html#method.is_benchmarking) is correct — it has the right RFC number — but the Markdown links are broken. Looks like a copy-and-paste error and a typo.
This PR fixes the links to make them clickable.
compiletest: Obtain timestamps for common inputs only once
Obtain timestamps for common inputs (e.g., libraries in run-lib path, or
sources in `src/tool/compiletest/`) only once and reuse the result,
instead of repeating the work for each test case.
Fix link to Exten in Vec::set_len
Fixes#66354
Unrelated to this PR, I think we should stop using `../../std/MODULE` and replace it with `../MODULE` that way if you're looking at docs in `core` or `alloc` clicking at a link won't forward you to `std`.
fix an ICE in macro's diagnostic message
This has two small fixes:
1. for the left brace, we don't need `<space>{`, simply `{` is enough.
2. for the right brace, it tries to peel off one character even when the close delim is missing. Without this fix, it would crash in some cases. (as shown in the new test case)
r? @estebank
Improve errors after re rebalance coherence
Following #65247, I noticed that some error messages should be updated to reflect the changes of `re_rebalance_coherence` (also there was a [note](https://rust-lang.github.io/rfcs/2451-re-rebalancing-coherence.html#teaching-users) in the RFC about it).
First, error message `E0210` was updated to match the RFC, and I also tried to improve a little the error when the "order" of types is problematic.
For code like this:
```
#![feature(re_rebalance_coherence)] // Now stable
struct Wrap<T>(T);
impl<T> From<Wrap<T>> for T {
fn from(x: Wrap<T>) -> T {
x.0
}
}
```
The old error was:
```
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> src/lib.rs:5:6
|
5 | impl<T> From<Wrap<T>> for T {
| ^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter
```
and the new error is:
```
error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Wrap<T>`)
--> main.rs:66:6
|
66 | impl<T> From<Wrap<T>> for T {
| ^ type parameter `T` must be covered by another type when it appears before the first local type (`Wrap<T>`)
|
= note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local, and no uncovered type parameters appear before that first local type
= note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last
```
I tried to point at the uncovered `T`, but couldn't get something which was reliable (but I'll be happy to try if someone points me in the right direction).
r? @estebank
cc @nikomatsakis
Fixes#65247
Split ConstValue into two enums
Hello,
Issue #59210 appeared abandoned, so I gave it a go.
Some further cleanup and refactoring may be mandated.
I did not test beyond `x.py check`, since my home computer dies compiling librustc.
Fixes#59210
Fix ICE when documentation includes intra-doc-link
When collecting intra-doc-links we could trigger the loading of extra crates into the crate store due to name resolution finding crates referred to in documentation but not in code. This might be due to
configuration differences or simply referring to something else.
This would cause an ICE because the newly loaded crate metadata existed in a crate store associated with the rustdoc global context, but the resolver had its own crate store cloned just before the documentation processing began and as such it could try and look up crates in a store which lacked them.
In this PR, I add support for `--extern-private` to the `rustdoc` tool so that it is supported for `compiletest` to then pass the crates in; and then I fix the issue by forcing the resolver to look over all the crates before we then lower the input ready for processing into documentation.
The first commit (the `--extern-private`) could be replaced with a commit which adds support for `--extern` to `compiletest` if preferred, though I think that adding `--extern-private` to `rustdoc` is more useful anyway since it makes the CLI a little more like `rustc`'s which might help reduce surprise for someone running it by hand or in their own test code.
The PR is meant to fix#66159 though it may also fix#65840.
cc @GuillaumeGomez
Add a HIR pass to check consts for `if`, `loop`, etc.
Resolves#66125.
This PR adds a HIR pass to check for high-level control flow constructs that are forbidden in a const-context. The MIR const-checker is unable to provide good spans for these since they are lowered to control flow primitives (e.g., `Goto` and `SwitchInt`), and these often don't map back to the underlying statement as a whole. This PR is intended only to improve diagnostics once `if` and `match` become commonplace in constants (behind a feature flag). The MIR const-checker will continue to operate unchanged, and will catch anything this check might miss.
In this implementation, the HIR const-checking pass is run much earlier than the MIR one, so it will supersede any errors from the latter. I will need some mentoring if we wish to change this, since I'm not familiar with the diagnostics system. Moving this pass into the same phase as the MIR const-checker could also help keep backwards compatibility for items like `const _: () = loop { break; };`, which are currently (erroneously?) accepted by the MIR const-checker (see #62272).
r? @Centril
cc @eddyb (since they filed #62272)
This PR BREAKS CODE THAT WAS ACCEPTED ON STABLE. It's arguably a bug
that this was accepted in the first place, but here we are. See #62272
for more info.
These errors will be triggered before the MIR const-checker runs,
causing all other errors to be silenced. They are now checked in the
`const-{if,loop}` tests.
These high-level constructs get mapped to control-flow primitives by the
time the MIR const-checker runs, making it hard to get the span for the
erroneous expression.
Obtain timestamps for common inputs (e.g., libraries in run-lib path, or
sources in `src/tool/compiletest/`) only once and reuse the result,
instead of repeating the work for each test case.
No functional changes intended.