Commit Graph

217865 Commits

Author SHA1 Message Date
Dylan DPC
e781a6ff3b
Rollup merge of #108105 - majaha:patch-1, r=cuviper
Explain the default panic hook better

This changes the documentation of `std::panic::set_hook` and `take_hook` to explain how the default panic hook works. In particular the fact that `take_hook` registers the default hook, rather than no hook at all, was missing from the docs.

I also reworded a few things for clarity.
2023-02-21 14:19:59 +05:30
Dylan DPC
4dea3a295f
Rollup merge of #108000 - y21:no-zero-init-for-uninhabited, r=jackh726
lint: don't suggest MaybeUninit::assume_init for uninhabited types

Creating a zeroed uninhabited type such as `!` or an empty enum with `mem::zeroed()` (or transmuting `()` to `!`) currently triggers this lint:
```rs
warning: the type `!` does not permit zero-initialization
 --> test.rs:5:23
  |
5 |         let _val: ! = mem::zeroed();
  |                       ^^^^^^^^^^^^^
  |                       |
  |                       this code causes undefined behavior when executed
  |                       help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
  |
  = note: the `!` type has no valid value
```
The `MaybeUninit` suggestion in the help message seems confusing/useless for uninhabited types, as such a type cannot be fully initialized in the first place (as the note implies).
This PR limits this help message to inhabited types which can be initialized
2023-02-21 14:19:58 +05:30
bors
f715e430aa Auto merge of #107728 - RalfJung:miri-dyn-star, r=RalfJung,oli-obk
Miri: basic dyn* support

As usual I am very unsure about the dynamic dispatch stuff, but it passes even the `Pin<&mut dyn* Trait>` test so that is something.

TBH I think it was a mistake to make `dyn Trait` and `dyn* Trait` part of the same `TyKind` variant. Almost everywhere in Miri this lead to the wrong default behavior, resulting in strange ICEs instead of nice "unimplemented" messages. The two types describe pretty different runtime data layout after all.

