Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #113004

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b551730
style-guide: Rewrite let-else section for clarity, without changing f…
joshtriplett Jun 21, 2023
e5e4805
Update runtests.py : grammar correction
preveen-stack Jun 22, 2023
a8fa961
Align search results horizontally for easy scanning
camelid Jun 22, 2023
c4fca72
Abbreviate long typenames so they don't get wrapped in results
camelid Jun 23, 2023
5a0c8e3
issue template: add clippy entry which points to the clippy repo
matthiaskrgr Jun 23, 2023
12de5b7
Make typenames a bit wider to support "existential type"
camelid Jun 23, 2023
5f433f3
Reduce typename width to 6.25rem
camelid Jun 23, 2023
13cc8dd
Add a regression test for #109141
JohnTitor Jun 24, 2023
a72013f
instantiate hidden types in root universe
aliemjay Jun 16, 2023
ce32691
bootstrap: Backup `settings.json` to the correct filename
camelid Jun 24, 2023
f799e78
Fix old python deprecation check in x.py
Noratrieb Jun 24, 2023
a8b50e2
Rollup merge of #112703 - aliemjay:next-solver-root-var, r=compiler-e…
GuillaumeGomez Jun 24, 2023
e81f72f
Rollup merge of #112912 - joshtriplett:style-let-else-clarifications,…
GuillaumeGomez Jun 24, 2023
43fe7b0
Rollup merge of #112915 - preveen-stack:patch-1, r=Mark-Simulacrum
GuillaumeGomez Jun 24, 2023
3b1a295
Rollup merge of #112937 - camelid:align-typenames, r=GuillaumeGomez
GuillaumeGomez Jun 24, 2023
2673e95
Rollup merge of #112971 - matthiaskrgr:templ_clippy, r=Mark-Simulacrum
GuillaumeGomez Jun 24, 2023
8ebe716
Rollup merge of #112989 - JohnTitor:issue-109141, r=compiler-errors
GuillaumeGomez Jun 24, 2023
c0fbc45
Rollup merge of #113002 - camelid:bootstrap-settings.bak, r=jyn514
GuillaumeGomez Jun 24, 2023
36a16b6
Rollup merge of #113003 - Nilstrieb:uh-yeah-so-about-that-deprecation…
GuillaumeGomez Jun 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ contact_links:
- name: Feature Request
url: https://internals.rust-lang.org/
about: Please discuss language feature requests on the internals forum.
- name: Clippy Bug
url: https://github.com/rust-lang/rust-clippy/issues/new/choose
about: Please report Clippy bugs such as false positives in the Clippy repo.
5 changes: 2 additions & 3 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
use rustc_mir_dataflow::move_paths::MoveData;
use rustc_mir_dataflow::ResultsCursor;

