about summary refs log tree commit diff
path: root/compiler/rustc_errors
AgeCommit message (Collapse)AuthorLines
2021-10-07use structured fields in some existing warningsEliza Weisman-1/+1
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
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-20Migrate to 2021Mark Rousskov-1/+1
2021-09-20Add some more tracingOli Scherer-1/+3
2021-09-20Workaround ICE with if-let and RFC 2229Mark Rousskov-4/+2
2021-09-17Make diagnostics clearer for `?` operatorsYuki Okushi-0/+12
2021-09-13Auto merge of #87915 - estebank:fancy-spans, r=oli-obkbors-0/+29
Use smaller spans for some structured suggestions Use more accurate suggestion spans for * argument parse error * fully qualified path * missing code block type * numeric casts
2021-09-08Bump stage0 compiler to 1.56Mark Rousskov-1/+0
2021-09-06Auto merge of #88493 - chenyukang:fix-duplicated-diagnostic, r=estebankbors-1/+49
Fix #88256 remove duplicated diagnostics Fix #88256
2021-09-04Fix #88256, remove duplicated diagnosticyukang-1/+49
2021-08-27Path remapping: Make behavior of diagnostics output dependent on presence of ↵Michael Woerister-6/+6
--remap-path-prefix.
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-11/+9
2021-08-23wipEsteban Kuber-20/+13
2021-08-23Account for tabs when highlighting multiline code suggestionsEsteban Kuber-25/+45
2021-08-12Use smaller spans for some structured suggestionsEsteban Kuber-0/+29
Use more accurate suggestion spans for * argument parse error * fully qualified path * missing code block type * numeric casts * E0212
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