Commit Graph

543 Commits

Author SHA1 Message Date
Maybe Waffle fd649a3cc5 Replace enum `==`s with `match`es where it makes sense 2023-01-30 12:26:26 +00:00
Lukas Markeffsky b9e8286c85 add debug assertion for suggestions with overlapping parts 2023-01-20 20:16:37 +01:00
Maybe Waffle 6a28fb42a8 Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
nils 73476554e9
Rollup merge of #106427 - mejrs:translation_errors, r=davidtwco
Improve fluent error messages

These have been really frustrating me while migrating diagnostics.
2023-01-11 17:30:54 +01:00
nils 0681a9652e
Rollup merge of #106321 - compiler-errors:delayed-bug-backtrace, r=Nilstrieb
Collect and emit proper backtraces for `delay_span_bug`s

This is a follow-up to #106317, which addresses this comment (https://github.com/rust-lang/rust/issues/106267#issuecomment-1367507507) which notes that `delay_span_bug`s' backtraces are nonsense.

Captures and emits the backtrace of the delayed span bug when it's *created*, rather than using the backtrace of the place where delayed bugs are flushed.

---

To test, I delayed a span bug during HIR typeck, specifically in `typeck_with_fallback`...

Before, note `flush_delayed` on frame 18. This is at the end of the compilation session, far from where the bug is being delayed.

```
error: internal compiler error: test
 --> /home/ubuntu/test.rs:1:1
  |
1 | fn main() {}
  | ^^^^^^^^^
  |
  = note: delayed at compiler/rustc_hir_typeck/src/lib.rs:196:14

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1634:13
stack backtrace:
   0:     0x7f9c3ec69dd1 - std::backtrace_rs::backtrace::libunwind::trace::h26056f81198c6594
                               at /home/ubuntu/rust2/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f9c3ec69dd1 - std::backtrace_rs::backtrace::trace_unsynchronized::hacfb345a0c6d5bb1
                               at /home/ubuntu/rust2/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f9c3ec69dd1 - std::sys_common::backtrace::_print_fmt::h18ea6016ac8030f3
                               at /home/ubuntu/rust2/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f9c3ec69dd1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he35dde201d0c2d09
                               at /home/ubuntu/rust2/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f9c3ecee308 - core::fmt::write::h094ad263467a053c
                               at /home/ubuntu/rust2/library/core/src/fmt/mod.rs:1208:17
   5:     0x7f9c3ec8aaf1 - std::io::Write::write_fmt::hd47b4e2324b4d9b7
                               at /home/ubuntu/rust2/library/std/src/io/mod.rs:1682:15
   6:     0x7f9c3ec69bfa - std::sys_common::backtrace::_print::h43044162653a17fc
                               at /home/ubuntu/rust2/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f9c3ec69bfa - std::sys_common::backtrace::print::hc8605da258fa5aeb
                               at /home/ubuntu/rust2/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f9c3ec4db87 - std::panicking::default_hook::{{closure}}::h9e37f23f75122a15
   9:     0x7f9c3ec4d97b - std::panicking::default_hook::h602873a063f84da2
                               at /home/ubuntu/rust2/library/std/src/panicking.rs:286:9
  10:     0x7f9c3f6672b2 - <alloc[48d7b30605060536]::boxed::Box<dyn for<'a, 'b> core[672e3947e150d6c6]::ops::function::Fn<(&'a core[672e3947e150d6c6]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[672e3947e150d6c6]::marker::Send + core[672e3947e150d6c6]::marker::Sync> as core[672e3947e150d6c6]::ops::function::Fn<(&core[672e3947e150d6c6]::panic::panic_info::PanicInfo,)>>::call
                               at /home/ubuntu/rust2/library/alloc/src/boxed.rs:2002:9
  11:     0x7f9c3f6672b2 - rustc_driver[f5b6d32d8905ecdd]::DEFAULT_HOOK::{closure#0}::{closure#0}
                               at /home/ubuntu/rust2/compiler/rustc_driver/src/lib.rs:1204:17
  12:     0x7f9c3ec4e0d3 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hfd13333ca953ae8e
                               at /home/ubuntu/rust2/library/alloc/src/boxed.rs:2002:9
  13:     0x7f9c3ec4e0d3 - std::panicking::rust_panic_with_hook::h45753e10264ebe7e
                               at /home/ubuntu/rust2/library/std/src/panicking.rs:692:13
  14:     0x7f9c422a1aa3 - std[3330b4673efabfce]::panicking::begin_panic::<rustc_errors[1b15f4e7e49d1fd5]::ExplicitBug>::{closure#0}
                               at /home/ubuntu/rust2/library/std/src/panicking.rs:608:9
  15:     0x7f9c422a1a46 - std[3330b4673efabfce]::sys_common::backtrace::__rust_end_short_backtrace::<std[3330b4673efabfce]::panicking::begin_panic<rustc_errors[1b15f4e7e49d1fd5]::ExplicitBug>::{closure#0}, !>
                               at /home/ubuntu/rust2/library/std/src/sys_common/backtrace.rs:137:18
  16:     0x7f9c3f63a996 - std[3330b4673efabfce]::panicking::begin_panic::<rustc_errors[1b15f4e7e49d1fd5]::ExplicitBug>
                               at /home/ubuntu/rust2/library/std/src/panicking.rs:607:12
  17:     0x7f9c4227a496 - std[3330b4673efabfce]::panic::panic_any::<rustc_errors[1b15f4e7e49d1fd5]::ExplicitBug>
                               at /home/ubuntu/rust2/library/std/src/panic.rs:61:5
  18:     0x7f9c4227cdf7 - <rustc_errors[1b15f4e7e49d1fd5]::HandlerInner>::flush_delayed::<alloc[48d7b30605060536]::vec::Vec<rustc_errors[1b15f4e7e49d1fd5]::diagnostic::Diagnostic>, &str, rustc_errors[1b15f4e7e49d1fd5]::ExplicitBug>
                               at /home/ubuntu/rust2/compiler/rustc_errors/src/lib.rs:1634:13
  19:     0x7f9c422498cf - <rustc_errors[1b15f4e7e49d1fd5]::Handler>::flush_delayed
                               at /home/ubuntu/rust2/compiler/rustc_errors/src/lib.rs:1225:9

[ FRAMES INTENTIONALLY OMITTED ]

  44:     0x7f9c3f6f3584 - <std[3330b4673efabfce]:🧵:Builder>::spawn_unchecked_::<rustc_interface[947706ead88047d0]::util::run_in_thread_pool_with_globals<rustc_interface[947706ead88047d0]::interface::run_compiler<core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>, rustc_driver[f5b6d32d8905ecdd]::run_compiler::{closure#1}>::{closure#0}, core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>>::{closure#1}
                               at /home/ubuntu/rust2/library/std/src/thread/mod.rs:549:30
  45:     0x7f9c3f6f3584 - <<std[3330b4673efabfce]:🧵:Builder>::spawn_unchecked_<rustc_interface[947706ead88047d0]::util::run_in_thread_pool_with_globals<rustc_interface[947706ead88047d0]::interface::run_compiler<core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>, rustc_driver[f5b6d32d8905ecdd]::run_compiler::{closure#1}>::{closure#0}, core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[672e3947e150d6c6]::result::Result<(), rustc_errors[1b15f4e7e49d1fd5]::ErrorGuaranteed>>::{closure#1} as core[672e3947e150d6c6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
                               at /home/ubuntu/rust2/library/core/src/ops/function.rs:250:5
  46:     0x7f9c3ec81968 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he8b26fc22c6f51ec
                               at /home/ubuntu/rust2/library/alloc/src/boxed.rs:1988:9
  47:     0x7f9c3ec81968 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h5cf9cbe75a8c3ddc
                               at /home/ubuntu/rust2/library/alloc/src/boxed.rs:1988:9
  48:     0x7f9c3ec5f99c - std::sys::unix:🧵:Thread:🆕:thread_start::h2d6dd4455e97d031
                               at /home/ubuntu/rust2/library/std/src/sys/unix/thread.rs:108:17
  49:     0x7f9c37c69609 - start_thread
  50:     0x7f9c3ead0133 - clone
  51:                0x0 - <unknown>
```

