Commit graph

1072 commits

Author SHA1 Message Date
Esteban Küber
72326bfe40 On long spans, trim the middle of them to make them fit in the terminal width
When encountering a single line span that is wider than the terminal, we keep context at the start and end of the span but otherwise remove the code from the middle. This is somewhat independent from whether the left and right margins of the output have been trimmed as well.

```
error[E0308]: mismatched types
  --> $DIR/long-span.rs:6:15
   |
LL | ... = [0, 0, 0, 0, ..., 0, 0];
   |       ^^^^^^^^^^^^^...^^^^^^^ expected `u8`, found `[{integer}; 1681]`
```

Address part of #137680 (missing handling of the long suggestion). Fix #125581.
2025-03-07 17:55:08 +00:00
Esteban Küber
d975bd3a67 Remove highlighting of spans on -Zteach
`-Zteach` is perma-unstable, barely used, the highlighting logic buggy and the flag being passed around is tech-debt. We should likely remove `-Zteach` in its entirely.
2025-03-07 17:55:08 +00:00
Matthias Krüger
acc7de6c77
Rollup merge of #138111 - estebank:use-dfv, r=nnethercote
Use `default_field_values` for `rustc_errors::Context`, `rustc_session::config::NextSolverConfig` and `rustc_session::config::ErrorOutputType`

