From 8d08983c2b14e5277580015006e334104cbbd7d1 Mon Sep 17 00:00:00 2001 From: Tim Hutt Date: Sat, 10 Sep 2022 12:43:30 +0100 Subject: [PATCH 1/8] Better documentation for env::home_dir()'s broken behaviour This improves the documentation to say *why* it was deprecated. The reason was because it reads `HOME` on Windows which is meaningless there. Note that the PR that deprecated it stated that returning an empty string if `HOME` is set to an empty string was a problem, however I can find no evidence that this is the case. `cd` handles it fine whereas if `HOME` is unset it gives an explicit `HOME not set` error. * Original deprecation reason: https://internals.rust-lang.org/t/deprecate-or-break-fix-std-env-home-dir/7315 * Original deprecation PR: https://github.com/rust-lang/rust/pull/51656 See #71684 --- library/std/src/env.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 463f714064c61..d78b1d7c9cfcd 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -570,6 +570,13 @@ impl Error for JoinPathsError { /// /// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectorya /// +/// # Deprecation +/// +/// This function is deprecated because the behaviour on Windows is not correct. +/// The 'HOME' environment variable has no meaning on Windows so it should not +/// be checked. This result is that under Cygwin or Mingw it will return `/home/you` +/// when it should return `C:\Users\you`. +/// /// # Examples /// /// ``` @@ -582,7 +589,7 @@ impl Error for JoinPathsError { /// ``` #[deprecated( since = "1.29.0", - note = "This function's behavior is unexpected and probably not what you want. \ + note = "This function's behavior may be unexpected on Windows. \ Consider using a crate from crates.io instead." )] #[must_use] From 8f0025e5a3346b1cfcc64abca7bf768f25d1ff9e Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 3 Oct 2022 17:27:13 +0100 Subject: [PATCH 2/8] Reword "has no meaning" per suggestion Co-authored-by: Josh Triplett --- library/std/src/env.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index d78b1d7c9cfcd..605925b5e96c4 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -573,8 +573,8 @@ impl Error for JoinPathsError { /// # Deprecation /// /// This function is deprecated because the behaviour on Windows is not correct. -/// The 'HOME' environment variable has no meaning on Windows so it should not -/// be checked. This result is that under Cygwin or Mingw it will return `/home/you` +/// The 'HOME' environment variable is not standard on Windows, and may not produce +/// desired results; for instance, under Cygwin or Mingw it will return `/home/you` /// when it should return `C:\Users\you`. /// /// # Examples From 64ad337a3bc50f7381f1afc1a0fc7006a8ad7f53 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 5 Dec 2022 03:17:53 +0000 Subject: [PATCH 3/8] Don't call diagnostic_hir_wf_check query if we have infer variables --- .../src/traits/error_reporting/mod.rs | 1 + src/test/ui/wf/hir-wf-canonicalized.rs | 18 +++++++++++ src/test/ui/wf/hir-wf-canonicalized.stderr | 32 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/test/ui/wf/hir-wf-canonicalized.rs create mode 100644 src/test/ui/wf/hir-wf-canonicalized.stderr diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 56dea916b305f..105dbf1e02935 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -555,6 +555,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // can get a better error message by performing HIR-based well-formedness checking. if let ObligationCauseCode::WellFormed(Some(wf_loc)) = root_obligation.cause.code().peel_derives() + && !obligation.predicate.has_non_region_infer() { if let Some(cause) = self .tcx diff --git a/src/test/ui/wf/hir-wf-canonicalized.rs b/src/test/ui/wf/hir-wf-canonicalized.rs new file mode 100644 index 0000000000000..bdb84409d009d --- /dev/null +++ b/src/test/ui/wf/hir-wf-canonicalized.rs @@ -0,0 +1,18 @@ +// incremental + +trait Foo { + type V; +} + +trait Callback: Fn(&Bar<'_, T>, &T::V) {} + +struct Bar<'a, T> { + callback: Box>>>, + //~^ ERROR the trait bound `Bar<'a, T>: Foo` is not satisfied + //~| ERROR the trait bound `(dyn Callback, for<'b, 'c, 'd> Output = ()> + 'static): Foo` is not satisfied + //~| ERROR the size for values of type `(dyn Callback, for<'b, 'c, 'd> Output = ()> + 'static)` cannot be known at compilation time +} + +impl Bar<'_, Bar<'_, T>> {} + +fn main() {} diff --git a/src/test/ui/wf/hir-wf-canonicalized.stderr b/src/test/ui/wf/hir-wf-canonicalized.stderr new file mode 100644 index 0000000000000..9fd0f9c81ebd8 --- /dev/null +++ b/src/test/ui/wf/hir-wf-canonicalized.stderr @@ -0,0 +1,32 @@ +error[E0277]: the trait bound `Bar<'a, T>: Foo` is not satisfied + --> $DIR/hir-wf-canonicalized.rs:10:15 + | +LL | callback: Box>>>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bar<'a, T>` + +error[E0277]: the trait bound `(dyn Callback, for<'b, 'c, 'd> Output = ()> + 'static): Foo` is not satisfied + --> $DIR/hir-wf-canonicalized.rs:10:15 + | +LL | callback: Box>>>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `(dyn Callback, for<'b, 'c, 'd> Output = ()> + 'static)` + +error[E0277]: the size for values of type `(dyn Callback, for<'b, 'c, 'd> Output = ()> + 'static)` cannot be known at compilation time + --> $DIR/hir-wf-canonicalized.rs:10:15 + | +LL | callback: Box>>>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `(dyn Callback, for<'b, 'c, 'd> Output = ()> + 'static)` +note: required by a bound in `Bar` + --> $DIR/hir-wf-canonicalized.rs:9:16 + | +LL | struct Bar<'a, T> { + | ^ required by this bound in `Bar` +help: consider relaxing the implicit `Sized` restriction + | +LL | struct Bar<'a, T: ?Sized> { + | ++++++++ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. From 5599f2ad09345b94487920b84029ad215c4dc743 Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 6 Dec 2022 21:00:38 +0800 Subject: [PATCH 4/8] fix #105226, Detect spurious ; before assoc fn body --- compiler/rustc_parse/src/parser/item.rs | 12 ++++++-- src/test/ui/suggestions/issue-105226.rs | 22 +++++++++++++++ src/test/ui/suggestions/issue-105226.stderr | 31 +++++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/suggestions/issue-105226.rs create mode 100644 src/test/ui/suggestions/issue-105226.stderr diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 84c632199203a..8f4f68fb067a7 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -707,9 +707,9 @@ impl<'a> Parser<'a> { } match parse_item(self) { Ok(None) => { - let is_unnecessary_semicolon = !items.is_empty() + let mut is_unnecessary_semicolon = !items.is_empty() // When the close delim is `)` in a case like the following, `token.kind` is expected to be `token::CloseDelim(Delimiter::Parenthesis)`, - // but the actual `token.kind` is `token::CloseDelim(Delimiter::Bracket)`. + // but the actual `token.kind` is `token::CloseDelim(Delimiter::Brace)`. // This is because the `token.kind` of the close delim is treated as the same as // that of the open delim in `TokenTreesReader::parse_token_tree`, even if the delimiters of them are different. // Therefore, `token.kind` should not be compared here. @@ -728,7 +728,13 @@ impl<'a> Parser<'a> { .span_to_snippet(self.prev_token.span) .map_or(false, |snippet| snippet == "}") && self.token.kind == token::Semi; - let semicolon_span = self.token.span; + let mut semicolon_span = self.token.span; + if !is_unnecessary_semicolon { + // #105369, Detect spurious `;` before assoc fn body + is_unnecessary_semicolon = self.token == token::OpenDelim(Delimiter::Brace) + && self.prev_token.kind == token::Semi; + semicolon_span = self.prev_token.span; + } // We have to bail or we'll potentially never make progress. let non_item_span = self.token.span; let is_let = self.token.is_keyword(kw::Let); diff --git a/src/test/ui/suggestions/issue-105226.rs b/src/test/ui/suggestions/issue-105226.rs new file mode 100644 index 0000000000000..f123dbf4cae0c --- /dev/null +++ b/src/test/ui/suggestions/issue-105226.rs @@ -0,0 +1,22 @@ +use std::fmt; + +struct S { +} + +impl S { + fn hello