After, note `typeck_with_fallback` on the 5th frame, that's where we *actually* need to be pointed to:

```
error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: test
 --> /home/ubuntu/test.rs:1:1
  |
1 | fn main() {}
  | ^^^^^^^^^
  |
  = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
                       at ./compiler/rustc_errors/src/lib.rs:1279:29
             1: <rustc_errors::HandlerInner>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
                       at ./compiler/rustc_errors/src/lib.rs:1553:9
             2: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
                       at ./compiler/rustc_errors/src/lib.rs:995:9
             3: <rustc_session::session::Session>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
                       at ./compiler/rustc_session/src/session.rs:600:9
             4: rustc_hir_typeck::typeck_with_fallback::<rustc_hir_typeck::typeck::{closure#0}>::{closure#0}
                       at ./compiler/rustc_hir_typeck/src/lib.rs:196:5
             5: rustc_hir_typeck::typeck_with_fallback::<rustc_hir_typeck::typeck::{closure#0}>
                       at ./compiler/rustc_hir_typeck/src/lib.rs:185:36
             6: rustc_hir_typeck::typeck
                       at ./compiler/rustc_hir_typeck/src/lib.rs:166:9

[ FRAMES INTENTIONALLY OMITTED ]

           108: std::panicking::try::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, core::panic::unwind_safe::AssertUnwindSafe<<std:🧵:Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#1}::{closure#0}>>
                       at ./library/std/src/panicking.rs:447:19
           109: std::panic::catch_unwind::<core::panic::unwind_safe::AssertUnwindSafe<<std:🧵:Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#1}::{closure#0}>, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
                       at ./library/std/src/panic.rs:140:14
           110: <std:🧵:Builder>::spawn_unchecked_::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#1}
                       at ./library/std/src/thread/mod.rs:549:30
           111: <<std:🧵:Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
                       at ./library/core/src/ops/function.rs:250:5
           112: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at ./library/alloc/src/boxed.rs:1988:9
           113: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at ./library/alloc/src/boxed.rs:1988:9
           114: std::sys::unix:🧵:Thread:🆕:thread_start
                       at ./library/std/src/sys/unix/thread.rs:108:17
           115: start_thread
           116: clone
```
2023-01-11 17:30:53 +01:00
ozkanonur 5fb9ca3c5e create helper function for `rustc_lint_defs::Level` and remove it's duplicated code r=ozkanonur
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-01-10 10:56:17 +03:00
Michael Goulet 05c1ac0215 Collect backtraces for delayed span-bugs too 2023-01-09 22:04:00 +00:00
mejrs 4c0c32c895 Fix tests 2023-01-09 00:23:27 +01:00
mejrs 262ff86138 Make translate_message return result and add tests 2023-01-08 23:35:43 +01:00
Matthias Krüger 771cfa5581
Rollup merge of #104543 - JhonnyBillM:migrate-codegen-ssa-to-diagnostics-structs-pt3, r=davidtwco
Migrate `codegen_ssa` to diagnostics structs - [Part 3]

Completes migrating `codegen_ssa` module except 2 outstanding errors that depend on other crates:
1. [`rustc_middle::mir::interpret::InterpError`](b6097f2e1b/compiler/rustc_middle/src/mir/interpret/error.rs (L475)): I saw `rustc_middle` is unassigned, I am open to take this work.

2.  `codegen_llvm`'s use of `fn span_invalid_monomorphization_error`, which I started to replace in the [last commit](9a31b3cdda) of this PR, but would like to know the team's preference on how we should keep replacing the other macros:
2.1. Update macros to expect a `Diagnostic`
2.2. Remove macros and expand the code on each use.
See [some examples of the different options in this experimental commit](64aee83e80)

_Part 2 - https://github.com/rust-lang/rust/pull/103792_

r? ``@davidtwco``
Cc ``@compiler-errors``
2023-01-07 20:43:19 +01:00
Matthias Krüger 7568c49bf0
Rollup merge of #106287 - Nilstrieb:its-bugging-me-how-we-dont-have-docs, r=jyn514
Add some docs to `bug`, `span_bug` and `delay_span_bug`

cc `@mejrs` as you wanted me to do this, does this look good and understandable?
2023-01-06 21:26:09 +01:00
mejrs 0b5d6ae5db Improve fluent error messages 2023-01-05 03:39:07 +01:00
bors fb9dfa8cef Auto merge of #84762 - cjgillot:resolve-span-opt, r=petrochenkov
Encode spans relative to the enclosing item -- enable on nightly

Follow-up to #84373 with the flag `-Zincremental-relative-spans` set by default.

This PR seeks to remove one of the main shortcomings of incremental: the handling of spans.
Changing the contents of a function may require redoing part of the compilation process for another function in another file because of span information is changed.
Within one file: all the spans in HIR change, so typechecking had to be re-done.
Between files: spans of associated types/consts/functions change, so type-based resolution needs to be re-done (hygiene information is stored in the span).

The flag `-Zincremental-relative-spans` encodes local spans relative to the span of an item, stored inside the `source_span` query.

Trap: stashed diagnostics are referenced by the "raw" span, so stealing them requires to remove the span's parent.

