Commit Graph

169319 Commits

Author SHA1 Message Date
Dylan DPC
5549d50ccf
Rollup merge of #97681 - GuillaumeGomez:more-eslint, r=Dylan-DPC
Add more eslint checks

A new batch of eslint rules:

 * [no-fallthrough](https://eslint.org/docs/rules/no-fallthrough)
 * [no-invalid-regexp](https://eslint.org/docs/rules/no-invalid-regexp)
 * [no-import-assign](https://eslint.org/docs/rules/no-import-assign)
 * [no-self-compare](https://eslint.org/docs/rules/no-self-compare)
 * [no-template-curly-in-string](https://eslint.org/docs/rules/no-template-curly-in-string)
 * [block-scoped-var](https://eslint.org/docs/rules/block-scoped-var)
 * [guard-for-in](https://eslint.org/docs/rules/guard-for-in)
 * [no-alert](https://eslint.org/docs/rules/no-alert)

r? ``@notriddle``
2022-06-03 17:10:53 +02:00
Dylan DPC
6b80b151b9
Rollup merge of #97471 - estebank:prohibit-generics, r=cjgillot
Provide more context when denying invalid type params
2022-06-03 17:10:52 +02:00
Dylan DPC
53ab3b2e6e
Rollup merge of #97415 - cjgillot:is-late-bound-solo, r=estebank
Compute `is_late_bound_map` query separately from lifetime resolution

This query is actually very simple, and is only useful for functions and method.  It can be computed directly by fetching the HIR, with no need to embed it within the lifetime resolution visitor.

Based on https://github.com/rust-lang/rust/pull/96296
2022-06-03 17:10:51 +02:00
Camille GILLOT
ba40fe99c3 Compute is_late_bound in a separate query.
The computation is actually much simpler, and can be done by directly
fetching the HIR for the `FnDecl` and its generics.
2022-06-03 12:05:04 +02:00
Camille GILLOT
b1294e86bb Manipulate lifetimes by LocalDefId for region resolution. 2022-06-03 12:03:20 +02:00
bors
72f7e3144a Auto merge of #97679 - Dylan-DPC:rollup-nswmgmx, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #97366 (Stabilize `{slice,array}::from_ref`)
 - #97653 (add cast kind of from_exposed_addr (int-to-ptr casts))
 - #97663 (take back half-baked noaliasing check in Assignment)
 - #97664 (On E0204 suggest missing type param bounds)
 - #97668 (rustdoc: clean up primitive.slice.html links)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-03 09:56:21 +00:00
Guillaume Gomez
6ce2e052e1 Add "no-alert" eslint rule 2022-06-03 11:29:49 +02:00
Guillaume Gomez
7db2b00be3 Add "guard-for-in" eslint rule 2022-06-03 11:28:34 +02:00
Guillaume Gomez
1e4a149823 Add "block-scoped-var" eslint rule 2022-06-03 11:20:46 +02:00
Dylan DPC
d6f35b3454
Rollup merge of #97668 - notriddle:notriddle/slice-link, r=jsha
rustdoc: clean up primitive.slice.html links

Before: <a href="https://doc.rust-lang.org/stable/std/boxed/struct.Box.html">Box</a>&lt;<a href="https://doc.rust-lang.org/stable/std/primitive.slice.html">[</a>T<a href="https://doc.rust-lang.org/stable/std/primitive.slice.html">]</a>&gt;

After: <a href="https://doc.rust-lang.org/stable/std/boxed/struct.Box.html">Box</a>&lt;<a href="https://doc.rust-lang.org/stable/std/primitive.slice.html">[T]</a>&gt;
2022-06-03 11:18:27 +02:00
Dylan DPC
b71ddd6861
Rollup merge of #97664 - estebank:suggest-bound-derive-copy, r=compiler-errors
On E0204 suggest missing type param bounds

```
error[E0204]: the trait `Copy` may not be implemented for this type
  --> f42.rs:9:17
   |
9  | #[derive(Debug, Copy, Clone)]
   |                 ^^^^
10 | pub struct AABB<K>{
11 |     pub loc: Vector2<K>,
   |     ------------------- this field does not implement `Copy`
12 |     pub size: Vector2<K>
   |     -------------------- this field does not implement `Copy`
   |
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
  --> f42.rs:11:5
   |
11 |     pub loc: Vector2<K>,
   |     ^^^^^^^^^^^^^^^^^^^
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
  --> f42.rs:12:5
   |
12 |     pub size: Vector2<K>
   |     ^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `K`
   |
10 | pub struct AABB<K: Debug>{
   |                  +++++++
```

Fix #89137.
2022-06-03 11:18:26 +02:00
Dylan DPC
a6d7939855
Rollup merge of #97663 - RalfJung:keine-halben-sachen, r=oli-obk
take back half-baked noaliasing check in Assignment

Doing an aliasing check in `copy_op` does not make a ton of sense. We have to eventually do something in the `Assignment` statement handling instead.
2022-06-03 11:18:25 +02:00
Dylan DPC
f116dd76ed
Rollup merge of #97653 - RalfJung:int-to-ptr, r=oli-obk
add cast kind of from_exposed_addr (int-to-ptr casts)

This is basically the dual to https://github.com/rust-lang/rust/pull/97582, for int2ptr casts.

Cc `@tmiasko` https://github.com/rust-lang/rust/issues/97649
2022-06-03 11:18:24 +02:00
Dylan DPC
025cf96615
Rollup merge of #97366 - WaffleLapkin:stabilize_array_slice_from_ref, r=dtolnay
Stabilize `{slice,array}::from_ref`

This PR stabilizes the following APIs as `const` functions in Rust `1.63`:
```rust
// core::array
pub const fn from_ref<T>(s: &T) -> &[T; 1];

// core::slice
pub const fn from_ref<T>(s: &T) -> &[T];
```

Note that the `mut` versions are not stabilized as unique references (`&mut _`) are [unstable in const context].

FCP: https://github.com/rust-lang/rust/issues/90206#issuecomment-1134586665

r? rust-lang/libs-api `@rustbot` label +T-libs-api -T-libs

[unstable in const context]: https://github.com/rust-lang/rust/issues/57349
2022-06-03 11:18:23 +02:00
Guillaume Gomez
72bd8e4996 Add "no-template-curly-in-string" eslint rule 2022-06-03 11:16:23 +02:00
Guillaume Gomez
584eec6c26 Add "no-self-compare" eslint rule 2022-06-03 11:14:07 +02:00
Guillaume Gomez
e7d1b5a952 Add "no-import-assign" eslint rule 2022-06-03 11:13:42 +02:00
Guillaume Gomez
fe503adf4c Add "no-invalid-regexp" eslint rule 2022-06-03 11:11:33 +02:00
Guillaume Gomez
e0cbac6a39 Add "no-fallthrough" eslint rule 2022-06-03 11:09:23 +02:00
bors
3a90bedb33 Auto merge of #96296 - cjgillot:remove-label-lt-shadow, r=petrochenkov
Remove label/lifetime shadowing warnings

This PR removes some pre-1.0 shadowing warnings for labels and lifetimes.

The current behaviour of the compiler is to warn
* labels that shadow unrelated labels in the same function --> removed
```rust
'a: loop {}
'a: loop {} // STOP WARNING
```

* labels that shadow enclosing labels --> kept, but only if shadowing is hygienic
```rust
'a: loop {
  'a: loop {} // KEEP WARNING
}
```

* labels that shadow lifetime --> removed
```rust
fn foo<'a>() {
  'a: loop {} // STOP WARNING
}
```

* lifetimes that shadow labels --> removed
```rust
'a: loop {
  let b = Box::new(|x: &i8| *x) as Box<dyn for <'a> Fn(&'a i8) -> i8>; // STOP WARNING
}
```

* lifetimes that shadow lifetimes --> kept
```rust
fn foo<'a>() {
  let b = Box::new(|x: &i8| *x) as Box<dyn for <'a> Fn(&'a i8) -> i8>; // KEEP WARNING
}
```

Closes https://github.com/rust-lang/rust/issues/31745.

-----

From `@petrochenkov` in https://github.com/rust-lang/rust/pull/95781#issuecomment-1105199014
> I think we should remove these silly checks entirely.
> They were introduced long time ago in case some new language features appear and require this space.
> Now we have another mechanism for such language changes - editions, and if "lifetimes in expressions" or something like that needs to be introduced it could be introduced as an edition change.
> However, there was no plans to introduce anything like for years, so it's unlikely that even the edition mechanism will be necessary.

r? rust-lang/lang
2022-06-03 07:27:09 +00:00
Camille GILLOT
2aa9c703ce Use the same message as type & const generics. 2022-06-03 08:26:10 +02:00
Camille GILLOT
86bd99060c Reuse resolve_label to check lifetime shadowing. 2022-06-03 08:26:10 +02:00
Camille GILLOT
c75409d5e4 Do not lower generic lifetime params when AST resolution emitted an error. 2022-06-03 08:26:10 +02:00
bors
f5507aa881 Auto merge of #97497 - c410-f3r:z-errors, r=petrochenkov
Move some tests to more reasonable places

r? `@petrochenkov`
2022-06-03 04:46:10 +00:00
bors
20ad820928 Auto merge of #97667 - matthiaskrgr:rollup-5cfxc85, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #97502 (rustdoc: Add more test coverage)
 - #97627 (update explicit impls error msg)
 - #97640 (Fix wrong suggestion for adding where clauses)
 - #97645 (don't use a `span_note` for ignored impls)
 - #97655 (Improve documentation for constructors of pinned `Box`es)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-03 00:21:29 +00:00
Esteban Küber
cd8cfbfb09 review comments 2022-06-02 15:29:20 -07:00
Esteban Küber
f9aa2e02cd Tweak output 2022-06-02 15:04:46 -07:00
Michael Howell
dadf3bdeff rustdoc: add channel normalization to htmldocck.py 2022-06-02 15:02:26 -07:00
Michael Howell
7dd3861235 rustdoc: clean up primitive.slice.html links 2022-06-02 15:02:19 -07:00
Matthias Krüger
5b64aab2b6
Rollup merge of #97655 - steffahn:better-pin-box-construction-docs, r=thomcc
Improve documentation for constructors of pinned `Box`es

Adds a cross-references between `Box::pin` and `Box::into_pin` (and other related methods, i.e. the equivalent `From` implementation, and the unstable `pin_in` method), in particular now that `into_pin` [was stabilized](https://github.com/rust-lang/rust/pull/97397). The main goal is to further improve visibility of the fact that `Box<T> -> Pin<Box<T>>` conversion exits in the first place, and that `Box::pin(x)` is – essentially – just a convenience function for `Box::into_pin(Box::new(x))`

The motivating context why I think this is important is even experienced Rust users overlooking the existence this kind of conversion, [e.g. in this thread on IRLO](https://internals.rust-lang.org/t/pre-rfc-function-variants/16732/7?u=steffahn); and also the fact that that discussion brought up that there would be a bunch of Box-construction methods "missing" such as e.g. methods with fallible allocation a la "`Box::try_pin`", and similar; while those are in fact *not* necessary, because you can use `Box::into_pin(Box::try_new(x)?)` instead.

I have *not* included explicit mention of methods (e.g. `try_new`) in the docs of stable methods (e.g. `into_pin`). (Referring to unstable API in stable API docs would be bad style IMO.) Stable examples I have in mind with the statement "constructing a (pinned) Box in a different way than with `Box::new`" are things like cloning a `Box`, or `Box::from_raw`. If/when `try_new` would get stabilized, it would become a very good concrete example use-case of `Box::into_pin` IMO.
2022-06-02 23:39:07 +02:00
Matthias Krüger
d1ae3a4c3b
Rollup merge of #97645 - lcnr:derived-impl-debug, r=cjgillot
don't use a `span_note` for ignored impls

Searching for the `derive` isn't too difficult as it's right above the field definition.

By using a span these errors are a lot more verbose than they should be, which is especially annoying as one can end up with a lot of `dead_code` warnings.
2022-06-02 23:39:06 +02:00
Matthias Krüger
0e33e97fc7
Rollup merge of #97640 - TaKO8Ki:fix-wrong-suggestion-for-adding-where-clauses, r=lcnr
Fix wrong suggestion for adding where clauses

closes #97576
2022-06-02 23:39:05 +02:00
Matthias Krüger
992ca9b601
Rollup merge of #97627 - lcnr:comment-tick, r=Dylan-DPC
update explicit impls error msg
2022-06-02 23:39:04 +02:00
Matthias Krüger
ba54e75b55
Rollup merge of #97502 - onlineSoftwareDevOK:rustdocTests, r=GuillaumeGomez
rustdoc: Add more test coverage

Related issue https://github.com/rust-lang/rust/issues/91113
2022-06-02 23:39:03 +02:00
bors
42bcd41d4d Auto merge of #97598 - spastorino:simplify-universal-impl-trait-lowering, r=cjgillot
Simplify universal impl trait lowering

Closes #96644

r? `@cjgillot`
2022-06-02 21:37:38 +00:00
Esteban Küber
8567b686f9 On E0204 suggest missing type param bounds
```
error[E0204]: the trait `Copy` may not be implemented for this type
  --> f42.rs:9:17
   |
9  | #[derive(Debug, Copy, Clone)]
   |                 ^^^^
10 | pub struct AABB<K>{
11 |     pub loc: Vector2<K>,
   |     ------------------- this field does not implement `Copy`
12 |     pub size: Vector2<K>
   |     -------------------- this field does not implement `Copy`
   |
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
  --> f42.rs:11:5
   |
11 |     pub loc: Vector2<K>,
   |     ^^^^^^^^^^^^^^^^^^^
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
  --> f42.rs:12:5
   |
12 |     pub size: Vector2<K>
   |     ^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `K`
   |
10 | pub struct AABB<K: Debug>{
   |                  +++++++
```

Fix #89137.
2022-06-02 12:54:04 -07:00
Ralf Jung
7676f07d0e take back half-baked noaliasing check in Assignment 2022-06-02 15:14:35 -04:00
bors
e71440575c Auto merge of #97575 - nnethercote:lazify-SourceFile-lines, r=Mark-Simulacrum
Lazify `SourceFile::lines`.

`SourceFile::lines` is a big part of metadata. It's stored in a compressed form
(a difference list) to save disk space. Decoding it is a big fraction of
compile time for very small crates/programs.

This commit introduces a new type `SourceFileLines` which has a `Lines`
form and a `Diffs` form. The latter is used when the metadata is first
read, and it is only decoded into the `Lines` form when line data is
actually needed. This avoids the decoding cost for many files,
especially in `std`. It's a performance win of up to 15% for tiny
crates/programs where metadata decoding is a high part of compilation
costs.

A `RefCell` is needed because the methods that access lines data (which can
trigger decoding) take `&self` rather than `&mut self`. To allow for this,
`SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather
than returning the lines slice.

r? `@Mark-Simulacrum`
2022-06-02 18:45:29 +00:00
Camille GILLOT
a265c49b25 Rebase fallout. 2022-06-02 19:24:32 +02:00
Camille GILLOT
be40b58895 Stop warning against unrelated labels. 2022-06-02 19:24:26 +02:00
Camille GILLOT
84e19930e3 Bless tests. 2022-06-02 19:24:24 +02:00
Camille GILLOT
257d8fce3e Do not report mixed label/lifetime shadowing. 2022-06-02 19:24:12 +02:00
Camille GILLOT
85cbd0bc18 Bless tests. 2022-06-02 19:24:10 +02:00
Camille GILLOT
6e1b0105c6 Diagnose shadowing on AST. 2022-06-02 19:23:39 +02:00
bors
44e9516c85 Auto merge of #97654 - Dylan-DPC:rollup-w6zrzxf, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #97420 (Be a little nicer with casts when formatting `fn` pointers)
 - #97450 ([RFC 2011] Basic compiler infrastructure)
 - #97599 (Fix JSON reexport ICE)
 - #97617 (Rustdoc anonymous reexports)
 - #97636 (Revert #96682.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-02 16:04:42 +00:00
Ralf Jung
d5a590f537 comment
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2022-06-02 11:12:12 -04:00
onlinesoftwaredevok@protonmail.com
9292c907fa rustdoc: Add more test coverage 2022-06-02 11:50:36 -03:00
Ralf Jung
fafccdced3 add cast kind of from_exposed_addr (int-to-ptr casts) 2022-06-02 10:46:13 -04:00
Frank Steffahn
6e2ac5df31 Improve documentation for constructors of pinned Boxes 2022-06-02 15:32:48 +02:00
Dylan DPC
1d71237646
Rollup merge of #97636 - nnethercote:revert-96682, r=dtolnay
Revert #96682.

The change was "Show invisible delimiters (within comments) when pretty
printing". It's useful to show these delimiters, but is a breaking
change for some proc macros.

Fixes #97608.

r? ``@petrochenkov``
2022-06-02 15:27:01 +02:00