From 6dff51f37d87eb02e8776032fa8da16c990a3283 Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 3 Jun 2021 09:01:25 +0100 Subject: [PATCH 01/11] rustdoc- Show defaults on const generics --- src/librustdoc/clean/auto_trait.rs | 5 ++++- src/librustdoc/clean/mod.rs | 13 ++++++++++--- src/librustdoc/clean/types.rs | 1 + src/librustdoc/html/format.rs | 16 +++++++++++++--- src/librustdoc/json/conversions.rs | 4 +++- src/rustdoc-json-types/lib.rs | 2 +- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 35ff57f85a562..a3f63ea1046e3 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -664,7 +664,10 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { } } GenericParamDefKind::Lifetime => {} - GenericParamDefKind::Const { .. } => {} + GenericParamDefKind::Const { ref mut default, .. } => { + // We never want something like `impl` + default.take(); + } } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 231f13adeb68c..d1c18821ea644 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -445,11 +445,15 @@ impl Clean for ty::GenericParamDef { }, ) } - ty::GenericParamDefKind::Const { .. } => ( + ty::GenericParamDefKind::Const { has_default, .. } => ( self.name, GenericParamDefKind::Const { did: self.def_id, ty: cx.tcx.type_of(self.def_id).clean(cx), + default: match has_default { + true => Some(cx.tcx.const_param_default(self.def_id).to_string()), + false => None, + }, }, ), }; @@ -487,12 +491,15 @@ impl Clean for hir::GenericParam<'_> { synthetic, }, ), - hir::GenericParamKind::Const { ref ty, default: _ } => ( + hir::GenericParamKind::Const { ref ty, default } => ( self.name.ident().name, GenericParamDefKind::Const { did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(), ty: ty.clean(cx), - // FIXME(const_generics_defaults): add `default` field here for docs + default: default.map(|ct| { + let def_id = cx.tcx.hir().local_def_id(ct.hir_id); + ty::Const::from_anon_const(cx.tcx, def_id).to_string() + }), }, ), }; diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index de88e249b67f8..e73eb6c48acdb 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1304,6 +1304,7 @@ crate enum GenericParamDefKind { Const { did: DefId, ty: Type, + default: Option, }, } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 3c1d03a78f1cd..10dba5a35c04a 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -177,12 +177,22 @@ impl clean::GenericParamDef { Ok(()) } - clean::GenericParamDefKind::Const { ref ty, .. } => { + clean::GenericParamDefKind::Const { ref ty, ref default, .. } => { if f.alternate() { - write!(f, "const {}: {:#}", self.name, ty.print(cx)) + write!(f, "const {}: {:#}", self.name, ty.print(cx))?; } else { - write!(f, "const {}: {}", self.name, ty.print(cx)) + write!(f, "const {}: {}", self.name, ty.print(cx))?; } + + if let Some(default) = default { + if f.alternate() { + write!(f, " = {:#}", default)?; + } else { + write!(f, " = {}", default)?; + } + } + + Ok(()) } }) } diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index c6646ba9ae4d2..a812a37823640 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -317,7 +317,9 @@ impl FromWithTcx for GenericParamDefKind { bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(), default: default.map(|x| x.into_tcx(tcx)), }, - Const { did: _, ty } => GenericParamDefKind::Const(ty.into_tcx(tcx)), + Const { did: _, ty, default } => { + GenericParamDefKind::Const { ty: ty.into_tcx(tcx), default } + } } } } diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 72a4d9a183011..6d9a5cb515a48 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -324,7 +324,7 @@ pub struct GenericParamDef { pub enum GenericParamDefKind { Lifetime, Type { bounds: Vec, default: Option }, - Const(Type), + Const { ty: Type, default: Option }, } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] From 3bd7de90df4539f07df0db3837e411253e76276f Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 3 Jun 2021 09:40:07 +0100 Subject: [PATCH 02/11] add test --- src/test/rustdoc/const-generics/const-generic-defaults.rs | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/test/rustdoc/const-generics/const-generic-defaults.rs diff --git a/src/test/rustdoc/const-generics/const-generic-defaults.rs b/src/test/rustdoc/const-generics/const-generic-defaults.rs new file mode 100644 index 0000000000000..efe35bf7aa442 --- /dev/null +++ b/src/test/rustdoc/const-generics/const-generic-defaults.rs @@ -0,0 +1,6 @@ +#![crate_name = "foo"] +#![feature(const_generics_defaults)] + +// @has foo/struct.Foo.html '//pre[@class="rust struct"]' \ +// 'pub struct Foo(_);' +pub struct Foo(T); From eb3fd6d208da80147430fea4be740acea687d8aa Mon Sep 17 00:00:00 2001 From: Reagan McFarland Date: Sun, 6 Jun 2021 16:21:47 -0400 Subject: [PATCH 03/11] Default panic message should print Box Prior to this patch, the default panic message (resulting from calling `panic_any(42);` for example), would print the following error message: ``` thread 'main' panicked at 'Box', ... ``` However, this should be `Box` instead. --- library/std/src/panicking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 02957e75a7409..e591e073e7bbb 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -193,7 +193,7 @@ fn default_hook(info: &PanicInfo<'_>) { Some(s) => *s, None => match info.payload().downcast_ref::() { Some(s) => &s[..], - None => "Box", + None => "Box", }, }; let thread = thread_info::current_thread(); From 570ba09cbe3922036db07f5862ebe6cc2a4b456e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 6 Jun 2021 23:06:01 +0200 Subject: [PATCH 04/11] Fix invalid weight for type pages --- src/librustdoc/html/static/rustdoc.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index d3f8a7aa67dd7..35b2785fac004 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -138,7 +138,7 @@ h2, h3, h4 { border-bottom: 1px solid; } .impl, .method, -.type, .associatedconstant, +.type:not(.container-rustdoc), .associatedconstant, .associatedtype { flex-basis: 100%; font-weight: 600; From 45973621bcc57adb4d97d23d20ae915041db5534 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 6 Jun 2021 23:06:49 +0200 Subject: [PATCH 05/11] Add test to check that font-weight is correctly set on type page --- src/test/rustdoc-gui/sidebar.goml | 3 ++- src/test/rustdoc-gui/src/lib.rs | 3 +++ src/test/rustdoc-gui/type-weight.rs | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-gui/type-weight.rs diff --git a/src/test/rustdoc-gui/sidebar.goml b/src/test/rustdoc-gui/sidebar.goml index 388ca120d770e..7703677154ef9 100644 --- a/src/test/rustdoc-gui/sidebar.goml +++ b/src/test/rustdoc-gui/sidebar.goml @@ -11,7 +11,8 @@ assert: (".sidebar-elems > .items > ul > li:nth-child(2)", "Structs") assert: (".sidebar-elems > .items > ul > li:nth-child(3)", "Enums") assert: (".sidebar-elems > .items > ul > li:nth-child(4)", "Traits") assert: (".sidebar-elems > .items > ul > li:nth-child(5)", "Functions") -assert: (".sidebar-elems > .items > ul > li:nth-child(6)", "Keywords") +assert: (".sidebar-elems > .items > ul > li:nth-child(6)", "Type Definitions") +assert: (".sidebar-elems > .items > ul > li:nth-child(7)", "Keywords") assert: ("#structs + table td > a", "Foo") click: "#structs + table td > a" diff --git a/src/test/rustdoc-gui/src/lib.rs b/src/test/rustdoc-gui/src/lib.rs index 272b1d05452e3..5141b6d1920ea 100644 --- a/src/test/rustdoc-gui/src/lib.rs +++ b/src/test/rustdoc-gui/src/lib.rs @@ -96,3 +96,6 @@ pub enum AnEnum { #[doc(keyword = "CookieMonster")] pub mod keyword {} + +/// Just some type alias. +pub type SomeType = u32; diff --git a/src/test/rustdoc-gui/type-weight.rs b/src/test/rustdoc-gui/type-weight.rs new file mode 100644 index 0000000000000..8b6518e7f317a --- /dev/null +++ b/src/test/rustdoc-gui/type-weight.rs @@ -0,0 +1,2 @@ +goto: file://|DOC_PATH|/test_docs/type.SomeType.html +assert-all: (".top-block .docblock p", {"font-weight": "400"}) From 8330233ba751778f8571c8879f85612fd2d9fb9a Mon Sep 17 00:00:00 2001 From: Reagan McFarland Date: Sun, 6 Jun 2021 19:38:53 -0400 Subject: [PATCH 06/11] Update testsuite to match new panic msg This patch fixes tests from failing that were matching on `Box`, which was the old panic message. Since the new panic message is `Box`, the tests have been updated to match against this instead. --- src/test/ui/panics/panic-macro-any-wrapped.rs | 2 +- src/test/ui/panics/panic-macro-any.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/ui/panics/panic-macro-any-wrapped.rs b/src/test/ui/panics/panic-macro-any-wrapped.rs index 95ae6ffe8be02..100ac10c76717 100644 --- a/src/test/ui/panics/panic-macro-any-wrapped.rs +++ b/src/test/ui/panics/panic-macro-any-wrapped.rs @@ -1,5 +1,5 @@ // run-fail -// error-pattern:panicked at 'Box' +// error-pattern:panicked at 'Box' // ignore-emscripten no processes #![allow(non_fmt_panic)] diff --git a/src/test/ui/panics/panic-macro-any.rs b/src/test/ui/panics/panic-macro-any.rs index d2a7ba3713a51..a5ba30220e89a 100644 --- a/src/test/ui/panics/panic-macro-any.rs +++ b/src/test/ui/panics/panic-macro-any.rs @@ -1,5 +1,5 @@ // run-fail -// error-pattern:panicked at 'Box' +// error-pattern:panicked at 'Box' // ignore-emscripten no processes #![feature(box_syntax)] From f7117f8c177c63d6aadfb569550839b4add617a9 Mon Sep 17 00:00:00 2001 From: Ellen Date: Mon, 7 Jun 2021 09:47:05 +0100 Subject: [PATCH 07/11] format version --- src/librustdoc/json/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index f8bd971081395..0d84bf250c9e3 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -234,7 +234,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { ) }) .collect(), - format_version: 5, + format_version: 6, }; let mut p = self.out_path.clone(); p.push(output.index.get(&output.root).unwrap().name.clone().unwrap()); From a20870bdb9ecce8af7acb2db13177fc52f890f92 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Mon, 7 Jun 2021 13:01:04 +0200 Subject: [PATCH 08/11] Comment out unused error codes in error_codes.rs --- compiler/rustc_error_codes/src/error_codes.rs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index c343809179b0a..f82c03a4f8894 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -553,8 +553,8 @@ E0783: include_str!("./error_codes/E0783.md"), E0311, // thing may not live long enough E0313, // lifetime of borrowed pointer outlives lifetime of captured // variable - E0314, // closure outlives stack frame - E0315, // cannot invoke closure outside of its lifetime +// E0314, // closure outlives stack frame +// E0315, // cannot invoke closure outside of its lifetime E0316, // nested quantification of lifetimes // E0319, // trait impls for defaulted traits allowed just for structs/enums E0320, // recursive overflow during dropck @@ -584,21 +584,21 @@ E0783: include_str!("./error_codes/E0783.md"), // E0470, removed // E0471, // constant evaluation error (in pattern) E0472, // llvm_asm! is unsupported on this target - E0473, // dereference of reference outside its lifetime - E0474, // captured variable `..` does not outlive the enclosing closure - E0475, // index of slice outside its lifetime +// E0473, // dereference of reference outside its lifetime +// E0474, // captured variable `..` does not outlive the enclosing closure +// E0475, // index of slice outside its lifetime E0476, // lifetime of the source pointer does not outlive lifetime bound... - E0479, // the type `..` (provided as the value of a type parameter) is... - E0480, // lifetime of method receiver does not outlive the method call - E0481, // lifetime of function argument does not outlive the function call +// E0479, // the type `..` (provided as the value of a type parameter) is... +// E0480, // lifetime of method receiver does not outlive the method call +// E0481, // lifetime of function argument does not outlive the function call E0482, // lifetime of return value does not outlive the function call - E0483, // lifetime of operand does not outlive the operation - E0484, // reference is not valid at the time of borrow - E0485, // automatically reference is not valid at the time of borrow - E0486, // type of expression contains references that are not valid during.. - E0487, // unsafe use of destructor: destructor might be called while... - E0488, // lifetime of variable does not enclose its declaration - E0489, // type/lifetime parameter not in scope here +// E0483, // lifetime of operand does not outlive the operation +// E0484, // reference is not valid at the time of borrow +// E0485, // automatically reference is not valid at the time of borrow +// E0486, // type of expression contains references that are not valid during.. +// E0487, // unsafe use of destructor: destructor might be called while... +// E0488, // lifetime of variable does not enclose its declaration +// E0489, // type/lifetime parameter not in scope here E0490, // a value of type `..` is borrowed for too long E0498, // malformed plugin attribute E0514, // metadata version mismatch From c01d63ab767084eba25bfc317d5aa1f21820836d Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Mon, 7 Jun 2021 13:05:17 +0200 Subject: [PATCH 09/11] Add E0316.md --- compiler/rustc_error_codes/src/error_codes.rs | 2 +- .../src/error_codes/E0316.md | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0316.md diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index f82c03a4f8894..f10efd832361c 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -157,6 +157,7 @@ E0308: include_str!("./error_codes/E0308.md"), E0309: include_str!("./error_codes/E0309.md"), E0310: include_str!("./error_codes/E0310.md"), E0312: include_str!("./error_codes/E0312.md"), +E0316: include_str!("./error_codes/E0316.md"), E0317: include_str!("./error_codes/E0317.md"), E0321: include_str!("./error_codes/E0321.md"), E0322: include_str!("./error_codes/E0322.md"), @@ -555,7 +556,6 @@ E0783: include_str!("./error_codes/E0783.md"), // variable // E0314, // closure outlives stack frame // E0315, // cannot invoke closure outside of its lifetime - E0316, // nested quantification of lifetimes // E0319, // trait impls for defaulted traits allowed just for structs/enums E0320, // recursive overflow during dropck // E0372, // coherence not object safe diff --git a/compiler/rustc_error_codes/src/error_codes/E0316.md b/compiler/rustc_error_codes/src/error_codes/E0316.md new file mode 100644 index 0000000000000..4368c321737b2 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0316.md @@ -0,0 +1,32 @@ +A `where` clause contains a nested quantification over lifetimes. + +Erroneous code example: + +```compile_fail,E0316 +trait Tr<'a, 'b> {} + +fn foo(t: T) +where + for<'a> &'a T: for<'b> Tr<'a, 'b>, // error: nested quantification +{ +} +``` + +Rust syntax allows lifetime quantifications in two places within +`where` clauses: Quantifying over the trait bound only (as in +`Ty: for<'l> Trait<'l>`) and quantifying over the whole clause +(as in `for<'l> &'l Ty: Trait<'l>`). Using both in the same clause +leads to a nested lifetime quantification, which is not supported. + +The following example compiles, because the clause with the nested +quantification has been rewritten to use only one `for<>`: + +``` +trait Tr<'a, 'b> {} + +fn foo(t: T) +where + for<'a, 'b> &'a T: Tr<'a, 'b>, // ok +{ +} +``` From 09307a3e0db0154ac0c37443463a73c32bfe9b5d Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Mon, 7 Jun 2021 15:00:47 +0200 Subject: [PATCH 10/11] Bless ui/where-clauses/where-for-self.rs test --- src/test/ui/where-clauses/where-for-self.stderr | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/where-clauses/where-for-self.stderr b/src/test/ui/where-clauses/where-for-self.stderr index 84430ffcf887f..d06afc1e42376 100644 --- a/src/test/ui/where-clauses/where-for-self.stderr +++ b/src/test/ui/where-clauses/where-for-self.stderr @@ -6,3 +6,4 @@ LL | where for<'a> &'a T: for<'b> Bar<'b> error: aborting due to previous error +For more information about this error, try `rustc --explain E0316`. From fb92c92a7211c45f8361f2e865512dce244f3c96 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 7 Jun 2021 09:50:07 -0500 Subject: [PATCH 11/11] Remove lifetime hack --- compiler/rustc_resolve/src/late/lifetimes.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index efa5d7e7b1139..ca7cdc4caf505 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -1841,14 +1841,6 @@ fn object_lifetime_defaults_for_item( } impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { - // FIXME(#37666) this works around a limitation in the region inferencer - fn hack(&mut self, f: F) - where - F: for<'b> FnOnce(&mut LifetimeContext<'b, 'tcx>), - { - f(self) - } - fn with(&mut self, wrap_scope: Scope<'_>, f: F) where F: for<'b> FnOnce(ScopeRef<'_>, &mut LifetimeContext<'b, 'tcx>), @@ -2252,7 +2244,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { }; self.with(scope, move |old_scope, this| { this.check_lifetime_params(old_scope, &generics.params); - this.hack(walk); // FIXME(#37666) workaround in place of `walk(this)` + walk(this); }); }