about summary refs log tree commit diff
path: root/compiler/rustc_errors
AgeCommit message (Collapse)AuthorLines
2021-08-11Modify structured suggestion outputEsteban Küber-25/+180
* 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-08-04Remove trailing whitespace from error messagesFabian Wolff-2/+5
2021-08-02Auto merge of #87535 - lf-:authors, r=Mark-Simulacrumbors-1/+0
rfc3052 followup: Remove authors field from Cargo manifests Since RFC 3052 soft deprecated the authors field, hiding it from crates.io, docs.rs, and making Cargo not add it by default, and it is not generally up to date/useful information for contributors, we may as well remove it from crates in this repo.
2021-07-30Use multispan suggestions more oftenEsteban Küber-0/+38
* Use more accurate span for `async move` suggestion * Use more accurate span for deref suggestion * Use `multipart_suggestion` more often
2021-07-29rfc3052: Remove authors field from Cargo manifestsJade-1/+0
Since RFC 3052 soft deprecated the authors field anyway, hiding it from crates.io, docs.rs, and making Cargo not add it by default, and it is not generally up to date/useful information, we should remove it from crates in this repo.
2021-07-19Various diagnostics clean ups/tweaksEsteban Küber-8/+19
* Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-11Simplify future incompatible reporting.Eric Huss-12/+6
2021-07-10rustc_span: Revert addition of `proc_macro` field to `ExpnKind::Macro`Vadim Petrochenkov-18/+3
The flag has a vague meaning and is used for a single diagnostic change that is low benefit and appears only under `-Z macro_backtrace`.
2021-07-08Rework SESSION_GLOBALS API to prevent overwriting itGuillaume Gomez-6/+1
2021-07-06Auto merge of #86572 - rylev:force-warnings-always, r=nikomatsakisbors-6/+43
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-6/+17
2021-06-28Update to new bootstrap compilerMark Rousskov-1/+0
2021-06-07Auto merge of #85903 - bjorn3:rustc_serialize_cleanup, r=varkorbors-2/+2
Remove unused functions and arguments from rustc_serialize
2021-06-02Miscellaneous inlining improvementsTomasz Miąsko-0/+2
2021-06-01Remove unused functions and arguments from rustc_serializebjorn3-2/+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-7/+7
When there are multiple macros in use, it can be difficult to tell which one was responsible for producing an error.
2021-05-12Auto merge of #83813 - cbeuw:remap-std, r=michaelwoeristerbors-6/+7
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths This PR fixes #73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped. `RealFileName::Named` introduced in #72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path. `RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure. When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host". `rustc_span::SourceFile`'s fields `unmapped_path` (introduced by #44940) and `name_was_remapped` (introduced by #41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`. cc `@eddyb` who implemented `/rustc/...` path devirtualisation
2021-05-12Implement span quoting for proc-macrosAaron Hill-3/+18
This PR implements span quoting, allowing proc-macros to produce spans pointing *into their own crate*. This is used by the unstable `proc_macro::quote!` macro, allowing us to get error messages like this: ``` error[E0412]: cannot find type `MissingType` in this scope --> $DIR/auxiliary/span-from-proc-macro.rs:37:20 | LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream { | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]` ... LL | field: MissingType | ^^^^^^^^^^^ not found in this scope | ::: $DIR/span-from-proc-macro.rs:8:1 | LL | #[error_from_attribute] | ----------------------- in this macro invocation ``` Here, `MissingType` occurs inside the implementation of the proc-macro `#[error_from_attribute]`. Previosuly, this would always result in a span pointing at `#[error_from_attribute]` This will make many proc-macro-related error message much more useful - when a proc-macro generates code containing an error, users will get an error message pointing directly at that code (within the macro definition), instead of always getting a span pointing at the macro invocation site. This is implemented as follows: * When a proc-macro crate is being *compiled*, it causes the `quote!` macro to get run. This saves all of the sapns in the input to `quote!` into the metadata of *the proc-macro-crate* (which we are currently compiling). The `quote!` macro then expands to a call to `proc_macro::Span::recover_proc_macro_span(id)`, where `id` is an opaque identifier for the span in the crate metadata. * When the same proc-macro crate is *run* (e.g. it is loaded from disk and invoked by some consumer crate), the call to `proc_macro::Span::recover_proc_macro_span` causes us to load the span from the proc-macro crate's metadata. The proc-macro then produces a `TokenStream` containing a `Span` pointing into the proc-macro crate itself. The recursive nature of 'quote!' can be difficult to understand at first. The file `src/test/ui/proc-macro/quote-debug.stdout` shows the output of the `quote!` macro, which should make this eaier to understand. This PR also supports custom quoting spans in custom quote macros (e.g. the `quote` crate). All span quoting goes through the `proc_macro::quote_span` method, which can be called by a custom quote macro to perform span quoting. An example of this usage is provided in `src/test/ui/proc-macro/auxiliary/custom-quote.rs` Custom quoting currently has a few limitations: In order to quote a span, we need to generate a call to `proc_macro::Span::recover_proc_macro_span`. However, proc-macros support renaming the `proc_macro` crate, so we can't simply hardcode this path. Previously, the `quote_span` method used the path `crate::Span` - however, this only works when it is called by the builtin `quote!` macro in the same crate. To support being called from arbitrary crates, we need access to the name of the `proc_macro` crate to generate a path. This PR adds an additional argument to `quote_span` to specify the name of the `proc_macro` crate. Howver, this feels kind of hacky, and we may want to change this before stabilizing anything quote-related. Additionally, using `quote_span` currently requires enabling the `proc_macro_internals` feature. The builtin `quote!` macro has an `#[allow_internal_unstable]` attribute, but this won't work for custom quote implementations. This will likely require some additional tricks to apply `allow_internal_unstable` to the span of `proc_macro::Span::recover_proc_macro_span`.
2021-05-10Rollup merge of #85050 - FabianWolff:issue-84592, r=jackh726Dylan DPC-1/+17
Fix suggestions for missing return type lifetime specifiers This pull request aims to fix #84592. The issue is that the current code seems to assume that there is only a single relevant span pointing to the missing lifetime, and only looks at the first one: https://github.com/rust-lang/rust/blob/e5f83d24aee866a14753a7cedbb4e301dfe5bef5/compiler/rustc_resolve/src/late/lifetimes.rs#L2959 This is incorrect, though, and leads to incorrect error messages and invalid suggestions. For instance, the example from #84592: ```rust struct TwoLifetimes<'x, 'y> { x: &'x (), y: &'y (), } fn two_lifetimes_needed(a: &(), b: &()) -> TwoLifetimes<'_, '_> { TwoLifetimes { x: &(), y: &() } } ``` currently leads to: ``` error[E0106]: missing lifetime specifiers --> src/main.rs:6:57 | 6 | fn two_lifetimes_needed(a: &(), b: &()) -> TwoLifetimes<'_, '_> { | --- --- ^^ expected 2 lifetime parameters | = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `a` or `b` help: consider introducing a named lifetime parameter | 6 | fn two_lifetimes_needed<'a>(a: &'a (), b: &'a ()) -> TwoLifetimes<'_<'a, 'a>, '_> { | ^^^^ ^^^^^^ ^^^^^^ ^^^^^^^^^^ ``` There are two problems: - The error message is wrong. There is only _one_ lifetime parameter expected at the location pointed to by the error message (and another one at a separate location). - The suggestion is incorrect and will not lead to correct code. With the changes in this PR, I get the following output: ``` error[E0106]: missing lifetime specifiers --> p.rs:6:57 | 6 | fn two_lifetimes_needed(a: &(), b: &()) -> TwoLifetimes<'_, '_> { | --- --- ^^ ^^ expected named lifetime parameter | | | expected named lifetime parameter | = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `a` or `b` help: consider introducing a named lifetime parameter | 6 | fn two_lifetimes_needed<'a>(a: &'a (), b: &'a ()) -> TwoLifetimes<'a, 'a> { | ^^^^ ^^^^^^ ^^^^^^ ^^ ^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0106`. ``` Mainly, I changed `add_missing_lifetime_specifiers_label()` to receive a _vector_ of spans (and counts) instead of just one, and adjusted its body accordingly.
2021-05-10More minor fixes suggested by @jackh726Fabian Wolff-13/+5
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-07Fix suggestions for missing return type lifetime parametersFabian Wolff-0/+24
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-05-05Use local and remapped paths where appropriateAndy Wang-6/+7
2021-04-25Rollup merge of #84235 - klensy:styled-buffer, r=lcnrDylan DPC-35/+55
refactor StyledBuffer Refactors StyledBuffer `text` and `styles` fields content into StyledChar and touches some other stuff.
2021-04-24reviewklensy-24/+14
2021-04-19fix few typosklensy-1/+1
2021-04-16rename StyledBuffer.text to linesklensy-18/+18
2021-04-16StyledBuffer::set_style: check overwrite firstklensy-2/+2
2021-04-16StyledBuffer::prepend: if line is empty, insert content without inserting spacesklensy-3/+5
2021-04-16added some docs for StyledBufferklensy-0/+17
2021-04-16added default for StyledCharklensy-2/+8
2021-04-16refactored StyledBuffer parts into StyledCharklensy-21/+26
2021-04-05Document compiler/ with -Aprivate-intra-doc-linksJoshua Nelson-9/+0
Since compiler/ always passes --document-private-items, it's ok to link to items that are private.
2021-04-04Rollup merge of #73945 - est31:unused_externs, r=Mark-SimulacrumDylan DPC-0/+36
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-30Auto merge of #83639 - osa1:issue83638, r=estebankbors-1/+1
Replace tabs in err messages before rendering This is done in other call sites, but was missing in one place. Fixes #83638
2021-03-29Replace tabs in err messages before renderingÖmer Sinan Ağacan-1/+1
This is done in other call sites, but was missing in one place. Fixes #83638
2021-03-27Fix compiler docsJoshua Nelson-0/+9
2021-03-27Remove (lots of) dead codeJoshua Nelson-82/+8
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-27Remove unused `DiagnosticBuilder::sub` functionJoshua Nelson-13/+2
`Diagnostic::sub` is only ever used directly; it doesn't need to be included in the builder.
2021-03-27Rollup merge of #82917 - cuviper:iter-zip, r=m-ou-seDylan DPC-5/+5
Add function core::iter::zip This makes it a little easier to `zip` iterators: ```rust for (x, y) in zip(xs, ys) {} // vs. for (x, y) in xs.into_iter().zip(ys) {} ``` You can `zip(&mut xs, &ys)` for the conventional `iter_mut()` and `iter()`, respectively. This can also support arbitrary nesting, where it's easier to see the item layout than with arbitrary `zip` chains: ```rust for ((x, y), z) in zip(zip(xs, ys), zs) {} for (x, (y, z)) in zip(xs, zip(ys, zs)) {} // vs. for ((x, y), z) in xs.into_iter().zip(ys).zip(xz) {} for (x, (y, z)) in xs.into_iter().zip((ys.into_iter().zip(xz)) {} ``` It may also format more nicely, especially when the first iterator is a longer chain of methods -- for example: ```rust iter::zip( trait_ref.substs.types().skip(1), impl_trait_ref.substs.types().skip(1), ) // vs. trait_ref .substs .types() .skip(1) .zip(impl_trait_ref.substs.types().skip(1)) ``` This replaces the tuple-pair `IntoIterator` in #78204. There is prior art for the utility of this in [`itertools::zip`]. [`itertools::zip`]: https://docs.rs/itertools/0.10.0/itertools/fn.zip.html
2021-03-27lazily calls some fnsklensy-1/+1
2021-03-26Use iter::zip in compiler/Josh Stone-5/+5
2021-03-24small cleanups in rustc_errors / emitterAndre Bogus-20/+14
2021-03-17Remove unnecessary `forward_inner_docs` hackJoshua Nelson-15/+7
and replace it with `extended_key_value_attributes` feature.