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 7 pull requests #78974

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8b20e9b
Add shortcut for theme picker menu
GuillaumeGomez Nov 5, 2020
1216432
Consider mutable ident binding patterns to be simple
ebkalderon Sep 15, 2020
26b11d6
Don't reuse bindings for `ref mut`
jyn514 Nov 8, 2020
d76cdb0
const param macro test
lcnr Nov 10, 2020
359031e
add generic param mismatch test
lcnr Nov 10, 2020
dd78188
add macro_rules test regarding braces
lcnr Nov 10, 2020
a8310e2
add associated type bounds test
lcnr Nov 10, 2020
19a3fe6
exhaustively enumerate all values of a const param
lcnr Nov 10, 2020
a30b28e
try referencing outer params
lcnr Nov 10, 2020
de1ebbb
const param in async
lcnr Nov 10, 2020
4b5cd04
add test for where clauses mentioning const params
lcnr Nov 10, 2020
f4790ec
add cross crate test
lcnr Nov 10, 2020
96793d3
Handle and test wildcard arguments
jyn514 Nov 10, 2020
46c921d
Improve the page title switch handling between search and doc
GuillaumeGomez Nov 10, 2020
9cf8a49
Don't print thread ids and names in `tracing` logs
jyn514 Nov 10, 2020
6e9ed8b
Enable thread names in debug logging only for `parallel_compiler`
jyn514 Nov 11, 2020
7d9f815
add rustdoc test
lcnr Nov 10, 2020
a9eacf3
add error-in-impl-trait const generics test
lcnr Nov 10, 2020
ad7f330
Add test `default_function_param`
eopb Nov 11, 2020
1d3f9d0
default_trait_param
eopb Nov 11, 2020
a8bc954
Update books
ehuss Nov 12, 2020
25fd89a
Rollup merge of #76730 - ebkalderon:rustdoc-fix-mut-args-async-fn, r=…
GuillaumeGomez Nov 12, 2020
7305584
Rollup merge of #78773 - GuillaumeGomez:theme-picker-shortcut, r=jyn514
GuillaumeGomez Nov 12, 2020
b31c678
Rollup merge of #78916 - lcnr:const-generics-tests, r=varkor
GuillaumeGomez Nov 12, 2020
7b25abf
Rollup merge of #78921 - GuillaumeGomez:search-result-title, r=jyn514
GuillaumeGomez Nov 12, 2020
9e28eb9
Rollup merge of #78933 - jyn514:tracing-output, r=oli-obk
GuillaumeGomez Nov 12, 2020
4ada95f
Rollup merge of #78960 - ethanboxx:const-gen-test-default-error, r=lcnr
GuillaumeGomez Nov 12, 2020
4d0f068
Rollup merge of #78971 - ehuss:update-books, r=ehuss
GuillaumeGomez Nov 12, 2020
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
14 changes: 12 additions & 2 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Check if this is a binding pattern, if so, we can optimize and avoid adding a
// `let <pat> = __argN;` statement. In this case, we do not rename the parameter.
let (ident, is_simple_parameter) = match parameter.pat.kind {
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, _) => {
(ident, true)
hir::PatKind::Binding(
hir::BindingAnnotation::Unannotated | hir::BindingAnnotation::Mutable,
_,
ident,
_,
) => (ident, true),
// For `ref mut` or wildcard arguments, we can't reuse the binding, but
// we can keep the same name for the parameter.
// This lets rustdoc render it correctly in documentation.
hir::PatKind::Binding(_, _, ident, _) => (ident, false),
hir::PatKind::Wild => {
(Ident::with_dummy_span(rustc_span::symbol::kw::Underscore), false)
}
_ => {
// Replace the ident for bindings that aren't simple.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,12 +1288,12 @@ pub fn init_env_logger(env: &str) {
.with_indent_lines(true)
.with_ansi(true)
.with_targets(true)
.with_thread_ids(true)
.with_thread_names(true)
.with_wraparound(10)
.with_verbose_exit(true)
.with_verbose_entry(true)
.with_indent_amount(2);
#[cfg(parallel_compiler)]
let layer = layer.with_thread_ids(true).with_thread_names(true);

use tracing_subscriber::layer::SubscriberExt;
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
Expand Down
2 changes: 1 addition & 1 deletion src/doc/edition-guide
2 changes: 1 addition & 1 deletion src/doc/rust-by-example
17 changes: 15 additions & 2 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function defocusSearchBar() {
var mouseMovedAfterSearch = true;

var titleBeforeSearch = document.title;
var searchTitle = null;

function clearInputTimeout() {
if (searchTimeout !== null) {
Expand Down Expand Up @@ -169,6 +170,7 @@ function defocusSearchBar() {
addClass(main, "hidden");
removeClass(search, "hidden");
mouseMovedAfterSearch = false;
document.title = searchTitle;
}

function hideSearchResults(search) {
Expand All @@ -177,6 +179,7 @@ function defocusSearchBar() {
}
addClass(search, "hidden");
removeClass(main, "hidden");
document.title = titleBeforeSearch;
}

// used for special search precedence
Expand Down Expand Up @@ -374,7 +377,6 @@ function defocusSearchBar() {
clearInputTimeout();
ev.preventDefault();
hideSearchResults(search);
document.title = titleBeforeSearch;
}
defocusSearchBar();
hideThemeButtonState();
Expand Down Expand Up @@ -415,6 +417,15 @@ function defocusSearchBar() {
displayHelp(true, ev);
break;

case "t":
case "T":
displayHelp(false, ev);
ev.preventDefault();
var themePicker = getThemePickerElement();
themePicker.click();
themePicker.focus();
break;

default:
var themePicker = getThemePickerElement();
if (themePicker.parentNode.contains(ev.target)) {
Expand Down Expand Up @@ -1782,7 +1793,7 @@ function defocusSearchBar() {
}

// Update document title to maintain a meaningful browser history
document.title = "Results for " + query.query + " - Rust";
searchTitle = "Results for " + query.query + " - Rust";

// Because searching is incremental by character, only the most
// recent search query is added to the browser history.
Expand Down Expand Up @@ -2736,6 +2747,7 @@ function defocusSearchBar() {
"",
"?search=" + encodeURIComponent(search_input.value));
}
document.title = searchTitle;
}
}

Expand Down Expand Up @@ -2852,6 +2864,7 @@ function defocusSearchBar() {
var shortcuts = [
["?", "Show this help dialog"],
["S", "Focus the search field"],
["T", "Focus the theme picker menu"],
["↑", "Move up in search results"],
["↓", "Move down in search results"],
["↹", "Switch tab"],
Expand Down
24 changes: 24 additions & 0 deletions src/test/rustdoc-ui/error-in-impl-trait/const-generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// check-pass
// edition:2018
#![feature(min_const_generics)]
trait ValidTrait {}

/// This has docs
pub fn extern_fn<const N: usize>() -> impl Iterator<Item = [u8; N]> {
loop {}
}

pub trait Trait<const N: usize> {}
impl Trait<1> for u8 {}
impl Trait<2> for u8 {}
impl<const N: usize> Trait<N> for [u8; N] {}

/// This also has docs
pub fn test<const N: usize>() -> impl Trait<N> where u8: Trait<N> {
loop {}
}

/// Document all the functions
pub async fn a_sink<const N: usize>(v: [u8; N]) -> impl Trait<N> {
loop {}
}
14 changes: 14 additions & 0 deletions src/test/rustdoc/async-fn.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// edition:2018
#![feature(min_const_generics)]

// @has async_fn/fn.foo.html '//pre[@class="rust fn"]' 'pub async fn foo() -> Option<Foo>'
pub async fn foo() -> Option<Foo> {
Expand All @@ -20,6 +21,12 @@ pub async unsafe fn qux() -> char {
'⚠'
}

// @has async_fn/fn.mut_args.html '//pre[@class="rust fn"]' 'pub async fn mut_args(a: usize)'
pub async fn mut_args(mut a: usize) {}

// @has async_fn/fn.mut_ref.html '//pre[@class="rust fn"]' 'pub async fn mut_ref(x: i32)'
pub async fn mut_ref(ref mut x: i32) {}

trait Bar {}

impl Bar for () {}
Expand All @@ -32,9 +39,16 @@ pub async fn quux() -> impl Bar {
// @has async_fn/struct.Foo.html
// @matches - '//code' 'pub async fn f\(\)$'
// @matches - '//code' 'pub async unsafe fn g\(\)$'
// @matches - '//code' 'pub async fn mut_self\(self, first: usize\)$'
pub struct Foo;

impl Foo {
pub async fn f() {}
pub async unsafe fn g() {}
pub async fn mut_self(mut self, mut first: usize) {}
}

pub trait Trait<const N: usize> {}
// @has async_fn/fn.const_generics.html
// @has - '//pre[@class="rust fn"]' 'pub async fn const_generics<const N: usize>(_: impl Trait<N>)'
pub async fn const_generics<const N: usize>(_: impl Trait<N>) {}
18 changes: 18 additions & 0 deletions src/test/rustdoc/const-generics/auxiliary/extern_crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// edition:2018
#![feature(min_const_generics)]

pub fn extern_fn<const N: usize>() -> impl Iterator<Item = [u8; N]> {
[[0; N]; N].iter().copied()
}

pub struct ExternTy<const N: usize> {
pub inner: [u8; N],
}

pub type TyAlias<const N: usize> = ExternTy<N>;

pub trait WTrait<const N: usize, const M: usize> {
fn hey<const P: usize>() -> usize {
N + M + P
}
}
130 changes: 130 additions & 0 deletions src/test/rustdoc/const-generics/const-generics-docs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// edition:2018
// aux-build: extern_crate.rs
#![feature(min_const_generics)]
#![crate_name = "foo"]

extern crate extern_crate;
// @has foo/fn.extern_fn.html '//pre[@class="rust fn"]' \
// 'pub fn extern_fn<const N: usize>() -> impl Iterator<Item = [u8; N]>'
pub use extern_crate::extern_fn;
// @has foo/struct.ExternTy.html '//pre[@class="rust struct"]' \
// 'pub struct ExternTy<const N: usize> {'
pub use extern_crate::ExternTy;
// @has foo/type.TyAlias.html '//pre[@class="rust typedef"]' \
// 'type TyAlias<const N: usize> = ExternTy<N>;'
pub use extern_crate::TyAlias;
// @has foo/trait.WTrait.html '//pre[@class="rust trait"]' \
// 'pub trait WTrait<const N: usize, const M: usize>'
// @has - '//*[@class="rust trait"]' 'fn hey<const P: usize>() -> usize'
pub use extern_crate::WTrait;

// @has foo/trait.Trait.html '//pre[@class="rust trait"]' \
// 'pub trait Trait<const N: usize>'
// @has - '//*[@id="impl-Trait%3C1_usize%3E-for-u8"]//code' 'impl Trait<1_usize> for u8'
// @has - '//*[@id="impl-Trait%3C2_usize%3E-for-u8"]//code' 'impl Trait<2_usize> for u8'
// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//code' 'impl Trait<{1 + 2}> for u8'
// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//code' \
// 'impl<const N: usize> Trait<N> for [u8; N]'
pub trait Trait<const N: usize> {}
impl Trait<1> for u8 {}
impl Trait<2> for u8 {}
impl Trait<{1 + 2}> for u8 {}
impl<const N: usize> Trait<N> for [u8; N] {}

// @has foo/struct.Foo.html '//pre[@class="rust struct"]' \
// 'pub struct Foo<const N: usize> where u8: Trait<N>'
pub struct Foo<const N: usize> where u8: Trait<N>;
// @has foo/struct.Bar.html '//pre[@class="rust struct"]' 'pub struct Bar<T, const N: usize>(_)'
pub struct Bar<T, const N: usize>([T; N]);

// @has foo/struct.Foo.html '//h3[@id="impl"]/code' 'impl<const M: usize> Foo<M> where u8: Trait<M>'
impl<const M: usize> Foo<M> where u8: Trait<M> {
// @has - '//*[@id="associatedconstant.FOO_ASSOC"]' 'pub const FOO_ASSOC: usize'
pub const FOO_ASSOC: usize = M + 13;

// @has - '//*[@id="method.hey"]' 'pub fn hey<const N: usize>(&self) -> Bar<u8, N>'
pub fn hey<const N: usize>(&self) -> Bar<u8, N> {
Bar([0; N])
}
}

// @has foo/struct.Bar.html '//h3[@id="impl"]/code' 'impl<const M: usize> Bar<u8, M>'
impl<const M: usize> Bar<u8, M> {
// @has - '//*[@id="method.hey"]' \
// 'pub fn hey<const N: usize>(&self) -> Foo<N> where u8: Trait<N>'
pub fn hey<const N: usize>(&self) -> Foo<N> where u8: Trait<N> {
Foo
}
}

// @has foo/fn.test.html '//pre[@class="rust fn"]' \
// 'pub fn test<const N: usize>() -> impl Trait<N> where u8: Trait<N>'
pub fn test<const N: usize>() -> impl Trait<N> where u8: Trait<N> {
2u8
}

// @has foo/fn.a_sink.html '//pre[@class="rust fn"]' \
// 'pub async fn a_sink<const N: usize>(v: [u8; N]) -> impl Trait<N>'
pub async fn a_sink<const N: usize>(v: [u8; N]) -> impl Trait<N> {
v
}

// @has foo/fn.b_sink.html '//pre[@class="rust fn"]' \
// 'pub async fn b_sink<const N: usize>(__arg0: impl Trait<N>)'
// FIXME(const_generics): This should be `_` not `__arg0`.
pub async fn b_sink<const N: usize>(_: impl Trait<N>) {}

// @has foo/fn.concrete.html '//pre[@class="rust fn"]' \
// 'pub fn concrete() -> [u8; 22]'
pub fn concrete() -> [u8; 3 + std::mem::size_of::<u64>() << 1] {
Default::default()
}

// @has foo/type.Faz.html '//pre[@class="rust typedef"]' \
// 'type Faz<const N: usize> = [u8; N];'
pub type Faz<const N: usize> = [u8; N];
// @has foo/type.Fiz.html '//pre[@class="rust typedef"]' \
// 'type Fiz<const N: usize> = [[u8; N]; 48];'
pub type Fiz<const N: usize> = [[u8; N]; 3 << 4];

macro_rules! define_me {
($t:tt<$q:tt>) => {
pub struct $t<const $q: usize>([u8; $q]);
}
}

// @has foo/struct.Foz.html '//pre[@class="rust struct"]' \
// 'pub struct Foz<const N: usize>(_);'
define_me!(Foz<N>);

trait Q {
const ASSOC: usize;
}

impl<const N: usize> Q for [u8; N] {
const ASSOC: usize = N;
}

// @has foo/fn.q_user.html '//pre[@class="rust fn"]' \
// 'pub fn q_user() -> [u8; 13]'
pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {
[0; <[u8; 13] as Q>::ASSOC]
}

// @has foo/union.Union.html '//pre[@class="rust union"]' \
// 'pub union Union<const N: usize>'
pub union Union<const N: usize> {
// @has - //pre "pub arr: [u8; N]"
pub arr: [u8; N],
// @has - //pre "pub another_arr: [(); N]"
pub another_arr: [(); N],
}

// @has foo/enum.Enum.html '//pre[@class="rust enum"]' \
// 'pub enum Enum<const N: usize>'
pub enum Enum<const N: usize> {
// @has - //pre "Variant([u8; N])"
Variant([u8; N]),
// @has - //pre "EmptyVariant"
EmptyVariant,
}
15 changes: 15 additions & 0 deletions src/test/ui/const-generics/associated-type-bound-fail.full.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
--> $DIR/associated-type-bound-fail.rs:14:5
|
LL | type Assoc: Bar<N>;
| ------ required by this bound in `Foo::Assoc`
...
LL | type Assoc = u16;
| ^^^^^^^^^^^^^^^^^ the trait `Bar<N>` is not implemented for `u16`
|
= help: the following implementations were found:
<u16 as Bar<3_usize>>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
15 changes: 15 additions & 0 deletions src/test/ui/const-generics/associated-type-bound-fail.min.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
--> $DIR/associated-type-bound-fail.rs:14:5
|
LL | type Assoc: Bar<N>;
| ------ required by this bound in `Foo::Assoc`
...
LL | type Assoc = u16;
| ^^^^^^^^^^^^^^^^^ the trait `Bar<N>` is not implemented for `u16`
|
= help: the following implementations were found:
<u16 as Bar<3_usize>>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
17 changes: 17 additions & 0 deletions src/test/ui/const-generics/associated-type-bound-fail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// revisions: full min
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(min, feature(min_const_generics))]

trait Bar<const N: usize> {}

trait Foo<const N: usize> {
type Assoc: Bar<N>;
}

impl Bar<3> for u16 {}
impl<const N: usize> Foo<N> for i16 {
type Assoc = u16; //~ ERROR the trait bound `u16: Bar<N>`
}

fn main() {}
Loading