Wanted to see  where `#![feature(default_field_values)]` could be used in the codebase. These three seemed like no-brainers. There are a bunch of more places where we could remove manual `Default` impls, but they `derive` other traits that rely on `syn`, which [doesn't yet support `default_field_values`](https://github.com/dtolnay/syn/issues/1774).
2025-03-07 10:12:48 +01:00
Michael Goulet
ca9f615525
Rollup merge of #137303 - compiler-errors:maybe-forgor, r=cjgillot
Remove `MaybeForgetReturn` suggestion

#115196 implemented a suggestion to add a missing `return` when there is an ambiguity error, when that ambiguity error could be constrained by the return type of the function.

I initially reviewed it and thought it could be useful; however, looking back at that code now, I feel like it's a bit too much of a hack to be worth keeping around in typeck, especially given how rare it's expected to fire in practice. This is especially true because it depends on `StashKey::MaybeForgetReturn`, which is only stashed when we have *Sized* obligation ambiguity errors. Let's remove it for now.

I'd like to note that it's basically impossible to get this suggestion to apply in its current state except for what I'd consider somewhat artificial examples, involving no generic trait bounds. For example, it's not triggered for:

```rust
struct W<T>(T);

fn bar<T: Default>() -> W<T> { todo!() }

fn foo() -> W<i32> {
    if true {
        bar();
    }
    W(0)
}
```

Nor is it triggered for:

```
fn foo() -> i32 {
    if true {
        Default::default();
    }
    0
}
```

It's basically only triggered iff there's only one ambiguity error on the type, which is `Sized`.

Generally, suggesting something that affects control flow is a pretty dramatic suggestion; therefore, both the accuracy and precision of this diagnostic should be pretty high.

One other, somewhat unrelated observation is that this might be using stashed diagnostics incorrectly (or at least unnecessarily). Stashed diagnostics are used when error detection is fragmented over several major stages of the compiler, like a parse or resolver error which later can be recovered in typeck. However, this one is a bit different since it is fully handled within typeck -- perhaps that suggests that if this were to be reimplemented, it wouldn't need to be so complicated of an implementation.
2025-03-06 12:22:10 -05:00
Esteban Küber
2a4204bf6c Use default field values in markdown::parse::Context 2025-03-03 20:04:20 +00:00
Esteban Küber
c550bee641 Fix rebase 2025-02-25 17:27:22 +00:00
Esteban Küber
a4e89deb52 add doc comment detail 2025-02-25 16:56:04 +00:00
Esteban Küber
d12ecaed55 Teach structured errors to display short Ty
Make it so that every structured error annotated with `#[derive(Diagnostic)]` that has a field of type `Ty<'_>`, the printing of that value into a `String` will look at the thread-local storage `TyCtxt` in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to.

```
error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)``
 --> long.rs:7:5
  |
6 | fn foo(x: D) { //~ `x` has type `(...
  |        - `x` has type `((..., ..., ..., ...), ..., ..., ...)`
7 |     x(); //~ ERROR expected function, found `(...
  |     ^--
  |     |
  |     call expression requires function
  |
  = note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt'
  = note: consider using `--verbose` to print the full type name to the console
```
2025-02-25 16:56:03 +00:00
bors
ad27045c31 Auto merge of #137571 - tgross35:rollup-i1tcnv1, r=tgross35
Rollup of 8 pull requests

Successful merges:

 - #134655 (Stabilize `hash_extract_if`)
 - #135933 (Explain how Vec::with_capacity is faithful)
 - #136668 (Stabilize `core::str::from_utf8_mut` as `const`)
 - #136775 (Update `String::from_raw_parts` safety requirements)
 - #137109 (stabilize extract_if)
 - #137349 (Implement `read_buf` for zkVM stdin)
 - #137493 (configure.py: don't instruct user to run nonexistent program)
 - #137516 (remove some unnecessary rustc_const_unstable)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-25 05:41:34 +00:00
Jana Dönszelmann
7e0f5b5016
Introduce new-style attribute parsers for several attributes
note: compiler compiles but librustdoc and clippy don't
2025-02-24 14:31:17 +01:00
bendn
c39f33baae
stabilize extract_if 2025-02-23 21:11:12 +07:00
Matthias Krüger
37e0d138cf
Rollup merge of #137333 - compiler-errors:edition-2024-fresh, r=Nadrieril
Use `edition = "2024"` in the compiler (redux)

Most of this is binding mode changes, which I fixed by running `x.py fix`.

Also adds some miscellaneous `unsafe` blocks for new unsafe standard library functions (the setenv ones), and a missing `unsafe extern` block in some enzyme codegen code, and fixes some precise capturing lifetime changes (but only when they led to errors).

cc ``@ehuss`` ``@traviscross``
2025-02-22 11:36:43 +01:00
Michael Goulet
9323ba54d3 Remove MaybeForgetReturn suggestion 2025-02-22 00:04:26 +00:00
Michael Goulet
76d341fa09 Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
Michael Goulet
160905b625 Trim suggestion part before generating highlights 2025-02-21 00:54:01 +00:00
Michael Goulet
0a7ab1d6df More sophisticated span trimming 2025-02-21 00:41:17 +00:00
Ben Kimock
4cf21866e8 Move hashes from rustc_data_structure to rustc_hashes so they can be shared with rust-analyzer 2025-02-16 16:18:30 -05:00
Michael Goulet
6d71251cf9 Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
Michael Goulet
f6406dfd4e Consider add-prefix replacements too 2025-02-14 00:27:17 -08:00
Michael Goulet
b480a9214a Use underline suggestions for purely 'additive' replacements 2025-02-14 00:27:13 -08:00
Jubilee Young
32fd1a7b72 compiler: replace ExternAbi::name calls with formatters
Most of these just format the ABI string, so... just format ExternAbi?
This makes it more consistent and less jank when we can do it.
2025-02-11 19:42:47 -08:00
Matthias Krüger
89ee41cc4c
Rollup merge of #136847 - nnethercote:simplify-intra-crate-quals, r=oli-obk
Simplify intra-crate qualifiers.

The following is a weird pattern for a file within `rustc_middle`:
```
use rustc_middle::aaa;
use crate::bbb;
```
More sensible and standard would be this:
```
use crate::{aaa, bbb};
```
I.e. we generally prefer using `crate::` to using a crate's own name. (Exceptions are things like in macros where `crate::` doesn't work because the macro is used in multiple crates.)

This commit fixes a bunch of these weird qualifiers.

r? `@jieyouxu`
2025-02-11 18:04:49 +01:00
Nicholas Nethercote
af6020320d Simplify intra-crate qualifiers.
The following is a weird pattern for a file within `rustc_middle`:
```
use rustc_middle::aaa;
use crate::bbb;
```
More sensible and standard would be this:
```
use crate::{aaa, bbb};
```
I.e. we generally prefer using `crate::` to using a crate's own name.
(Exceptions are things like in macros where `crate::` doesn't work
because the macro is used in multiple crates.)

This commit fixes a bunch of these weird qualifiers.
2025-02-11 14:59:13 +11:00
Esteban Küber
f0845adb0c Show diff suggestion format on verbose replacement
```
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
  --> $DIR/attempted-access-non-fatal.rs:7:15
   |
LL |     let _ = 2.l;
   |               ^
   |
help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix
   |
LL -     let _ = 2.l;
LL +     let _ = 2.0f64;
   |
```
2025-02-10 20:21:39 +00:00
bjorn3
1fcae03369 Rustfmt 2025-02-08 22:12:13 +00:00
Matthias Krüger
79e5424e31
Rollup merge of #136636 - bjorn3:error_cleanup, r=compiler-errors
Couple of minor cleanups to the diagnostic infrastructure
2025-02-06 21:56:28 +01:00
Matthias Krüger
3eb1ef836e
Rollup merge of #136580 - bjorn3:miri_fixes, r=lqd
Couple of changes to run rustc in miri

This is not the full set of patches required to run rustc in miri, but it is the fast majority of the changes to rustc itself. There is also a change to the jobserver crate necessary and on arm64 a change to the memchr crate. Running rustc in miri has already found some UB: https://github.com/rust-lang/rust/pull/136579

cc https://github.com/rust-lang/rust/issues/135870#issuecomment-2612470540
2025-02-06 21:56:27 +01:00
bjorn3
8a0adec05b Avoid manually producing FatalError in a couple of places 2025-02-06 17:29:15 +00:00
bjorn3
e27495c015 Couple of changes to run rustc in miri 2025-02-05 13:52:22 +00:00
Askar Safin
0a21f1d0a2 tree-wide: parallel: Fully removed all Lrc, replaced with Arc 2025-02-03 13:25:57 +03:00
Matthias Krüger
f1bdf3ba4a
Rollup merge of #136445 - bjorn3:diag_ctxt_cleanup, r=oli-obk
Couple of cleanups to DiagCtxt and EarlyDiagCtxt
2025-02-02 23:06:57 +01:00
Matthias Krüger
7e3d872bc0
Rollup merge of #136415 - estebank:highlight-clarification, r=compiler-errors
Highlight clarifying information in "expected/found" error

When the expected and found types have the same textual representation, we add clarifying in parentheses. We now visually highlight it in the output.

Detect a corner case where the clarifying information would be the same for both types and skip it, as it doesn't add anything useful.

![Screenshot of the rustc highlighted output on the terminal](https://github.com/user-attachments/assets/aa4b9433-5332-4941-b2c2-1a43e5cadff7)
2025-02-02 18:05:24 +01:00
bjorn3
6a566ee092 Replace ParseSess::set_dcx with DiagCtxt::set_emitter
Replacing the error emitter doesn't accidentally clear the error count.
2025-02-02 16:09:39 +00:00
bjorn3
6556147d15 Use fallback fluent bundle from inner emitter in SilentEmitter 2025-02-02 16:06:43 +00:00
bjorn3
aa2b870bb5 Slightly simplify DiagCtxt::make_silent 2025-02-02 16:06:43 +00:00
Matthias Krüger
3559a48b8e
Rollup merge of #136368 - estebank:listify, r=fee1-dead
Make comma separated lists of anything easier to make for errors

Provide a new function `listify`, meant to be used in cases similar to `pluralize!`. When you have a slice of arbitrary elements that need to be presented to the user, `listify` allows you to turn that into a list of comma separated strings.

This reduces a lot of redundant logic that happens often in diagnostics.
2025-02-02 12:31:57 +01:00
Esteban Küber
c75e601543 Highlight clarifying information in "expected/found" error
When the expected and found types have the same textual representation, we add clarifying in parentheses. We now visually highlight it in the output.

Detect a corner case where the clarifying information would be the same for both types and skip it, as it doesn't add anything useful.
2025-02-02 02:39:43 +00:00
Esteban Küber
0751e9036a Rework "long type names" printing logic
Make it so more type-system types can be printed in a shortened version (like `Predicate`s).

Centralize printing the information about the "full type name path".

Make the "long type path" for the file where long types are written part of `Diag`, so that it becomes easier to keep track of it, and ensure it will always will be printed out last in the diagnostic by making its addition to the output implicit.

Tweak the shortening of types in "expected/found" labels.

Remove dead file `note.rs`.
2025-01-31 20:39:01 +00:00
Esteban Küber
8e9422f94e Make comma separated lists of anything easier to make for errors
Provide a new function `listify`, meant to be used in cases similar to `pluralize!`. When you have a slice of arbitrary elements that need to be presented to the user, `listify` allows you to turn that into a list of comma separated strings.

This reduces a lot of redundant logic that happens often in diagnostics.
2025-01-31 20:36:44 +00:00
bors
f7cc13af82 Auto merge of #119286 - jyn514:linker-output, r=bjorn3
show linker output even if the linker succeeds

Show stderr and stderr by default, controlled by a new `linker_messages` lint.

fixes https://github.com/rust-lang/rust/issues/83436. fixes https://github.com/rust-lang/rust/issues/38206. cc 408986134

<!-- try-job: dist-x86_64-msvc -->
try-job: aarch64-apple

r? `@bjorn3`
2025-01-25 17:16:33 +00:00
klensy
84ce2e129a bumpt compiler and tools to windows 0.59 2025-01-21 16:48:44 +03:00
jyn
b757663a00 don't ICE when emitting linker errors during -Z link-only
note that this still ICEs when passed `-Z link-only --error-format json` because i can't be bothered to fix it right now
2025-01-20 16:46:45 -05:00
Yotam Ofek
1951d86a35 Manual cleanup of some is_{or_none|some_and} usages 2025-01-19 20:50:43 +00:00
Yotam Ofek
264fa0fc54 Run clippy --fix for unnecessary_map_or lint 2025-01-19 19:15:00 +00:00
bors
7bb9888953 Auto merge of #135402 - matthiaskrgr:rollup-cz7hs13, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #129259 (Add inherent versions of MaybeUninit methods for slices)
 - #135374 (Suggest typo fix when trait path expression is typo'ed)
 - #135377 (Make MIR cleanup for functions with impossible predicates into a real MIR pass)
 - #135378 (Remove a bunch of diagnostic stashing that doesn't do anything)
 - #135397 (compiletest: add erroneous variant to `string_enum`s conversions error)
 - #135398 (add more crash tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-12 14:43:10 +00:00
Michael Goulet
85c9ce6d79 Remove a bunch of diagnostic stashing that doesn't do anything 2025-01-11 19:22:06 +00:00
Yotam Ofek
86d2129a78 fix it's -> its in doc comment 2025-01-11 13:16:56 +00:00
Michael Goulet
aea2a6f836 Convert some Into impls into From impls 2024-12-31 01:56:33 +00:00
Esteban Küber
12d66d9506 Account for removal of multiline span in suggestion
When highlighting the removed parts of a suggestion, properly account for spans that cover more than one line.

Fix #134485.
2024-12-26 17:41:43 +00:00
DianQK
1652e3a560
Rollup merge of #134366 - harrisonkaiser:no-break-space, r=davidtwco
Fix logical error with what text is considered whitespace.

There appears to be a logical issue around what counts as leading white-space. There is code which does a subtraction assuming that no errors will be reported inside the leading whitespace. However we compute the length of that whitespace with std::char::is_whitespace and not rustc_lexer::is_whitespace. The former will include a no-break space while later will excluded it. We can only safely make the assumption that no errors will be reported  in whitespace if it is all "Rust Standard" whitespace. Indeed an error does occur in unicode whitespace if it contains a no-break space. In that case the subtraction will cause a ICE (for a compiler in debug mode) as described in https://github.com/rust-lang/rust/issues/132918.
2024-12-20 21:46:59 +08:00