Strangely I did not need to do the equivalent of [this diff](https://github.com/rust-lang/rust/pull/106532#discussion_r1087095963) in Miri. Maybe that is because the unsizing logic matches on `ty::Dynamic(.., ty::Dyn)` already? In `unsized_info` I don't think the `target_dyn_kind` can be `DynStar`, since then it wouldn't be unsized!

r? `@oli-obk` Cc `@eholk` (dyn-star) https://github.com/rust-lang/rust/issues/102425
2023-02-21 04:22:23 +00:00
bors
2deff71719 Auto merge of #105462 - oli-obk:feeding_full, r=cjgillot,petrochenkov
give the resolver access to TyCtxt

The resolver is now created after TyCtxt is created. Then macro expansion and name resolution are run and the results fed into queries just like before this PR.

Since the resolver had (before this PR) mutable access to the `CStore` and the source span table, these two datastructures are now behind a `RwLock`. To ensure that these are not mutated anymore after the resolver is done, a read lock to them is leaked right after the resolver finishes.

### PRs split out of this one and leading up to it:

* https://github.com/rust-lang/rust/pull/105423
* https://github.com/rust-lang/rust/pull/105357
* https://github.com/rust-lang/rust/pull/105603
* https://github.com/rust-lang/rust/pull/106776
* https://github.com/rust-lang/rust/pull/106810
* https://github.com/rust-lang/rust/pull/106812
* https://github.com/rust-lang/rust/pull/108032
2023-02-21 01:19:25 +00:00
Matt Harding
ec9a4ce19e Explain the default panic hook better
This changes the documentation of `std::panic::set_hook` and `take_hook` to better explain how the default panic hook works. In particular the fact that `take_hook` registers the default hook, rather than no hook at all, was missing from the docs.
2023-02-20 23:37:19 +00:00
bors
8f55d6025f Auto merge of #108286 - matthiaskrgr:rollup-dwy99rf, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #108241 (Fix handling of reexported macro in doc hidden items)
 - #108254 (Refine error span for trait error into borrowed expression)
 - #108255 (Remove old FIXMEs referring to #19596)
 - #108257 (Remove old FIXME that no longer applies)
 - #108276 (small `opaque_type_origin` cleanup)
 - #108279 (Use named arguments for `{,u}int_impls` macro)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-20 22:01:48 +00:00
Matthias Krüger
4f532dacfc
Rollup merge of #108279 - Nilstrieb:int, r=scottmcm
Use named arguments for `{,u}int_impls` macro

This makes it way easier to understand.

r? `@scottmcm`
2023-02-20 22:12:20 +01:00
Matthias Krüger
ea7ca705e6
Rollup merge of #108276 - lcnr:opaque-tys, r=oli-obk
small `opaque_type_origin` cleanup

r? `@oli-obk`
2023-02-20 22:12:20 +01:00
Matthias Krüger
02842d4f69
Rollup merge of #108257 - fee1-dead-contrib:fixme-1, r=tmiasko
Remove old FIXME that no longer applies

it looks like Encodable was fallible at some point, but that was changed which means that this FIXME is no longer applicable
2023-02-20 22:12:19 +01:00
Matthias Krüger
7022ae4f8c
Rollup merge of #108255 - fee1-dead-contrib:fix-old-fixme, r=cjgillot
Remove old FIXMEs referring to #19596

Having an inner function that accepts a mutable reference seems to be the only way this can be expressed. Taking a mutable reference would call the same function with a new type &mut F which then causes the infinite recursion error in #19596.
2023-02-20 22:12:18 +01:00
Matthias Krüger
194d52cc18
Rollup merge of #108254 - Nathan-Fenner:nathanf/error-span-ref-trait-refine, r=WaffleLapkin
Refine error span for trait error into borrowed expression

Extends the error span refinement in #106477 to drill into borrowed expressions just like tuples/struct/enum literals. For example,

```rs
trait Fancy {}
trait Good {}
impl <'a, T> Fancy for &'a T where T: Good {}
impl <S> Good for Option<S> where S: Iterator {}

fn want_fancy<F>(f: F) where F: Fancy {}

fn example() {
    want_fancy(&Some(5));
//  (BEFORE)   ^^^^^^^^ `{integer}` is not an iterator
//  (AFTER)          ^  `{integer}` is not an iterator
}
```

Existing heuristics try to find the right part of the expression to "point at"; current heuristics look at e.g. struct constructors and tuples. This PR adds a new check for borrowed expressions when looking into a borrowed type.
2023-02-20 22:12:18 +01:00
Matthias Krüger
52fa8fe376
Rollup merge of #108241 - GuillaumeGomez:fix-reexported-macro-handling, r=notriddle
Fix handling of reexported macro in doc hidden items

Fixes https://github.com/rust-lang/rust/issues/108231.
Fixes #59368.

r? `@notriddle`
2023-02-20 22:12:17 +01:00
Guillaume Gomez
fc6a05c463 Add test for reexported hidden macro 2023-02-20 20:19:21 +01:00
Guillaume Gomez
e2d9dee9eb Add regression test for #108231 2023-02-20 20:19:21 +01:00
Guillaume Gomez
24b23aa958 Fix handling of reexported macro in doc hidden items 2023-02-20 20:19:21 +01:00
bors
5243ea5c29 Auto merge of #108260 - lnicola:rust-analyzer-2023-02-20, r=lnicola
⬆️ rust-analyzer

r? `@ghost`
2023-02-20 19:04:51 +00:00
Nilstrieb
eb5d82bc9c Use named arguments for int_impl macro
This makes it easier to understand.
2023-02-20 18:18:49 +00:00
Nilstrieb
d3b46bb74e Use named arguments for uint_impl macro
This makes it easier to understand.
2023-02-20 18:10:51 +00:00
lcnr
f97a8f017d small opaque_type_origin cleanup 2023-02-20 18:00:57 +01:00
bors
8973049549 Auto merge of #108268 - matthiaskrgr:rollup-4tdvnx6, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #108124 (Document that CStr::as_ptr returns a type alias)
 - #108171 (Improve building compiler artifacts output)
 - #108200 (Use restricted Damerau-Levenshtein distance for diagnostics)
 - #108259 (remove FIXME that doesn't require fixing)
 - #108265 ("`const` generic" -> "const parameter")

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-20 16:19:06 +00:00
Oli Scherer
0847b79ada Remove ResolverTree 2023-02-20 15:28:59 +00:00
Oli Scherer
2a47113efa Remove IntoDefIdTree 2023-02-20 15:28:59 +00:00
Oli Scherer
1ab14ea7c2 Remove some unnecessary tcx-passing 2023-02-20 15:28:59 +00:00
Oli Scherer
acbcfaaf7b Stop passing in values that one can also get from the tcx lazily 2023-02-20 15:28:59 +00:00
Oli Scherer
c3522d0637 Move the resolver into a query 2023-02-20 15:28:59 +00:00
Oli Scherer
37e2f4f487 Make configure_and_expand "infalllible" by just aborting the compilation if it fails instead of bubbling out an error 2023-02-20 15:28:59 +00:00
Oli Scherer
63c8d00090 Use tcx queries instead of passing the values to configure_and_expand. 2023-02-20 15:28:59 +00:00
Oli Scherer
1202fce40e Remove definitions field that is only needed for one method 2023-02-20 15:28:59 +00:00
Oli Scherer
4953d70e2f Stuff a TyCtxt into the Resolver 2023-02-20 15:28:59 +00:00
Oli Scherer
9fb91b8742 Remove a redundant function argument 2023-02-20 15:28:58 +00:00
Oli Scherer
8f132d8549 Run the resolver after TyCtxt construction 2023-02-20 15:28:58 +00:00
Oli Scherer
6924e3c374 Make untracked.source_span lockable so that resolution can still write to it when using TyCtxt 2023-02-20 15:28:58 +00:00
Oli Scherer
ade3dceb38 Make untracked.cstore lockable so that resolution can still write to it when using TyCtxt 2023-02-20 15:28:58 +00:00
Oli Scherer
054c76d658 Revert most of the custom place computation, it was unnecessary. 2023-02-20 14:56:44 +00:00
Oli Scherer
82f1e341a3 Remove commented out code 2023-02-20 14:11:38 +00:00
Oli Scherer
472059d854 Deduplicate some logic between dyn* and dyn 2023-02-20 14:11:38 +00:00
Ralf Jung
ad6dd60396 fix Stacked Borrows interaction with dyn* 2023-02-20 15:08:05 +01:00
Ralf Jung
57056d7f8f slightly beef up dyn-star-to-dyn test 2023-02-20 15:08:05 +01:00
Ralf Jung
b2f58146b9 basic dyn* support for Miri 2023-02-20 15:08:05 +01:00
Matthias Krüger
e4dadd6416
Rollup merge of #108265 - lcnr:cg-error-msg, r=BoxyUwU
"`const` generic" -> "const parameter"
2023-02-20 14:32:56 +01:00
Matthias Krüger
133afeb6e3
Rollup merge of #108259 - fee1-dead-contrib:fixme-2, r=TaKO8Ki
remove FIXME that doesn't require fixing
2023-02-20 14:32:55 +01:00
Matthias Krüger
226ce31edd
Rollup merge of #108200 - jhpratt:restricted-damerau-levenshtein-distance, r=tmiasko
Use restricted Damerau-Levenshtein distance for diagnostics

This replaces the existing Levenshtein algorithm with the Damerau-Levenshtein algorithm. This means that "ab" to "ba" is one change (a transposition) instead of two (a deletion and insertion). More specifically, this is a _restricted_ implementation, in that "ca" to "abc" cannot be performed as "ca" → "ac" → "abc", as there is an insertion in the middle of a transposition. I believe that errors like that are sufficiently rare that it's not worth taking into account.

This was first brought up [on IRLO](https://internals.rust-lang.org/t/18227) when it was noticed that the diagnostic for `prinltn!` (transposed L and T) was `print!` and not `println!`. Only a single existing UI test was effected, with the result being an objective improvement.

~~I have left the method name and various other references to the Levenshtein algorithm untouched, as the exact manner in which the edit distance is calculated should not be relevant to the caller.~~

r? ``@estebank``

``@rustbot`` label +A-diagnostics +C-enhancement
2023-02-20 14:32:55 +01:00
Matthias Krüger
1f5c2b1efd
Rollup merge of #108171 - mattjperez:compiler-artifacts-output, r=jyn514
Improve building compiler artifacts output

Fixes #108051

``@Manishearth,`` ``@jyn514`` mentioned you might be interested in these changes to the outputs.
2023-02-20 14:32:54 +01:00
Matthias Krüger
fde38f1174
Rollup merge of #108124 - kornelski:cstr_c_char, r=thomcc
Document that CStr::as_ptr returns a type alias

Rustdoc resolves type aliases too eagerly #15823 which makes the [std re-export](https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.as_ptr) of `CStr::as_ptr` show `i8` instead of `c_char`. To work around this I've added info about `c_char` in the method's description.

BTW, I've also added a comment to what-not-to-do example in case someone copypasted it without reading the surrounding text.
2023-02-20 14:32:54 +01:00
bors
267cd1d2c5 Auto merge of #107721 - megakorre:issue_105700, r=petrochenkov
create dummy placeholder crate to prevent compiler from panicing

This PR is to address the panic found in https://github.com/rust-lang/rust/issues/105700.

There are 2 separate things going on with this panic.
First the code could not generate a dummy response for crate fragment types when it hits the recursion limit.
This PR adds the method to the trait implementation for `DymmyResult` to be able to create a dummy crate node.
This stops the panic from happening.

The second thing that is not addressed (and maybe does not need addressing? 🤷🏻)
is that when you have multiple attributes it ends up treating attributes that follow another as being the result of expanding the former (maybe there is a better way to say that). So you end up hitting the recursion limit. Even though you would think there is no expansion happening here.

If you did not hit the recursion limit the compiler would output that `invalid_attribute` does not exists. But it currently exits before the resolution step when the recursion limit is reached here.
2023-02-20 13:23:47 +00:00
lcnr
2cbe583593 const generic -> const parameter in err msg 2023-02-20 12:58:11 +01:00
Oli Scherer
e8e227aec8 Prepare crate loader for LockGuard 2023-02-20 10:49:42 +00:00
Oli Scherer
d191de63f0 Prepare for adding a TyCtxt to Resolver 2023-02-20 10:38:48 +00:00
bors
e7eaed21d5 Auto merge of #107969 - b-naber:proj-relate-variance, r=lcnr
Use covariance on type relations of field projection types if possible

It's fine to use covariance here unless we're in a mutating context.

Fixes https://github.com/rust-lang/rust/issues/96514

Supersedes https://github.com/rust-lang/rust/pull/105958

r? `@lcnr`
2023-02-20 09:25:51 +00:00
Patrik Kårlin
0fd2a70b90
create dummy placeholder crate to prevent compiler 2023-02-20 10:20:57 +01:00