In order to avoid too much traffic in the span interner, span encoding uses the `ctxt_or_tag` field to encode:
- the parent when the `SyntaxContext` is 0;
- the `SyntaxContext` when the parent is `None`.
Even with this, the PR creates a lot of traffic to the Span interner, when a Span has both a LocalDefId parent and a non-root SyntaxContext. They appear in lowering, when we add a parent to all spans, including those which come from macros, and during inlining when we mark inlined spans.

The last commit changes how queries of `LocalDefId` manage their cache. I can put this in a separate PR if required.

Possible future directions:
- validate that all spans are marked in HIR validation;
- mark macro-expanded spans relative to the def-site and not the use-site.
2023-01-02 13:10:16 +00:00
Esteban Küber 5bfcfeee2a Merge multiple mutable borrows of immutable binding errors
Fix #53466.
2023-01-01 10:09:26 -08:00
Michael Goulet 5d62a737d7 Only deduplicate stack traces for good path bugs 2022-12-31 02:14:26 +00:00
Nilstrieb 0047e25090 Add some docs to `bug`, `span_bug` and `delay_span_bug` 2022-12-30 16:47:56 +01:00
Esteban Küber af74ca0666 Account for multiple multiline spans with empty padding
Instead of

```
LL |    fn oom(
   |  __^
   | | _|
   | ||
LL | || ) {
   | ||_-
LL | |  }
   | |__^
```

emit

```
LL | // fn oom(
LL | || ) {
   | ||_-
LL | |  }
   | |__^
   ```
2022-12-29 09:13:40 -08:00
Jhonny Bill Mena 27744460e2 ADD - create and emit Bug support for Diagnostics
UPDATE - migrate constant span_bug to translatable diagnostic.
2022-12-27 20:59:22 -05:00
Jhonny Bill Mena d1030fab22 UPDATE - migrate fn simd_simple_float_intrinsic error messages 2022-12-27 20:59:21 -05:00
Camille GILLOT 4719cb3036 Ignore span references from diagnostics.
The diagnostics are replayed at the correct place anyway.
2022-12-25 18:48:42 +00:00
Camille GILLOT 66e0316414 Use absolute spans when trying to steal an AST diagnostic. 2022-12-25 18:48:30 +00:00
Matthias Krüger d8874f259a fix more clippy::style findings
match_result_ok
obfuscated_if_else
single_char_add
writeln_empty_string
collapsible_match
iter_cloned_collect
unnecessary_mut_passed
2022-12-25 17:32:26 +01:00
Matthias Krüger de59844c98 more clippy::complexity fixes 2022-12-15 00:09:10 +01:00
Oli Scherer 59554a2b54 Avoid rendering empty annotations 2022-12-13 10:06:08 +00:00
Oli Scherer 2e2a4797a2 Don't emit empty notes 2022-12-13 09:53:36 +00:00
Matthias Krüger 2707801858
Rollup merge of #105625 - matthiaskrgr:clippy_dec12, r=compiler-errors
minor code cleanups

r? `@compiler-errors`
2022-12-13 01:17:10 +01:00
Matthias Krüger 2ea368e53c minor code cleanups 2022-12-12 19:49:53 +01:00
Esteban Küber 2838b8e515 Point at method call when it is the source of the bound error 2022-12-11 14:49:50 -08:00
Matthias Krüger 2daa3bcbc2
Rollup merge of #105537 - kadiwa4:remove_some_imports, r=fee1-dead
compiler: remove unnecessary imports and qualified paths

Some of these imports were necessary before Edition 2021, others were already in the prelude.

I hope it's fine that this PR is so spread-out across files :/
2022-12-11 09:51:57 +01:00
KaDiWa 9bc69925cb
compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
nils 2f9f097cb8 Migrate parts of `rustc_expand` to session diagnostics
This migrates everything but the `mbe` and `proc_macro` modules. It also
contains a few cleanups and drive-by/accidental diagnostic improvements
which can be seen in the diff for the UI tests.
2022-12-10 11:02:41 +01:00
Oli Scherer f89d6236aa Properly indent messages 2022-12-06 18:59:46 +00:00
Oli Scherer 10b75cbbb0 Start emitting labels even if their pointed to file is not available locally 2022-12-06 18:59:46 +00:00
Oli Scherer 19d7dceed3 remove an unnecessary `?` 2022-12-06 18:59:45 +00:00
Oli Scherer 9eb9176b08 Simplify span fallback 2022-12-06 18:59:45 +00:00
Oli Scherer b9bf119c4f Simplify some nested conditions 2022-12-06 18:59:45 +00:00
Matthias Krüger 7dbd1603b8
Rollup merge of #101975 - chenyukang:fix-101749, r=compiler-errors
Suggest to use . instead of :: when accessing a method of an object

Fixes #101749
Fixes #101542
2022-12-04 16:25:32 +01:00
yukang fb004e9a95 fix #101749, use . instead of :: when accessing a method of an object 2022-12-03 22:41:12 +08:00
Maybe Waffle f2b97a8bfe Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
Esteban Küber 6f64432a39 Tweak output 2022-11-28 00:11:12 -08:00
Esteban Küber ab04080b56 Change multiline span ASCII art visual order 2022-11-28 00:11:12 -08:00
Matthias Krüger 4843946a10
Rollup merge of #104780 - BoxyUwU:error_reported_not_be_bad, r=oli-obk
make `error_reported` check for delayed bugs

Fixes #104768

`error_reported()` was only checking if there were errors emitted, not for `delay_bug`s which can also be a source of `ErrorGuaranteed`. I assume the same is true of `lint_err_count` but i dont know
2022-11-24 21:34:54 +01:00
Boxy 72d8879c29 make `error_reported` check for delayed bugs 2022-11-24 11:12:46 +00:00
bors 872631d0f0 Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiser
Use `as_deref` in compiler (but only where it makes sense)

This simplifies some code :3

(there are some changes that are not exacly `as_deref`, but more like "clever `Option`/`Result` method use")
2022-11-24 00:17:35 +00:00
Matthias Krüger fce077b053
Rollup merge of #104504 - compiler-errors:fru-syntax-note, r=estebank
Add a detailed note for missing comma typo w/ FRU syntax

Thanks to `@pierwill` for working on this with me!

Fixes #104373, perhaps `@alice-i-cecile` can comment on the new error for the example provided on that issue -- feedback is welcome.

