From e1f735a5d1d39cd1d609fe7708bd79639cfa0e64 Mon Sep 17 00:00:00 2001 From: b-naber Date: Thu, 29 Sep 2022 18:33:58 +0200 Subject: [PATCH 01/20] don't repeat lifetime names from outer binder in print --- compiler/rustc_middle/src/ty/print/pretty.rs | 69 ++++++++++++++++---- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index f69ac0768204a..ad76422ef6618 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2055,7 +2055,14 @@ struct RegionFolder<'a, 'tcx> { tcx: TyCtxt<'tcx>, current_index: ty::DebruijnIndex, region_map: BTreeMap>, - name: &'a mut (dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx> + 'a), + name: &'a mut ( + dyn FnMut( + Option, + ty::DebruijnIndex, + ty::BoundRegion, + ) -> ty::Region<'tcx> + + 'a + ), } impl<'a, 'tcx> ty::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> { @@ -2086,7 +2093,9 @@ impl<'a, 'tcx> ty::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { let name = &mut self.name; let region = match *r { - ty::ReLateBound(_, br) => *self.region_map.entry(br).or_insert_with(|| name(br)), + ty::ReLateBound(db, br) => { + *self.region_map.entry(br).or_insert_with(|| name(Some(db), self.current_index, br)) + } ty::RePlaceholder(ty::PlaceholderRegion { name: kind, .. }) => { // If this is an anonymous placeholder, don't rename. Otherwise, in some // async fns, we get a `for<'r> Send` bound @@ -2095,7 +2104,10 @@ impl<'a, 'tcx> ty::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> { _ => { // Index doesn't matter, since this is just for naming and these never get bound let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind }; - *self.region_map.entry(br).or_insert_with(|| name(br)) + *self + .region_map + .entry(br) + .or_insert_with(|| name(None, self.current_index, br)) } } } @@ -2234,24 +2246,57 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { }) } else { let tcx = self.tcx; - let mut name = |br: ty::BoundRegion| { - start_or_continue(&mut self, "for<", ", "); - let kind = match br.kind { + let mut name = |db: Option, + binder_level: ty::DebruijnIndex, + br: ty::BoundRegion| { + let (name, kind) = match br.kind { ty::BrAnon(_) | ty::BrEnv => { let name = next_name(&self); - do_continue(&mut self, name); - ty::BrNamed(CRATE_DEF_ID.to_def_id(), name) + + if let Some(db) = db { + if db > binder_level { + let kind = ty::BrNamed(CRATE_DEF_ID.to_def_id(), name); + return tcx.mk_region(ty::ReLateBound( + ty::INNERMOST, + ty::BoundRegion { var: br.var, kind }, + )); + } + } + + (name, ty::BrNamed(CRATE_DEF_ID.to_def_id(), name)) } ty::BrNamed(def_id, kw::UnderscoreLifetime) => { let name = next_name(&self); - do_continue(&mut self, name); - ty::BrNamed(def_id, name) + + if let Some(db) = db { + if db > binder_level { + let kind = ty::BrNamed(def_id, name); + return tcx.mk_region(ty::ReLateBound( + ty::INNERMOST, + ty::BoundRegion { var: br.var, kind }, + )); + } + } + + (name, ty::BrNamed(def_id, name)) } ty::BrNamed(_, name) => { - do_continue(&mut self, name); - br.kind + if let Some(db) = db { + if db > binder_level { + let kind = br.kind; + return tcx.mk_region(ty::ReLateBound( + ty::INNERMOST, + ty::BoundRegion { var: br.var, kind }, + )); + } + } + + (name, br.kind) } }; + + start_or_continue(&mut self, "for<", ", "); + do_continue(&mut self, name); tcx.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { var: br.var, kind })) }; let mut folder = RegionFolder { From a8f17e3ad49090fd4b7c1301fbea6858453ecfb9 Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 30 Sep 2022 14:21:17 +0200 Subject: [PATCH 02/20] bless tests --- .../issue-70935-complex-spans.drop_tracking.stderr | 2 +- .../coherence-fn-covariant-bound-vs-static.stderr | 4 ++-- src/test/ui/lifetimes/re-empty-in-error.stderr | 2 +- src/test/ui/regions/issue-102392.rs | 6 ++++++ src/test/ui/regions/issue-102392.stderr | 14 ++++++++++++++ .../higher-ranked-fn-type.quiet.stderr | 4 ++-- src/test/ui/where-clauses/higher-ranked-fn-type.rs | 2 +- 7 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/regions/issue-102392.rs create mode 100644 src/test/ui/regions/issue-102392.stderr diff --git a/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr b/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr index 85f7d1dd6748b..7fb8811666536 100644 --- a/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr +++ b/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr @@ -18,7 +18,7 @@ LL | async fn baz(_c: impl FnMut() -> T) where T: Future { | ___________________________________________________________________^ LL | | } | |_^ - = note: required because it captures the following types: `ResumeTy`, `impl for<'a, 'b, 'c> Future`, `()` + = note: required because it captures the following types: `ResumeTy`, `impl Future`, `()` note: required because it's used within this `async` block --> $DIR/issue-70935-complex-spans.rs:16:16 | diff --git a/src/test/ui/coherence/coherence-fn-covariant-bound-vs-static.stderr b/src/test/ui/coherence/coherence-fn-covariant-bound-vs-static.stderr index cfcef9699f372..7dabd97b94e82 100644 --- a/src/test/ui/coherence/coherence-fn-covariant-bound-vs-static.stderr +++ b/src/test/ui/coherence/coherence-fn-covariant-bound-vs-static.stderr @@ -1,10 +1,10 @@ -error[E0119]: conflicting implementations of trait `Trait` for type `for<'r> fn(for<'r> fn(&'r ()))` +error[E0119]: conflicting implementations of trait `Trait` for type `for<'r> fn(fn(&'r ()))` --> $DIR/coherence-fn-covariant-bound-vs-static.rs:17:1 | LL | impl Trait for for<'r> fn(fn(&'r ())) {} | ------------------------------------- first implementation here LL | impl<'a> Trait for fn(fn(&'a ())) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'r> fn(for<'r> fn(&'r ()))` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'r> fn(fn(&'r ()))` | = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details diff --git a/src/test/ui/lifetimes/re-empty-in-error.stderr b/src/test/ui/lifetimes/re-empty-in-error.stderr index 840707d947081..c35d8ecec5e2d 100644 --- a/src/test/ui/lifetimes/re-empty-in-error.stderr +++ b/src/test/ui/lifetimes/re-empty-in-error.stderr @@ -4,7 +4,7 @@ error: higher-ranked lifetime error LL | foo(&10); | ^^^^^^^^ | - = note: could not prove `for<'b, 'a> &'b (): 'a` + = note: could not prove `for<'b> &'b (): 'a` error: aborting due to previous error diff --git a/src/test/ui/regions/issue-102392.rs b/src/test/ui/regions/issue-102392.rs new file mode 100644 index 0000000000000..87cc1a8e7a88d --- /dev/null +++ b/src/test/ui/regions/issue-102392.rs @@ -0,0 +1,6 @@ +fn g(f: for<'a> fn(fn(&str, &'a str))) -> bool { + f + //~^ ERROR mismatched types +} + +fn main() {} diff --git a/src/test/ui/regions/issue-102392.stderr b/src/test/ui/regions/issue-102392.stderr new file mode 100644 index 0000000000000..56f4c0c5db4b7 --- /dev/null +++ b/src/test/ui/regions/issue-102392.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/issue-102392.rs:2:5 + | +LL | fn g(f: for<'a> fn(fn(&str, &'a str))) -> bool { + | ---- expected `bool` because of return type +LL | f + | ^ expected `bool`, found fn pointer + | + = note: expected type `bool` + found fn pointer `for<'a> fn(for<'b> fn(&'b str, &'a str))` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/where-clauses/higher-ranked-fn-type.quiet.stderr b/src/test/ui/where-clauses/higher-ranked-fn-type.quiet.stderr index d9950a3d9b7cd..30248a7a397b3 100644 --- a/src/test/ui/where-clauses/higher-ranked-fn-type.quiet.stderr +++ b/src/test/ui/where-clauses/higher-ranked-fn-type.quiet.stderr @@ -1,8 +1,8 @@ -error[E0277]: the trait bound `for<'b> for<'b> fn(&'b ()): Foo` is not satisfied +error[E0277]: the trait bound `for<'b> fn(&'b ()): Foo` is not satisfied --> $DIR/higher-ranked-fn-type.rs:20:5 | LL | called() - | ^^^^^^ the trait `for<'b> Foo` is not implemented for `for<'b> fn(&'b ())` + | ^^^^^^ the trait `for<'b> Foo` is not implemented for `fn(&'b ())` | note: required by a bound in `called` --> $DIR/higher-ranked-fn-type.rs:12:25 diff --git a/src/test/ui/where-clauses/higher-ranked-fn-type.rs b/src/test/ui/where-clauses/higher-ranked-fn-type.rs index 0d8893e08d319..ab6edde4ee7ea 100644 --- a/src/test/ui/where-clauses/higher-ranked-fn-type.rs +++ b/src/test/ui/where-clauses/higher-ranked-fn-type.rs @@ -18,7 +18,7 @@ where (for<'a> fn(&'a ())): Foo, { called() - //[quiet]~^ ERROR the trait bound `for<'b> for<'b> fn(&'b ()): Foo` is not satisfied + //[quiet]~^ ERROR the trait bound `for<'b> fn(&'b ()): Foo` is not satisfied //[verbose]~^^ ERROR the trait bound `for<'b> fn(&ReLateBound( } From e83dcf4ecd678bac474d6aaca1cf0294bcbcd1b3 Mon Sep 17 00:00:00 2001 From: b-naber Date: Mon, 3 Oct 2022 17:37:22 +0200 Subject: [PATCH 03/20] re-name params + add comments --- compiler/rustc_middle/src/ty/print/pretty.rs | 26 ++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index ad76422ef6618..b78661270e181 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2057,8 +2057,8 @@ struct RegionFolder<'a, 'tcx> { region_map: BTreeMap>, name: &'a mut ( dyn FnMut( - Option, - ty::DebruijnIndex, + Option, // Debruijn index of the folded late-bound region + ty::DebruijnIndex, // Index corresponding to binder level ty::BoundRegion, ) -> ty::Region<'tcx> + 'a @@ -2246,15 +2246,21 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { }) } else { let tcx = self.tcx; - let mut name = |db: Option, - binder_level: ty::DebruijnIndex, + + // Closure used in `RegionFolder` to create names for anonymous late-bound + // regions. We use two `DebruijnIndex`es (one for the currently folded + // late-bound region and the other for the binder level) to determine + // whether a name has already been created for the currently folded region, + // see issue #102392. + let mut name = |lifetime_idx: Option, + binder_level_idx: ty::DebruijnIndex, br: ty::BoundRegion| { let (name, kind) = match br.kind { ty::BrAnon(_) | ty::BrEnv => { let name = next_name(&self); - if let Some(db) = db { - if db > binder_level { + if let Some(lt_idx) = lifetime_idx { + if lt_idx > binder_level_idx { let kind = ty::BrNamed(CRATE_DEF_ID.to_def_id(), name); return tcx.mk_region(ty::ReLateBound( ty::INNERMOST, @@ -2268,8 +2274,8 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { ty::BrNamed(def_id, kw::UnderscoreLifetime) => { let name = next_name(&self); - if let Some(db) = db { - if db > binder_level { + if let Some(lt_idx) = lifetime_idx { + if lt_idx > binder_level_idx { let kind = ty::BrNamed(def_id, name); return tcx.mk_region(ty::ReLateBound( ty::INNERMOST, @@ -2281,8 +2287,8 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { (name, ty::BrNamed(def_id, name)) } ty::BrNamed(_, name) => { - if let Some(db) = db { - if db > binder_level { + if let Some(lt_idx) = lifetime_idx { + if lt_idx > binder_level_idx { let kind = br.kind; return tcx.mk_region(ty::ReLateBound( ty::INNERMOST, From 31bc385fa1d46d5affdab32b6e8a1a876b10443f Mon Sep 17 00:00:00 2001 From: chrysn Date: Tue, 4 Oct 2022 16:55:40 +0200 Subject: [PATCH 04/20] rustdoc: Document effect of fundamental types --- src/doc/rustdoc/src/unstable-features.md | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index 32b350074903e..c6c05e3009083 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -197,6 +197,35 @@ To do so, the `#[doc(keyword = "...")]` attribute is used. Example: mod empty_mod {} ``` +## Effects of other nightly features + +These nightly-only features are not primarily related to Rustdoc, +but have convenient effects on the documentation produced. + +### `fundamental` types + +Annotating a type with `#[fundamental]` primarily influences coherence rules about generic types, +i.e., they alter whether other crates can provide implementations for that type. +The unstable book [links to further information][unstable-fundamental]. + +[unstable-fundamental]: https://doc.rust-lang.org/unstable-book/language-features/fundamental.html + +For documentation, this has an additional side effect: +If a method is implemented on `F` (or `F<&T>`), +where `F` is a fundamental type, +then the method is not only documented at the page about `F`, +but also on the page about `T`. +In a sense, it makes the type transparent to Rustdoc. +This is especially convenient for types that work as annotated pointers, +such as `Pin<&mut T>`, +as it ensures that methods only implemented through those annotated pointers +can still be found with the type they act on. + +If the `fundamental` feature's effect on coherence is not intended, +such a type can be marked as fundamental only for purposes of documentation +by introducing a custom feature and +limiting the use of `fundamental` to when documentation is built. + ## Unstable command-line arguments These features are enabled by passing a command-line flag to Rustdoc, but the flags in question are From f708c82af74d0af607a750542ef56c3f44598109 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 6 Oct 2022 12:33:29 +0200 Subject: [PATCH 05/20] rename rustc_allocator_nounwind to rustc_nounwind --- compiler/rustc_feature/src/builtin_attrs.rs | 2 +- compiler/rustc_hir_analysis/src/collect.rs | 2 +- compiler/rustc_span/src/symbol.rs | 2 +- library/alloc/src/alloc.rs | 12 ++++++++---- .../function_calls/exported_symbol_bad_unwind2.rs | 4 ++-- .../rust-analyzer/crates/hir-def/src/builtin_attr.rs | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 5ee6c9f238770..92d0fb1aec83f 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -536,7 +536,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // ========================================================================== rustc_attr!(rustc_allocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL), - rustc_attr!(rustc_allocator_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL), + rustc_attr!(rustc_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL), rustc_attr!(rustc_reallocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL), rustc_attr!(rustc_deallocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL), rustc_attr!(rustc_allocator_zeroed, Normal, template!(Word), WarnFollowing, IMPL_DETAIL), diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index ab4b861b6cb60..8d48a25f290e3 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1647,7 +1647,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs { ) .emit(); } - } else if attr.has_name(sym::rustc_allocator_nounwind) { + } else if attr.has_name(sym::rustc_nounwind) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND; } else if attr.has_name(sym::rustc_reallocator) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR; diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 8cb7d147d0253..7f187e0fc7735 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1230,7 +1230,6 @@ symbols! { rust_oom, rustc, rustc_allocator, - rustc_allocator_nounwind, rustc_allocator_zeroed, rustc_allow_const_fn_unstable, rustc_allow_incoherent_impl, @@ -1277,6 +1276,7 @@ symbols! { rustc_mir, rustc_must_implement_one_of, rustc_nonnull_optimization_guaranteed, + rustc_nounwind, rustc_object_lifetime_default, rustc_on_unimplemented, rustc_outlives, diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 80b067812ba7d..8187517ccfbb4 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -28,16 +28,20 @@ extern "Rust" { // The rustc fork of LLVM 14 and earlier also special-cases these function names to be able to optimize them // like `malloc`, `realloc`, and `free`, respectively. #[rustc_allocator] - #[rustc_allocator_nounwind] + #[cfg_attr(not(bootstrap), rustc_nounwind)] + #[cfg_attr(bootstrap, rustc_allocator_nounwind)] fn __rust_alloc(size: usize, align: usize) -> *mut u8; #[rustc_deallocator] - #[rustc_allocator_nounwind] + #[cfg_attr(not(bootstrap), rustc_nounwind)] + #[cfg_attr(bootstrap, rustc_allocator_nounwind)] fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize); #[rustc_reallocator] - #[rustc_allocator_nounwind] + #[cfg_attr(not(bootstrap), rustc_nounwind)] + #[cfg_attr(bootstrap, rustc_allocator_nounwind)] fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8; #[rustc_allocator_zeroed] - #[rustc_allocator_nounwind] + #[cfg_attr(not(bootstrap), rustc_nounwind)] + #[cfg_attr(bootstrap, rustc_allocator_nounwind)] fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8; } diff --git a/src/tools/miri/tests/fail/function_calls/exported_symbol_bad_unwind2.rs b/src/tools/miri/tests/fail/function_calls/exported_symbol_bad_unwind2.rs index d9aacdb8aea4e..f85ad5ae5072f 100644 --- a/src/tools/miri/tests/fail/function_calls/exported_symbol_bad_unwind2.rs +++ b/src/tools/miri/tests/fail/function_calls/exported_symbol_bad_unwind2.rs @@ -1,7 +1,7 @@ //@revisions: extern_block definition both #![feature(rustc_attrs, c_unwind)] -#[cfg_attr(any(definition, both), rustc_allocator_nounwind)] +#[cfg_attr(any(definition, both), rustc_nounwind)] #[no_mangle] extern "C-unwind" fn nounwind() { //[definition]~^ ERROR: abnormal termination: the program aborted execution @@ -11,7 +11,7 @@ extern "C-unwind" fn nounwind() { fn main() { extern "C-unwind" { - #[cfg_attr(any(extern_block, both), rustc_allocator_nounwind)] + #[cfg_attr(any(extern_block, both), rustc_nounwind)] fn nounwind(); } unsafe { nounwind() } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs b/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs index 0e7ce5f85f966..39581b33a8da2 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs @@ -379,7 +379,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[ // ========================================================================== rustc_attr!(rustc_allocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL), - rustc_attr!(rustc_allocator_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL), + rustc_attr!(rustc_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL), gated!( alloc_error_handler, Normal, template!(Word), WarnFollowing, experimental!(alloc_error_handler) From 128344196ba5d7da8185e498706996a135849b5f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 7 Oct 2022 11:24:02 -0700 Subject: [PATCH 06/20] Let llvm-config tell us where to find its tools --- src/bootstrap/native.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 9045354d0b20a..fcd4148145163 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -497,18 +497,13 @@ impl Step for Llvm { // https://llvm.org/docs/HowToCrossCompileLLVM.html if target != builder.config.build { - builder.ensure(Llvm { target: builder.config.build }); - // FIXME: if the llvm root for the build triple is overridden then we - // should use llvm-tblgen from there, also should verify that it - // actually exists most of the time in normal installs of LLVM. - let host_bin = builder.llvm_out(builder.config.build).join("bin"); + let llvm_config = builder.ensure(Llvm { target: builder.config.build }); + let llvm_bindir = output(Command::new(&llvm_config).arg("--bindir")); + let host_bin = Path::new(llvm_bindir.trim()); cfg.define("LLVM_TABLEGEN", host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION)); // LLVM_NM is required for cross compiling using MSVC cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION)); - cfg.define( - "LLVM_CONFIG_PATH", - host_bin.join("llvm-config").with_extension(EXE_EXTENSION), - ); + cfg.define("LLVM_CONFIG_PATH", llvm_config); if builder.config.llvm_clang { let build_bin = builder.llvm_out(builder.config.build).join("build").join("bin"); let clang_tblgen = build_bin.join("clang-tblgen").with_extension(EXE_EXTENSION); From 40e497fc9cc271e4935a68854c7888fb56fccb1e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 7 Oct 2022 11:25:01 -0700 Subject: [PATCH 07/20] Add llvm-tblgen to rust-dev for cross-compiling --- src/bootstrap/dist.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 7eb8f8bbb30ed..5a7a193897bfa 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -2028,6 +2028,7 @@ impl Step for RustDev { "llvm-nm", "llvm-dwarfdump", "llvm-dis", + "llvm-tblgen", ] { tarball.add_file(src_bindir.join(exe(bin, target)), "bin", 0o755); } From c3277198a1feccef6d96c84e6d40665a49820e8f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 7 Oct 2022 11:29:24 -0700 Subject: [PATCH 08/20] Bump download-ci-llvm-stamp --- src/bootstrap/download-ci-llvm-stamp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/download-ci-llvm-stamp b/src/bootstrap/download-ci-llvm-stamp index 2e11cf19c3f6a..d19a1ae95cf14 100644 --- a/src/bootstrap/download-ci-llvm-stamp +++ b/src/bootstrap/download-ci-llvm-stamp @@ -1,4 +1,4 @@ Change this file to make users of the `download-ci-llvm` configuration download a new version of LLVM from CI, even if the LLVM submodule hasn’t changed. -Last change is for: https://github.com/rust-lang/rust/pull/97550 +Last change is for: https://github.com/rust-lang/rust/pull/102790 From a027474ea6b424aa4101edc9d15d8ebe677783e9 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 7 Oct 2022 15:12:27 -0700 Subject: [PATCH 09/20] Don't run llvm-config in dry runs --- src/bootstrap/native.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index fcd4148145163..ea97ae4f65127 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -498,11 +498,16 @@ impl Step for Llvm { // https://llvm.org/docs/HowToCrossCompileLLVM.html if target != builder.config.build { let llvm_config = builder.ensure(Llvm { target: builder.config.build }); - let llvm_bindir = output(Command::new(&llvm_config).arg("--bindir")); - let host_bin = Path::new(llvm_bindir.trim()); - cfg.define("LLVM_TABLEGEN", host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION)); - // LLVM_NM is required for cross compiling using MSVC - cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION)); + if !builder.config.dry_run { + let llvm_bindir = output(Command::new(&llvm_config).arg("--bindir")); + let host_bin = Path::new(llvm_bindir.trim()); + cfg.define( + "LLVM_TABLEGEN", + host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION), + ); + // LLVM_NM is required for cross compiling using MSVC + cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION)); + } cfg.define("LLVM_CONFIG_PATH", llvm_config); if builder.config.llvm_clang { let build_bin = builder.llvm_out(builder.config.build).join("build").join("bin"); From fc3d7eb91dcea2f77a51368681dd2674b232a426 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Wed, 27 Jul 2022 20:54:59 +0300 Subject: [PATCH 10/20] don't ICE when normalizing closure input tys `normalize_and_add_constraints` doesn't add entries in `universe_causes` when creating new universes, causing an ICE. Remove it! Add spans to track normalization constraints. Fix couple places where `universe_causes` is not updated correctly to track newly added universes. --- .../src/type_check/canonical.rs | 17 +-- .../src/type_check/free_region_relations.rs | 8 +- .../src/type_check/input_output.rs | 39 +------ compiler/rustc_borrowck/src/type_check/mod.rs | 9 +- ...malformed-projection-input-issue-102800.rs | 31 ++++++ ...ormed-projection-input-issue-102800.stderr | 104 ++++++++++++++++++ 6 files changed, 150 insertions(+), 58 deletions(-) create mode 100644 src/test/ui/nll/closure-malformed-projection-input-issue-102800.rs create mode 100644 src/test/ui/nll/closure-malformed-projection-input-issue-102800.stderr diff --git a/compiler/rustc_borrowck/src/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs index 9271a2f4dc718..a581726a15c9c 100644 --- a/compiler/rustc_borrowck/src/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -52,11 +52,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Some(error_info) => error_info.to_universe_info(old_universe), None => UniverseInfo::other(), }; - for u in old_universe..universe { - self.borrowck_context - .constraints - .universe_causes - .insert(u + 1, universe_info.clone()); + for u in (old_universe + 1)..=universe { + self.borrowck_context.constraints.universe_causes.insert(u, universe_info.clone()); } } @@ -71,15 +68,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { where T: TypeFoldable<'tcx>, { + let old_universe = self.infcx.universe(); + let (instantiated, _) = self.infcx.instantiate_canonical_with_fresh_inference_vars(span, canonical); - for u in 0..canonical.max_universe.as_u32() { - let info = UniverseInfo::other(); - self.borrowck_context - .constraints - .universe_causes - .insert(ty::UniverseIndex::from_u32(u), info); + for u in (old_universe + 1)..=self.infcx.universe() { + self.borrowck_context.constraints.universe_causes.insert(u, UniverseInfo::other()); } instantiated diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs index e0140e281ee73..7d71f0b23d180 100644 --- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -8,7 +8,6 @@ use rustc_infer::infer::InferCtxt; use rustc_middle::mir::ConstraintCategory; use rustc_middle::traits::query::OutlivesBound; use rustc_middle::ty::{self, RegionVid, Ty}; -use rustc_span::DUMMY_SP; use rustc_trait_selection::traits::query::type_op::{self, TypeOp}; use std::rc::Rc; use type_op::TypeOpOutput; @@ -219,6 +218,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> { } pub(crate) fn create(mut self) -> CreateResult<'tcx> { + let span = self.infcx.tcx.def_span(self.universal_regions.defining_ty.def_id()); let unnormalized_input_output_tys = self .universal_regions .unnormalized_input_tys @@ -250,7 +250,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> { self.infcx .tcx .sess - .delay_span_bug(DUMMY_SP, &format!("failed to normalize {:?}", ty)); + .delay_span_bug(span, &format!("failed to normalize {:?}", ty)); TypeOpOutput { output: self.infcx.tcx.ty_error(), constraints: None, @@ -301,8 +301,8 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> { &self.region_bound_pairs, self.implicit_region_bound, self.param_env, - Locations::All(DUMMY_SP), - DUMMY_SP, + Locations::All(span), + span, ConstraintCategory::Internal, &mut self.constraints, ) diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs index 4431a2e8ec60d..a66ddd27dbb2e 100644 --- a/compiler/rustc_borrowck/src/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -7,16 +7,11 @@ //! `RETURN_PLACE` the MIR arguments) are always fully normalized (and //! contain revealed `impl Trait` values). -use crate::type_check::constraint_conversion::ConstraintConversion; use rustc_index::vec::Idx; use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_middle::mir::*; use rustc_middle::ty::Ty; use rustc_span::Span; -use rustc_span::DUMMY_SP; -use rustc_trait_selection::traits::query::type_op::{self, TypeOp}; -use rustc_trait_selection::traits::query::Fallible; -use type_op::TypeOpOutput; use crate::universal_regions::UniversalRegions; @@ -185,7 +180,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } - #[instrument(skip(self, span), level = "debug")] + #[instrument(skip(self), level = "debug")] fn equate_normalized_input_or_output(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, span: Span) { if let Err(_) = self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation) @@ -194,13 +189,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // `rustc_traits::normalize_after_erasing_regions`. Ideally, we'd // like to normalize *before* inserting into `local_decls`, but // doing so ends up causing some other trouble. - let b = match self.normalize_and_add_constraints(b) { - Ok(n) => n, - Err(_) => { - debug!("equate_inputs_and_outputs: NoSolution"); - b - } - }; + let b = self.normalize(b, Locations::All(span)); // Note: if we have to introduce new placeholders during normalization above, then we won't have // added those universes to the universe info, which we would want in `relate_tys`. @@ -218,28 +207,4 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } } - - pub(crate) fn normalize_and_add_constraints(&mut self, t: Ty<'tcx>) -> Fallible> { - let TypeOpOutput { output: norm_ty, constraints, .. } = - self.param_env.and(type_op::normalize::Normalize::new(t)).fully_perform(self.infcx)?; - - debug!("{:?} normalized to {:?}", t, norm_ty); - - for data in constraints { - ConstraintConversion::new( - self.infcx, - &self.borrowck_context.universal_regions, - &self.region_bound_pairs, - self.implicit_region_bound, - self.param_env, - Locations::All(DUMMY_SP), - DUMMY_SP, - ConstraintCategory::Internal, - &mut self.borrowck_context.constraints, - ) - .convert_all(&*data); - } - - Ok(norm_ty) - } } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index d03f036964857..101b33c4580f9 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -138,8 +138,6 @@ pub(crate) fn type_check<'mir, 'tcx>( use_polonius: bool, ) -> MirTypeckResults<'tcx> { let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body)); - let mut universe_causes = FxHashMap::default(); - universe_causes.insert(ty::UniverseIndex::from_u32(0), UniverseInfo::other()); let mut constraints = MirTypeckRegionConstraints { placeholder_indices: PlaceholderIndices::default(), placeholder_index_to_region: IndexVec::default(), @@ -148,7 +146,7 @@ pub(crate) fn type_check<'mir, 'tcx>( member_constraints: MemberConstraintSet::default(), closure_bounds_mapping: Default::default(), type_tests: Vec::default(), - universe_causes, + universe_causes: FxHashMap::default(), }; let CreateResult { @@ -165,9 +163,8 @@ pub(crate) fn type_check<'mir, 'tcx>( debug!(?normalized_inputs_and_output); - for u in ty::UniverseIndex::ROOT..infcx.universe() { - let info = UniverseInfo::other(); - constraints.universe_causes.insert(u, info); + for u in ty::UniverseIndex::ROOT..=infcx.universe() { + constraints.universe_causes.insert(u, UniverseInfo::other()); } let mut borrowck_context = BorrowCheckContext { diff --git a/src/test/ui/nll/closure-malformed-projection-input-issue-102800.rs b/src/test/ui/nll/closure-malformed-projection-input-issue-102800.rs new file mode 100644 index 0000000000000..25f47f5b6f6c9 --- /dev/null +++ b/src/test/ui/nll/closure-malformed-projection-input-issue-102800.rs @@ -0,0 +1,31 @@ +// Regression test for #102800 +// +// Here we are generating higher-ranked region constraints when normalizing and relating closure +// input types. Previously this was an ICE in the error path because we didn't register enough +// diagnostic information to render the higher-ranked subtyping error. + +// check-fail + +trait Trait { + type Ty; +} + +impl Trait for &'static () { + type Ty = (); +} + +fn main() { + let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + //~^ ERROR lifetime may not live long enough + //~| ERROR higher-ranked subtype error + //~| ERROR higher-ranked subtype error + //~| ERROR implementation of `Trait` is not general enough + //~| ERROR implementation of `Trait` is not general enough + //~| ERROR implementation of `Trait` is not general enough + //~| ERROR implementation of `Trait` is not general enough + //~| ERROR implementation of `Trait` is not general enough + //~| ERROR implementation of `Trait` is not general enough + //~| ERROR implementation of `Trait` is not general enough + //~| ERROR implementation of `Trait` is not general enough + //~| ERROR implementation of `Trait` is not general enough +} diff --git a/src/test/ui/nll/closure-malformed-projection-input-issue-102800.stderr b/src/test/ui/nll/closure-malformed-projection-input-issue-102800.stderr new file mode 100644 index 0000000000000..dbd5dabd1dacc --- /dev/null +++ b/src/test/ui/nll/closure-malformed-projection-input-issue-102800.stderr @@ -0,0 +1,104 @@ +error: lifetime may not live long enough + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^-^ + | || + | |has type `<&'1 () as Trait>::Ty` + | requires that `'1` must outlive `'static` + +error: higher-ranked subtype error + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^^^ + +error: higher-ranked subtype error + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^^^ + +error: implementation of `Trait` is not general enough + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^^^^^^ implementation of `Trait` is not general enough + | + = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`... + = note: ...but `Trait` is actually implemented for the type `&'static ()` + +error: implementation of `Trait` is not general enough + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:12 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough + | + = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`... + = note: ...but `Trait` is actually implemented for the type `&'static ()` + +error: implementation of `Trait` is not general enough + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:12 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough + | + = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`... + = note: ...but `Trait` is actually implemented for the type `&'static ()` + +error: implementation of `Trait` is not general enough + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:12 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough + | + = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`... + = note: ...but `Trait` is actually implemented for the type `&'static ()` + +error: implementation of `Trait` is not general enough + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:12 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough + | + = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`... + = note: ...but `Trait` is actually implemented for the type `&'static ()` + +error: implementation of `Trait` is not general enough + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^^^^^^ implementation of `Trait` is not general enough + | + = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`... + = note: ...but `Trait` is actually implemented for the type `&'static ()` + +error: implementation of `Trait` is not general enough + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^^^^^^ implementation of `Trait` is not general enough + | + = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`... + = note: ...but `Trait` is actually implemented for the type `&'static ()` + +error: implementation of `Trait` is not general enough + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^^^^^^ implementation of `Trait` is not general enough + | + = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`... + = note: ...but `Trait` is actually implemented for the type `&'static ()` + +error: implementation of `Trait` is not general enough + --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48 + | +LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {}; + | ^^^^^^ implementation of `Trait` is not general enough + | + = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`... + = note: ...but `Trait` is actually implemented for the type `&'static ()` + +error: aborting due to 12 previous errors + From b7562b110ff2ff8545dc63c1cde7f07ec45f6749 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 6 Oct 2022 12:40:43 +0200 Subject: [PATCH 11/20] add panic_fmt_nounwind for panicing without unwinding, and use it for panic_no_unwind --- compiler/rustc_hir_analysis/src/collect.rs | 7 ------- library/core/src/panicking.rs | 23 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 8d48a25f290e3..07a850486294a 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1580,13 +1580,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs { codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER; } - // The panic_no_unwind function called by TerminatorKind::Abort will never - // unwind. If the panic handler that it invokes unwind then it will simply - // call the panic handler again. - if Some(did.to_def_id()) == tcx.lang_items().panic_no_unwind() { - codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND; - } - let supported_target_features = tcx.supported_target_features(LOCAL_CRATE); let mut inline_span = None; diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index d4afe0f5326a3..4935f9962e1ef 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -84,12 +84,26 @@ fn panic_bounds_check(index: usize, len: usize) -> ! { panic!("index out of bounds: the len is {len} but the index is {index}") } -// This function is called directly by the codegen backend, and must not have -// any extra arguments (including those synthesized by track_caller). +/// Panic because we cannot unwind out of a function. +/// +/// This function is called directly by the codegen backend, and must not have +/// any extra arguments (including those synthesized by track_caller). #[cold] -#[inline(never)] #[lang = "panic_no_unwind"] // needed by codegen for panic in nounwind function +#[cfg_attr(not(bootstrap), rustc_nounwind)] +#[cfg_attr(bootstrap, rustc_allocator_nounwind)] fn panic_no_unwind() -> ! { + panic_str_nounwind("panic in a function that cannot unwind") +} + +/// Like panic_fmt, but without unwinding and track_caller to reduce the impact on codesize. +/// Also just works on `str`, as a `fmt::Arguments` needs more space to be passed. +#[cold] +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] +#[cfg_attr(feature = "panic_immediate_abort", inline)] +#[cfg_attr(not(bootstrap), rustc_nounwind)] +#[cfg_attr(bootstrap, rustc_allocator_nounwind)] +pub fn panic_str_nounwind(msg: &'static str) -> ! { if cfg!(feature = "panic_immediate_abort") { super::intrinsics::abort() } @@ -102,7 +116,8 @@ fn panic_no_unwind() -> ! { } // PanicInfo with the `can_unwind` flag set to false forces an abort. - let fmt = format_args!("panic in a function that cannot unwind"); + let pieces = [msg]; + let fmt = fmt::Arguments::new_v1(&pieces, &[]); let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), false); // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call. From ba380307b1ea84a6d194dea144f482e632c6d96a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 6 Oct 2022 12:40:56 +0200 Subject: [PATCH 12/20] use panic_fmt_nounwind for assert_unsafe_precondition --- library/core/src/intrinsics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 15ee14398b676..2399262c05b46 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2210,8 +2210,8 @@ macro_rules! assert_unsafe_precondition { #[inline(always)] fn runtime$(<$($tt)*>)?($($i:$ty),*) { if !$e { - // abort instead of panicking to reduce impact on code size - ::core::intrinsics::abort(); + // don't unwind to reduce impact on code size + ::core::panicking::panic_str_nounwind("unsafe precondition violated"); } } #[allow(non_snake_case)] From 27f0a5faf8a68b9951db432ebf98cfb2afa48e0a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 8 Oct 2022 10:48:53 +0200 Subject: [PATCH 13/20] reorder panicking.rs to put main entry points at the top --- library/core/src/panicking.rs | 128 ++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 61 deletions(-) diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 4935f9962e1ef..c4a1b0b0832ab 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -29,6 +29,73 @@ use crate::fmt; use crate::panic::{Location, PanicInfo}; +// First we define the two main entry points that all panics go through. +// In the end both are just convenience wrappers around `panic_impl`. + +/// The entry point for panicking with a formatted message. +/// +/// This is designed to reduce the amount of code required at the call +/// site as much as possible (so that `panic!()` has as low an impact +/// on (e.g.) the inlining of other functions as possible), by moving +/// the actual formatting into this shared place. +#[cold] +// If panic_immediate_abort, inline the abort call, +// otherwise avoid inlining because of it is cold path. +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] +#[cfg_attr(feature = "panic_immediate_abort", inline)] +#[track_caller] +#[lang = "panic_fmt"] // needed for const-evaluated panics +#[rustc_do_not_const_check] // hooked by const-eval +#[rustc_const_unstable(feature = "core_panic", issue = "none")] +pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! { + if cfg!(feature = "panic_immediate_abort") { + super::intrinsics::abort() + } + + // NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call + // that gets resolved to the `#[panic_handler]` function. + extern "Rust" { + #[lang = "panic_impl"] + fn panic_impl(pi: &PanicInfo<'_>) -> !; + } + + let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), true); + + // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call. + unsafe { panic_impl(&pi) } +} + +/// Like panic_fmt, but without unwinding and track_caller to reduce the impact on codesize. +/// Also just works on `str`, as a `fmt::Arguments` needs more space to be passed. +#[cold] +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] +#[cfg_attr(feature = "panic_immediate_abort", inline)] +#[cfg_attr(not(bootstrap), rustc_nounwind)] +#[cfg_attr(bootstrap, rustc_allocator_nounwind)] +pub fn panic_str_nounwind(msg: &'static str) -> ! { + if cfg!(feature = "panic_immediate_abort") { + super::intrinsics::abort() + } + + // NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call + // that gets resolved to the `#[panic_handler]` function. + extern "Rust" { + #[lang = "panic_impl"] + fn panic_impl(pi: &PanicInfo<'_>) -> !; + } + + // PanicInfo with the `can_unwind` flag set to false forces an abort. + let pieces = [msg]; + let fmt = fmt::Arguments::new_v1(&pieces, &[]); + let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), false); + + // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call. + unsafe { panic_impl(&pi) } +} + +// Next we define a bunch of higher-level wrappers that all bottom out in the two core functions +// above. + /// The underlying implementation of libcore's `panic!` macro when no formatting is used. #[cold] // never inline unless panic_immediate_abort to avoid code @@ -96,67 +163,6 @@ fn panic_no_unwind() -> ! { panic_str_nounwind("panic in a function that cannot unwind") } -/// Like panic_fmt, but without unwinding and track_caller to reduce the impact on codesize. -/// Also just works on `str`, as a `fmt::Arguments` needs more space to be passed. -#[cold] -#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] -#[cfg_attr(feature = "panic_immediate_abort", inline)] -#[cfg_attr(not(bootstrap), rustc_nounwind)] -#[cfg_attr(bootstrap, rustc_allocator_nounwind)] -pub fn panic_str_nounwind(msg: &'static str) -> ! { - if cfg!(feature = "panic_immediate_abort") { - super::intrinsics::abort() - } - - // NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call - // that gets resolved to the `#[panic_handler]` function. - extern "Rust" { - #[lang = "panic_impl"] - fn panic_impl(pi: &PanicInfo<'_>) -> !; - } - - // PanicInfo with the `can_unwind` flag set to false forces an abort. - let pieces = [msg]; - let fmt = fmt::Arguments::new_v1(&pieces, &[]); - let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), false); - - // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call. - unsafe { panic_impl(&pi) } -} - -/// The entry point for panicking with a formatted message. -/// -/// This is designed to reduce the amount of code required at the call -/// site as much as possible (so that `panic!()` has as low an impact -/// on (e.g.) the inlining of other functions as possible), by moving -/// the actual formatting into this shared place. -#[cold] -// If panic_immediate_abort, inline the abort call, -// otherwise avoid inlining because of it is cold path. -#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] -#[cfg_attr(feature = "panic_immediate_abort", inline)] -#[track_caller] -#[lang = "panic_fmt"] // needed for const-evaluated panics -#[rustc_do_not_const_check] // hooked by const-eval -#[rustc_const_unstable(feature = "core_panic", issue = "none")] -pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! { - if cfg!(feature = "panic_immediate_abort") { - super::intrinsics::abort() - } - - // NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call - // that gets resolved to the `#[panic_handler]` function. - extern "Rust" { - #[lang = "panic_impl"] - fn panic_impl(pi: &PanicInfo<'_>) -> !; - } - - let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), true); - - // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call. - unsafe { panic_impl(&pi) } -} - /// This function is used instead of panic_fmt in const eval. #[lang = "const_panic_fmt"] #[rustc_const_unstable(feature = "core_panic", issue = "none")] From 7e640009154968b769584dbc39f2a1c3a9ab3f0f Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Sat, 8 Oct 2022 12:13:57 +0100 Subject: [PATCH 14/20] Document `rust-docs-json` component --- src/doc/rustdoc/src/unstable-features.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index 32b350074903e..545855942443b 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -465,6 +465,16 @@ Note that the third item is the crate root, which in this case is undocumented. [JSON format](https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc_json_types/). `--output-format html` has no effect, and is also accepted on stable toolchains. +JSON Output for toolchain crates (`std`, `alloc`, `core`, `test`, and `proc_macro`) +is available via the `rust-docs-json` rustup component. + +```shell +rustup component add --toolchain nightly rust-docs-json +``` + +Then the json files will be present in the `share/doc/rust/json/` directory +of the rustup toolchain directory. + It can also be used with `--show-coverage`. Take a look at its [documentation](#--show-coverage-calculate-the-percentage-of-items-with-documentation) for more information. From d60e8ecdd69aadb7fddec6aebed6cee46656a7b1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 12 Sep 2022 15:02:45 +0200 Subject: [PATCH 15/20] Change default lint level of INVALID_HTML_TAGS to warning --- src/librustdoc/lint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index e76c19a61c541..3aad97bc296fb 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -148,7 +148,7 @@ declare_rustdoc_lint! { /// /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags INVALID_HTML_TAGS, - Allow, + Warn, "detects invalid HTML tags in doc comments" } From bdb502f8c42ae60297c58b0c2f3c0517c82e4be3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 13 Sep 2022 12:01:07 +0200 Subject: [PATCH 16/20] Update rustdoc tests --- .../intra-doc/malformed-generics.rs | 9 ++ .../intra-doc/malformed-generics.stderr | 82 ++++++++++++++++--- .../extern-crate-only-used-in-link.rs | 2 +- 3 files changed, 79 insertions(+), 14 deletions(-) diff --git a/src/test/rustdoc-ui/intra-doc/malformed-generics.rs b/src/test/rustdoc-ui/intra-doc/malformed-generics.rs index 15e02925ed90d..161625ed28c29 100644 --- a/src/test/rustdoc-ui/intra-doc/malformed-generics.rs +++ b/src/test/rustdoc-ui/intra-doc/malformed-generics.rs @@ -3,17 +3,26 @@ //! [Vec<] //~ ERROR //! [Vec] //~ ERROR +//~^ WARN //! [Vec>>] //~ ERROR +//~^ WARN //! [Vec>>] //~ ERROR +//~^ WARN //! [] //~ ERROR +//~^ WARN //! [] //~ ERROR +//~^ WARN //! [Vec::new()] //~ ERROR +//~^ WARN //! [Vec<>] //~ ERROR +//~^ WARN //! [Vec<>] //~ ERROR //! [Vec<<>>] //~ ERROR // FIXME(#74563) support UFCS //! [::into_iter] //~ ERROR +//~^ WARN //! [ as IntoIterator>::iter] //~ ERROR +//~^ WARN diff --git a/src/test/rustdoc-ui/intra-doc/malformed-generics.stderr b/src/test/rustdoc-ui/intra-doc/malformed-generics.stderr index 5bc0f84e24d13..08349fef88d38 100644 --- a/src/test/rustdoc-ui/intra-doc/malformed-generics.stderr +++ b/src/test/rustdoc-ui/intra-doc/malformed-generics.stderr @@ -23,67 +23,67 @@ LL | //! [Vec] | ^^^^^^^^^^ unbalanced angle brackets error: unresolved link to `Vec>>` - --> $DIR/malformed-generics.rs:6:6 + --> $DIR/malformed-generics.rs:7:6 | LL | //! [Vec>>] | ^^^^^^^^^^^^ unbalanced angle brackets error: unresolved link to `Vec>>` - --> $DIR/malformed-generics.rs:7:6 + --> $DIR/malformed-generics.rs:9:6 | LL | //! [Vec>>] | ^^^^^^^^ unbalanced angle brackets error: unresolved link to ` $DIR/malformed-generics.rs:8:6 + --> $DIR/malformed-generics.rs:11:6 | LL | //! [ $DIR/malformed-generics.rs:9:6 + --> $DIR/malformed-generics.rs:12:6 | LL | //! [Vec::<] | ^^^^^^ unbalanced angle brackets error: unresolved link to `` - --> $DIR/malformed-generics.rs:10:6 + --> $DIR/malformed-generics.rs:13:6 | LL | //! [] | ^^^ missing type for generic parameters error: unresolved link to `` - --> $DIR/malformed-generics.rs:11:6 + --> $DIR/malformed-generics.rs:15:6 | LL | //! [] | ^^^^^^^^^^^^^^^^ missing type for generic parameters error: unresolved link to `Vec::new` - --> $DIR/malformed-generics.rs:12:6 + --> $DIR/malformed-generics.rs:17:6 | LL | //! [Vec::new()] | ^^^^^^^^^^^^^ has invalid path separator error: unresolved link to `Vec<>` - --> $DIR/malformed-generics.rs:13:6 + --> $DIR/malformed-generics.rs:19:6 | LL | //! [Vec<>] | ^^^^^^^^ too many angle brackets error: unresolved link to `Vec<>` - --> $DIR/malformed-generics.rs:14:6 + --> $DIR/malformed-generics.rs:21:6 | LL | //! [Vec<>] | ^^^^^ empty angle brackets error: unresolved link to `Vec<<>>` - --> $DIR/malformed-generics.rs:15:6 + --> $DIR/malformed-generics.rs:22:6 | LL | //! [Vec<<>>] | ^^^^^^^ too many angle brackets error: unresolved link to `::into_iter` - --> $DIR/malformed-generics.rs:18:6 + --> $DIR/malformed-generics.rs:25:6 | LL | //! [::into_iter] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ fully-qualified syntax is unsupported @@ -91,12 +91,68 @@ LL | //! [::into_iter] = note: see https://github.com/rust-lang/rust/issues/74563 for more information error: unresolved link to ` as IntoIterator>::iter` - --> $DIR/malformed-generics.rs:19:6 + --> $DIR/malformed-generics.rs:27:6 | LL | //! [ as IntoIterator>::iter] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ fully-qualified syntax is unsupported | = note: see https://github.com/rust-lang/rust/issues/74563 for more information -error: aborting due to 15 previous errors +warning: unclosed HTML tag `T` + --> $DIR/malformed-generics.rs:5:13 + | +LL | //! [Vec] + | ^^^ + | + = note: `#[warn(rustdoc::invalid_html_tags)]` on by default + +warning: unclosed HTML tag `T` + --> $DIR/malformed-generics.rs:7:13 + | +LL | //! [Vec>>] + | ^^^ + +warning: unclosed HTML tag `T` + --> $DIR/malformed-generics.rs:9:9 + | +LL | //! [Vec>>] + | ^^^ + +warning: unclosed HTML tag `T` + --> $DIR/malformed-generics.rs:13:6 + | +LL | //! [] + | ^^^ + +warning: unclosed HTML tag `invalid` + --> $DIR/malformed-generics.rs:15:6 + | +LL | //! [] + | ^^^^^^^^ + +warning: unclosed HTML tag `T` + --> $DIR/malformed-generics.rs:17:10 + | +LL | //! [Vec::new()] + | ^^^ + +warning: unclosed HTML tag `T` + --> $DIR/malformed-generics.rs:19:10 + | +LL | //! [Vec<>] + | ^^^ + +warning: unclosed HTML tag `Vec` + --> $DIR/malformed-generics.rs:25:6 + | +LL | //! [::into_iter] + | ^^^^ + +warning: unclosed HTML tag `T` + --> $DIR/malformed-generics.rs:27:10 + | +LL | //! [ as IntoIterator>::iter] + | ^^^ + +error: aborting due to 15 previous errors; 9 warnings emitted diff --git a/src/test/rustdoc/intra-doc/extern-crate-only-used-in-link.rs b/src/test/rustdoc/intra-doc/extern-crate-only-used-in-link.rs index 5d8dcf8bc1d16..ad50887e9221c 100644 --- a/src/test/rustdoc/intra-doc/extern-crate-only-used-in-link.rs +++ b/src/test/rustdoc/intra-doc/extern-crate-only-used-in-link.rs @@ -16,4 +16,4 @@ //! [`empty`] // @has - '//a[@href="../empty2/index.html"]' 'empty2' -//! [empty2] +//! [`empty2`] From e340796c23276b20584f0b16a9a49da42b59c344 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 12 Sep 2022 12:07:43 +0200 Subject: [PATCH 17/20] Stabilize rustdoc CHECK_INVALID_HTML_TAGS check --- src/librustdoc/passes/html_tags.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index 694b03161d929..67fc71665ccf7 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -22,10 +22,8 @@ struct InvalidHtmlTagsLinter<'a, 'tcx> { } pub(crate) fn check_invalid_html_tags(krate: Crate, cx: &mut DocContext<'_>) -> Crate { - if cx.tcx.sess.is_nightly_build() { - let mut coll = InvalidHtmlTagsLinter { cx }; - coll.visit_crate(&krate); - } + let mut coll = InvalidHtmlTagsLinter { cx }; + coll.visit_crate(&krate); krate } From 4ee7db23b6b8fa9f8a66b4f378387715c95a5b86 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 8 Oct 2022 14:42:38 +0200 Subject: [PATCH 18/20] Fix doc lint error --- compiler/rustc_errors/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 94a493992e593..2f6686f81965b 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -411,7 +411,7 @@ struct HandlerInner { /// would be unnecessary repetition. taught_diagnostics: FxHashSet, - /// Used to suggest rustc --explain + /// Used to suggest rustc --explain `` emitted_diagnostic_codes: FxIndexSet, /// This set contains a hash of every diagnostic that has been emitted by From 4d9d7bf312929ec55987b586f249c547b47140f9 Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 8 Oct 2022 15:55:15 +0200 Subject: [PATCH 19/20] Remove empty core::lazy and std::lazy PR #98165 with commits 7c360dc117d554a11f7193505da0835c4b890c6f and c1a2db3372a4d6896744919284f3287650a38ab7 has moved all of the components of these modules into different places, namely {std,core}::sync and {std,core}::cell. The empty modules remained. As they are unstable, we can simply remove them. --- library/core/src/lazy.rs | 1 - library/core/src/lib.rs | 2 -- library/std/src/lazy.rs | 1 - library/std/src/lib.rs | 3 --- 4 files changed, 7 deletions(-) delete mode 100644 library/core/src/lazy.rs delete mode 100644 library/std/src/lazy.rs diff --git a/library/core/src/lazy.rs b/library/core/src/lazy.rs deleted file mode 100644 index f8c06c3f9aedb..0000000000000 --- a/library/core/src/lazy.rs +++ /dev/null @@ -1 +0,0 @@ -//! Lazy values and one-time initialization of static data. diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index ca02ae90fdeb2..4c0a3049e75be 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -326,8 +326,6 @@ pub mod cell; pub mod char; pub mod ffi; pub mod iter; -#[unstable(feature = "once_cell", issue = "74465")] -pub mod lazy; pub mod option; pub mod panic; pub mod panicking; diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs deleted file mode 100644 index f8c06c3f9aedb..0000000000000 --- a/library/std/src/lazy.rs +++ /dev/null @@ -1 +0,0 @@ -//! Lazy values and one-time initialization of static data. diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index a497acda4f60c..5484d9c332abd 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -529,9 +529,6 @@ pub mod process; pub mod sync; pub mod time; -#[unstable(feature = "once_cell", issue = "74465")] -pub mod lazy; - // Pull in `std_float` crate into libstd. The contents of // `std_float` are in a different repository: rust-lang/portable-simd. #[path = "../../portable-simd/crates/std_float/src/lib.rs"] From 048e637e9ee4c9fe8813109d89f97e140776b0a4 Mon Sep 17 00:00:00 2001 From: b-naber Date: Sat, 8 Oct 2022 15:52:59 +0200 Subject: [PATCH 20/20] handle late-bound vars from inner binders correctly and add test --- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- src/test/ui/lifetimes/nested-binder-print.rs | 10 ++++++++++ src/test/ui/lifetimes/nested-binder-print.stderr | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/lifetimes/nested-binder-print.rs create mode 100644 src/test/ui/lifetimes/nested-binder-print.stderr diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index b78661270e181..659bd884556a3 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2093,7 +2093,7 @@ impl<'a, 'tcx> ty::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { let name = &mut self.name; let region = match *r { - ty::ReLateBound(db, br) => { + ty::ReLateBound(db, br) if db >= self.current_index => { *self.region_map.entry(br).or_insert_with(|| name(Some(db), self.current_index, br)) } ty::RePlaceholder(ty::PlaceholderRegion { name: kind, .. }) => { diff --git a/src/test/ui/lifetimes/nested-binder-print.rs b/src/test/ui/lifetimes/nested-binder-print.rs new file mode 100644 index 0000000000000..f97f349fd8243 --- /dev/null +++ b/src/test/ui/lifetimes/nested-binder-print.rs @@ -0,0 +1,10 @@ +struct TwoLt<'a, 'b>(&'a (), &'b ()); +type Foo<'a> = fn(TwoLt<'_, 'a>); + +fn foo() { + let y: for<'a> fn(Foo<'a>); + let x: u32 = y; + //~^ ERROR mismatched types +} + +fn main() {} diff --git a/src/test/ui/lifetimes/nested-binder-print.stderr b/src/test/ui/lifetimes/nested-binder-print.stderr new file mode 100644 index 0000000000000..32dd896932d2e --- /dev/null +++ b/src/test/ui/lifetimes/nested-binder-print.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/nested-binder-print.rs:6:18 + | +LL | let x: u32 = y; + | --- ^ expected `u32`, found fn pointer + | | + | expected due to this + | + = note: expected type `u32` + found fn pointer `for<'a> fn(for<'b> fn(TwoLt<'b, 'a>))` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`.