about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2021-09-22Rollup merge of #89046 - oli-obk:fix_oflo, r=estebankthe8472-1/+3
"Fix" an overflow in byte position math r? `@estebank` help! I fixed the ICE only to brick the diagnostic. I mean, it was wrong previously (using an already expanded macro span), but it is really bad now XD
2021-09-20Add some more tracingOli Scherer-1/+3
2021-09-20Workaround ICE with if-let and RFC 2229Mark Rousskov-4/+2
2021-09-08Bump stage0 compiler to 1.56Mark Rousskov-1/+0
2021-08-25Use if-let guards in the codebaseLéo Lanteri Thauvin-7/+9
2021-08-23review commentsEsteban Kuber-5/+26
2021-08-23remove unnecessary `info!()` loggingEsteban Kuber-2/+1
2021-08-23Fixes to span locationsEsteban Kuber-2/+1
2021-08-23wipEsteban Kuber-1/+2
2021-08-23Account for tabs when highlighting multiline code suggestionsEsteban Kuber-6/+16
2021-08-11Modify structured suggestion outputEsteban Küber-7/+76
* On suggestions that include deletions, use a diff inspired output format * When suggesting addition, use `+` as underline * Color highlight modified span
2021-08-05Remove warnings/errors from compiler when using typeck_body in rustdoc span ↵Guillaume Gomez-1/+16
map builder
2021-07-11Simplify future incompatible reporting.Eric Huss-2/+1
2021-07-06Auto merge of #86572 - rylev:force-warnings-always, r=nikomatsakisbors-2/+31
Force warnings even when can_emit_warnings == false Fixes an issue mentioned in #85512 with --cap-lints overriding --force-warnings. Fixes https://github.com/rust-lang/rust/issues/86751 r? `@ehuss`
2021-07-06Add missing docs and remove dead codeRyan Levick-2/+10
2021-07-01New force_warn diagnostic builder and ensure cap-lints doesn't reduce ↵Ryan Levick-0/+18
force_warn level
2021-06-30Force warnings even when can_emit_warnings == falseRyan Levick-2/+5
2021-06-28Update to new bootstrap compilerMark Rousskov-1/+0
2021-06-02Miscellaneous inlining improvementsTomasz Miąsko-0/+2
2021-05-18Stabilize extended_key_value_attributesJoshua Nelson-1/+1
# Stabilization report ## Summary This stabilizes using macro expansion in key-value attributes, like so: ```rust #[doc = include_str!("my_doc.md")] struct S; #[path = concat!(env!("OUT_DIR"), "/generated.rs")] mod m; ``` See the changes to the reference for details on what macros are allowed; see Petrochenkov's excellent blog post [on internals](https://internals.rust-lang.org/t/macro-expansion-points-in-attributes/11455) for alternatives that were considered and rejected ("why accept no more and no less?") This has been available on nightly since 1.50 with no major issues. ## Notes ### Accepted syntax The parser accepts arbitrary Rust expressions in this position, but any expression other than a macro invocation will ultimately lead to an error because it is not expected by the built-in expression forms (e.g., `#[doc]`). Note that decorators and the like may be able to observe other expression forms. ### Expansion ordering Expansion of macro expressions in "inert" attributes occurs after decorators have executed, analogously to macro expressions appearing in the function body or other parts of decorator input. There is currently no way for decorators to accept macros in key-value position if macro expansion must be performed before the decorator executes (if the macro can simply be copied into the output for later expansion, that can work). ## Test cases - https://github.com/rust-lang/rust/blob/master/src/test/ui/attributes/key-value-expansion-on-mac.rs - https://github.com/rust-lang/rust/blob/master/src/test/rustdoc/external-doc.rs The feature has also been dogfooded extensively in the compiler and standard library: - https://github.com/rust-lang/rust/pull/83329 - https://github.com/rust-lang/rust/pull/83230 - https://github.com/rust-lang/rust/pull/82641 - https://github.com/rust-lang/rust/pull/80534 ## Implementation history - Initial proposal: https://github.com/rust-lang/rust/issues/55414#issuecomment-554005412 - Experiment to see how much code it would break: https://github.com/rust-lang/rust/pull/67121 - Preliminary work to restrict expansion that would conflict with this feature: https://github.com/rust-lang/rust/pull/77271 - Initial implementation: https://github.com/rust-lang/rust/pull/78837 - Fix for an ICE: https://github.com/rust-lang/rust/pull/80563 ## Unresolved Questions ~~https://github.com/rust-lang/rust/pull/83366#issuecomment-805180738 listed some concerns, but they have been resolved as of this final report.~~ ## Additional Information There are two workarounds that have a similar effect for `#[doc]` attributes on nightly. One is to emulate this behavior by using a limited version of this feature that was stabilized for historical reasons: ```rust macro_rules! forward_inner_docs { ($e:expr => $i:item) => { #[doc = $e] $i }; } forward_inner_docs!(include_str!("lib.rs") => struct S {}); ``` This also works for other attributes (like `#[path = concat!(...)]`). The other is to use `doc(include)`: ```rust #![feature(external_doc)] #[doc(include = "lib.rs")] struct S {} ``` The first works, but is non-trivial for people to discover, and difficult to read and maintain. The second is a strange special-case for a particular use of the macro. This generalizes it to work for any use case, not just including files. I plan to remove `doc(include)` when this is stabilized. The `forward_inner_docs` workaround will still compile without warnings, but I expect it to be used less once it's no longer necessary.
2021-05-12Show macro name in 'this error originates in macro' messageAaron Hill-0/+1
When there are multiple macros in use, it can be difficult to tell which one was responsible for producing an error.
2021-05-08Note why `Handler::fatal` is different from `Sesssion::fatal`Joshua Nelson-0/+1
2021-05-08Make `Diagnostic::span_fatal` unconditionally raise an errorJoshua Nelson-4/+4
It had no callers which didn't immediately call `raise()`, and this unifies the behavior with `Session`.
2021-05-05lazify backtrace formatting for delayed diagnosticsThe8472-5/+22
This defers backtrace formatting to the point where we actually want to flush delayed diagnostics. If they are discarded before that point then we can avoid invoking the backtrace formatting machinery which will parse debug info and symbol tables. for debuginfo=2 this leads to a 20% walltime reduction of the UI testsuite
2021-04-19fix few typosklensy-1/+1
2021-04-04Rollup merge of #73945 - est31:unused_externs, r=Mark-SimulacrumDylan DPC-0/+8
Add an unstable --json=unused-externs flag to print unused externs This adds an unstable flag to print a list of the extern names not used by cargo. This PR will enable cargo to collect unused dependencies from all units and provide warnings. The companion PR to cargo is: https://github.com/rust-lang/cargo/pull/8437 The goal is eventual stabilization of this flag in rustc as well as in cargo. Discussion of this feature is mostly contained inside these threads: #57274 #72342 #72603 The feature builds upon the internal datastructures added by #72342 Externs are uniquely identified by name and the information is sufficient for cargo. If the mode is enabled, rustc will print json messages like: ``` {"unused_extern_names":["byteorder","openssl","webpki"]} ``` For a crate that got passed byteorder, openssl and webpki dependencies but needed none of them. ### Q: Why not pass -Wunused-crate-dependencies? A: See [ehuss's comment here](https://github.com/rust-lang/rust/issues/57274#issuecomment-624839355) TLDR: it's cleaner. Rust's warning system wasn't built to be filtered or edited by cargo. Even a basic implementation of the feature would have to change the "n warnings emitted" line that rustc prints at the end. Cargo ideally wants to synthesize its own warnings anyways. For example, it would be hard for rustc to emit warnings like "dependency foo is only used by dev targets", suggesting to make it a dev-dependency instead. ### Q: Make rustc emit used or unused externs? A: Emitting used externs has the advantage that it simplifies cargo's collection job. However, emitting unused externs creates less data to be communicated between rustc and cargo. Often you want to paste a cargo command obtained from `cargo build -vv` for doing something completely unrelated. The message is emitted always, even if no warning or error is emitted. At that point, even this tiny difference in "noise" matters. That's why I went with emitting unused externs. ### Q: One json msg per extern or a collective json msg? A: Same as above, the data format should be concise. Having 30 lines for the 30 crates a crate uses would be disturbing to readers. Also it helps the cargo implementation to know that there aren't more unused deps coming. ### Q: Why use names of externs instead of e.g. paths? A: Names are both sufficient as well as neccessary to uniquely identify a passed `--extern` arg. Names are sufficient because you *must* pass a name when passing an `--extern` arg. Passing a path is optional on the other hand so rustc might also figure out a crate's location from the file system. You can also put multiple paths for the same extern name, via e.g. `--extern hello=/usr/lib/hello.rmeta --extern hello=/usr/local/lib/hello.rmeta`, but rustc will only ever use one of those paths. Also, paths don't identify a dependency uniquely as it is possible to have multiple different extern names point to the same path. So paths are ill-suited for identification. ### Q: What about 2015 edition crates? A: They are fully supported. Even on the 2015 edition, an explicit `--extern` flag is is required to enable `extern crate foo;` to work (outside of sysroot crates, which this flag doesn't warn about anyways). So the lint would still fire on 2015 edition crates if you haven't included a dependency specified in Cargo.toml using `extern crate foo;` or similar. The lint won't fire if your sole use in the crate is through a `extern crate foo;` statement, but that's not its job. For detecting unused `extern crate foo` statements, there is the `unused_extern_crates` lint which can be enabled by `#![warn(unused_extern_crates)]` or similar. cc ```@jsgf``` ```@ehuss``` ```@petrochenkov``` ```@estebank```
2021-03-27Remove (lots of) dead codeJoshua Nelson-4/+0
Found with https://github.com/est31/warnalyzer. Dubious changes: - Is anyone else using rustc_apfloat? I feel weird completely deleting x87 support. - Maybe some of the dead code in rustc_data_structures, in case someone wants to use it in the future? - Don't change rustc_serialize I plan to scrap most of the json module in the near future (see https://github.com/rust-lang/compiler-team/issues/418) and fixing the tests needed more work than I expected. TODO: check if any of the comments on the deleted code should be kept.
2021-03-26Use iter::zip in compiler/Josh Stone-0/+1
2021-03-17Remove unnecessary `forward_inner_docs` hackJoshua Nelson-0/+1
and replace it with `extended_key_value_attributes` feature.
2021-03-08Emit the lint level of the unused-crate-dependenciesest31-4/+4
Also, turn off the lint when the unused dependencies json flag is specified so that cargo doesn't have to supress the lint
2021-03-08Emit unused externsest31-0/+8
2021-03-06Change x64 size checks to not apply to x32.Harald van Dijk-1/+1
Rust contains various size checks conditional on target_arch = "x86_64", but these checks were never intended to apply to x86_64-unknown-linux-gnux32. Add target_pointer_width = "64" to the conditions.
2021-02-18nhwn: make treat_err_as_bug Option<NonZeroUsize>Nathan Nguyen-6/+7
2021-02-07Implement Encoder for Diagnostic manuallyJeremy Fitzhardinge-0/+4
...so we can skip serializing `tool_metadata` if it hasn't been set. This makes the output a bit cleaner, and avoiding having to update a bunch of unrelated tests.
2021-02-07Add `--extern-loc` to augment unused crate dependency diagnosticsJeremy Fitzhardinge-1/+34
This allows a build system to indicate a location in its own dependency specification files (eg Cargo's `Cargo.toml`) which can be reported along side any unused crate dependency. This supports several types of location: - 'json' - provide some json-structured data, which is included in the json diagnostics in a `tool_metadata` field - 'raw' - emit the provided string into the output. This also appears as a json string in `tool_metadata`. If no `--extern-location` is explicitly provided then a default json entry of the form `"tool_metadata":{"name":<cratename>,"path":<cratepath>}` is emitted.
2021-02-03Make panic/assert calls in rustc compatible with Rust 2021.Mara Bos-2/+2
2021-01-14Use Option::map_or instead of `.map(..).unwrap_or(..)`LingMan-2/+2
2020-10-30Implement rustc side of report-future-incompatAaron Hill-29/+82
2020-10-30Fix even more clippy warningsJoshua Nelson-8/+2
2020-09-23/nightly/nightly-rustcErik Hofmayer-1/+1
2020-09-23Updated html_root_url for compiler cratesErik Hofmayer-1/+1
2020-09-18Simplify panic_if_treat_err_as_bug avoiding allocationsJuan Aguilar Santillana-7/+5
2020-09-02rustc_{errors,session}: add `delay_good_path_bug`Dan Aloni-7/+48
The first use case of this detection of regression for trimmed paths computation, that is in the case of rustc, which should be computed only in case of errors or warnings. Our current user of this method is deeply nested, being a side effect from `Display` formatting on lots of rustc types. So taking only the caller to the error message is not enough - we should collect the traceback instead.
2020-08-30mv compiler to compiler/mark-0/+1021