```
error[E0063]: missing field `defaulted` in initializer of `Outer`
  --> $DIR/multi-line-fru-suggestion.rs:14:5
   |
LL |     Outer {
   |     ^^^^^ missing `defaulted`
   |
note: this expression may have been misinterpreted as a `..` range expression
  --> $DIR/multi-line-fru-suggestion.rs:16:16
   |
LL |           inner: Inner {
   |  ________________^
LL | |             a: 1,
LL | |             b: 2,
LL | |         }
   | |_________^ this expression does not end in a comma...
LL |           ..Default::default()
   |           ^^^^^^^^^^^^^^^^^^^^ ... so this is interpreted as a `..` range expression, instead of functional record update syntax
help: to set the remaining fields from `Default::default()`, separate the last named field with a comma
   |
LL |         },
   |          +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0063`.
```
2022-11-20 23:50:27 +01:00
Matthias Krüger 52cc0d5360
Rollup merge of #103117 - joshtriplett:use-is-terminal, r=eholk
Use `IsTerminal` in place of `atty`

In any crate that can use nightly features, use `IsTerminal` rather than
`atty`:

- Use `IsTerminal` in `rustc_errors`
- Use `IsTerminal` in `rustc_driver`
- Use `IsTerminal` in `rustc_log`
- Use `IsTerminal` in `librustdoc`
2022-11-19 15:35:18 +01:00
bors ff0ffda6b3 Auto merge of #104591 - Manishearth:rollup-b3ser4e, r=Manishearth
Rollup of 8 pull requests

Successful merges:

 - #102977 (remove HRTB from `[T]::is_sorted_by{,_key}`)
 - #103378 (Fix mod_inv termination for the last iteration)
 - #103456 (`unchecked_{shl|shr}` should use `u32` as the RHS)
 - #103701 (Simplify some pointer method implementations)
 - #104047 (Diagnostics `icu4x` based list formatting.)
 - #104338 (Enforce that `dyn*` coercions are actually pointer-sized)
 - #104498 (Edit docs for `rustc_errors::Handler::stash_diagnostic`)
 - #104556 (rustdoc: use `code-header` class to format enum variants)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-18 23:20:53 +00:00
Manish Goregaokar a065e97bdc
Rollup merge of #104498 - pierwill:stash-diag-docs, r=compiler-errors
Edit docs for `rustc_errors::Handler::stash_diagnostic`

Clarify that the diagnostic can be retrieved with `steal_diagnostic`.

r? ```@compiler-errors```
2022-11-18 17:48:19 -05:00
Charles Lew b21e0b82c5 Fix compilation issue after rebase 2022-11-18 14:46:36 -08:00
Charles Lew d15b020278 Enable icu sync feature for parallel compiler 2022-11-18 14:46:35 -08:00
Charles Lew a775004322 Migrate diagnostics list output to use icu list formatter. 2022-11-18 14:46:35 -08:00
Michael Goulet bb0cb9ae9f Add a detailed note for missing comma in FRU syntax typo 2022-11-18 17:27:55 +00:00
Matthias Krüger 3e5965722c
Rollup merge of #101162 - rajputrajat:master, r=davidtwco
Migrate rustc_resolve to use SessionDiagnostic, part # 1

crate a somewhat on larger size, so plz allow some time to get it finished.
2022-11-18 14:13:35 +01:00
pierwill 19b63bc791 Edit docs for `rustc_errors::Handler::stash_diagnostic`
Clarify that the diagnostic can be retrieved with `steal_diagnostic`.
2022-11-17 15:45:46 -06:00
Maybe Waffle 94470f4efd Use `as_deref` in compiler (but only where it makes sense) 2022-11-16 21:58:58 +00:00
Matthias Krüger abda584a5a
Rollup merge of #104229 - compiler-errors:overlap-full-path, r=davidtwco
Don't print full paths in overlap errors

We don't print the full path in other diagnostics -- I don't think it particularly helps with the error message. I also delayed the printing until actually needing to render the error message.

r? diagnostics
2022-11-14 19:26:16 +01:00
bors 338cfd3cce Auto merge of #103858 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini
Bump bootstrap compiler to 1.66

This PR:

- Bumps version placeholders to release
- Bumps to latest beta
- cfg-steps code

r? `@pietroalbini`
2022-11-14 00:07:19 +00:00
Rajput, Rajat 269ce369fe migrating rustc_resolve to SessionDiagnostic. work in progress. start
implement binding_shadows

migrate till self-in-generic-param-default

use braces in fluent message as suggested by @compiler-errors.

to fix lock file issue reported by CI

migrate 'unreachable label' error

run formatter

name the variables correctly in fluent file

SessionDiagnostic -> Diagnostic

test "pattern/pat-tuple-field-count-cross.rs" passed

test "resolve/bad-env-capture2.rs" passed

test "enum/enum-in-scope.rs" and other depended on "resolve_binding_shadows_something_unacceptable" should be passed now.

fix crash errors while running test-suite. there might be more.

then_some(..) suits better here.

all tests passed

convert TraitImpl and InvalidAsm. TraitImpl is buggy yet. will fix after receiving help from Zulip

migrate "Ralative-2018"

migrate "ancestor only"

migrate "expected found"

migrate "Indeterminate"

migrate "module only"

revert to the older implementation for now. since this is failing at the moment.

follow the convension for fluent variable

order the diag attribute as suggested in review comment

fix merge error. migrate trait-impl-duplicate

make the changes compatible with "Flatten diagnostic slug modules #103345"

fix merge

remove commented code

merge issues

fix review comments

fix tests
2022-11-13 19:39:26 +05:30
Dylan DPC fcbe990093
Rollup merge of #103970 - oli-obk:unhide_unknown_spans, r=estebank
Unhide unknown spans

r? ```@estebank```
2022-11-12 12:02:51 +05:30
Dylan DPC 6026785b7a
Rollup merge of #104217 - Nilstrieb:funny-dollar-syntax, r=TaKO8Ki
Display help message when fluent arg was referenced incorrectly

The fluent argument syntax is a little special and easy to get wrong, so we emit a small help message when someone gets it wrong.

Example:
```
parser_mismatched_closing_delimiter = mismatched closing delimiter: `${delimiter}`
```
panics with
```
thread 'rustc' panicked at 'Encountered errors while formatting message for `parser_mismatched_closing_delimiter`
help: Argument `delimiter` exists but was not referenced correctly. Try using `{$delimiter}` instead
attr: `None`
args: `FluentArgs([("delimiter", String("}"))])`
errors: `[ResolverError(Reference(Message { id: "delimiter", attribute: None }))]`', compiler/rustc_errors/src/translation.rs:123:21
```

fixes #103539
2022-11-11 20:51:41 +05:30
Oli Scherer df2adc4760 Print all labels, even if they have no span. Fall back to main item's span. 2022-11-11 14:45:28 +00:00
Oli Scherer 014f7f4092 Remove some redundant arguments 2022-11-11 14:17:27 +00:00
Michael Goulet e5ecf629dd
Rollup merge of #102763 - compiler-errors:nits, r=cjgillot
Some diagnostic-related nits

1. Use `&mut Diagnostic` instead of `&mut DiagnosticBuilder<'_, T>`
2. Make `diag.span_suggestions` take an `IntoIterator` instead of `Iterator`, just to remove some `.into_iter` calls on the caller.

