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 5 pull requests #110836

Closed
wants to merge 10 commits into from
Closed
15 changes: 4 additions & 11 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1576,17 +1576,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
&& let hir::OpaqueTyOrigin::FnReturn(source) | hir::OpaqueTyOrigin::AsyncFn(source) = opaque.origin
&& source == self.fn_def_id
{
let opaque_ty = tcx.fold_regions(unshifted_opaque_ty, |re, depth| {
if let ty::ReLateBound(index, bv) = re.kind() {
if depth != ty::INNERMOST {
return tcx.mk_re_error_with_message(
DUMMY_SP,
"we shouldn't walk non-predicate binders with `impl Trait`...",
);
}
tcx.mk_re_late_bound(index.shifted_out_to_binder(self.depth), bv)
} else {
re
let opaque_ty = tcx.fold_regions(unshifted_opaque_ty, |re, _depth| {
match re.kind() {
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReError(_) => re,
r => bug!("unexpected region: {r:?}"),
}
});
for (bound, bound_span) in tcx
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,10 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {

fn ct_infer(&self, ty: Ty<'tcx>, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
let ty = self.tcx.fold_regions(ty, |r, _| match *r {
ty::ReErased => self.tcx.lifetimes.re_static,
_ => r,
// This is never reached in practice. If it ever is reached,
// `ReErased` should be changed to `ReStatic`, and any other region
// left alone.
r => bug!("unexpected region: {r:?}"),
});
self.tcx().const_error_with_message(ty, span, "bad placeholder constant")
}
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_middle/src/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,13 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for SubstFolder<'a, 'tcx> {
None => region_param_out_of_range(data, self.substs),
}
}
_ => r,
ty::ReLateBound(..)
| ty::ReFree(_)
| ty::ReStatic
| ty::RePlaceholder(_)
| ty::ReErased
| ty::ReError(_) => r,
ty::ReVar(_) => bug!("unexpected region: {r:?}"),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ pub(in crate::solve) fn replace_erased_lifetimes_with_bound_vars<'tcx>(
) -> ty::Binder<'tcx, Ty<'tcx>> {
debug_assert!(!ty.has_late_bound_regions());
let mut counter = 0;
let ty = tcx.fold_regions(ty, |mut r, current_depth| {
if let ty::ReErased = r.kind() {
let ty = tcx.fold_regions(ty, |r, current_depth| match r.kind() {
ty::ReErased => {
let br =
ty::BoundRegion { var: ty::BoundVar::from_u32(counter), kind: ty::BrAnon(None) };
counter += 1;
r = tcx.mk_re_late_bound(current_depth, br);
tcx.mk_re_late_bound(current_depth, br)
}
r
// All free regions should be erased here.
r => bug!("unexpected region: {r:?}"),
});
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(
(0..counter).map(|_| ty::BoundVariableKind::Region(ty::BrAnon(None))),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3006,16 +3006,16 @@ fn bind_generator_hidden_types_above<'tcx>(

// Only remap erased regions if we use them.
if considering_regions {
ty = tcx.fold_regions(ty, |mut r, current_depth| {
if let ty::ReErased = r.kind() {
ty = tcx.fold_regions(ty, |r, current_depth| match r.kind() {
ty::ReErased => {
let br = ty::BoundRegion {
var: ty::BoundVar::from_u32(counter),
kind: ty::BrAnon(None),
};
counter += 1;
r = tcx.mk_re_late_bound(current_depth, br);
tcx.mk_re_late_bound(current_depth, br)
}
r
r => bug!("unexpected region: {r:?}"),
})
}

Expand Down
62 changes: 28 additions & 34 deletions library/core/src/iter/adapters/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,12 @@ where
}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<T, I, F, const N: usize> TrustedLen for FlatMap<I, [T; N], F>
unsafe impl<I, U, F> TrustedLen for FlatMap<I, U, F>
where
I: TrustedLen,
F: FnMut(I::Item) -> [T; N],
{
}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<'a, T, I, F, const N: usize> TrustedLen for FlatMap<I, &'a [T; N], F>
where
I: TrustedLen,
F: FnMut(I::Item) -> &'a [T; N],
{
}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<'a, T, I, F, const N: usize> TrustedLen for FlatMap<I, &'a mut [T; N], F>
where
I: TrustedLen,
F: FnMut(I::Item) -> &'a mut [T; N],
I: Iterator,
U: IntoIterator,
F: FnMut(I::Item) -> U,
FlattenCompat<Map<I, F>, <U as IntoIterator>::IntoIter>: TrustedLen,
{
}

Expand Down Expand Up @@ -298,8 +284,8 @@ where
#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<I> TrustedLen for Flatten<I>
where
I: TrustedLen,
<I as Iterator>::Item: TrustedConstSize,
I: Iterator<Item: IntoIterator>,
FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>: TrustedLen,
{
}

Expand Down Expand Up @@ -660,6 +646,27 @@ where
}
}

unsafe impl<const N: usize, I, T> TrustedLen
for FlattenCompat<I, <[T; N] as IntoIterator>::IntoIter>
where
I: TrustedLen<Item = [T; N]>,
{
}

unsafe impl<'a, const N: usize, I, T> TrustedLen
for FlattenCompat<I, <&'a [T; N] as IntoIterator>::IntoIter>
where
I: TrustedLen<Item = &'a [T; N]>,
{
}

unsafe impl<'a, const N: usize, I, T> TrustedLen
for FlattenCompat<I, <&'a mut [T; N] as IntoIterator>::IntoIter>
where
I: TrustedLen<Item = &'a mut [T; N]>,
{
}

trait ConstSizeIntoIterator: IntoIterator {
// FIXME(#31844): convert to an associated const once specialization supports that
fn size() -> Option<usize>;
Expand Down Expand Up @@ -696,19 +703,6 @@ impl<T, const N: usize> ConstSizeIntoIterator for &mut [T; N] {
}
}

#[doc(hidden)]
#[unstable(feature = "std_internals", issue = "none")]
// FIXME(#20400): Instead of this helper trait there should be multiple impl TrustedLen for Flatten<>
// blocks with different bounds on Iterator::Item but the compiler erroneously considers them overlapping
pub unsafe trait TrustedConstSize: IntoIterator {}

#[unstable(feature = "std_internals", issue = "none")]
unsafe impl<T, const N: usize> TrustedConstSize for [T; N] {}
#[unstable(feature = "std_internals", issue = "none")]
unsafe impl<T, const N: usize> TrustedConstSize for &'_ [T; N] {}
#[unstable(feature = "std_internals", issue = "none")]
unsafe impl<T, const N: usize> TrustedConstSize for &'_ mut [T; N] {}

#[inline]
fn and_then_or_clear<T, U>(opt: &mut Option<T>, f: impl FnOnce(&mut T) -> Option<U>) -> Option<U> {
let x = f(opt.as_mut()?);
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustdoc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [What is rustdoc?](what-is-rustdoc.md)
- [Command-line arguments](command-line-arguments.md)
- [How to read rustdoc output](how-to-read-rustdoc.md)
- [In-doc settings](read-documentation/in-doc-settings.md)
- [How to write documentation](how-to-write-documentation.md)
- [What to include (and exclude)](write-documentation/what-to-include.md)
- [The `#[doc]` attribute](write-documentation/the-doc-attribute.md)
Expand Down
7 changes: 1 addition & 6 deletions src/doc/rustdoc/src/how-to-read-rustdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Typing in the search bar instantly searches the available documentation for
the string entered with a fuzzy matching algorithm that is tolerant of minor
typos.

By default, the search results give are "In Names",
By default, the search results given are "In Names",
meaning that the fuzzy match is made against the names of items.
Matching names are shown on the left, and the first few words of their
descriptions are given on the right.
Expand Down Expand Up @@ -105,11 +105,6 @@ will match these queries:

But it *does not* match `Result<Vec, u8>` or `Result<u8<Vec>>`.

### Changing displayed theme

You can change the displayed theme by opening the settings menu (the gear
icon in the upper right) and then pick a new one from there.

### Shortcuts

Pressing `S` while focused elsewhere on the page will move focus to the
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions src/doc/rustdoc/src/read-documentation/in-doc-settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Rustdoc in-doc settings

Rustdoc's HTML output includes a settings menu, and this chapter describes what
each setting in this menu does.

It can be accessed by clicking on the gear button
(<i class="fa fa-cog" aria-hidden="true"></i>) in the upper right.

## Changing displayed theme

It is possible to change the theme. If you pick the "system preference", you
will be able to see two new sub-menus: "Preferred light theme" and "Preferred
dark theme". It means that if your system preference is set to "light", then
rustdoc will use the theme you selected in "Preferred light theme".

## Auto-hide item contents for large items

If the type definition contains more than 12 items, and this setting is enabled,
it'll collapse them by default. You can see them by clicking on the `[+]` button
to expand them.

A good example of this setting in use can be seen in the
[`Iterator`](https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html) doc
page:

![Collapsed long item](../images/collapsed-long-item.png)

## Auto-hide item methods' documentation

If enabled, this setting will collapse all trait implementations blocks. It is
convenient if you just want an overview of all the methods available. You can
still see a method's documentation by expanding it.

## Auto-hide trait implementation documentation

If enabled, this setting will collapse all trait implementations blocks (you can
see them in the "Trait Implementations" section). It is convenient if you just
want an overview of all the trait implemented on a type. You can still see
a trait implementation's associated items by expanding it.

Example:

![Collapsed trait implementations](../images/collapsed-trait-impls.png)

## Directly go to item in search if there is only one result

If this setting is enabled, you will directly be taken to the result page if
your search only returned one element. Useful if you know exactly what you're
looking for and want to be taken there directly and not waste time selecting the
only search result.

## Show line numbers on code examples

If enabled, this setting will add line numbers to the code examples in the
documentation. It provides a visual aide for the code reading.

## Disable keyboard shortcuts

If this setting is enabled, the keyboard shortcuts will be disabled. It's useful
in case some of these shortcuts are already used by a web extension you're
using.

To see the full list of the rustdoc keyboard shortcuts, you can open the help
menu (the button with the question mark on the left of the setting menu button).
4 changes: 3 additions & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,10 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for RegionReplacer<'a, 'tcx> {

fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r {
// These are the regions that can be seen in the AST.
ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned().unwrap_or(r),
_ => r,
ty::ReEarlyBound(_) | ty::ReStatic | ty::ReLateBound(..) | ty::ReError(_) => r,
r => bug!("unexpected region: {r:?}"),
}
}
}
4 changes: 4 additions & 0 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,10 @@ pub(crate) fn make_test(
// parse the source, but only has false positives, not false
// negatives.
if s.contains(crate_name) {
// rustdoc implicitly inserts an `extern crate` item for the own crate
// which may be unused, so we need to allow the lint.
prog.push_str(&format!("#[allow(unused_extern_crates)]\n"));

prog.push_str(&format!("extern crate r#{crate_name};\n"));
line_offset += 1;
}
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/doctest/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fn make_test_crate_name() {
let input = "use asdf::qwop;
assert_eq!(2+2, 4);";
let expected = "#![allow(unused)]
#[allow(unused_extern_crates)]
extern crate r#asdf;
fn main() {
use asdf::qwop;
Expand Down Expand Up @@ -128,6 +129,7 @@ fn make_test_opts_attrs() {
let input = "use asdf::qwop;
assert_eq!(2+2, 4);";
let expected = "#![feature(sick_rad)]
#[allow(unused_extern_crates)]
extern crate r#asdf;
fn main() {
use asdf::qwop;
Expand All @@ -141,6 +143,7 @@ assert_eq!(2+2, 4);
opts.attrs.push("feature(hella_dope)".to_string());
let expected = "#![feature(sick_rad)]
#![feature(hella_dope)]
#[allow(unused_extern_crates)]
extern crate r#asdf;
fn main() {
use asdf::qwop;
Expand Down Expand Up @@ -236,6 +239,7 @@ assert_eq!(asdf::foo, 4);";

let expected = "#![allow(unused)]
extern crate hella_qwop;
#[allow(unused_extern_crates)]
extern crate r#asdf;
fn main() {
assert_eq!(asdf::foo, 4);
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc/playground-arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
pub fn dummy() {}

// ensure that `extern crate foo;` was inserted into code snips automatically:
// @matches foo/index.html '//a[@class="test-arrow"][@href="https://example.com/?code=%23!%5Ballow(unused)%5D%0Aextern+crate+r%23foo;%0Afn+main()+%7B%0Ause+foo::dummy;%0Adummy();%0A%7D&edition=2015"]' "Run"
// @matches foo/index.html '//a[@class="test-arrow"][@href="https://example.com/?code=%23!%5Ballow(unused)%5D%0A%23%5Ballow(unused_extern_crates)%5D%0Aextern+crate+r%23foo;%0Afn+main()+%7B%0Ause+foo::dummy;%0Adummy();%0A%7D&edition=2015"]' "Run"
10 changes: 10 additions & 0 deletions tests/ui/inference/issue-70082.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
// this closure is fine, and should not get any error annotations
let em = |v: f64| -> f64 { v };

let x: f64 = em(1i16.into());

let y: f64 = 0.01f64 * 1i16.into();
//~^ ERROR type annotations needed
//~| HELP try using a fully qualified path
}
17 changes: 17 additions & 0 deletions tests/ui/inference/issue-70082.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0284]: type annotations needed
--> $DIR/issue-70082.rs:7:33
|
LL | let y: f64 = 0.01f64 * 1i16.into();
| - ^^^^
| |
| type must be known at this point
|
= note: cannot satisfy `<f64 as Mul<_>>::Output == f64`
help: try using a fully qualified path to specify the expected types
|
LL | let y: f64 = 0.01f64 * <i16 as Into<T>>::into(1i16);
| +++++++++++++++++++++++ ~

error: aborting due to previous error

For more information about this error, try `rustc --explain E0284`.