Use ident.span instead of def_span in dead-code pass
Hello! First time contributor! :)
This should fix#58729.
According to @estebank in the duplicate #63064, def_span scans forward on the line until it finds a {,
and if it can't find one, falls back to the span for the whole item. This
was apparently written before the identifier span was explicitly tracked on
each node.
This means that if an unused function signature spans multiple lines, the
entire function (potentially hundreds of lines) gets flagged as dead code.
This could, for example, cause IDEs to add error squiggly's to the whole
function.
By using the span from the ident instead, we narrow the scope of this in
most cases. In a wider sense, it's probably safe to use ident.span
instead of def_span in most locations throughout the whole code base,
but since this is my first contribution, I kept it small.
Some interesting points that came up while I was working on this:
- I reorganized the tests a bit to bring some of the dead code ones all
into the same location
- A few tests were for things unrelated to dead code (like the
path-lookahead for parens), so I added #![allow(dead_code)] and
cleaned up the stderr file to reduce noise in the future
- The same fix doesn't apply to const and static declarations. I tried
adding these cases to the match expression, but that created a much
wider change to tests and error messages, so I left it off until I
could get some code review to validate the approach.
Rollup of 9 pull requests
Successful merges:
- #65776 (Rename `LocalInternedString` and more)
- #65973 (caller_location: point to macro invocation sites, like file!/line!, and use in core::panic!.)
- #66015 (librustc_lexer: Refactor the module)
- #66062 (Configure LLVM module PIC level)
- #66086 (bump smallvec to 1.0)
- #66092 (Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.)
- #66103 (Add target thumbv7neon-unknown-linux-musleabihf)
- #66133 (Update the bundled `wasi-libc` repository)
- #66139 (use American spelling for `pluralize!`)
Failed merges:
r? @ghost
Update the bundled `wasi-libc` repository
This updates the libc that the `wasm32-wasi` target links against to the
latest revision, mostly just bringing in minor bug fixes and minor wasm
size improvements.
Add target thumbv7neon-unknown-linux-musleabihf
This is a copy of thumbv7neon-unknown-linux-gnueabihf with musl changes
merged from armv7-unknown-linux-musleabihf. This appears to have been
missed when adding the other ARMv7-A thumb targets.
Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.
This system call is present on all supported NetBSD versions and provides an endless stream of non-blocking random data from the kernel's ChaCha20-based CSPRNG. It doesn't require a file like `/dev/urandom` to be opened.
The system call is documented here (under kern.arandom):
https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7+NetBSD-7.0
And defined here:
https://nxr.netbsd.org/xref/src/sys/sys/sysctl.h#273
The semantics are the same as FreeBSD so reading 256 bytes per call is fine.
Similar change for getrandom crate: rust-random/getrandom#115
Configure LLVM module PIC level
As of LLVM 9, this is required for 32-bit PowerPC to properly generate
PLT references. Previously, only BigPIC was supported; now LLVM supports
both BigPIC and SmallPIC, and there is no default value provided.
librustc_lexer: Refactor the module
This PR introduces a refactoring of the `librustc_lexer` in order to improve readability.
All the changes performed are only cosmetic and do not introduce any changes the lexer logic or performance.
Newly introduced modules `literal`, `token` and `utils` are just copy-pasted from the `lib.rs` and do not contain even cosmetic changes (I decided to do so so it'll be easier to review changes looking only on diff).
r? @petrochenkov
cc @Centril @matklad
caller_location: point to macro invocation sites, like file!/line!, and use in core::panic!.
The main change here is to `core::panic!`, trying to fix this remaining regression: https://github.com/rust-lang/rust/pull/65927#issuecomment-547625147
However, in order for `caller_location` to be usable from macros the same way `file!()`/`line!()` are, it needs to have the same behavior (of extracting the macro invocation site `Span` and using that).
Arguably we would've had to do this at some point anyway, if we want to use `#[track_caller]` to replace the `file!()`/`line!()` uses from macros, but I'm not sure the RFC mentions this at all.
r? @petrochenkov cc @anp @nnethercote
Rename `LocalInternedString` and more
This PR renames `LocalInternedString` as `SymbolStr`, removes an unnecessary `impl` from it, improves comments, and cleans up some `SymbolStr` uses.
r? @estebank
Rollup of 11 pull requests
Successful merges:
- #65892 (Remove `PartialEq` and `Eq` from the `SpecialDerives`.)
- #66014 (Show type parameter name and definition in type mismatch error messages )
- #66027 (Move has_panic_handler to query)
- #66054 (syntax: Avoid span arithmetic for delimiter tokens)
- #66068 (use silent emitter for rustdoc highlighting pass)
- #66081 (let caller of check_ptr_access_align control the error message)
- #66093 (Do not ICE with a precision flag in formatting str and no format arguments)
- #66098 (Detect `::` -> `:` typo when involving turbofish)
- #66101 (Tweak type mismatch caused by break on tail expr)
- #66106 (Fix typo in explanation of `E0080`)
- #66115 (rustc: remove "GlobalMetaData" dead code from hir::map::definitions.)
Failed merges:
r? @ghost
rustc: remove "GlobalMetaData" dead code from hir::map::definitions.
Spotted while refactoring uses of `DefIndex` and/or `LocalDefId`.
r? @michaelwoerister
Tweak type mismatch caused by break on tail expr
When `break;` has a type mismatch because the `Destination` points at a tail
expression with an obligation flowing from a return type, point at the
return type.
Fix#39968.
syntax: Avoid span arithmetic for delimiter tokens
The +/-1 logic is from the time where the whole group had a single span and the delimiter spans had to be calculated from it.
Now the delimiters have their own spans which are constructed by lexer or proc macro API and can be used directly.
If those spans are not perfect, then it should be fixed by tweaking the corresponding lexer logic rather than by trying to add or substract `1` from the span boundaries.
Fixes https://github.com/rust-lang/rust/issues/62524
r? @estebank
Move has_panic_handler to query
Moves us off of a global Once instead re-querying the lang item each time. The conditions on when we set it to true change a little (previously we'd make sure a few more lang items were `Some`) but I think they in practice don't matter, we won't compile later on if we don't have them.
Remove `PartialEq` and `Eq` from the `SpecialDerives`.
Now that PR #65519 landed, this is the follow-on work of removing `PartialEq` and `Eq` from the set of `SpecialDerives` .
The existing code (which looks like it was copied from MIPS) passes
aggregates by value in registers. This is wrong. According to the SVR4
powerpc psABI, all aggregates are passed indirectly.
See #64259 for more discussion, which addresses the ABI for the special
case of ZSTs (empty structs).
When `break;` has a type mismatch because the `Destination` points at a tail
expression with an obligation flowing from a return type, point at the
return type.
Fix#39968.
When a formatting string contains an invalid descriptor, point at it
instead of the argument:
```
error: unknown format trait `foo`
--> $DIR/ifmt-bad-arg.rs:86:17
|
LL | println!("{:foo}", 1);
| ^^^
|
= note: the only appropriate formatting traits are:
- ``, which uses the `Display` trait
- `?`, which uses the `Debug` trait
- `e`, which uses the `LowerExp` trait
- `E`, which uses the `UpperExp` trait
- `o`, which uses the `Octal` trait
- `p`, which uses the `Pointer` trait
- `b`, which uses the `Binary` trait
- `x`, which uses the `LowerHex` trait
- `X`, which uses the `UpperHex` trait
```
This updates the libc that the `wasm32-wasi` target links against to the
latest revision, mostly just bringing in minor bug fixes and minor wasm
size improvements.