idk if I should add a lint to make sure people use `&mut Diagnostic` instead of `&mut DiagnosticBuilder<'_, T>` in cases where we're just, e.g., adding subdiagnostics to the diagnostic... maybe a followup.
2022-11-09 21:53:34 -08:00
Michael Goulet f902b495ba Don't print full paths in overlap errors 2022-11-10 05:41:09 +00:00
Nilstrieb bd3c4fb2f6
Display help message when fluent arg was referenced incorrectly
The fluent argument syntax is a little special and easy to get wrong, so
we emit a small help message when someone gets it wrong.

Example:
```
parser_mismatched_closing_delimiter = mismatched closing delimiter: `${delimiter}`
```
panics with
```
thread 'rustc' panicked at 'Encountered errors while formatting message for `parser_mismatched_closing_delimiter`
help: Argument `delimiter` exists but was not referenced correctly. Try using `{$delimiter}` instead
attr: `None`
args: `FluentArgs([("delimiter", String("}"))])`
errors: `[ResolverError(Reference(Message { id: "delimiter", attribute: None }))]`', compiler/rustc_errors/src/translation.rs:123:21
```
2022-11-09 22:38:10 +01:00
Michael Goulet 9568138069 rebase conflict 2022-11-09 19:42:23 +00:00
Michael Goulet e807cb3c41 Make span_suggestions take IntoIterator 2022-11-09 19:42:23 +00:00
SLASHLogin caada745d1 Add missing `emitted_at` to the `Diagnostic` 2022-11-09 15:14:58 +01:00
SLASHLogin 39895b0716 Add constructor for `Diagnostic` that takes `Vec<(DiagnosticMessage, Style)>` 2022-11-09 14:57:54 +01:00
SLASHLogin 0381e51822 Formatting 2022-11-09 14:56:21 +01:00
SLASHLogin 3b949eb7c1 Add `replace_args` method for `rustc_errors::diagnostic::Diagnostic` 2022-11-09 14:56:21 +01:00
SLASHLogin b4820a3b94 Delay diagnostic translation in `rustc_codegen_ssa` 2022-11-09 14:56:21 +01:00
SLASHLogin c01546fcd6 Port `DlltoolFailImportLibrary` and implement `IntoDiagnosticArg` for `Cow<'a, str>` 2022-11-09 14:56:21 +01:00
yukang 1f21b96dce add 'ty_error_with_guaranteed' and 'const_error_with_guaranteed' 2022-11-08 11:17:46 +08:00
Mark Rousskov 40290505fb cfg-step code 2022-11-06 17:21:21 -05:00
Matthias Krüger 1cb8684dde
Rollup merge of #103792 - JhonnyBillM:migrate-codegen-ssa-to-diagnostics-structs-pt2, r=davidtwco
Migrate `codegen_ssa` to diagnostics structs - [Part 2]

Completes migrating `link.rs` in `codegen_ssa` module.

_Part 1 - https://github.com/rust-lang/rust/pull/102612_

r? `@davidtwco`
2022-11-04 18:52:27 +01:00
Matthias Krüger 612bb7890c
Rollup merge of #103397 - crlf0710:port_dead_code_lint, r=davidtwco
Port `dead_code` lints to be translatable.

This adds an additional comma to lists with three or more items, to be consistent with list formatters like `icu4x`.

r? `@davidtwco`
2022-11-04 18:52:26 +01:00
Jhonny Bill Mena 540c3f94d7 UPDATE - accept dyn error and make Box<dyn error> conform to IntoDiagnosticArg 2022-11-04 01:17:03 -04:00
Jhonny Bill Mena 4c80f50fc6 UPDATE - Complete link.rs migration to new diagnostics infraestructure 2022-11-04 01:17:02 -04:00
bors 11ebe6512b Auto merge of #103217 - mejrs:track, r=eholk
Track where diagnostics were created.

This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`.

For example, the following code...

```rust
struct A;
struct B;

fn main(){
    let _: A = B;
}
```
...now emits the following error message:

```
error[E0308]: mismatched types
 --> src\main.rs:5:16
  |
5 |     let _: A = B;
  |            -   ^ expected struct `A`, found struct `B`
  |            |
  |            expected due to this
-Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31
```
2022-11-01 21:09:45 +00:00
mejrs cbeb244b05 Add more track_caller 2022-10-31 16:14:29 +01:00
mejrs 854b3166a0 Address some comments 2022-10-24 20:52:51 +02:00
Charles Lew 113e8dfb72 Port `dead_code` lints to be translatable. 2022-10-24 17:02:31 +08:00
Xiretza 8bc43f99e9 Allow specifying multiple alternative suggestions
This allows porting uses of span_suggestions() to diagnostic structs.

Doesn't work for multipart_suggestions() because the rank would be
reversed - the struct would specify multiple spans, each of which has
multiple possible replacements, while multipart_suggestions() creates
multiple possible replacements, each with multiple spans.
2022-10-23 18:59:13 +02:00
bors 9be2f35a4c Auto merge of #103431 - Dylan-DPC:rollup-oozfo89, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #101293 (Recover when unclosed char literal is parsed as a lifetime in some positions)
 - #101908 (Suggest let for assignment, and some code refactor)
 - #103192 (rustdoc: Eliminate uses of `EarlyDocLinkResolver::all_traits`)
 - #103226 (Check `needs_infer` before `needs_drop` during HIR generator analysis)
 - #103249 (resolve: Revert "Set effective visibilities for imports more precisely")
 - #103305 (Move some tests to more reasonable places)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-23 11:33:18 +00:00
Dylan DPC e029c1fd43
Rollup merge of #101293 - compiler-errors:lt-is-actually-char, r=estebank
Recover when unclosed char literal is parsed as a lifetime in some positions

Fixes #101278
2022-10-23 15:20:16 +05:30
Nilstrieb c65ebae221
Migrate all diagnostics 2022-10-23 10:09:44 +02:00
Michael Goulet 0270b50eb0 Recover unclosed char literal being parsed as lifetime 2022-10-22 06:57:12 +00:00
Dylan DPC e11511dfa6
Rollup merge of #103051 - davidtwco:translation-tidying-up, r=compiler-errors
translation: doc comments with derives, subdiagnostic-less enum variants, more derive use

- Adds support for `doc` attributes in the diagnostic derives so that documentation comments don't result in the derive failing.
- Adds support for enum variants in the subdiagnostic derive to not actually correspond to an addition to a diagnostic.
- Made use of the derive in more places in the `rustc_ast_lowering`, `rustc_ast_passes`, `rustc_lint`, `rustc_session`, `rustc_infer` - taking advantage of recent additions like eager subdiagnostics, multispan suggestions, etc.

cc #100717
2022-10-21 17:29:58 +05:30
Kevin Per 28d0312b7d Implement assertions and fixes to not emit empty spans without suggestions 2022-10-20 08:25:31 +00:00
mejrs 406e1dc8eb Implement -Ztrack-diagnostics 2022-10-19 00:08:20 +02:00
David Wood 21d3bbd8b6 lint: use derive more
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17 09:54:24 +01:00
Josh Triplett c5ad97da25 Use IsTerminal in rustc_errors 2022-10-16 15:10:40 +01:00
Jhonny Bill Mena be221573c8 UPDATE - Move IntoDiagnosticArg implementations to diagnostic_impls file 2022-10-12 16:55:28 -04:00
Jhonny Bill Mena 5645cd5b09 ADD - IntoDiagnostic conformance for TargetDataLayoutErrors in rustc_errors
This way we comply with the Coherence rule given that IntoDiagnostic trait is defined in rustc_errors, and almost all other crates depend on it.
2022-10-12 16:54:25 -04:00
Dylan DPC dc9f6f3243
Rollup merge of #102623 - davidtwco:translation-eager, r=compiler-errors
translation: eager translation

Part of #100717. See [Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20lists!/near/295010720) for additional context.

- **Store diagnostic arguments in a `HashMap`**: Eager translation will enable subdiagnostics to be translated multiple times with different arguments - this requires the ability to replace the value of one argument with a new value, which is better suited to a `HashMap` than the previous storage, a `Vec`.
- **Add `AddToDiagnostic::add_to_diagnostic_with`**: `AddToDiagnostic::add_to_diagnostic_with` is similar to the previous `AddToDiagnostic::add_to_diagnostic` but takes a function that can be used by the caller to modify diagnostic messages originating from the subdiagnostic (such as performing translation eagerly). `add_to_diagnostic` now just calls `add_to_diagnostic_with` with an empty closure.
- **Add `DiagnosticMessage::Eager`**: Add variant of `DiagnosticMessage` for eagerly translated messages
(messages in the target language which don't need translated by the emitter during emission). Also adds `eager_subdiagnostic` function which is intended to be invoked by the diagnostic derive for subdiagnostic fields which are marked as needing eager translation.
- **Support `#[subdiagnostic(eager)]`**: Add support for `eager` argument to the `subdiagnostic` attribute which generates a call to `eager_subdiagnostic`.
- **Finish migrating `rustc_query_system`**: Using eager translation, migrate the remaining repeated cycle stack diagnostic.
- **Split formatting initialization and use in diagnostic derives**: Diagnostic derives have previously had to take special care when ordering the generated code so that fields were not used after a move.

  This is unlikely for most fields because a field is either annotated with a subdiagnostic attribute and is thus likely a `Span` and copiable, or is a argument, in which case it is only used once by `set_arg`
anyway.

  However, format strings for code in suggestions can result in fields being used after being moved if not ordered carefully. As a result, the derive currently puts `set_arg` calls last (just before emission), such as:

      let diag = { /* create diagnostic */ };

      diag.span_suggestion_with_style(
          span,
          fluent::crate::slug,
          format!("{}", __binding_0),
          Applicability::Unknown,
          SuggestionStyle::ShowAlways
      );
      /* + other subdiagnostic additions */

      diag.set_arg("foo", __binding_0);
      /* + other `set_arg` calls */

      diag.emit();

  For eager translation, this doesn't work, as the message being translated eagerly can assume that all arguments are available - so arguments _must_ be set first.

  Format strings for suggestion code are now separated into two parts - an initialization line that performs the formatting into a variable, and a usage in the subdiagnostic addition.

  By separating these parts, the initialization can happen before arguments are set, preserving the desired order so that code compiles, while still enabling arguments to be set before subdiagnostics are added.

      let diag = { /* create diagnostic */ };

      let __code_0 = format!("{}", __binding_0);
      /* + other formatting */

      diag.set_arg("foo", __binding_0);
      /* + other `set_arg` calls */

      diag.span_suggestion_with_style(
          span,
          fluent::crate::slug,
          __code_0,
          Applicability::Unknown,
          SuggestionStyle::ShowAlways
      );
      /* + other subdiagnostic additions */

      diag.emit();

- **Remove field ordering logic in diagnostic derive:** Following the approach taken in earlier commits to separate formatting initialization from use in the subdiagnostic derive, simplify the diagnostic derive by removing the field-ordering logic that previously solved this problem.

r? ```@compiler-errors```
2022-10-12 22:13:23 +05:30
Dylan DPC 32471a7035
Rollup merge of #102110 - CleanCut:migrate_rustc_passes_diagnostics, r=davidtwco
Migrate rustc_passes diagnostics

Picks up abandoned work from https://github.com/rust-lang/rust/pull/100870

I would like to do this collaboratively, as there is a lot of work! Here's the process:

