From c20bdf247bd9266afe685ebe60a775d5bfa43373 Mon Sep 17 00:00:00 2001 From: Takashi Idobe Date: Fri, 22 Dec 2023 18:28:19 -0500 Subject: [PATCH 1/6] fix some typos found scrolling through the docs --- .../src/platform-support/wasm32-wasi-preview1-threads.md | 2 +- src/doc/rustdoc/src/lints.md | 4 ++-- src/doc/unstable-book/src/compiler-flags/check-cfg.md | 2 +- src/librustdoc/lint.rs | 4 ++-- src/tools/tidy/src/style.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md b/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md index 23b9992489973..b719cb53aba40 100644 --- a/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md +++ b/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md @@ -90,7 +90,7 @@ The target intends to match the corresponding Clang target for its `"C"` ABI. ## Platform requirements -The runtime should support the same set of APIs as any other supported wasi target for interacting with the host environment through the WASI standard. The runtime also should have implemetation of [wasi-threads proposal](https://github.com/WebAssembly/wasi-threads). +The runtime should support the same set of APIs as any other supported wasi target for interacting with the host environment through the WASI standard. The runtime also should have implementation of [wasi-threads proposal](https://github.com/WebAssembly/wasi-threads). This target is not a stable target. This means that there are a few engines which implement the `wasi-threads` feature and if they do they're likely behind a diff --git a/src/doc/rustdoc/src/lints.md b/src/doc/rustdoc/src/lints.md index f15e6e451e757..63451e787631f 100644 --- a/src/doc/rustdoc/src/lints.md +++ b/src/doc/rustdoc/src/lints.md @@ -415,9 +415,9 @@ warning: 1 warning emitted ## `redundant_explicit_links` -This lint is **warned by default**. It detects explicit links that are same +This lint is **warn-by-default**. It detects explicit links that are same as computed automatic links. -This usually means the explicit links is removeable. For example: +This usually means the explicit links are removeable. For example: ```rust #![warn(rustdoc::redundant_explicit_links)] // note: unnecessary - warns by default. diff --git a/src/doc/unstable-book/src/compiler-flags/check-cfg.md b/src/doc/unstable-book/src/compiler-flags/check-cfg.md index a5b9169c9f3d1..8ab6e83d99e79 100644 --- a/src/doc/unstable-book/src/compiler-flags/check-cfg.md +++ b/src/doc/unstable-book/src/compiler-flags/check-cfg.md @@ -107,7 +107,7 @@ fn poke_platypus() {} fn tame_lion() {} // This is UNEXPECTED, because 'windows' is a well known condition name, -// and because 'windows' doens't take any values, +// and because 'windows' doesn't take any values, // and will cause a compiler warning (by default). #[cfg(windows = "unix")] fn tame_windows() {} diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index 267f1cb0b72b5..f78743a7917ce 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -186,8 +186,8 @@ declare_rustdoc_lint! { } declare_rustdoc_lint! { - /// This lint is **warned by default**. It detects explicit links that are same - /// as computed automatic links. This usually means the explicit links is removeable. + /// This lint is **warn-by-default**. It detects explicit links that are the same + /// as computed automatic links. This usually means the explicit links are removeable. /// This is a `rustdoc` only lint, see the documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#redundant_explicit_links diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index cb40c6e3a386f..8b0e80a94b0b3 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -494,7 +494,7 @@ pub fn check(path: &Path, bad: &mut bool) { let mut err = |_| { tidy_error!(bad, "{}: leading newline", file.display()); }; - suppressible_tidy_err!(err, skip_leading_newlines, "mising leading newline"); + suppressible_tidy_err!(err, skip_leading_newlines, "missing leading newline"); } let mut err = |msg: &str| { tidy_error!(bad, "{}: {}", file.display(), msg); From 9a2d890c09eb5f8c38dc0411277a7496954426b1 Mon Sep 17 00:00:00 2001 From: Takashi Idobe Date: Fri, 22 Dec 2023 18:29:51 -0500 Subject: [PATCH 2/6] fix missed typo --- src/doc/rustdoc/src/lints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustdoc/src/lints.md b/src/doc/rustdoc/src/lints.md index 63451e787631f..7d573ac950d8e 100644 --- a/src/doc/rustdoc/src/lints.md +++ b/src/doc/rustdoc/src/lints.md @@ -415,7 +415,7 @@ warning: 1 warning emitted ## `redundant_explicit_links` -This lint is **warn-by-default**. It detects explicit links that are same +This lint is **warn-by-default**. It detects explicit links that are the same as computed automatic links. This usually means the explicit links are removeable. For example: From 1349d86c72fe4d57134edb025d64e0ddff804d77 Mon Sep 17 00:00:00 2001 From: Alona Enraght-Moony Date: Fri, 22 Dec 2023 23:29:20 +0000 Subject: [PATCH 3/6] bool->enum for ast::PatKind::Struct presence of `..` See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed. --- compiler/rustc_ast/src/ast.rs | 12 ++++++++++-- compiler/rustc_ast_lowering/src/pat.rs | 2 +- compiler/rustc_ast_pretty/src/pprust/state.rs | 4 ++-- compiler/rustc_expand/src/build.rs | 2 +- compiler/rustc_parse/src/parser/pat.rs | 11 ++++++----- .../clippy/clippy_lints/src/unnested_or_patterns.rs | 2 +- src/tools/rustfmt/src/patterns.rs | 12 +++++++++--- 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index a121b5a9bed3d..027b09b7f30b8 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -779,8 +779,7 @@ pub enum PatKind { Ident(BindingAnnotation, Ident, Option>), /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`). - /// The `bool` is `true` in the presence of a `..`. - Struct(Option>, Path, ThinVec, /* recovered */ bool), + Struct(Option>, Path, ThinVec, PatFieldsRest), /// A tuple struct/variant pattern (`Variant(x, y, .., z)`). TupleStruct(Option>, Path, ThinVec>), @@ -837,6 +836,15 @@ pub enum PatKind { MacCall(P), } +/// Whether the `..` is present in a struct fields pattern. +#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq)] +pub enum PatFieldsRest { + /// `module::StructName { field, ..}` + Rest, + /// `module::StructName { field }` + None, +} + /// The kind of borrow in an `AddrOf` expression, /// e.g., `&place` or `&raw const place`. #[derive(Clone, Copy, PartialEq, Eq, Debug)] diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index 017314ee4d14a..3ffa4f1f2e6eb 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -82,7 +82,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { span: self.lower_span(f.span), } })); - break hir::PatKind::Struct(qpath, fs, *etc); + break hir::PatKind::Struct(qpath, fs, *etc == ast::PatFieldsRest::Rest); } PatKind::Tuple(pats) => { let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple"); diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index d6c15ec35b603..619fd7a49ebe3 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1427,7 +1427,7 @@ impl<'a> State<'a> { } self.nbsp(); self.word("{"); - let empty = fields.is_empty() && !etc; + let empty = fields.is_empty() && *etc == ast::PatFieldsRest::None; if !empty { self.space(); } @@ -1445,7 +1445,7 @@ impl<'a> State<'a> { }, |f| f.pat.span, ); - if *etc { + if *etc == ast::PatFieldsRest::Rest { if !fields.is_empty() { self.word_space(","); } diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 86f555fa08bcf..c17d8472dcca3 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -488,7 +488,7 @@ impl<'a> ExtCtxt<'a> { path: ast::Path, field_pats: ThinVec, ) -> P { - self.pat(span, PatKind::Struct(None, path, field_pats, false)) + self.pat(span, PatKind::Struct(None, path, field_pats, ast::PatFieldsRest::None)) } pub fn pat_tuple(&self, span: Span, pats: ThinVec>) -> P { self.pat(span, PatKind::Tuple(pats)) diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 80233eddb9b7f..3fc4179af65ad 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -15,7 +15,7 @@ use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter}; use rustc_ast::{ self as ast, AttrVec, BindingAnnotation, ByRef, Expr, ExprKind, MacCall, Mutability, Pat, - PatField, PatKind, Path, QSelf, RangeEnd, RangeSyntax, + PatField, PatFieldsRest, PatKind, Path, QSelf, RangeEnd, RangeSyntax, }; use rustc_ast_pretty::pprust; use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, PResult}; @@ -890,7 +890,8 @@ impl<'a> Parser<'a> { e.span_label(path.span, "while parsing the fields for this pattern"); e.emit(); self.recover_stmt(); - (ThinVec::new(), true) + // When recovering, pretend we had `Foo { .. }`, to avoid cascading errors. + (ThinVec::new(), PatFieldsRest::Rest) }); self.bump(); Ok(PatKind::Struct(qself, path, fields, etc)) @@ -964,9 +965,9 @@ impl<'a> Parser<'a> { } /// Parses the fields of a struct-like pattern. - fn parse_pat_fields(&mut self) -> PResult<'a, (ThinVec, bool)> { + fn parse_pat_fields(&mut self) -> PResult<'a, (ThinVec, PatFieldsRest)> { let mut fields = ThinVec::new(); - let mut etc = false; + let mut etc = PatFieldsRest::None; let mut ate_comma = true; let mut delayed_err: Option> = None; let mut first_etc_and_maybe_comma_span = None; @@ -1000,7 +1001,7 @@ impl<'a> Parser<'a> { || self.check_noexpect(&token::DotDotDot) || self.check_keyword(kw::Underscore) { - etc = true; + etc = PatFieldsRest::Rest; let mut etc_sp = self.token.span; if first_etc_and_maybe_comma_span.is_none() { if let Some(comma_tok) = self diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs index 65600009c1d79..77adcdd0e6bfb 100644 --- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs @@ -293,7 +293,7 @@ fn extend_with_struct_pat( qself1: &Option>, path1: &ast::Path, fps1: &mut [ast::PatField], - rest1: bool, + rest1: ast::PatFieldsRest, start: usize, alternatives: &mut ThinVec>, ) -> bool { diff --git a/src/tools/rustfmt/src/patterns.rs b/src/tools/rustfmt/src/patterns.rs index 8504999b8ff51..0fa6edaa5d78b 100644 --- a/src/tools/rustfmt/src/patterns.rs +++ b/src/tools/rustfmt/src/patterns.rs @@ -259,9 +259,15 @@ impl Rewrite for Pat { None, None, ), - PatKind::Struct(ref qself, ref path, ref fields, ellipsis) => { - rewrite_struct_pat(qself, path, fields, ellipsis, self.span, context, shape) - } + PatKind::Struct(ref qself, ref path, ref fields, rest) => rewrite_struct_pat( + qself, + path, + fields, + rest == ast::PatFieldsRest::Rest, + self.span, + context, + shape, + ), PatKind::MacCall(ref mac) => { rewrite_macro(mac, None, context, shape, MacroPosition::Pat) } From ca2f8da5f16892f100017d043866d12b87a13287 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 23 Dec 2023 11:15:00 +0100 Subject: [PATCH 4/6] Improve documentation for using warning blocks in documentation --- .../rustdoc/src/how-to-write-documentation.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/doc/rustdoc/src/how-to-write-documentation.md b/src/doc/rustdoc/src/how-to-write-documentation.md index acab1a93690c5..8994c01f82486 100644 --- a/src/doc/rustdoc/src/how-to-write-documentation.md +++ b/src/doc/rustdoc/src/how-to-write-documentation.md @@ -267,6 +267,22 @@ you can wrap it like this: /// more documentation ``` +Please note that if you want to put markdown in the HTML tag and for it to +be interpreted as such, you need to have an empty line between the HTML tags +and your markdown content. For example if you want to use a link: + +```md +/// documentation +/// +///
+/// +/// Go to [this link](https://rust-lang.org)! +/// +///
+/// +/// more documentation +``` + [`backtrace`]: https://docs.rs/backtrace/0.3.50/backtrace/ [commonmark markdown specification]: https://commonmark.org/ [commonmark quick reference]: https://commonmark.org/help/ From 8a7513d5aff957b04af8d487f059648a0a1a77f6 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 23 Dec 2023 09:57:06 -0300 Subject: [PATCH 5/6] Add spastorino to users_on_vacation --- triagebot.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/triagebot.toml b/triagebot.toml index e4b104cdb8677..27b174454b4e0 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -639,7 +639,7 @@ cc = ["@nnethercote"] [assign] warn_non_default_branch = true contributing_url = "https://rustc-dev-guide.rust-lang.org/getting-started.html" -users_on_vacation = ["jyn514", "oli-obk"] +users_on_vacation = ["jyn514", "oli-obk", "spastorino"] [assign.adhoc_groups] compiler-team = [ From 49103dc553990e93b72a86183e14697c97eb5b2c Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Sat, 23 Dec 2023 13:59:10 +0100 Subject: [PATCH 6/6] move rustc_outlives test code from query to dedicated function --- .../src/error_codes/E0640.md | 1 + .../rustc_hir_analysis/src/outlives/mod.rs | 20 ------------- .../rustc_hir_analysis/src/outlives/test.rs | 29 ++++++++++++------- src/tools/tidy/src/error_codes.rs | 2 +- 4 files changed, 20 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0640.md b/compiler/rustc_error_codes/src/error_codes/E0640.md index 7edd93e56a945..f7bbeb293caef 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0640.md +++ b/compiler/rustc_error_codes/src/error_codes/E0640.md @@ -1 +1,2 @@ #### This error code is internal to the compiler and will not be emitted with normal Rust code. +#### Note: this error code is no longer emitted by the compiler. diff --git a/compiler/rustc_hir_analysis/src/outlives/mod.rs b/compiler/rustc_hir_analysis/src/outlives/mod.rs index 9541e51070265..5d2aea7441bc9 100644 --- a/compiler/rustc_hir_analysis/src/outlives/mod.rs +++ b/compiler/rustc_hir_analysis/src/outlives/mod.rs @@ -4,7 +4,6 @@ use rustc_hir::def_id::LocalDefId; use rustc_middle::query::Providers; use rustc_middle::ty::GenericArgKind; use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt}; -use rustc_span::symbol::sym; use rustc_span::Span; mod explicit; @@ -49,25 +48,6 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clau let predicates = crate_map.predicates.get(&item_def_id.to_def_id()).copied().unwrap_or(&[]); - if tcx.has_attr(item_def_id, sym::rustc_outlives) { - let mut pred: Vec = predicates - .iter() - .map(|(out_pred, _)| match out_pred.kind().skip_binder() { - ty::ClauseKind::RegionOutlives(p) => p.to_string(), - ty::ClauseKind::TypeOutlives(p) => p.to_string(), - err => bug!("unexpected clause {:?}", err), - }) - .collect(); - pred.sort(); - - let span = tcx.def_span(item_def_id); - let mut err = tcx.sess.struct_span_err(span, "rustc_outlives"); - for p in pred { - err.note(p); - } - err.emit(); - } - debug!("inferred_outlives_of({:?}) = {:?}", item_def_id, predicates); predicates diff --git a/compiler/rustc_hir_analysis/src/outlives/test.rs b/compiler/rustc_hir_analysis/src/outlives/test.rs index 60f8e246ad662..b3cbc312721c0 100644 --- a/compiler/rustc_hir_analysis/src/outlives/test.rs +++ b/compiler/rustc_hir_analysis/src/outlives/test.rs @@ -1,5 +1,4 @@ -use rustc_errors::struct_span_err; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{self, TyCtxt}; use rustc_span::symbol::sym; pub fn test_inferred_outlives(tcx: TyCtxt<'_>) { @@ -7,15 +6,23 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) { // For unit testing: check for a special "rustc_outlives" // attribute and report an error with various results if found. if tcx.has_attr(id.owner_id, sym::rustc_outlives) { - let inferred_outlives_of = tcx.inferred_outlives_of(id.owner_id); - struct_span_err!( - tcx.sess, - tcx.def_span(id.owner_id), - E0640, - "{:?}", - inferred_outlives_of - ) - .emit(); + let predicates = tcx.inferred_outlives_of(id.owner_id); + let mut pred: Vec = predicates + .iter() + .map(|(out_pred, _)| match out_pred.kind().skip_binder() { + ty::ClauseKind::RegionOutlives(p) => p.to_string(), + ty::ClauseKind::TypeOutlives(p) => p.to_string(), + err => bug!("unexpected clause {:?}", err), + }) + .collect(); + pred.sort(); + + let span = tcx.def_span(id.owner_id); + let mut err = tcx.sess.struct_span_err(span, "rustc_outlives"); + for p in pred { + err.note(p); + } + err.emit(); } } } diff --git a/src/tools/tidy/src/error_codes.rs b/src/tools/tidy/src/error_codes.rs index 3e67bac499b0b..094efa981d3e3 100644 --- a/src/tools/tidy/src/error_codes.rs +++ b/src/tools/tidy/src/error_codes.rs @@ -27,7 +27,7 @@ const ERROR_DOCS_PATH: &str = "compiler/rustc_error_codes/src/error_codes/"; const ERROR_TESTS_PATH: &str = "tests/ui/error-codes/"; // Error codes that (for some reason) can't have a doctest in their explanation. Error codes are still expected to provide a code example, even if untested. -const IGNORE_DOCTEST_CHECK: &[&str] = &["E0464", "E0570", "E0601", "E0602", "E0640", "E0717"]; +const IGNORE_DOCTEST_CHECK: &[&str] = &["E0464", "E0570", "E0601", "E0602", "E0717"]; // Error codes that don't yet have a UI test. This list will eventually be removed. const IGNORE_UI_TEST_CHECK: &[&str] =