Add error annotations in UI tests
As discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Improve.20UI.20error.20checks), this PR adds missing error annotations in UI tests.
I used this script to generate them:
<details>
```python
import os
def handle_err(line, stderr, elems, kind, i):
msg = line.split("{}: ".format(kind), 1)[1]
i += 1
try:
line_nb = int(stderr[i].split(":")[1])
except Exception:
return i
in_macro = False
note_found = False
help_found = False
elem = {"kind": kind, "msg": msg, "line": line_nb, "notes": [], "helps": []}
while i < len(stderr):
if len(stderr[i]) == 0:
break
elif stderr[i].startswith("note:"):
note_found = True # error checker doesn't like multi-note apparently.
elif stderr[i].startswith(" = note:"):
if not note_found and not help_found and "this error originates in the macro" not in stderr[i]:
elem["notes"].append(stderr[i].split(" = note:", 1)[1].strip())
note_found = True # error checker doesn't like multi-note apparently.
elif stderr[i].startswith(" = help:") or stderr[i].startswith("help:"):
help_found = True
# elif stderr[i].startswith("help:"):
# if not help_found:
# elem["helps"].append(stderr[i].split("help:", 1)[1].strip())
# help_found = True # error checker doesn't like multi-help apparently.
elif "in this macro invocation" in stderr[i]:
in_macro = True
i += 1
if not in_macro:
elems.append(elem)
return i
def show_kind(kind):
if kind == "error":
return "ERROR"
elif kind == "warning":
return "WARNING"
elif kind == "note":
return "NOTE"
return "HELP"
def generate_code_err(indent, elem, up):
content = "{}//~{} {}: {}".format(indent, up, show_kind(elem["kind"]), elem["msg"])
if up == "^":
up = "|"
for note in elem["notes"]:
content += "\n{}//~{} {}: {}".format(indent, up, show_kind("note"), note)
for help_msg in elem["helps"]:
content += "\n{}//~{} {}: {}".format(indent, up, show_kind("help"), help_msg)
return content, up
def update_content(p, content):
TO_IGNORE = [
"needless_bool/simple.rs", # https://github.com/rust-lang/rust-clippy/issues/11248
"crashes/ice-7868.rs", # Has errors but in another file.
"trivially_copy_pass_by_ref.rs", # the `N` in the stderr needs to be replaced by the number
"tests/ui/large_types_passed_by_value.rs", # the `N` in the stderr needs to be replaced by the number
]
for to_ignore in TO_IGNORE:
if p.endswith(to_ignore):
return
try:
with open(p.replace(".rs", ".stderr"), "r", encoding="utf8") as f:
stderr = f.read().split('\n')
except Exception:
return
print("Updating `{}`".format(p))
i = 0
elems = []
while i < len(stderr):
line = stderr[i]
if line.startswith("error: ") and not line.startswith("error: aborting due to"):
i = handle_err(line, stderr, elems, "error", i)
elif line.startswith("warning: ") and not line.endswith("warning emitted") and line.endswith("warnings emitted"):
i = handle_err(line, stderr, elems, "warning", i)
i += 1
elems.sort(key=lambda e: e["line"], reverse=True)
i = 0
while i < len(elems):
elem = elems[i]
indent = ""
c = 0
line = content[elem["line"] - 1]
while c < len(line) and line[c] == ' ':
indent += " "
c += 1
new_content, up = generate_code_err(indent, elem, "^")
i += 1
while i < len(elems) and elems[i]["line"] == elem["line"]:
elem = elems[i]
ret = generate_code_err(indent, elem, up)
new_content += "\n" + ret[0]
up = ret[1]
i += 1
content.insert(elem["line"], new_content)
with open(p, "w", encoding="utf8") as f:
f.write("\n".join(content))
def check_if_contains_ui_test(p):
if not p.endswith(".rs"):
return
with open(p, "r", encoding="utf8") as f:
x = f.read()
if "//~" not in x and "`@run-rustfix"` not in x and "`@aux-build"` not in x:
update_content(p, x.split("\n"))
for path, subdirs, files in os.walk("tests/ui"):
for name in files:
check_if_contains_ui_test(os.path.join(path, name))
```
</details>
Then ran `cargo uibless`.
changelog: none
Redefine the pluralize macro's arm
Redefine the unintuitive pluralize macro's arm because of the negation. The initial code starts with check if count is not 1, which is confusing and unintuitive.
The arm shoud start with checking,
- if "count" `is 1` then, append `""` (empty string) - indicate as singular
- Then check if "count" `is not 1` (more than 1), append `"s"` - indicate as plural
Before:
```rs
// This arm is abit confusing since it start with checking, if "count" is more than 1, append "s".
($x:expr) => {
if $x != 1 { "s" } else { "" }
};
```
After:
```rs
// Pluralize based on count (e.g., apples)
($x:expr) => {
if $x == 1 { "" } else { "s" }
};
```
in commit 8dd0ec6, the `GDB_ARGS` variable was split across 3 lines. However, extra quotes were added to each line, such that the shell interprets the 3 lines as space separated strings, and tries to execute the latter two lines.
This commit simply removes the extra quotes.
Coverage statements in MIR are heavily tied to internal details of the coverage
implementation that are likely to change, and are unlikely to be useful to
third-party tools for the foreseeable future.
[Two users over on zulip](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Bootstrapping.20on.20NixOS) bumped into issues where NixOS wasn't being properly detected.
I believe this was caused by the presence of `/lib` on their machines. `/lib` is not standard on NixOS but can still be created by users or scripts.
We are already checking `/etc/os-release`. The presence of `ID=nixos` in it's output should be trustworthy and we shouldn't then go on to also check for `/lib`.
Remove myself from review rotation
I'll.. still be around, just not as active as I had been. I'm not adding myself to `users_on_vacation`, because anyone should still feel free to r? me if they want a specific review from me.
Sometimes people are inspired by rustc to add size assertions to their
code and copy the macro. This is bad because it causes hard build
errors. rustc happens to be special where it makes this okay.
Reassign sparc-unknown-none-elf to tier 3
It should never have been moved to tier 2. It is a new platform and the maintainer has agreed to do tier 3 maintenance for it, not tier 2.
r? `@jonathanpallant`
Fix table issues in platform support documentation (closes#115047)
mdBook needs an empty line before and after the table block.
In addition, in the tier-3 list three targets forgot about the host column and therefore showed the notes in the host column.
Closes#115047
Add `suggestion` for some `#[deprecated]` items
Consider code:
```rust
fn main() {
let _ = ["a", "b"].connect(" ");
}
```
Currently it shows deprecated warning:
```rust
warning: use of deprecated method `std::slice::<impl [T]>::connect`: renamed to join
--> src/main.rs:2:24
|
2 | let _ = ["a", "b"].connect(" ");
| ^^^^^^^
|
= note: `#[warn(deprecated)]` on by default
```
This PR adds `suggestion` for `connect` and some other deprecated items, so the warning will be changed to this:
```rust
warning: use of deprecated method `std::slice::<impl [T]>::connect`: renamed to join
--> src/main.rs:2:24
|
2 | let _ = ["a", "b"].connect(" ");
| ^^^^^^^
|
= note: `#[warn(deprecated)]` on by default
help: replace the use of the deprecated method
|
2 | let _ = ["a", "b"].join(" ");
| ^^^^
```
As of Xcode 15 Apple's linker has become a bit more strict about the
warnings it produces. One of those new warnings requires all valid
Mach-O object files in an archive to have a LC_BUILD_VERSION load
command:
```
ld: warning: no platform load command found in 'ARCHIVE[arm64][2106](lib.rmeta)', assuming: iOS-simulator
```
This was already being done for Mac Catalyst so this change expands this
logic to include it for all Apple platforms. I filed this behavior
change as FB12546320 and was told it was the new intentional behavior.