- Comment below that you are willing to help and I will add you as a collaborator to my `rust` fork (that gives you write access)
- Indicate which file/task you would like to work on (so we don't duplicate work) from the list below
- Do the work, push up a commit, comment that you're done with that file/task
- Repeat until done 😄

### Files to Migrate (in `compiler/rustc_passes/src/`)

- [x] check_attr.rs ``@CleanCut``
- [x] check_const.rs ``@CleanCut``
- [x] dead.rs ``@CleanCut``
- [x] debugger_visualizer.rs ``@CleanCut``
- [x] diagnostic_items.rs ``@CleanCut``
- [x] entry.rs ``@CleanCut``
- [x] lang_items.rs ``@CleanCut``
- [x] layout_test.rs ``@CleanCut``
- [x] lib_features.rs ``@CleanCut``
- [x] ~liveness.rs~ ``@CleanCut`` Nothing to do
- [x] loops.rs ``@CleanCut``
- [x] naked_functions.rs ``@CleanCut``
- [x] stability.rs ``@CleanCut``
- [x] weak_lang_items.rs ``@CleanCut``

### Tasks

- [x] Rebase on current `master` ``@CleanCut``
- [x] Review work from [the earlier PR](https://github.com/rust-lang/rust/pull/100870) and make sure it all looks good
  - [x] compiler/rustc_error_messages/locales/en-US/passes.ftl ``@CleanCut``
  - [x] compiler/rustc_passes/src/check_attr.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/errors.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/lang_items.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/lib.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/weak_lang_items.rs ``@CleanCut``
2022-10-12 11:11:23 +05:30
Guillaume Gomez 3416fa1882 Fix doc lint error 2022-10-10 18:28:29 +02:00
David Wood 540b203bf9 errors: `DiagnosticMessage::Eager`
Add variant of `DiagnosticMessage` for eagerly translated messages
(messages in the target language which don't need translated by the
emitter during emission). Also adds `eager_subdiagnostic` function which
is intended to be invoked by the diagnostic derive for subdiagnostic
fields which are marked as needing eager translation.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 14:20:16 +01:00
David Wood b4ac26289f errors: `AddToDiagnostic::add_to_diagnostic_with`
`AddToDiagnostic::add_to_diagnostic_with` is similar to the previous
`AddToDiagnostic::add_to_diagnostic` but takes a function that can be
used by the caller to modify diagnostic messages originating from the
subdiagnostic (such as performing translation eagerly).

`add_to_diagnostic` now just calls `add_to_diagnostic_with` with an
empty closure.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 14:20:16 +01:00
David Wood 508d7e6d26 errors: use `HashMap` to store diagnostic args
Eager translation will enable subdiagnostics to be translated multiple
times with different arguments - this requires the ability to replace
the value of one argument with a new value, which is better suited to a
`HashMap` than the previous storage, a `Vec`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 14:20:16 +01:00
Nathan Stocks a7aa1850b2 migrate dead.rs to translateable diagnostics 2022-10-07 13:19:27 -06:00
David Wood f8ebc72b4a errors: add `emit_note`/`create_note`
Add `Noted` marker struct that implements `EmissionGuarantee` so that
`emit_note` and `create_note` can be implemented for struct diagnostics.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-07 13:19:27 -06:00
bors 4bd30785eb Auto merge of #102726 - matthiaskrgr:rollup-2ghn38b, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #102672 (rustdoc: remove unused CSS class `in-band`)
 - #102693 (Revert "Use getentropy when possible on all Apple platforms")
 - #102694 (Suggest calling method if fn does not exist)
 - #102708 (Suggest `==` to wrong assign expr)
 - #102710 (Add test for issue 82633)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-06 05:58:27 +00:00
bors 0152393048 Auto merge of #99324 - reez12g:issue-99144, r=jyn514
Enable doctests in compiler/ crates

Helps with https://github.com/rust-lang/rust/issues/99144
2022-10-06 03:01:57 +00:00
Michael Goulet 66c8c5ad1d Delay function resolution error until typeck 2022-10-05 06:42:35 +00:00
Deadbeef 3cb1811e45 Compute `lint_levels` by definition 2022-10-01 16:12:50 +02:00
bors 744e397d88 Auto merge of #101986 - WaffleLapkin:move_lint_note_to_the_bottom, r=estebank
Move lint level source explanation to the bottom

So, uhhhhh

r? `@estebank`

## User-facing change

"note: `#[warn(...)]` on by default" and such are moved to the bottom of the diagnostic:
```diff
-   = note: `#[warn(unsupported_calling_conventions)]` on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
+   = note: `#[warn(unsupported_calling_conventions)]` on by default
```

Why warning is enabled is the least important thing, so it shouldn't be the first note the user reads, IMO.

## Developer-facing change

`struct_span_lint` and similar methods have a different signature.

Before: `..., impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>)`
After: `..., impl Into<DiagnosticMessage>, impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>`

The reason for this is that `struct_span_lint` needs to edit the diagnostic _after_ `decorate` closure is called. This also makes lint code a little bit nicer in my opinion.

Another option is to use `impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>) -> DiagnosticBuilder<'a, ()>` altough I don't _really_ see reasons to do `let lint = lint.build(message)` everywhere.

## Subtle problem

By moving the message outside of the closure (that may not be called if the lint is disabled) `format!(...)` is executed earlier, possibly formatting `Ty` which may call a query that trims paths that crashes the compiler if there were no warnings...

I don't think it's that big of a deal, considering that we move from `format!(...)` to `fluent` (which is lazy by-default) anyway, however this required adding a workaround which is unfortunate.

## P.S.

I'm sorry, I do not how to make this PR smaller/easier to review. Changes to the lint API affect SO MUCH 😢
2022-10-01 10:44:25 +00:00
Maybe Waffle b5b3ffe3fc Remove `LintDiagnosticBuilder` 2022-10-01 10:03:07 +00:00
Maybe Waffle a8f7e244b7 Refactor rustc lint API 2022-10-01 10:03:06 +00:00
Matthias Krüger eaf1c7a0da
Rollup merge of #102493 - nnethercote:improve-size-assertions-some-more, r=lqd
Group together more size assertions.

Also add a few more assertions for some relevant token-related types.

And fix an erroneous comment in `rustc_errors`.

r? `@lqd`
2022-09-30 23:38:27 +02:00
Matthias Krüger 9ec772e223
Rollup merge of #102373 - Nilstrieb:cannot-get-layout-of-branch-error, r=cjgillot
Flush delayed bugs before codegen

Sometimes it can happen that invalid code like a TyKind::Error makes its way through the compiler without triggering any errors (this is always a bug in rustc but bugs do happen sometimes :)). These ICEs will manifest in the backend like as cg_llvm not being able to get the layout of `[type error]`, which makes it hard to debug. By flushing before codegen, we display all the delayed bugs, making it easier to trace it to the root of the problem.

I tried this on #102366 and it showed tons of of delayed bugs and no error in cg_llvm, so it seems to be working.
2022-09-30 23:38:25 +02:00
Nicholas Nethercote 5ab68a82d5 Group together more size assertions.
Also add a few more assertions for some relevant token-related types.

And fix an erroneous comment in `rustc_errors`.
2022-10-01 07:30:23 +10:00
Matthias Krüger 25017f8bce
Rollup merge of #101075 - ellishg:rustc_codegen_gcc_diagnostics, r=davidtwco
Migrate rustc_codegen_gcc to SessionDiagnostics

As part of #100717 this pr migrates diagnostics to `SessionDiagnostics` for the `rustc_codegen_gcc` crate.

``@rustbot`` label +A-translation
2022-09-30 10:22:36 +02:00
reez12g 9a4c5abe45 Remove from compiler/ crates 2022-09-29 16:49:04 +09:00
bors 09ae7846a2 Auto merge of #101619 - Xiretza:rustc_parse-session-diagnostics, r=davidtwco
Migrate more of rustc_parse to SessionDiagnostic

Still far from complete, but I thought I'd add a checkpoint here because rebasing was starting to get annoying.
2022-09-28 11:11:42 +00:00
bors 6201eabde8 Auto merge of #102302 - nnethercote:more-lexer-improvements, r=matklad
More lexer improvements