(&self, val: &P) where P: fmt::Display; { + //~^ ERROR non-item in item list + //~| ERROR associated function in `impl` without body + println!("val: {}", val); + } +} + +impl S { + fn hello_empty

(&self, val: &P) where P: fmt::Display; + //~^ ERROR associated function in `impl` without body +} + +fn main() { + let s = S{}; + s.hello(&32); +} diff --git a/src/test/ui/suggestions/issue-105226.stderr b/src/test/ui/suggestions/issue-105226.stderr new file mode 100644 index 0000000000000..f16a809010390 --- /dev/null +++ b/src/test/ui/suggestions/issue-105226.stderr @@ -0,0 +1,31 @@ +error: non-item in item list + --> $DIR/issue-105226.rs:7:56 + | +LL | impl S { + | - item list starts here +LL | fn hello

(&self, val: &P) where P: fmt::Display; { + | - ^ non-item starts here + | | + | help: consider removing this semicolon +... +LL | } + | - item list ends here + +error: associated function in `impl` without body + --> $DIR/issue-105226.rs:7:5 + | +LL | fn hello

(&self, val: &P) where P: fmt::Display; { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- + | | + | help: provide a definition for the function: `{ }` + +error: associated function in `impl` without body + --> $DIR/issue-105226.rs:15:5 + | +LL | fn hello_empty

(&self, val: &P) where P: fmt::Display; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- + | | + | help: provide a definition for the function: `{ }` + +error: aborting due to 3 previous errors + From 99d229095e856c7f9a2ec3663e17f30967e4098e Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 8 Dec 2022 11:56:43 -0300 Subject: [PATCH 5/8] Make encode_info_for_trait_item use queries instead of accessing the HIR --- compiler/rustc_metadata/src/rmeta/encoder.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 8b4c4bb2675cb..29f9e82da75cc 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1337,24 +1337,16 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id); let tcx = self.tcx; - let ast_item = tcx.hir().expect_trait_item(def_id.expect_local()); - self.tables.impl_defaultness.set(def_id.index, ast_item.defaultness); + let impl_defaultness = tcx.impl_defaultness(def_id.expect_local()); + self.tables.impl_defaultness.set(def_id.index, impl_defaultness); let trait_item = tcx.associated_item(def_id); self.tables.assoc_container.set(def_id.index, trait_item.container); match trait_item.kind { ty::AssocKind::Const => {} ty::AssocKind::Fn => { - let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind else { bug!() }; - match *m { - hir::TraitFn::Required(ref names) => { - record_array!(self.tables.fn_arg_names[def_id] <- *names) - } - hir::TraitFn::Provided(body) => { - record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body)) - } - }; - self.tables.asyncness.set(def_id.index, m_sig.header.asyncness); + record_array!(self.tables.fn_arg_names[def_id] <- tcx.fn_arg_names(def_id)); + self.tables.asyncness.set(def_id.index, tcx.asyncness(def_id)); self.tables.constness.set(def_id.index, hir::Constness::NotConst); } ty::AssocKind::Type => { From 6a4394637052a9536ff994faed88ee95e8172fe1 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Sat, 10 Dec 2022 04:48:37 +0200 Subject: [PATCH 6/8] separate heading from body --- compiler/rustc_span/src/symbol.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 6125384549723..ba77c5d94fd9c 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1710,7 +1710,8 @@ impl fmt::Display for Ident { } } -/// This is the most general way to print identifiers. +/// The most general type to print identifiers. +/// /// AST pretty-printer is used as a fallback for turning AST structures into token streams for /// proc macros. Additionally, proc macros may stringify their input and expect it survive the /// stringification (especially true for proc macro derives written between Rust 1.15 and 1.30). From cbdc00f6e61132cbb74397cbb91171756e5d5834 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Sun, 11 Dec 2022 09:14:50 +0000 Subject: [PATCH 7/8] llvm-wrapper: adapt for LLVM API changes This is a follow-up of https://github.com/rust-lang/rust/commit/75aec4703dea7ef8e13924ccfa3a3d2e8c5c7cff. There, I updated the wrapper to only include llvm/ADT/Optional.h for LLVM version below 16. But I missed updating some of the None references. Found by our experimental rust + llvm at HEAD bot: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/15587#0185006b-e0af-49e5-8b06-280ed125ff0d/200-539 --- compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 4 ++++ compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 1a3d458c30067..2865ea8927336 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -223,7 +223,11 @@ fromRust(LLVMRustCodeModel Model) { case LLVMRustCodeModel::Large: return CodeModel::Large; case LLVMRustCodeModel::None: +#if LLVM_VERSION_LT(16, 0) return None; +#else + return std::nullopt; +#endif default: report_fatal_error("Bad CodeModel."); } diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 5831d4693f18b..279b699185421 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -322,7 +322,13 @@ extern "C" LLVMAttributeRef LLVMRustCreateUWTableAttr(LLVMContextRef C, bool Asy } extern "C" LLVMAttributeRef LLVMRustCreateAllocSizeAttr(LLVMContextRef C, uint32_t ElementSizeArg) { - return wrap(Attribute::getWithAllocSizeArgs(*unwrap(C), ElementSizeArg, None)); + return wrap(Attribute::getWithAllocSizeArgs(*unwrap(C), ElementSizeArg, +#if LLVM_VERSION_LT(16, 0) + None +#else + std::nullopt +#endif + )); } #if LLVM_VERSION_GE(15, 0) @@ -717,7 +723,11 @@ static std::optional fromRust(LLVMRustChecksumKind Kind) { #endif switch (Kind) { case LLVMRustChecksumKind::None: +#if LLVM_VERSION_LT(16, 0) return None; +#else + return std::nullopt; +#endif case LLVMRustChecksumKind::MD5: return DIFile::ChecksumKind::CSK_MD5; case LLVMRustChecksumKind::SHA1: From 6e583ffbd9a12e4bcfbf3f066fb8dd1e792d9883 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 11 Dec 2022 14:37:55 +0100 Subject: [PATCH 8/8] Extend rustdoc hashtag prepended line test --- src/librustdoc/html/markdown/tests.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index 68b31a6ee083d..5878c58264ec3 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -343,6 +343,14 @@ fn test_ascii_with_prepending_hashtag() { #..#.#....#....#....#..#. #..#.#....#....#....#..#. #..#.####.####.####..##.. +", + ); + t( + r#"```markdown +# hello +```"#, + "

\
+# hello
 
", ); }