use crate::renumber::RegionCtxt;
use crate::session_diagnostics::MoveUnsized;
use crate::{
borrow_set::BorrowSet,
Expand Down Expand Up @@ -1040,9 +1039,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
.collect();

let renumbered_opaques = self.infcx.tcx.fold_regions(opaques, |_, _| {
self.infcx.next_nll_region_var(
self.infcx.next_nll_region_var_in_universe(
NllRegionVariableOrigin::Existential { from_forall: false },
|| RegionCtxt::Unknown,
ty::UniverseIndex::ROOT,
)
});

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,7 @@ impl<'tcx> InferCtxt<'tcx> {
/// universes. Updates `self.universe` to that new universe.
pub fn create_next_universe(&self) -> ty::UniverseIndex {
let u = self.universe.get().next_universe();
debug!("create_next_universe {u:?}");
self.universe.set(u);
u
}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ fn create_vscode_settings_maybe(config: &Config) -> io::Result<()> {
Some(false) => {
// exists and is not current version or outdated, so back it up
let mut backup = vscode_settings.clone();
backup.set_extension("bak");
backup.set_extension("json.bak");
eprintln!("warning: copying `settings.json` to `settings.json.bak`");
fs::copy(&vscode_settings, &backup)?;
"Updated"
Expand Down
105 changes: 62 additions & 43 deletions src/doc/style-guide/src/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,69 @@ let Foo {

#### else blocks (let-else statements)

If a let statement contains an `else` component, also known as a let-else statement,
then the `else` component should be formatted according to the same rules as the `else` block
in [control flow expressions (i.e. if-else, and if-let-else expressions)](./expressions.md#control-flow-expressions).
Apply the same formatting rules to the components preceding
the `else` block (i.e. the `let pattern: Type = initializer_expr ...` portion)
as described [above](#let-statements)

Similarly to if-else expressions, if the initializer
expression is multi-lined, then the `else` keyword and opening brace of the block (i.e. `else {`)
should be put on the same line as the end of the initializer
expression with a preceding space if all the following are true:
A let statement can contain an `else` component, making it a let-else statement.
In this case, always apply the same formatting rules to the components preceding
the `else` block (i.e. the `let pattern: Type = initializer_expr` portion)
as described [for other let statements](#let-statements).

The entire let-else statement may be formatted on a single line if all the
following are true:

* the entire statement is *short*
* the `else` block contains only a single-line expression and no statements
* the `else` block contains no comments
* the let statement components preceding the `else` block can be formatted on a single line

```rust
let Some(1) = opt else { return };
```

Formatters may allow users to configure the value of the threshold
used to determine whether a let-else statement is *short*.

Otherwise, the let-else statement requires some line breaks.

If breaking a let-else statement across multiple lines, never break between the
`else` and the `{`, and always break before the `}`.

If the let statement components preceding the `else` can be formatted on a
single line, but the let-else does not qualify to be placed entirely on a
single line, put the `else {` on the same line as the initializer expression,
with a space between them, then break the line after the `{`. Indent the
closing `}` to match the `let`, and indent the contained block one step
further.

```rust
let Some(1) = opt else {
return;
};

let Some(1) = opt else {
// nope
return
};
```

If the let statement components preceding the `else` can be formatted on a
single line, but the `else {` does not fit on the same line, break the line
before the `else`.

```rust
let Some(x) = some_really_really_really_really_really_really_really_really_really_long_name
else {
return;
};
```

If the initializer expression is multi-line, the `else` keyword and opening
brace of the block (i.e. `else {`) should be put on the same line as the end of
the initializer expression, with a space between them, if all the following are
true:

* The initializer expression ends with one or more closing
parentheses, square brackets, and/or braces
* There is nothing else on that line
* That line is not indented beyond the indent of the first line containing the `let` keyword
* That line has the same indentation level as the initial `let` keyword.

For example:

Expand All @@ -135,7 +182,9 @@ let Some(x) = y.foo(
}
```

Otherwise, the `else` keyword and opening brace should be placed on the next line after the end of the initializer expression, and should not be indented (the `else` keyword should be aligned with the `let` keyword).
Otherwise, the `else` keyword and opening brace should be placed on the next
line after the end of the initializer expression, and the `else` keyword should
have the same indentation level as the `let` keyword.

For example:

Expand All @@ -155,11 +204,6 @@ fn main() {
return
};

let Some(x) = some_really_really_really_really_really_really_really_really_really_long_name
else {
return;
};

let Some(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
else {
Expand All @@ -168,31 +212,6 @@ fn main() {
}
```

##### Single line let-else statements

The entire let-else statement may be formatted on a single line if all the following are true:

* the entire statement is *short*
* the `else` block contains a single-line expression and no statements
* the `else` block contains no comments
* the let statement components preceding the `else` block can be formatted on a single line

```rust
let Some(1) = opt else { return };

let Some(1) = opt else {
return;
};

let Some(1) = opt else {
// nope
return
};
```

Formatters may allow users to configure the value of the threshold
used to determine whether a let-else statement is *short*.

### Macros in statement position

A macro use in statement position should use parentheses or square brackets as
Expand Down
2 changes: 1 addition & 1 deletion src/etc/test-float-parse/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def write_errors():
if not have_seen_error:
have_seen_error = True
msg("Something is broken:", *args)
msg("Future errors logged to errors.txt")
msg("Future errors will be logged to errors.txt")
exit_status = 101


Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,10 @@ so that we can apply CSS-filters to change the arrow color in themes */
color: var(--search-results-grey-color);
}
.search-results .result-name .typename {
display: inline-block;
color: var(--search-results-grey-color);
font-size: 0.875rem;
width: 6.25rem;
}

.popover {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ const longItemTypes = [
"enum variant",
"macro",
"primitive type",
"associated type",
"assoc type",
"constant",
"associated constant",
"assoc const",
"union",
"foreign type",
"keyword",
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/const-generics/generic_const_exprs/issue-109141.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

impl EntriesBuffer {
fn a(&self) -> impl Iterator {
self.0.iter_mut() //~ ERROR: cannot borrow `*self.0` as mutable, as it is behind a `&` reference
}
}

struct EntriesBuffer(Box<[[u8; HashesEntryLEN]; 5]>);
//~^ ERROR: cannot find value `HashesEntryLEN` in this scope

fn main() {}
26 changes: 26 additions & 0 deletions tests/ui/const-generics/generic_const_exprs/issue-109141.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error[E0425]: cannot find value `HashesEntryLEN` in this scope
--> $DIR/issue-109141.rs:10:32
|
LL | struct EntriesBuffer(Box<[[u8; HashesEntryLEN]; 5]>);
| ^^^^^^^^^^^^^^ not found in this scope
|
help: you might be missing a const parameter
|
LL | struct EntriesBuffer<const HashesEntryLEN: /* Type */>(Box<[[u8; HashesEntryLEN]; 5]>);
| ++++++++++++++++++++++++++++++++++

error[E0596]: cannot borrow `*self.0` as mutable, as it is behind a `&` reference
--> $DIR/issue-109141.rs:6:9
|
LL | self.0.iter_mut()
| ^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable
|
help: consider changing this to be a mutable reference
|
LL | fn a(&mut self) -> impl Iterator {
| ~~~~~~~~~

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0425, E0596.
For more information about an error, try `rustc --explain E0425`.
17 changes: 17 additions & 0 deletions tests/ui/traits/new-solver/member-constraints-in-root-universe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// compile-flags: -Ztrait-solver=next
// check-pass

trait Trait {
type Ty;
}

impl Trait for for<'a> fn(&'a u8, &'a u8) {
type Ty = ();
}

// argument is necessary to create universes before registering the hidden type.
fn test<'a>(_: <fn(&u8, &u8) as Trait>::Ty) -> impl Sized {
"hidden type is `&'?0 str` with '?0 member of ['static,]"
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
error: concrete type differs from previous defining opaque type use
--> $DIR/normalize-hidden-types.rs:25:20
|
LL | fn define() -> Opaque {
| ^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)`
|
note: previous use here
--> $DIR/normalize-hidden-types.rs:27:9
|
LL | dyn_hoops::<_>(0)
| ^^^^^^^^^^^^^^^^^

error: concrete type differs from previous defining opaque type use
--> $DIR/normalize-hidden-types.rs:34:22
|
LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) }
| ^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)`
|
note: previous use here
--> $DIR/normalize-hidden-types.rs:34:31
|
LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) }
| ^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> $DIR/normalize-hidden-types.rs:44:25
|
LL | type Opaque = impl Sized;
| ---------- the expected opaque type
...
LL | let _: Opaque = dyn_hoops::<u8>(0);
| ------ ^^^^^^^^^^^^^^^^^^ expected opaque type, found `*const dyn FnOnce(())`
| |
| expected due to this
|
= note: expected opaque type `typeck::Opaque`
found raw pointer `*const (dyn FnOnce(()) + 'static)`
= help: consider constraining the associated type `<u8 as Trait>::Gat<'_>` to `()` or calling a method that returns `<u8 as Trait>::Gat<'_>`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

error: concrete type differs from previous defining opaque type use
--> $DIR/normalize-hidden-types.rs:54:25
|
LL | let _: Opaque = dyn_hoops::<_>(0);
| ^^^^^^^^^^^^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)`
|
note: previous use here
--> $DIR/normalize-hidden-types.rs:56:9
|
LL | None
| ^^^^

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0308`.
60 changes: 60 additions & 0 deletions tests/ui/type-alias-impl-trait/normalize-hidden-types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Regression test for #112691
//
// revisions: current next
// [next] compile-flags: -Ztrait-solver=next
// [next] check-pass
// [current]: known-bug: #112691

#![feature(type_alias_impl_trait)]

trait Trait {
type Gat<'lt>;
}

impl Trait for u8 {
type Gat<'lt> = ();
}

fn dyn_hoops<T: Trait>(_: T) -> *const dyn FnOnce(T::Gat<'_>) {
loop {}
}

mod typeof_1 {
use super::*;
type Opaque = impl Sized;
fn define() -> Opaque {
//[current]~^ ERROR concrete type differs
dyn_hoops::<_>(0)
}
}

mod typeof_2 {
use super::*;
type Opaque = impl Sized;
fn define_1() -> Opaque { dyn_hoops::<_>(0) }
//[current]~^ ERROR concrete type differs
fn define_2() -> Opaque { dyn_hoops::<u8>(0) }
}

mod typeck {
use super::*;
type Opaque = impl Sized;
fn define() -> Option<Opaque> {
let _: Opaque = dyn_hoops::<_>(0);
let _: Opaque = dyn_hoops::<u8>(0);
//[current]~^ ERROR mismatched types
None
}
}

mod borrowck {
use super::*;
type Opaque = impl Sized;
fn define() -> Option<Opaque> {
let _: Opaque = dyn_hoops::<_>(0);
//[current]~^ ERROR concrete type differs
None
}
}

fn main() {}
2 changes: 1 addition & 1 deletion x.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

# soft deprecation of old python versions
skip_check = os.environ.get("RUST_IGNORE_OLD_PYTHON") == "1"
if major < 3 or (major == 3 and minor < 6):
if not skip_check and (major < 3 or (major == 3 and minor < 6)):
msg = cleandoc("""
Using python {}.{} but >= 3.6 is recommended. Your python version
should continue to work for the near future, but this will
Expand Down