A follow-up to #99884.

r? `@matklad`
2022-09-28 08:14:04 +00:00
Nilstrieb 8a96884981
Flush delayed bugs before codegen
Sometimes it can happen that invalid code like a TyKind::Error makes
its way through the compiler without triggering any errors (this is
always a bug in rustc but bugs do happen sometimes :)). These ICEs
will manifest in the backend like as cg_llvm not being able to get
the layout of `[type error]`, which makes it hard to debug. By flushing
before codegen, we display all the delayed bugs, making it easier to
trace it to the root of the problem.
2022-09-27 20:56:05 +02:00
Xiretza d7c64574e0 Implement IntoDiagnosticArg for rustc_ast::token::Token(Kind) 2022-09-27 20:29:19 +02:00
Xiretza 8489a67f0b Implement IntoDiagnosticArg for rustc_ast::Path 2022-09-27 20:29:18 +02:00
Pietro Albini 3975d55d98
remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Nicholas Nethercote 66e9b1149c Rearrange `TokenTreesReader::parse_token_tree`.
`parse_token_tree` is basically a match with four arms: `Eof`,
`OpenDelim`, `CloseDelim`, and "other". It has two call sites, and at
each call site one of the arms is unreachable. It's also not inlined.

This commit removes `parse_token_tree` by splitting it into four
functions and inlining them. This avoids some repeated conditional
tests and also some non-inlined function calls on the hot path.
2022-09-26 08:28:45 +10:00
Ellis Hoag 5c7e629b63 rebase and update trait names 2022-09-24 11:06:05 -07:00
Ellis Hoag fb488ad366 remove IntoDiagnosticArg impl for Option 2022-09-24 10:24:48 -07:00
Ellis Hoag 9363f0fda5 Add RanlibFailure 2022-09-24 10:24:48 -07:00
Camille GILLOT fc43df0333 Revert "Auto merge of #101620 - cjgillot:compute_lint_levels_by_def, r=oli-obk"
This reverts commit 2cb9a65684, reversing
changes made to 750bd1a7ff.
2022-09-22 19:36:11 +02:00
Jhonny Bill Mena e52e2344dc FIX - adopt new Diagnostic naming in newly migrated modules
FIX - ambiguous Diagnostic link in docs

UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic

[Gardening] FIX - formatting via `x fmt`

FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way

DELETE - unneeded allow attributes in Handler method

FIX - broken test

FIX - Rebase conflict

UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
2022-09-21 11:43:22 -04:00
Jhonny Bill Mena 5f91719f75 UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic
Also renames:
- sym::AddSubdiagnostic to sym:: Subdiagnostic
- rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21 11:39:53 -04:00
Jhonny Bill Mena a3396b2070 UPDATE - rename DiagnosticHandler macro to Diagnostic 2022-09-21 11:39:53 -04:00
Jhonny Bill Mena 191fac6826 UPDATE - rename AddSubdiagnostic trait to AddToDiagnostic 2022-09-21 11:39:53 -04:00
Jhonny Bill Mena 19b348fed4 UPDATE - rename DiagnosticHandler trait to IntoDiagnostic 2022-09-21 11:39:52 -04:00
Jhonny Bill Mena 5b8152807c UPDATE - move SessionDiagnostic from rustc_session to rustc_errors 2022-09-21 11:39:52 -04:00
Dylan DPC 4c64c14420
Rollup merge of #101790 - TaKO8Ki:do-not-suggest-placeholder-to-const-and-static-without-type, r=compiler-errors
Do not suggest a placeholder to const and static without a type

Fixes #101755
2022-09-17 15:31:08 +05:30
Takayuki Maeda 527292a1a6 do not suggest a placeholder to const and static without a type 2022-09-16 11:24:14 +09:00
est31 173eb6f407 Only enable the let_else feature on bootstrap
On later stages, the feature is already stable.

Result of running:

rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-15 21:06:45 +02:00
Deadbeef eb19a8a620 Compute `lint_levels` by definition 2022-09-14 19:02:44 +02:00
Matthias Krüger bc8ec5e5fa
Rollup merge of #101266 - LuisCardosoOliveira:translation-rustcsession-pt3, r=davidtwco
translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Final

# Description
This is the final part of the rustc_session https://github.com/rust-lang/rust/issues/100717#issuecomment-1220279883.

Please only review this [commit](a545347037). The other ones are from the PR https://github.com/rust-lang/rust/pull/101041# that is not yet merged.

In this PR, we migrate the file `output.rs`
2022-09-13 22:25:34 +02:00
Michael Goulet cd962e66cf Don't render inline suggestions of only spaces 2022-09-13 03:52:43 +00:00
Michael Goulet c2cff68d84 Don't trim substitution if it's only whitespace 2022-09-12 22:08:30 +00:00
Michael Goulet 370c816a71 A SubstitutionPart is not a deletion if it replaces nothing with nothing 2022-09-12 22:08:30 +00:00
Niklas Jonsson 8d3c30c004 rustc_error, rustc_private, rustc_ast: Switch to stable hash containers 2022-09-10 11:49:12 +02:00
Luis Cardoso 329d5014b6 translations(rustc_session): migrate output.rs 2022-09-10 08:19:17 +02:00
Dylan DPC 720a82dd52
Rollup merge of #101545 - TaKO8Ki:remove-unnecessary-partialord-ord, r=oli-obk
Remove unnecessary `PartialOrd` and `Ord`
2022-09-08 20:48:38 +05:30
Luis Cardoso 0e497a714e translations(rustc_session): migrates two diagnostics in session.rs 2022-09-08 12:22:51 +02:00
Luis Cardoso 0f06320c24 translations(rustc_session): migrate TargetDataLayout::parse 2022-09-08 08:30:57 +02:00
Takayuki Maeda bdc865d8f7 remove unnecessary `PartialOrd` and `Ord` 2022-09-08 06:15:33 +09:00
Michael Benfield d7a750b504 Use niche-filling optimization even when multiple variants have data.
Fixes #46213
2022-09-07 20:12:45 +00:00
Michael Goulet 38935bbe6a Report number of delayed bugs properly with -Ztreat-err-as-bug 2022-09-06 07:12:52 +00:00
Dylan DPC a0056795da
Rollup merge of #100928 - CleanCut:rustc_metadata_diagnostics, r=davidtwco
Migrate rustc_metadata to SessionDiagnostics

Migrate rustc_metadata to SessionDiagnostics.

Part of https://github.com/rust-lang/rust/issues/100717
2022-09-03 10:33:05 +05:30
Oli Scherer ee3c835018 Always import all tracing macros for the entire crate instead of piecemeal by module 2022-09-01 14:54:27 +00:00