From 6c0dbb8cc6ba28facf5d70e77373a776500a1701 Mon Sep 17 00:00:00 2001 From: r01and Date: Tue, 12 Dec 2023 07:03:37 +0000 Subject: [PATCH 01/15] Remove dead codes in core --- library/core/src/fmt/num.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index 778515f8616c4..ab2158394bf1e 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -15,7 +15,7 @@ trait DisplayInt: fn zero() -> Self; fn from_u8(u: u8) -> Self; fn to_u8(&self) -> u8; - fn to_u16(&self) -> u16; + #[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32")))] fn to_u32(&self) -> u32; fn to_u64(&self) -> u64; fn to_u128(&self) -> u128; @@ -27,7 +27,7 @@ macro_rules! impl_int { fn zero() -> Self { 0 } fn from_u8(u: u8) -> Self { u as Self } fn to_u8(&self) -> u8 { *self as u8 } - fn to_u16(&self) -> u16 { *self as u16 } + #[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32")))] fn to_u32(&self) -> u32 { *self as u32 } fn to_u64(&self) -> u64 { *self as u64 } fn to_u128(&self) -> u128 { *self as u128 } @@ -40,7 +40,7 @@ macro_rules! impl_uint { fn zero() -> Self { 0 } fn from_u8(u: u8) -> Self { u as Self } fn to_u8(&self) -> u8 { *self as u8 } - fn to_u16(&self) -> u16 { *self as u16 } + #[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32")))] fn to_u32(&self) -> u32 { *self as u32 } fn to_u64(&self) -> u64 { *self as u64 } fn to_u128(&self) -> u128 { *self as u128 } From fb32eb3529abac81b0246f7247cbfd6a1271c6a0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 12 Dec 2023 12:10:36 +0100 Subject: [PATCH 02/15] Clean up CodeBlocks::next code --- src/librustdoc/html/markdown.rs | 67 ++++++++++++++------------------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index abc27bcdf0782..e871cd866c9b0 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -234,10 +234,6 @@ impl<'a, I: Iterator>> Iterator for CodeBlocks<'_, 'a, I> { fn next(&mut self) -> Option { let event = self.inner.next(); - let compile_fail; - let should_panic; - let ignore; - let edition; let Some(Event::Start(Tag::CodeBlock(kind))) = event else { return event; }; @@ -253,49 +249,44 @@ impl<'a, I: Iterator>> Iterator for CodeBlocks<'_, 'a, I> { } } - let parse_result = match kind { - CodeBlockKind::Fenced(ref lang) => { - let parse_result = LangString::parse_without_check( - lang, - self.check_error_codes, - false, - self.custom_code_classes_in_docs, - ); - if !parse_result.rust { - let added_classes = parse_result.added_classes; - let lang_string = if let Some(lang) = parse_result.unknown.first() { - format!("language-{}", lang) - } else { - String::new() - }; - let whitespace = if added_classes.is_empty() { "" } else { " " }; - return Some(Event::Html( - format!( - "
\ + let LangString { added_classes, compile_fail, should_panic, ignore, edition, .. } = + match kind { + CodeBlockKind::Fenced(ref lang) => { + let parse_result = LangString::parse_without_check( + lang, + self.check_error_codes, + false, + self.custom_code_classes_in_docs, + ); + if !parse_result.rust { + let added_classes = parse_result.added_classes; + let lang_string = if let Some(lang) = parse_result.unknown.first() { + format!("language-{}", lang) + } else { + String::new() + }; + let whitespace = if added_classes.is_empty() { "" } else { " " }; + return Some(Event::Html( + format!( + "
\
\
                                      {text}\
                                  
\
", - added_classes = added_classes.join(" "), - text = Escape(&original_text), - ) - .into(), - )); + added_classes = added_classes.join(" "), + text = Escape(&original_text), + ) + .into(), + )); + } + parse_result } - parse_result - } - CodeBlockKind::Indented => Default::default(), - }; + CodeBlockKind::Indented => Default::default(), + }; - let added_classes = parse_result.added_classes; let lines = original_text.lines().filter_map(|l| map_line(l).for_html()); let text = lines.intersperse("\n".into()).collect::(); - compile_fail = parse_result.compile_fail; - should_panic = parse_result.should_panic; - ignore = parse_result.ignore; - edition = parse_result.edition; - let explicit_edition = edition.is_some(); let edition = edition.unwrap_or(self.edition); From 95b5a80f47fa30a594985f36eab87d1ccbd0435a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Oko=C5=84ski?= Date: Tue, 12 Dec 2023 13:11:59 +0100 Subject: [PATCH 03/15] Fix alignment passed down to LLVM for simd_masked_load --- compiler/rustc_codegen_llvm/src/intrinsic.rs | 2 +- .../simd-intrinsic/simd-intrinsic-generic-masked-load.rs | 2 +- .../simd-intrinsic/simd-intrinsic-generic-masked-store.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 23b424f25baf2..58e68a6490798 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -1568,7 +1568,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( // Alignment of T, must be a constant integer value: let alignment_ty = bx.type_i32(); - let alignment = bx.const_i32(bx.align_of(values_ty).bytes() as i32); + let alignment = bx.const_i32(bx.align_of(values_elem).bytes() as i32); // Truncate the mask vector to a vector of i1s: let (mask, mask_ty) = { diff --git a/tests/codegen/simd-intrinsic/simd-intrinsic-generic-masked-load.rs b/tests/codegen/simd-intrinsic/simd-intrinsic-generic-masked-load.rs index 7b1fb320894ae..e573b7d21bd2f 100644 --- a/tests/codegen/simd-intrinsic/simd-intrinsic-generic-masked-load.rs +++ b/tests/codegen/simd-intrinsic/simd-intrinsic-generic-masked-load.rs @@ -21,7 +21,7 @@ extern "platform-intrinsic" { #[no_mangle] pub unsafe fn load_f32x2(mask: Vec2, pointer: *const f32, values: Vec2) -> Vec2 { - // CHECK: call <2 x float> @llvm.masked.load.v2f32.p0(ptr {{.*}}, i32 {{.*}}, <2 x i1> {{.*}}, <2 x float> {{.*}}) + // CHECK: call <2 x float> @llvm.masked.load.v2f32.p0(ptr {{.*}}, i32 4, <2 x i1> {{.*}}, <2 x float> {{.*}}) simd_masked_load(mask, pointer, values) } diff --git a/tests/codegen/simd-intrinsic/simd-intrinsic-generic-masked-store.rs b/tests/codegen/simd-intrinsic/simd-intrinsic-generic-masked-store.rs index d8a37020f23be..91656622216dc 100644 --- a/tests/codegen/simd-intrinsic/simd-intrinsic-generic-masked-store.rs +++ b/tests/codegen/simd-intrinsic/simd-intrinsic-generic-masked-store.rs @@ -20,7 +20,7 @@ extern "platform-intrinsic" { // CHECK-LABEL: @store_f32x2 #[no_mangle] pub unsafe fn store_f32x2(mask: Vec2, pointer: *mut f32, values: Vec2) { - // CHECK: call void @llvm.masked.store.v2f32.p0(<2 x float> {{.*}}, ptr {{.*}}, i32 {{.*}}, <2 x i1> {{.*}}) + // CHECK: call void @llvm.masked.store.v2f32.p0(<2 x float> {{.*}}, ptr {{.*}}, i32 4, <2 x i1> {{.*}}) simd_masked_store(mask, pointer, values) } From 04f3adb4a73e07fa32be69205c64ff3a8e64b15f Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Tue, 12 Dec 2023 14:38:13 +0100 Subject: [PATCH 04/15] fix `waker_getters` tracking issue number --- library/core/src/task/wake.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index 1a11291e86b9d..9c41b8b4f46a6 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -48,7 +48,7 @@ impl RawWaker { /// Get the `data` pointer used to create this `RawWaker`. #[inline] #[must_use] - #[unstable(feature = "waker_getters", issue = "87021")] + #[unstable(feature = "waker_getters", issue = "96992")] pub fn data(&self) -> *const () { self.data } @@ -56,7 +56,7 @@ impl RawWaker { /// Get the `vtable` pointer used to create this `RawWaker`. #[inline] #[must_use] - #[unstable(feature = "waker_getters", issue = "87021")] + #[unstable(feature = "waker_getters", issue = "96992")] pub fn vtable(&self) -> &'static RawWakerVTable { self.vtable } @@ -371,7 +371,7 @@ impl Waker { /// Get a reference to the underlying [`RawWaker`]. #[inline] #[must_use] - #[unstable(feature = "waker_getters", issue = "87021")] + #[unstable(feature = "waker_getters", issue = "96992")] pub fn as_raw(&self) -> &RawWaker { &self.waker } From d3cb25f4cfc15d0c8a13836d52352d1c3225ebd6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 12 Dec 2023 14:27:20 +0100 Subject: [PATCH 05/15] Add `rustX` check to codeblock attributes lint --- src/librustdoc/html/markdown.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index e871cd866c9b0..d963eb6adfae2 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -1284,6 +1284,16 @@ impl LangString { LangStringToken::LangToken(x) if x.starts_with("edition") => { data.edition = x[7..].parse::().ok(); } + LangStringToken::LangToken(x) + if x.starts_with("rust") && x[4..].parse::().is_ok() => + { + if let Some(extra) = extra { + extra.error_invalid_codeblock_attr(format!( + "unknown attribute `{x}`. Did you mean `edition{}`?", + &x[4..] + )); + } + } LangStringToken::LangToken(x) if allow_error_code_check && x.starts_with('E') && x.len() == 5 => { From 98aa20b0a7ee519b23f37d76c1d093f50c43d863 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 12 Dec 2023 14:27:35 +0100 Subject: [PATCH 06/15] Add test for `rustX` codeblock attribute --- tests/rustdoc-ui/lints/check-attr.rs | 8 ++++++++ tests/rustdoc-ui/lints/check-attr.stderr | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/rustdoc-ui/lints/check-attr.rs b/tests/rustdoc-ui/lints/check-attr.rs index 0b3f7bedda5cf..38f5b3851d03d 100644 --- a/tests/rustdoc-ui/lints/check-attr.rs +++ b/tests/rustdoc-ui/lints/check-attr.rs @@ -39,3 +39,11 @@ pub fn foobar() {} /// boo /// ``` pub fn b() {} + +/// b +//~^ ERROR +/// +/// ```rust2018 +/// boo +/// ``` +pub fn c() {} diff --git a/tests/rustdoc-ui/lints/check-attr.stderr b/tests/rustdoc-ui/lints/check-attr.stderr index f66e63ab727ea..cd2f1eea7ce45 100644 --- a/tests/rustdoc-ui/lints/check-attr.stderr +++ b/tests/rustdoc-ui/lints/check-attr.stderr @@ -171,5 +171,16 @@ LL | | /// ``` | = help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function -error: aborting due to 12 previous errors +error: unknown attribute `rust2018`. Did you mean `edition2018`? + --> $DIR/check-attr.rs:43:1 + | +LL | / /// b +LL | | +LL | | /// +LL | | /// ```rust2018 +LL | | /// boo +LL | | /// ``` + | |_______^ + +error: aborting due to 13 previous errors From bb0fd665a88e0902847f118ec753bd51dbe05480 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 12 Dec 2023 14:41:24 +0100 Subject: [PATCH 07/15] Follow guidelines for lint suggestions --- src/librustdoc/html/markdown.rs | 30 +++++++++----- .../rustdoc-ui/doctest/check-attr-test.stderr | 36 +++++++++++------ tests/rustdoc-ui/lints/check-attr.stderr | 40 +++++++++++++------ tests/rustdoc-ui/lints/check-fail.stderr | 6 ++- 4 files changed, 76 insertions(+), 36 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index d963eb6adfae2..dfad1ab10dbe0 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -27,7 +27,7 @@ //! ``` use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; +use rustc_errors::{DiagnosticBuilder, DiagnosticMessage}; use rustc_hir::def_id::DefId; use rustc_middle::ty::TyCtxt; pub(crate) use rustc_resolve::rustdoc::main_body_opts; @@ -843,7 +843,9 @@ impl<'tcx> ExtraInfo<'tcx> { fn error_invalid_codeblock_attr_with_help( &self, msg: impl Into, - help: impl Into, + f: impl for<'a, 'b> FnOnce( + &'b mut DiagnosticBuilder<'a, ()>, + ) -> &'b mut DiagnosticBuilder<'a, ()>, ) { if let Some(def_id) = self.def_id.as_local() { self.tcx.struct_span_lint_hir( @@ -851,7 +853,7 @@ impl<'tcx> ExtraInfo<'tcx> { self.tcx.local_def_id_to_hir_id(def_id), self.sp, msg, - |lint| lint.help(help), + f, ); } } @@ -1288,10 +1290,15 @@ impl LangString { if x.starts_with("rust") && x[4..].parse::().is_ok() => { if let Some(extra) = extra { - extra.error_invalid_codeblock_attr(format!( - "unknown attribute `{x}`. Did you mean `edition{}`?", - &x[4..] - )); + extra.error_invalid_codeblock_attr_with_help( + format!("unknown attribute `{x}`"), + |lint| { + lint.help(format!( + "there is an attribute with a similar name: `edition{}`", + &x[4..], + )) + }, + ); } } LangStringToken::LangToken(x) @@ -1338,8 +1345,13 @@ impl LangString { } { if let Some(extra) = extra { extra.error_invalid_codeblock_attr_with_help( - format!("unknown attribute `{x}`. Did you mean `{flag}`?"), - help, + format!("unknown attribute `{x}`"), + |lint| { + lint.help(format!( + "there is an attribute with a similar name: `{flag}`" + )) + .help(help) + }, ); } } diff --git a/tests/rustdoc-ui/doctest/check-attr-test.stderr b/tests/rustdoc-ui/doctest/check-attr-test.stderr index 01beba1ffc4a4..10f763a6f9d86 100644 --- a/tests/rustdoc-ui/doctest/check-attr-test.stderr +++ b/tests/rustdoc-ui/doctest/check-attr-test.stderr @@ -1,4 +1,4 @@ -error: unknown attribute `compile-fail`. Did you mean `compile_fail`? +error: unknown attribute `compile-fail` --> $DIR/check-attr-test.rs:5:1 | 5 | / /// foo @@ -8,6 +8,7 @@ error: unknown attribute `compile-fail`. Did you mean `compile_fail`? 9 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `compile_fail` = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully note: the lint level is defined here --> $DIR/check-attr-test.rs:3:9 @@ -15,7 +16,7 @@ note: the lint level is defined here 3 | #![deny(rustdoc::invalid_codeblock_attributes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: unknown attribute `compilefail`. Did you mean `compile_fail`? +error: unknown attribute `compilefail` --> $DIR/check-attr-test.rs:5:1 | 5 | / /// foo @@ -25,9 +26,10 @@ error: unknown attribute `compilefail`. Did you mean `compile_fail`? 9 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `compile_fail` = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully -error: unknown attribute `comPile_fail`. Did you mean `compile_fail`? +error: unknown attribute `comPile_fail` --> $DIR/check-attr-test.rs:5:1 | 5 | / /// foo @@ -37,9 +39,10 @@ error: unknown attribute `comPile_fail`. Did you mean `compile_fail`? 9 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `compile_fail` = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully -error: unknown attribute `should-panic`. Did you mean `should_panic`? +error: unknown attribute `should-panic` --> $DIR/check-attr-test.rs:12:1 | 12 | / /// bar @@ -49,9 +52,10 @@ error: unknown attribute `should-panic`. Did you mean `should_panic`? 16 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `should_panic` = help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running -error: unknown attribute `shouldpanic`. Did you mean `should_panic`? +error: unknown attribute `shouldpanic` --> $DIR/check-attr-test.rs:12:1 | 12 | / /// bar @@ -61,9 +65,10 @@ error: unknown attribute `shouldpanic`. Did you mean `should_panic`? 16 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `should_panic` = help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running -error: unknown attribute `shOuld_panic`. Did you mean `should_panic`? +error: unknown attribute `shOuld_panic` --> $DIR/check-attr-test.rs:12:1 | 12 | / /// bar @@ -73,9 +78,10 @@ error: unknown attribute `shOuld_panic`. Did you mean `should_panic`? 16 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `should_panic` = help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running -error: unknown attribute `no-run`. Did you mean `no_run`? +error: unknown attribute `no-run` --> $DIR/check-attr-test.rs:19:1 | 19 | / /// foobar @@ -85,9 +91,10 @@ error: unknown attribute `no-run`. Did you mean `no_run`? 23 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `no_run` = help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want) -error: unknown attribute `norun`. Did you mean `no_run`? +error: unknown attribute `norun` --> $DIR/check-attr-test.rs:19:1 | 19 | / /// foobar @@ -97,9 +104,10 @@ error: unknown attribute `norun`. Did you mean `no_run`? 23 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `no_run` = help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want) -error: unknown attribute `nO_run`. Did you mean `no_run`? +error: unknown attribute `nO_run` --> $DIR/check-attr-test.rs:19:1 | 19 | / /// foobar @@ -109,9 +117,10 @@ error: unknown attribute `nO_run`. Did you mean `no_run`? 23 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `no_run` = help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want) -error: unknown attribute `test-harness`. Did you mean `test_harness`? +error: unknown attribute `test-harness` --> $DIR/check-attr-test.rs:26:1 | 26 | / /// b @@ -121,9 +130,10 @@ error: unknown attribute `test-harness`. Did you mean `test_harness`? 30 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `test_harness` = help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function -error: unknown attribute `testharness`. Did you mean `test_harness`? +error: unknown attribute `testharness` --> $DIR/check-attr-test.rs:26:1 | 26 | / /// b @@ -133,9 +143,10 @@ error: unknown attribute `testharness`. Did you mean `test_harness`? 30 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `test_harness` = help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function -error: unknown attribute `tesT_harness`. Did you mean `test_harness`? +error: unknown attribute `tesT_harness` --> $DIR/check-attr-test.rs:26:1 | 26 | / /// b @@ -145,6 +156,7 @@ error: unknown attribute `tesT_harness`. Did you mean `test_harness`? 30 | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `test_harness` = help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function error: aborting due to 12 previous errors diff --git a/tests/rustdoc-ui/lints/check-attr.stderr b/tests/rustdoc-ui/lints/check-attr.stderr index cd2f1eea7ce45..c736fa8a91fe5 100644 --- a/tests/rustdoc-ui/lints/check-attr.stderr +++ b/tests/rustdoc-ui/lints/check-attr.stderr @@ -1,4 +1,4 @@ -error: unknown attribute `compile-fail`. Did you mean `compile_fail`? +error: unknown attribute `compile-fail` --> $DIR/check-attr.rs:3:1 | LL | / /// foo @@ -10,6 +10,7 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `compile_fail` = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully note: the lint level is defined here --> $DIR/check-attr.rs:1:9 @@ -17,7 +18,7 @@ note: the lint level is defined here LL | #![deny(rustdoc::invalid_codeblock_attributes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: unknown attribute `compilefail`. Did you mean `compile_fail`? +error: unknown attribute `compilefail` --> $DIR/check-attr.rs:3:1 | LL | / /// foo @@ -29,9 +30,10 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `compile_fail` = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully -error: unknown attribute `comPile_fail`. Did you mean `compile_fail`? +error: unknown attribute `comPile_fail` --> $DIR/check-attr.rs:3:1 | LL | / /// foo @@ -43,9 +45,10 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `compile_fail` = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully -error: unknown attribute `should-panic`. Did you mean `should_panic`? +error: unknown attribute `should-panic` --> $DIR/check-attr.rs:13:1 | LL | / /// bar @@ -57,9 +60,10 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `should_panic` = help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running -error: unknown attribute `shouldpanic`. Did you mean `should_panic`? +error: unknown attribute `shouldpanic` --> $DIR/check-attr.rs:13:1 | LL | / /// bar @@ -71,9 +75,10 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `should_panic` = help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running -error: unknown attribute `sHould_panic`. Did you mean `should_panic`? +error: unknown attribute `sHould_panic` --> $DIR/check-attr.rs:13:1 | LL | / /// bar @@ -85,9 +90,10 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `should_panic` = help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running -error: unknown attribute `no-run`. Did you mean `no_run`? +error: unknown attribute `no-run` --> $DIR/check-attr.rs:23:1 | LL | / /// foobar @@ -99,9 +105,10 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `no_run` = help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want) -error: unknown attribute `norun`. Did you mean `no_run`? +error: unknown attribute `norun` --> $DIR/check-attr.rs:23:1 | LL | / /// foobar @@ -113,9 +120,10 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `no_run` = help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want) -error: unknown attribute `no_Run`. Did you mean `no_run`? +error: unknown attribute `no_Run` --> $DIR/check-attr.rs:23:1 | LL | / /// foobar @@ -127,9 +135,10 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `no_run` = help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want) -error: unknown attribute `test-harness`. Did you mean `test_harness`? +error: unknown attribute `test-harness` --> $DIR/check-attr.rs:33:1 | LL | / /// b @@ -141,9 +150,10 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `test_harness` = help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function -error: unknown attribute `testharness`. Did you mean `test_harness`? +error: unknown attribute `testharness` --> $DIR/check-attr.rs:33:1 | LL | / /// b @@ -155,9 +165,10 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `test_harness` = help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function -error: unknown attribute `teSt_harness`. Did you mean `test_harness`? +error: unknown attribute `teSt_harness` --> $DIR/check-attr.rs:33:1 | LL | / /// b @@ -169,9 +180,10 @@ LL | | /// boo LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `test_harness` = help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function -error: unknown attribute `rust2018`. Did you mean `edition2018`? +error: unknown attribute `rust2018` --> $DIR/check-attr.rs:43:1 | LL | / /// b @@ -181,6 +193,8 @@ LL | | /// ```rust2018 LL | | /// boo LL | | /// ``` | |_______^ + | + = help: there is an attribute with a similar name: `edition2018` error: aborting due to 13 previous errors diff --git a/tests/rustdoc-ui/lints/check-fail.stderr b/tests/rustdoc-ui/lints/check-fail.stderr index f05e457af6452..99b01bac59882 100644 --- a/tests/rustdoc-ui/lints/check-fail.stderr +++ b/tests/rustdoc-ui/lints/check-fail.stderr @@ -22,7 +22,7 @@ note: the lint level is defined here LL | #![deny(rustdoc::missing_doc_code_examples)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: unknown attribute `testharness`. Did you mean `test_harness`? +error: unknown attribute `testharness` --> $DIR/check-fail.rs:8:1 | LL | / //! ```rust,testharness @@ -31,6 +31,7 @@ LL | | //! let x = 12; LL | | //! ``` | |_______^ | + = help: there is an attribute with a similar name: `test_harness` = help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function note: the lint level is defined here --> $DIR/check-fail.rs:6:9 @@ -39,7 +40,7 @@ LL | #![deny(rustdoc::all)] | ^^^^^^^^^^^^ = note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(rustdoc::all)]` -error: unknown attribute `testharness`. Did you mean `test_harness`? +error: unknown attribute `testharness` --> $DIR/check-fail.rs:17:1 | LL | / /// hello @@ -50,6 +51,7 @@ LL | | /// let x = 12; LL | | /// ``` | |_______^ | + = help: there is an attribute with a similar name: `test_harness` = help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function error: aborting due to 4 previous errors From 6892fcd690fe252062ffc8621e2878069a1ee3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 12 Dec 2023 18:42:37 +0100 Subject: [PATCH 08/15] simplify merging of two vecs --- compiler/rustc_pattern_analysis/src/constructor.rs | 2 +- compiler/rustc_resolve/src/late/diagnostics.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_pattern_analysis/src/constructor.rs b/compiler/rustc_pattern_analysis/src/constructor.rs index 716ccdd4dcd00..02039679517ca 100644 --- a/compiler/rustc_pattern_analysis/src/constructor.rs +++ b/compiler/rustc_pattern_analysis/src/constructor.rs @@ -979,7 +979,7 @@ impl ConstructorSet { && !(pcx.is_top_level && matches!(self, Self::NoConstructors)) { // Treat all missing constructors as nonempty. - missing.extend(missing_empty.drain(..)); + missing.append(&mut missing_empty); } SplitConstructorSet { present, missing, missing_empty } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index df30c185c6062..ded1408b990df 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -2178,7 +2178,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { let (span, text) = match path.segments.first() { Some(seg) if let Some(name) = seg.ident.as_str().strip_prefix("let") => { // a special case for #117894 - let name = name.strip_prefix("_").unwrap_or(name); + let name = name.strip_prefix('_').unwrap_or(name); (ident_span, format!("let {name}")) } _ => (ident_span.shrink_to_lo(), "let ".to_string()), From d707461a1a02edd7a1f2591d62499d00b370e75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 12 Dec 2023 19:28:13 +0100 Subject: [PATCH 09/15] clippy::complexity fixes filter_map_identity needless_bool search_is_some unit_arg map_identity needless_question_mark derivable_impls --- compiler/rustc_const_eval/src/interpret/visitor.rs | 2 +- compiler/rustc_driver_impl/src/lib.rs | 4 +--- .../rustc_hir_analysis/src/collect/item_bounds.rs | 11 ++++------- compiler/rustc_hir_typeck/src/upvar.rs | 7 ++----- compiler/rustc_mir_transform/src/jump_threading.rs | 2 +- .../rustc_query_system/src/dep_graph/serialized.rs | 14 +------------- compiler/rustc_smir/src/rustc_smir/context.rs | 2 +- .../traits/error_reporting/type_err_ctxt_ext.rs | 2 +- src/librustdoc/html/render/type_layout.rs | 3 ++- 9 files changed, 14 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/visitor.rs b/compiler/rustc_const_eval/src/interpret/visitor.rs index 5c5a6e8db57a2..de0590a4b14de 100644 --- a/compiler/rustc_const_eval/src/interpret/visitor.rs +++ b/compiler/rustc_const_eval/src/interpret/visitor.rs @@ -21,7 +21,7 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized { /// `read_discriminant` can be hooked for better error messages. #[inline(always)] fn read_discriminant(&mut self, v: &Self::V) -> InterpResult<'tcx, VariantIdx> { - Ok(self.ecx().read_discriminant(&v.to_op(self.ecx())?)?) + self.ecx().read_discriminant(&v.to_op(self.ecx())?) } /// This function provides the chance to reorder the order in which fields are visited for diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 8b7a4dbff9d58..e49db64536f16 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -587,10 +587,8 @@ fn show_md_content_with_pager(content: &str, color: ColorConfig) { let mut print_formatted = if pager_name == "less" { cmd.arg("-r"); true - } else if ["bat", "catbat", "delta"].iter().any(|v| *v == pager_name) { - true } else { - false + ["bat", "catbat", "delta"].iter().any(|v| *v == pager_name) }; if color == ColorConfig::Never { diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs index 4d0fd2b691a9e..78d408cf5c0e9 100644 --- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs +++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs @@ -34,17 +34,14 @@ fn associated_type_bounds<'tcx>( let trait_def_id = tcx.local_parent(assoc_item_def_id); let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id); - let bounds_from_parent = trait_predicates - .predicates - .iter() - .copied() - .filter(|(pred, _)| match pred.kind().skip_binder() { + let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| { + match pred.kind().skip_binder() { ty::ClauseKind::Trait(tr) => tr.self_ty() == item_ty, ty::ClauseKind::Projection(proj) => proj.projection_ty.self_ty() == item_ty, ty::ClauseKind::TypeOutlives(outlives) => outlives.0 == item_ty, _ => false, - }) - .map(|(clause, span)| (clause, span)); + } + }); let all_bounds = tcx.arena.alloc_from_iter(bounds.clauses().chain(bounds_from_parent)); debug!( diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index c0a5818b9e5f9..17e4f40fe2182 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -315,11 +315,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let final_tupled_upvars_type = Ty::new_tup(self.tcx, &final_upvar_tys); self.demand_suptype(span, args.tupled_upvars_ty(), final_tupled_upvars_type); - let fake_reads = delegate - .fake_reads - .into_iter() - .map(|(place, cause, hir_id)| (place, cause, hir_id)) - .collect(); + let fake_reads = delegate.fake_reads; + self.typeck_results.borrow_mut().closure_fake_reads.insert(closure_def_id, fake_reads); if self.tcx.sess.opts.unstable_opts.profile_closures { diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index 36a15f472761e..a41d8e212454e 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -649,7 +649,7 @@ impl OpportunitySet { // `succ` must be a successor of `current`. If it is not, this means this TO is not // satisfiable and a previous TO erased this edge, so we bail out. - if basic_blocks[current].terminator().successors().find(|s| *s == succ).is_none() { + if !basic_blocks[current].terminator().successors().any(|s| s == succ) { debug!("impossible"); return; } diff --git a/compiler/rustc_query_system/src/dep_graph/serialized.rs b/compiler/rustc_query_system/src/dep_graph/serialized.rs index a70f4138cfb53..504763f6cdb38 100644 --- a/compiler/rustc_query_system/src/dep_graph/serialized.rs +++ b/compiler/rustc_query_system/src/dep_graph/serialized.rs @@ -70,7 +70,7 @@ const DEP_NODE_PAD: usize = DEP_NODE_SIZE - 1; const DEP_NODE_WIDTH_BITS: usize = DEP_NODE_SIZE / 2; /// Data for use when recompiling the **current crate**. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct SerializedDepGraph { /// The set of all DepNodes in the graph nodes: IndexVec, @@ -89,18 +89,6 @@ pub struct SerializedDepGraph { index: Vec>, } -impl Default for SerializedDepGraph { - fn default() -> Self { - SerializedDepGraph { - nodes: Default::default(), - fingerprints: Default::default(), - edge_list_indices: Default::default(), - edge_list_data: Default::default(), - index: Default::default(), - } - } -} - impl SerializedDepGraph { #[inline] pub fn edge_targets_from( diff --git a/compiler/rustc_smir/src/rustc_smir/context.rs b/compiler/rustc_smir/src/rustc_smir/context.rs index 4ec5e2a538708..241a0c2231064 100644 --- a/compiler/rustc_smir/src/rustc_smir/context.rs +++ b/compiler/rustc_smir/src/rustc_smir/context.rs @@ -157,7 +157,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> { (name == crate_name).then(|| smir_crate(tables.tcx, *crate_num)) }) .into_iter() - .filter_map(|c| c) + .flatten() .collect(); crates } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 8fa0dceda8742..66452adbd69c1 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -1069,7 +1069,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if !self.tcx.is_diagnostic_item(sym::Result, def.did()) { return None; } - Some(arg.as_type()?) + arg.as_type() }; let mut suggested = false; diff --git a/src/librustdoc/html/render/type_layout.rs b/src/librustdoc/html/render/type_layout.rs index ee581173a4a11..738ea0aee7e9d 100644 --- a/src/librustdoc/html/render/type_layout.rs +++ b/src/librustdoc/html/render/type_layout.rs @@ -79,6 +79,7 @@ pub(crate) fn document_type_layout<'a, 'cx: 'a>( TypeLayoutSize { is_unsized, is_uninhabited, size } }); - Ok(TypeLayout { variants, type_layout_size }.render_into(f).unwrap()) + TypeLayout { variants, type_layout_size }.render_into(f).unwrap(); + Ok(()) }) } From f1342f30a5da43a28e25ffccd10ead85f24a7195 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 12 Dec 2023 19:31:43 +0100 Subject: [PATCH 10/15] Clean up variables in `search.js` --- src/librustdoc/html/static/js/search.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 8f68796ad26b8..96a46d33c9e1f 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -2102,8 +2102,6 @@ function initSearch(rawSearchIndex) { } function innerRunQuery() { - let elem, i, nSearchWords, in_returned, row; - let queryLen = 0; for (const elem of parsedQuery.elems) { queryLen += elem.name.length; @@ -2225,8 +2223,8 @@ function initSearch(rawSearchIndex) { if (parsedQuery.foundElems === 1) { if (parsedQuery.elems.length === 1) { - elem = parsedQuery.elems[0]; - for (i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) { + const elem = parsedQuery.elems[0]; + for (let i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) { // It means we want to check for this element everywhere (in names, args and // returned). handleSingleArg( @@ -2241,10 +2239,9 @@ function initSearch(rawSearchIndex) { } } else if (parsedQuery.returned.length === 1) { // We received one returned argument to check, so looking into returned values. - elem = parsedQuery.returned[0]; - for (i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) { - row = searchIndex[i]; - in_returned = row.type && unifyFunctionTypes( + for (let i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) { + const row = searchIndex[i]; + const in_returned = row.type && unifyFunctionTypes( row.type.output, parsedQuery.returned, row.type.where_clause @@ -2262,7 +2259,7 @@ function initSearch(rawSearchIndex) { } } } else if (parsedQuery.foundElems > 0) { - for (i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) { + for (let i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) { handleArgs(searchIndex[i], i, results_others); } } @@ -2418,7 +2415,6 @@ function initSearch(rawSearchIndex) { const extraClass = display ? " active" : ""; const output = document.createElement("div"); - let length = 0; if (array.length > 0) { output.className = "search-results " + extraClass; @@ -2428,8 +2424,6 @@ function initSearch(rawSearchIndex) { const longType = longItemTypes[item.ty]; const typeName = longType.length !== 0 ? `${longType}` : "?"; - length += 1; - const link = document.createElement("a"); link.className = "result-" + type; link.href = item.href; @@ -2477,7 +2471,7 @@ ${item.displayPath}${name}\ "href=\"https://docs.rs\">Docs.rs for documentation of crates released on" + " crates.io."; } - return [output, length]; + return [output, array.length]; } function makeTabHeader(tabNb, text, nbElems) { From 58327c10c5c7424352e4579bf793e9cfaf9733bc Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 12 Dec 2023 19:41:09 +0100 Subject: [PATCH 11/15] Add a test for a codeblock with multiple invalid attributes --- tests/rustdoc-ui/lints/check-attr.rs | 9 +++++++ tests/rustdoc-ui/lints/check-attr.stderr | 31 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/rustdoc-ui/lints/check-attr.rs b/tests/rustdoc-ui/lints/check-attr.rs index 38f5b3851d03d..3c06e6c076bf6 100644 --- a/tests/rustdoc-ui/lints/check-attr.rs +++ b/tests/rustdoc-ui/lints/check-attr.rs @@ -47,3 +47,12 @@ pub fn b() {} /// boo /// ``` pub fn c() {} + +/// b +//~^ ERROR +//~| ERROR +/// +/// ```rust2018 shouldpanic +/// boo +/// ``` +pub fn d() {} diff --git a/tests/rustdoc-ui/lints/check-attr.stderr b/tests/rustdoc-ui/lints/check-attr.stderr index c736fa8a91fe5..d640125ab5133 100644 --- a/tests/rustdoc-ui/lints/check-attr.stderr +++ b/tests/rustdoc-ui/lints/check-attr.stderr @@ -196,5 +196,34 @@ LL | | /// ``` | = help: there is an attribute with a similar name: `edition2018` -error: aborting due to 13 previous errors +error: unknown attribute `rust2018` + --> $DIR/check-attr.rs:51:1 + | +LL | / /// b +LL | | +LL | | +LL | | /// +LL | | /// ```rust2018 shouldpanic +LL | | /// boo +LL | | /// ``` + | |_______^ + | + = help: there is an attribute with a similar name: `edition2018` + +error: unknown attribute `shouldpanic` + --> $DIR/check-attr.rs:51:1 + | +LL | / /// b +LL | | +LL | | +LL | | /// +LL | | /// ```rust2018 shouldpanic +LL | | /// boo +LL | | /// ``` + | |_______^ + | + = help: there is an attribute with a similar name: `should_panic` + = help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running + +error: aborting due to 15 previous errors From 046f2dea33fddc389aa56c5ac74a651cd3091b96 Mon Sep 17 00:00:00 2001 From: Samuel Moelius <35515885+smoelius@users.noreply.github.com> Date: Tue, 12 Dec 2023 13:48:20 -0500 Subject: [PATCH 12/15] Typo --- .../rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index e49d134659ec6..3d673f2f1ec04 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -364,7 +364,7 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String { // _ZTSFvu27NvNtC1234_5crate6Trait13fooIu22NtC1234_5crate7Struct1Iu3i32ES_EE // // The reason for not using v0's extended form of paths is to use a consistent and simpler - // encoding, as the reasoning for using it isn't relevand for type metadata identifiers (i.e., + // encoding, as the reasoning for using it isn't relevant for type metadata identifiers (i.e., // keep symbol names close to how methods are represented in error messages). See // https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html#methods. let mut s = String::new(); From 3795cc8eb04b5b95c6a7a8dd7bcf357adb01169e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 12 Dec 2023 20:41:51 +0100 Subject: [PATCH 13/15] more clippy::complexity fixes redundant_guards redundant_slicing filter_next needless_borrowed_reference useless_format --- compiler/rustc_hir_typeck/src/coercion.rs | 6 +++--- compiler/rustc_hir_typeck/src/demand.rs | 2 +- compiler/rustc_infer/src/infer/error_reporting/mod.rs | 2 +- compiler/rustc_mir_build/src/thir/pattern/mod.rs | 2 +- compiler/rustc_resolve/src/imports.rs | 8 ++------ compiler/rustc_resolve/src/late/diagnostics.rs | 11 +++-------- compiler/rustc_smir/src/rustc_smir/convert/mir.rs | 2 +- compiler/rustc_trait_selection/src/infer.rs | 3 +-- .../src/traits/error_reporting/suggestions.rs | 2 +- src/librustdoc/clean/types.rs | 8 ++++---- 10 files changed, 18 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 0d3bb0f7e0ca9..f697182e45a71 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1701,7 +1701,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { && !ty.is_never() { let indentation = if let None = block.expr - && let [.., last] = &block.stmts[..] + && let [.., last] = &block.stmts { tcx.sess.source_map().indentation_before(last.span).unwrap_or_else(String::new) } else if let Some(expr) = block.expr { @@ -1710,7 +1710,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { String::new() }; if let None = block.expr - && let [.., last] = &block.stmts[..] + && let [.., last] = &block.stmts { err.span_suggestion_verbose( last.span.shrink_to_hi(), @@ -1750,7 +1750,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { } } if let None = block.expr - && let [.., last] = &block.stmts[..] + && let [.., last] = &block.stmts { sugg.push((last.span.shrink_to_hi(), format!("\n{indentation}None"))); } else if let Some(expr) = block.expr { diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 8f63383488531..f2301407813a1 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -862,7 +862,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { mutability, ), ), - match &args[..] { + match &args { [] => (base.span.shrink_to_hi().with_hi(deref.span.hi()), ")".to_string()), [first, ..] => (base.span.between(first.span), ", ".to_string()), }, diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 745c3d195ada7..e568ff9f28202 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2452,7 +2452,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if !suggs.is_empty() { err.multipart_suggestion_verbose( - format!("{msg}"), + msg, suggs, Applicability::MaybeIncorrect, // Issue #41966 ); diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index af0dab4ebc7f4..c7762f8ce4e32 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -174,7 +174,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { span: Span, ) -> Result, ErrorGuaranteed> { if lo_expr.is_none() && hi_expr.is_none() { - let msg = format!("found twice-open range pattern (`..`) outside of error recovery"); + let msg = "found twice-open range pattern (`..`) outside of error recovery"; return Err(self.tcx.sess.span_delayed_bug(span, msg)); } diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index e601ceaa50cc0..39e82da6d9dd0 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -1063,12 +1063,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { initial_binding.res() }); let res = binding.res(); - let has_ambiguity_error = this - .ambiguity_errors - .iter() - .filter(|error| !error.warning) - .next() - .is_some(); + let has_ambiguity_error = + this.ambiguity_errors.iter().any(|error| !error.warning); if res == Res::Err || has_ambiguity_error { this.tcx .sess diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index df30c185c6062..3bd6b0f1d77c6 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1829,13 +1829,12 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { ) .iter() .filter_map(|candidate| candidate.did) - .filter(|did| { + .find(|did| { self.r .tcx .get_attrs(*did, sym::rustc_diagnostic_item) .any(|attr| attr.value_str() == Some(sym::Default)) - }) - .next(); + }); let Some(default_trait) = default_trait else { return; }; @@ -1880,11 +1879,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { }; fields.is_some_and(|fields| { - fields - .iter() - .filter(|vis| !self.r.is_accessible_from(**vis, self.parent_scope.module)) - .next() - .is_some() + fields.iter().any(|vis| !self.r.is_accessible_from(*vis, self.parent_scope.module)) }) } diff --git a/compiler/rustc_smir/src/rustc_smir/convert/mir.rs b/compiler/rustc_smir/src/rustc_smir/convert/mir.rs index 0cea3fcc7f7ac..8c1767501d9a0 100644 --- a/compiler/rustc_smir/src/rustc_smir/convert/mir.rs +++ b/compiler/rustc_smir/src/rustc_smir/convert/mir.rs @@ -707,7 +707,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> { let id = tables.intern_const(*self); Const::new(kind, ty, id) } - mir::Const::Val(val, ty) if matches!(val, mir::ConstValue::ZeroSized) => { + mir::Const::Val(mir::ConstValue::ZeroSized, ty) => { let ty = ty.stable(tables); let id = tables.intern_const(*self); Const::new(ConstantKind::ZeroSized, ty, id) diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index 4b11cc3ace90a..251f0628a7130 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -101,11 +101,10 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { self.tcx.impl_trait_ref(impl_def_id).map(|r| (impl_def_id, r)) }) .map(|(impl_def_id, imp)| (impl_def_id, imp.skip_binder())) - .filter(|(_, imp)| match imp.self_ty().peel_refs().kind() { + .find(|(_, imp)| match imp.self_ty().peel_refs().kind() { ty::Adt(i_def, _) if i_def.did() == def.did() => true, _ => false, }) - .next() { let mut fulfill_cx = FulfillmentCtxt::new(self); // We get all obligations from the impl to talk about specific diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index f7e8dc62a625d..1033fe6814029 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2167,7 +2167,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { }) .collect(); err.multipart_suggestion( - format!("consider wrapping the function in a closure"), + "consider wrapping the function in a closure", vec![ (arg.span.shrink_to_lo(), format!("|{}| ", closure_names.join(", "))), (arg.span.shrink_to_hi(), format!("({})", call_names.join(", "))), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 0a14404d68998..150625c6d920f 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2245,8 +2245,8 @@ impl GenericArgs { } pub(crate) fn bindings<'a>(&'a self) -> Box + 'a> { match self { - &GenericArgs::AngleBracketed { ref bindings, .. } => Box::new(bindings.iter().cloned()), - &GenericArgs::Parenthesized { ref output, .. } => Box::new( + GenericArgs::AngleBracketed { bindings, .. } => Box::new(bindings.iter().cloned()), + GenericArgs::Parenthesized { output, .. } => Box::new( output .as_ref() .map(|ty| TypeBinding { @@ -2270,8 +2270,8 @@ impl<'a> IntoIterator for &'a GenericArgs { type Item = GenericArg; fn into_iter(self) -> Self::IntoIter { match self { - &GenericArgs::AngleBracketed { ref args, .. } => Box::new(args.iter().cloned()), - &GenericArgs::Parenthesized { ref inputs, .. } => { + GenericArgs::AngleBracketed { args, .. } => Box::new(args.iter().cloned()), + GenericArgs::Parenthesized { inputs, .. } => { Box::new(inputs.iter().cloned().map(GenericArg::Type)) } } From 2a1acc26a0533b82faa5ab18b56cff032e6ca3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 12 Dec 2023 21:12:19 +0100 Subject: [PATCH 14/15] Update compiler/rustc_pattern_analysis/src/constructor.rs add note that `missing_empty` is cleared now Co-authored-by: Nadrieril --- compiler/rustc_pattern_analysis/src/constructor.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_pattern_analysis/src/constructor.rs b/compiler/rustc_pattern_analysis/src/constructor.rs index 02039679517ca..3bca7894a2921 100644 --- a/compiler/rustc_pattern_analysis/src/constructor.rs +++ b/compiler/rustc_pattern_analysis/src/constructor.rs @@ -979,6 +979,7 @@ impl ConstructorSet { && !(pcx.is_top_level && matches!(self, Self::NoConstructors)) { // Treat all missing constructors as nonempty. + // This clears `missing_empty`. missing.append(&mut missing_empty); } From 1d78ce681e4bf0c0259fc97e422298d68635dc4f Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 12 Dec 2023 20:08:34 +0000 Subject: [PATCH 15/15] Actually parse async gen blocks correctly --- compiler/rustc_parse/src/parser/expr.rs | 27 ++++++++++------ tests/ui/coroutine/async-gen-deduce-yield.rs | 14 ++++++++ .../feature-gate-gen_blocks.e2024.stderr | 32 ++++++++++++++++--- .../feature-gate-gen_blocks.none.stderr | 14 +++++++- .../feature-gates/feature-gate-gen_blocks.rs | 15 ++++++++- 5 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 tests/ui/coroutine/async-gen-deduce-yield.rs diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 3c0627526bed5..3606c0fa09871 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1440,21 +1440,23 @@ impl<'a> Parser<'a> { } else if this.eat_keyword(kw::Underscore) { Ok(this.mk_expr(this.prev_token.span, ExprKind::Underscore)) } else if this.token.uninterpolated_span().at_least_rust_2018() { - // `Span:.at_least_rust_2018()` is somewhat expensive; don't get it repeatedly. - if this.check_keyword(kw::Async) { + // `Span::at_least_rust_2018()` is somewhat expensive; don't get it repeatedly. + if this.token.uninterpolated_span().at_least_rust_2024() + // check for `gen {}` and `gen move {}` + // or `async gen {}` and `async gen move {}` + && (this.is_gen_block(kw::Gen, 0) + || (this.check_keyword(kw::Async) && this.is_gen_block(kw::Gen, 1))) + { + // FIXME: (async) gen closures aren't yet parsed. + this.parse_gen_block() + } else if this.check_keyword(kw::Async) { // FIXME(gen_blocks): Parse `gen async` and suggest swap if this.is_gen_block(kw::Async, 0) { // Check for `async {` and `async move {`, - // or `async gen {` and `async gen move {`. this.parse_gen_block() } else { this.parse_expr_closure() } - } else if this.token.uninterpolated_span().at_least_rust_2024() - && (this.is_gen_block(kw::Gen, 0) - || (this.check_keyword(kw::Async) && this.is_gen_block(kw::Gen, 1))) - { - this.parse_gen_block() } else if this.eat_keyword_noexpect(kw::Await) { this.recover_incorrect_await_syntax(lo, this.prev_token.span) } else { @@ -3219,9 +3221,16 @@ impl<'a> Parser<'a> { if self.eat_keyword(kw::Gen) { GenBlockKind::AsyncGen } else { GenBlockKind::Async } } else { assert!(self.eat_keyword(kw::Gen)); - self.sess.gated_spans.gate(sym::gen_blocks, lo.to(self.token.span)); GenBlockKind::Gen }; + match kind { + GenBlockKind::Async => { + // `async` blocks are stable + } + GenBlockKind::Gen | GenBlockKind::AsyncGen => { + self.sess.gated_spans.gate(sym::gen_blocks, lo.to(self.prev_token.span)); + } + } let capture_clause = self.parse_capture_clause()?; let (attrs, body) = self.parse_inner_attrs_and_block()?; let kind = ExprKind::Gen(capture_clause, body, kind); diff --git a/tests/ui/coroutine/async-gen-deduce-yield.rs b/tests/ui/coroutine/async-gen-deduce-yield.rs new file mode 100644 index 0000000000000..9ccc8ee41f667 --- /dev/null +++ b/tests/ui/coroutine/async-gen-deduce-yield.rs @@ -0,0 +1,14 @@ +// compile-flags: --edition 2024 -Zunstable-options +// check-pass + +#![feature(async_iterator, gen_blocks)] + +use std::async_iter::AsyncIterator; + +fn deduce() -> impl AsyncIterator { + async gen { + yield Default::default(); + } +} + +fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-gen_blocks.e2024.stderr b/tests/ui/feature-gates/feature-gate-gen_blocks.e2024.stderr index 1462c41e957b2..c582ca7ba3d58 100644 --- a/tests/ui/feature-gates/feature-gate-gen_blocks.e2024.stderr +++ b/tests/ui/feature-gates/feature-gate-gen_blocks.e2024.stderr @@ -2,16 +2,34 @@ error[E0658]: gen blocks are experimental --> $DIR/feature-gate-gen_blocks.rs:5:5 | LL | gen {}; - | ^^^^^ + | ^^^ | = note: see issue #117078 for more information = help: add `#![feature(gen_blocks)]` to the crate attributes to enable error[E0658]: gen blocks are experimental - --> $DIR/feature-gate-gen_blocks.rs:13:5 + --> $DIR/feature-gate-gen_blocks.rs:12:5 + | +LL | async gen {}; + | ^^^^^^^^^ + | + = note: see issue #117078 for more information + = help: add `#![feature(gen_blocks)]` to the crate attributes to enable + +error[E0658]: gen blocks are experimental + --> $DIR/feature-gate-gen_blocks.rs:22:5 | LL | gen {}; - | ^^^^^ + | ^^^ + | + = note: see issue #117078 for more information + = help: add `#![feature(gen_blocks)]` to the crate attributes to enable + +error[E0658]: gen blocks are experimental + --> $DIR/feature-gate-gen_blocks.rs:25:5 + | +LL | async gen {}; + | ^^^^^^^^^ | = note: see issue #117078 for more information = help: add `#![feature(gen_blocks)]` to the crate attributes to enable @@ -22,7 +40,13 @@ error[E0282]: type annotations needed LL | gen {}; | ^^ cannot infer type -error: aborting due to 3 previous errors +error[E0282]: type annotations needed + --> $DIR/feature-gate-gen_blocks.rs:12:15 + | +LL | async gen {}; + | ^^ cannot infer type + +error: aborting due to 6 previous errors Some errors have detailed explanations: E0282, E0658. For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/feature-gates/feature-gate-gen_blocks.none.stderr b/tests/ui/feature-gates/feature-gate-gen_blocks.none.stderr index 56f8309a69f9b..b4b37f0e63847 100644 --- a/tests/ui/feature-gates/feature-gate-gen_blocks.none.stderr +++ b/tests/ui/feature-gates/feature-gate-gen_blocks.none.stderr @@ -1,9 +1,21 @@ +error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `gen` + --> $DIR/feature-gate-gen_blocks.rs:12:11 + | +LL | async gen {}; + | ^^^ expected one of 8 possible tokens + +error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `gen` + --> $DIR/feature-gate-gen_blocks.rs:25:11 + | +LL | async gen {}; + | ^^^ expected one of 8 possible tokens + error[E0422]: cannot find struct, variant or union type `gen` in this scope --> $DIR/feature-gate-gen_blocks.rs:5:5 | LL | gen {}; | ^^^ not found in this scope -error: aborting due to 1 previous error +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0422`. diff --git a/tests/ui/feature-gates/feature-gate-gen_blocks.rs b/tests/ui/feature-gates/feature-gate-gen_blocks.rs index e2e1574a36a0f..ff9a0b139c057 100644 --- a/tests/ui/feature-gates/feature-gate-gen_blocks.rs +++ b/tests/ui/feature-gates/feature-gate-gen_blocks.rs @@ -1,15 +1,28 @@ // revisions: e2024 none //[e2024] compile-flags: --edition 2024 -Zunstable-options -fn main() { +fn test_gen() { gen {}; //[none]~^ ERROR: cannot find struct, variant or union type `gen` //[e2024]~^^ ERROR: gen blocks are experimental //[e2024]~| ERROR: type annotations needed } +fn test_async_gen() { + async gen {}; + //[none]~^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `gen` + //[e2024]~^^ ERROR: gen blocks are experimental + //[e2024]~| ERROR: type annotations needed +} + +fn main() {} + #[cfg(FALSE)] fn foo() { gen {}; //[e2024]~^ ERROR: gen blocks are experimental + + async gen {}; + //[e2024]~^ ERROR: gen blocks are experimental + //[none]~^^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `gen` }