From adcc55d622e92b6067deb76c6c1159802ed96fae Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 10 Sep 2022 14:27:42 +0200 Subject: [PATCH 01/15] Cleanups in SessionDiagnostic derive --- .../src/diagnostics/diagnostic_builder.rs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 32d6ba62a0d3e..2bff12b0059d7 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -155,7 +155,7 @@ impl DiagnosticDeriveBuilder { } else { Ident::new(name, attr.span()) }; - return Ok(quote! { #diag.#fn_name(rustc_errors::fluent::_subdiag::#fn_name); }); + return Ok(self.add_subdiagnostic(&fn_name, parse_quote! { _subdiag::#fn_name })); } _ => throw_invalid_attr!(attr, &meta), }; @@ -449,20 +449,18 @@ impl DiagnosticDeriveBuilder { let (span_field, mut applicability) = self.span_and_applicability_of_ty(info)?; - let mut msg = None; let mut code = None; let mut nested_iter = nested.into_iter().peekable(); - if let Some(nested_attr) = nested_iter.peek() { - if let NestedMeta::Meta(Meta::Path(path)) = nested_attr { - msg = Some(path.clone()); - } + let msg = if let Some(NestedMeta::Meta(Meta::Path(path))) = nested_iter.peek() { + let path = path.clone(); + // Move the iterator forward if a path was found (don't otherwise so that + // code/applicability can be found or an error emitted). + nested_iter.next(); + Some(path) + } else { + None }; - // Move the iterator forward if a path was found (don't otherwise so that - // code/applicability can be found or an error emitted). - if msg.is_some() { - let _ = nested_iter.next(); - } for nested_attr in nested_iter { let meta = match nested_attr { From 2e72387fd03082cd067a4a56acf4b231b543c7fd Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 10 Sep 2022 14:28:12 +0200 Subject: [PATCH 02/15] Ensure code= in #[suggestion(...)] is only set once --- .../src/diagnostics/diagnostic_builder.rs | 4 ++-- .../session-diagnostic/diagnostic-derive.rs | 8 ++++++++ .../session-diagnostic/diagnostic-derive.stderr | 14 +++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 2bff12b0059d7..11459e181907a 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -476,7 +476,7 @@ impl DiagnosticDeriveBuilder { match nested_name { "code" => { let formatted_str = self.build_format(&s.value(), s.span()); - code = Some(formatted_str); + code.set_once((formatted_str, span)); } "applicability" => { applicability = match applicability { @@ -524,7 +524,7 @@ impl DiagnosticDeriveBuilder { let msg = msg.unwrap_or_else(|| parse_quote! { _subdiag::suggestion }); let msg = quote! { rustc_errors::fluent::#msg }; - let code = code.unwrap_or_else(|| quote! { String::new() }); + let code = code.value().unwrap_or_else(|| quote! { String::new() }); Ok(quote! { #diag.#method(#span_field, #msg, #code, #applicability); }) } diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index 80ea908288103..a113f2a034ae9 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -581,3 +581,11 @@ struct LintAttributeOnSessionDiag {} //~| ERROR diagnostic slug not specified //~| ERROR cannot find attribute `lint` in this scope struct LintAttributeOnLintDiag {} + +#[derive(Diagnostic)] +#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] +struct DuplicatedSuggestionCode { + #[suggestion(typeck::suggestion, code = "...", code = ",,,")] + //~^ ERROR specified multiple times + suggestion: Span, +} diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index c3972beb51282..aa768e28334fa 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -403,6 +403,18 @@ LL | | struct LintAttributeOnLintDiag {} | = help: specify the slug as the first argument to the attribute, such as `#[diag(typeck::example_error)]` +error: specified multiple times + --> $DIR/diagnostic-derive.rs:588:52 + | +LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")] + | ^^^^^^^^^^^^ + | +note: previously specified here + --> $DIR/diagnostic-derive.rs:588:38 + | +LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")] + | ^^^^^^^^^^^^ + error: cannot find attribute `nonsense` in this scope --> $DIR/diagnostic-derive.rs:53:3 | @@ -459,7 +471,7 @@ LL | arg: impl IntoDiagnosticArg, | ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg` = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 55 previous errors +error: aborting due to 56 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. From ec85a1b2634edae81c77f5ea5d1d422215ecc457 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 10 Sep 2022 14:43:07 +0200 Subject: [PATCH 03/15] Ensure #[suggestion] is only applied to correct tuple types --- .../src/diagnostics/diagnostic_builder.rs | 57 ++++++++----------- .../session-diagnostic/diagnostic-derive.rs | 20 ++++++- .../diagnostic-derive.stderr | 50 +++++++++++----- 3 files changed, 79 insertions(+), 48 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 11459e181907a..6dd2161e0f95b 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -571,46 +571,37 @@ impl DiagnosticDeriveBuilder { let mut span_idx = None; let mut applicability_idx = None; + fn type_err(span: &Span) -> Result { + span_err(span.unwrap(), "wrong types for suggestion") + .help( + "`#[suggestion(...)]` on a tuple field must be applied to fields \ + of type `(Span, Applicability)`", + ) + .emit(); + Err(DiagnosticDeriveError::ErrorHandled) + } + for (idx, elem) in tup.elems.iter().enumerate() { if type_matches_path(elem, &["rustc_span", "Span"]) { - if span_idx.is_none() { - span_idx = Some(syn::Index::from(idx)); - } else { - throw_span_err!( - info.span.unwrap(), - "type of field annotated with `#[suggestion(...)]` contains more \ - than one `Span`" - ); - } + span_idx.set_once((syn::Index::from(idx), elem.span().unwrap())); } else if type_matches_path(elem, &["rustc_errors", "Applicability"]) { - if applicability_idx.is_none() { - applicability_idx = Some(syn::Index::from(idx)); - } else { - throw_span_err!( - info.span.unwrap(), - "type of field annotated with `#[suggestion(...)]` contains more \ - than one Applicability" - ); - } + applicability_idx.set_once((syn::Index::from(idx), elem.span().unwrap())); + } else { + type_err(&elem.span())?; } } - if let Some(span_idx) = span_idx { - let binding = &info.binding.binding; - let span = quote!(#binding.#span_idx); - let applicability = applicability_idx - .map(|applicability_idx| quote!(#binding.#applicability_idx)) - .unwrap_or_else(|| quote!(rustc_errors::Applicability::Unspecified)); - - return Ok((span, Some(applicability))); - } + let Some((span_idx, _)) = span_idx else { + type_err(&tup.span())?; + }; + let Some((applicability_idx, _applicability_span)) = applicability_idx else { + type_err(&tup.span())?; + }; + let binding = &info.binding.binding; + let span = quote!(#binding.#span_idx); + let applicability = quote!(#binding.#applicability_idx); - throw_span_err!(info.span.unwrap(), "wrong types for suggestion", |diag| { - diag.help( - "`#[suggestion(...)]` on a tuple field must be applied to fields of type \ - `(Span, Applicability)`", - ) - }); + Ok((span, Some(applicability))) } // If `ty` isn't a `Span` or `(Span, Applicability)` then emit an error. _ => throw_span_err!(info.span.unwrap(), "wrong field type for suggestion", |diag| { diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index a113f2a034ae9..c774484d8bfb4 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -269,16 +269,16 @@ struct SuggestWithSpanOnly { #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithDuplicateSpanAndApplicability { #[suggestion(typeck::suggestion, code = "This is suggested code")] - //~^ ERROR type of field annotated with `#[suggestion(...)]` contains more than one `Span` suggestion: (Span, Span, Applicability), + //~^ ERROR specified multiple times } #[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithDuplicateApplicabilityAndSpan { #[suggestion(typeck::suggestion, code = "This is suggested code")] - //~^ ERROR type of field annotated with `#[suggestion(...)]` contains more than one suggestion: (Applicability, Applicability, Span), + //~^ ERROR specified multiple times } #[derive(Diagnostic)] @@ -589,3 +589,19 @@ struct DuplicatedSuggestionCode { //~^ ERROR specified multiple times suggestion: Span, } + +#[derive(Diagnostic)] +#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] +struct InvalidTypeInSuggestionTuple { + #[suggestion(typeck::suggestion, code = "...")] + suggestion: (Span, usize), + //~^ ERROR wrong types for suggestion +} + +#[derive(Diagnostic)] +#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] +struct MissingApplicabilityInSuggestionTuple { + #[suggestion(typeck::suggestion, code = "...")] + suggestion: (Span,), + //~^ ERROR wrong types for suggestion +} diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index aa768e28334fa..084a021ac208a 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -263,21 +263,29 @@ LL | | suggestion: Applicability, | = help: `#[suggestion(...)]` should be applied to fields of type `Span` or `(Span, Applicability)` -error: type of field annotated with `#[suggestion(...)]` contains more than one `Span` - --> $DIR/diagnostic-derive.rs:271:5 +error: specified multiple times + --> $DIR/diagnostic-derive.rs:272:24 | -LL | / #[suggestion(typeck::suggestion, code = "This is suggested code")] -LL | | -LL | | suggestion: (Span, Span, Applicability), - | |___________________________________________^ +LL | suggestion: (Span, Span, Applicability), + | ^^^^ + | +note: previously specified here + --> $DIR/diagnostic-derive.rs:272:18 + | +LL | suggestion: (Span, Span, Applicability), + | ^^^^ -error: type of field annotated with `#[suggestion(...)]` contains more than one Applicability - --> $DIR/diagnostic-derive.rs:279:5 +error: specified multiple times + --> $DIR/diagnostic-derive.rs:280:33 | -LL | / #[suggestion(typeck::suggestion, code = "This is suggested code")] -LL | | -LL | | suggestion: (Applicability, Applicability, Span), - | |____________________________________________________^ +LL | suggestion: (Applicability, Applicability, Span), + | ^^^^^^^^^^^^^ + | +note: previously specified here + --> $DIR/diagnostic-derive.rs:280:18 + | +LL | suggestion: (Applicability, Applicability, Span), + | ^^^^^^^^^^^^^ error: `#[label = ...]` is not a valid attribute --> $DIR/diagnostic-derive.rs:287:5 @@ -415,6 +423,22 @@ note: previously specified here LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")] | ^^^^^^^^^^^^ +error: wrong types for suggestion + --> $DIR/diagnostic-derive.rs:597:24 + | +LL | suggestion: (Span, usize), + | ^^^^^ + | + = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` + +error: wrong types for suggestion + --> $DIR/diagnostic-derive.rs:605:17 + | +LL | suggestion: (Span,), + | ^^^^^^^ + | + = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` + error: cannot find attribute `nonsense` in this scope --> $DIR/diagnostic-derive.rs:53:3 | @@ -471,7 +495,7 @@ LL | arg: impl IntoDiagnosticArg, | ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg` = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 56 previous errors +error: aborting due to 58 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. From efb20bc85547b48c2de0950fbca1dd5b2ed2a564 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 10 Sep 2022 14:48:01 +0200 Subject: [PATCH 04/15] Point to previous applicability when declared multiple times --- .../src/diagnostics/diagnostic_builder.rs | 35 ++++++------------- .../session-diagnostic/diagnostic-derive.rs | 2 +- .../diagnostic-derive.stderr | 8 ++++- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 6dd2161e0f95b..1e1bfbb943ecf 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -478,26 +478,12 @@ impl DiagnosticDeriveBuilder { let formatted_str = self.build_format(&s.value(), s.span()); code.set_once((formatted_str, span)); } - "applicability" => { - applicability = match applicability { - Some(v) => { - span_err( - span, - "applicability cannot be set in both the field and \ - attribute", - ) - .emit(); - Some(v) - } - None => match Applicability::from_str(&s.value()) { - Ok(v) => Some(quote! { #v }), - Err(()) => { - span_err(span, "invalid applicability").emit(); - None - } - }, + "applicability" => match Applicability::from_str(&s.value()) { + Ok(v) => applicability.set_once((quote! { #v }, span)), + Err(()) => { + span_err(span, "invalid applicability").emit(); } - } + }, _ => throw_invalid_nested_attr!(attr, &nested_attr, |diag| { diag.help( "only `message`, `code` and `applicability` are valid field \ @@ -516,8 +502,9 @@ impl DiagnosticDeriveBuilder { } } - let applicability = - applicability.unwrap_or_else(|| quote!(rustc_errors::Applicability::Unspecified)); + let applicability = applicability + .value() + .unwrap_or_else(|| quote!(rustc_errors::Applicability::Unspecified)); let name = path.segments.last().unwrap().ident.to_string(); let method = format_ident!("span_{}", name); @@ -559,7 +546,7 @@ impl DiagnosticDeriveBuilder { fn span_and_applicability_of_ty( &self, info: FieldInfo<'_>, - ) -> Result<(TokenStream, Option), DiagnosticDeriveError> { + ) -> Result<(TokenStream, Option<(TokenStream, proc_macro::Span)>), DiagnosticDeriveError> { match &info.ty { // If `ty` is `Span` w/out applicability, then use `Applicability::Unspecified`. ty @ Type::Path(..) if type_matches_path(ty, &["rustc_span", "Span"]) => { @@ -594,14 +581,14 @@ impl DiagnosticDeriveBuilder { let Some((span_idx, _)) = span_idx else { type_err(&tup.span())?; }; - let Some((applicability_idx, _applicability_span)) = applicability_idx else { + let Some((applicability_idx, applicability_span)) = applicability_idx else { type_err(&tup.span())?; }; let binding = &info.binding.binding; let span = quote!(#binding.#span_idx); let applicability = quote!(#binding.#applicability_idx); - Ok((span, Some(applicability))) + Ok((span, Some((applicability, applicability_span)))) } // If `ty` isn't a `Span` or `(Span, Applicability)` then emit an error. _ => throw_span_err!(info.span.unwrap(), "wrong field type for suggestion", |diag| { diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index c774484d8bfb4..c3d3c23fe5bad 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -436,7 +436,7 @@ struct ErrorWithNoteCustomWrongOrder { #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ApplicabilityInBoth { #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")] - //~^ ERROR applicability cannot be set in both the field and attribute + //~^ ERROR specified multiple times suggestion: (Span, Applicability), } diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index 084a021ac208a..f5432b0bf6561 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -293,11 +293,17 @@ error: `#[label = ...]` is not a valid attribute LL | #[label = "bar"] | ^^^^^^^^^^^^^^^^ -error: applicability cannot be set in both the field and attribute +error: specified multiple times --> $DIR/diagnostic-derive.rs:438:52 | LL | #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: previously specified here + --> $DIR/diagnostic-derive.rs:440:24 + | +LL | suggestion: (Span, Applicability), + | ^^^^^^^^^^^^^ error: invalid applicability --> $DIR/diagnostic-derive.rs:446:52 From d4a1a6f6986fd722506f7019d4ad669e46f15129 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sun, 11 Sep 2022 18:30:18 +0200 Subject: [PATCH 05/15] Make SetOnce nicer to use --- .../src/diagnostics/diagnostic_builder.rs | 22 +++++++------- .../src/diagnostics/subdiagnostic.rs | 29 ++++++++++--------- .../rustc_macros/src/diagnostics/utils.rs | 14 +++++++-- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 1e1bfbb943ecf..72f20efc8346b 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -18,6 +18,8 @@ use syn::{ }; use synstructure::{BindingInfo, Structure}; +use super::utils::SpannedOption; + /// What kind of diagnostic is being derived - a fatal/error/warning or a lint? #[derive(Copy, Clone, PartialEq, Eq)] pub(crate) enum DiagnosticDeriveKind { @@ -40,10 +42,10 @@ pub(crate) struct DiagnosticDeriveBuilder { pub kind: DiagnosticDeriveKind, /// Slug is a mandatory part of the struct attribute as corresponds to the Fluent message that /// has the actual diagnostic message. - pub slug: Option<(Path, proc_macro::Span)>, + pub slug: SpannedOption, /// Error codes are a optional part of the struct attribute - this is only set to detect /// multiple specifications. - pub code: Option<(String, proc_macro::Span)>, + pub code: SpannedOption, } impl HasFieldMap for DiagnosticDeriveBuilder { @@ -191,7 +193,7 @@ impl DiagnosticDeriveBuilder { match nested_attr { NestedMeta::Meta(Meta::Path(path)) => { if is_diag { - self.slug.set_once((path.clone(), span)); + self.slug.set_once(path.clone(), span); } else { let fn_name = proc_macro2::Ident::new(name, attr.span()); return Ok(quote! { #diag.#fn_name(rustc_errors::fluent::#path); }); @@ -224,8 +226,8 @@ impl DiagnosticDeriveBuilder { let span = s.span().unwrap(); match nested_name.as_str() { "code" => { - self.code.set_once((s.value(), span)); - let code = &self.code.as_ref().map(|(v, _)| v); + self.code.set_once(s.value(), span); + let code = &self.code.value_ref(); tokens.push(quote! { #diag.code(rustc_errors::DiagnosticId::Error(#code.to_string())); }); @@ -476,10 +478,10 @@ impl DiagnosticDeriveBuilder { match nested_name { "code" => { let formatted_str = self.build_format(&s.value(), s.span()); - code.set_once((formatted_str, span)); + code.set_once(formatted_str, span); } "applicability" => match Applicability::from_str(&s.value()) { - Ok(v) => applicability.set_once((quote! { #v }, span)), + Ok(v) => applicability.set_once(quote! { #v }, span), Err(()) => { span_err(span, "invalid applicability").emit(); } @@ -546,7 +548,7 @@ impl DiagnosticDeriveBuilder { fn span_and_applicability_of_ty( &self, info: FieldInfo<'_>, - ) -> Result<(TokenStream, Option<(TokenStream, proc_macro::Span)>), DiagnosticDeriveError> { + ) -> Result<(TokenStream, SpannedOption), DiagnosticDeriveError> { match &info.ty { // If `ty` is `Span` w/out applicability, then use `Applicability::Unspecified`. ty @ Type::Path(..) if type_matches_path(ty, &["rustc_span", "Span"]) => { @@ -570,9 +572,9 @@ impl DiagnosticDeriveBuilder { for (idx, elem) in tup.elems.iter().enumerate() { if type_matches_path(elem, &["rustc_span", "Span"]) { - span_idx.set_once((syn::Index::from(idx), elem.span().unwrap())); + span_idx.set_once(syn::Index::from(idx), elem.span().unwrap()); } else if type_matches_path(elem, &["rustc_errors", "Applicability"]) { - applicability_idx.set_once((syn::Index::from(idx), elem.span().unwrap())); + applicability_idx.set_once(syn::Index::from(idx), elem.span().unwrap()); } else { type_err(&elem.span())?; } diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index bdeca3420bcca..9116dd186f96d 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -15,6 +15,8 @@ use std::str::FromStr; use syn::{spanned::Spanned, Attribute, Meta, MetaList, MetaNameValue, NestedMeta, Path}; use synstructure::{BindingInfo, Structure, VariantInfo}; +use super::utils::SpannedOption; + /// Which kind of suggestion is being created? #[derive(Clone, Copy)] enum SubdiagnosticSuggestionKind { @@ -195,10 +197,10 @@ struct SubdiagnosticDeriveBuilder<'a> { fields: HashMap, /// Identifier for the binding to the `#[primary_span]` field. - span_field: Option<(proc_macro2::Ident, proc_macro::Span)>, + span_field: SpannedOption, /// If a suggestion, the identifier for the binding to the `#[applicability]` field or a /// `rustc_errors::Applicability::*` variant directly. - applicability: Option<(TokenStream, proc_macro::Span)>, + applicability: SpannedOption, /// Set to true when a `#[suggestion_part]` field is encountered, used to generate an error /// during finalization if still `false`. @@ -283,7 +285,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { if let Some(nested_attr) = nested_iter.next() { match nested_attr { NestedMeta::Meta(Meta::Path(path)) => { - slug.set_once((path.clone(), span)); + slug.set_once(path.clone(), span); } NestedMeta::Meta(meta @ Meta::NameValue(_)) if matches!( @@ -326,7 +328,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { "code" => { if matches!(kind, SubdiagnosticKind::Suggestion { .. }) { let formatted_str = self.build_format(&value.value(), value.span()); - code.set_once((formatted_str, span)); + code.set_once(formatted_str, span); } else { span_err( span, @@ -349,7 +351,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { span_err(span, "invalid applicability").emit(); Applicability::Unspecified }); - self.applicability.set_once((quote! { #value }, span)); + self.applicability.set_once(quote! { #value }, span); } else { span_err( span, @@ -485,7 +487,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { report_error_if_not_applied_to_span(attr, &info)?; let binding = info.binding.binding.clone(); - self.span_field.set_once((binding, span)); + self.span_field.set_once(binding, span); Ok(quote! {}) } @@ -509,7 +511,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { report_error_if_not_applied_to_applicability(attr, &info)?; let binding = info.binding.binding.clone(); - self.applicability.set_once((quote! { #binding }, span)); + self.applicability.set_once(quote! { #binding }, span); } else { span_err(span, "`#[applicability]` is only valid on suggestions").emit(); } @@ -577,7 +579,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { match nested_name { "code" => { let formatted_str = self.build_format(&value.value(), value.span()); - code.set_once((formatted_str, span)); + code.set_once(formatted_str, span); } _ => throw_invalid_nested_attr!(attr, &nested_attr, |diag| { diag.help("`code` is the only valid nested attribute") @@ -635,11 +637,12 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { .map(|binding| self.generate_field_attr_code(binding, kind_stats)) .collect(); - let span_field = self.span_field.as_ref().map(|(span, _)| span); - let applicability = self.applicability.take().map_or_else( - || quote! { rustc_errors::Applicability::Unspecified }, - |(applicability, _)| applicability, - ); + let span_field = self.span_field.value_ref(); + let applicability = self + .applicability + .take() + .value() + .unwrap_or_else(|| quote! { rustc_errors::Applicability::Unspecified }); let diag = &self.diag; let mut calls = TokenStream::new(); diff --git a/compiler/rustc_macros/src/diagnostics/utils.rs b/compiler/rustc_macros/src/diagnostics/utils.rs index ad9ecd39b9e85..3efcd216d1931 100644 --- a/compiler/rustc_macros/src/diagnostics/utils.rs +++ b/compiler/rustc_macros/src/diagnostics/utils.rs @@ -172,13 +172,17 @@ pub(crate) struct FieldInfo<'a> { /// Small helper trait for abstracting over `Option` fields that contain a value and a `Span` /// for error reporting if they are set more than once. pub(crate) trait SetOnce { - fn set_once(&mut self, _: (T, Span)); + fn set_once(&mut self, value: T, span: Span); fn value(self) -> Option; + fn value_ref(&self) -> Option<&T>; } -impl SetOnce for Option<(T, Span)> { - fn set_once(&mut self, (value, span): (T, Span)) { +/// An [`Option`] that keeps track of the span that caused it to be set; used with [`SetOnce`]. +pub(super) type SpannedOption = Option<(T, Span)>; + +impl SetOnce for SpannedOption { + fn set_once(&mut self, value: T, span: Span) { match self { None => { *self = Some((value, span)); @@ -194,6 +198,10 @@ impl SetOnce for Option<(T, Span)> { fn value(self) -> Option { self.map(|(v, _)| v) } + + fn value_ref(&self) -> Option<&T> { + self.as_ref().map(|(v, _)| v) + } } pub(crate) trait HasFieldMap { From e7251cc441f19306e6e71715a9ab36029c543268 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Mon, 12 Sep 2022 20:44:28 +0200 Subject: [PATCH 06/15] Extract subdiagnostic attribute parsing --- .../src/diagnostics/subdiagnostic.rs | 273 +++--------------- .../rustc_macros/src/diagnostics/utils.rs | 256 +++++++++++++++- .../subdiagnostic-derive.rs | 16 +- .../subdiagnostic-derive.stderr | 172 ++++++----- 4 files changed, 402 insertions(+), 315 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index 9116dd186f96d..9ea03e186e72a 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -4,100 +4,16 @@ use crate::diagnostics::error::{ span_err, throw_invalid_attr, throw_invalid_nested_attr, throw_span_err, DiagnosticDeriveError, }; use crate::diagnostics::utils::{ - report_error_if_not_applied_to_applicability, report_error_if_not_applied_to_span, - Applicability, FieldInfo, FieldInnerTy, HasFieldMap, SetOnce, + report_error_if_not_applied_to_applicability, report_error_if_not_applied_to_span, FieldInfo, + FieldInnerTy, HasFieldMap, SetOnce, }; use proc_macro2::TokenStream; use quote::{format_ident, quote}; use std::collections::HashMap; -use std::fmt; -use std::str::FromStr; use syn::{spanned::Spanned, Attribute, Meta, MetaList, MetaNameValue, NestedMeta, Path}; use synstructure::{BindingInfo, Structure, VariantInfo}; -use super::utils::SpannedOption; - -/// Which kind of suggestion is being created? -#[derive(Clone, Copy)] -enum SubdiagnosticSuggestionKind { - /// `#[suggestion]` - Normal, - /// `#[suggestion_short]` - Short, - /// `#[suggestion_hidden]` - Hidden, - /// `#[suggestion_verbose]` - Verbose, -} - -impl FromStr for SubdiagnosticSuggestionKind { - type Err = (); - - fn from_str(s: &str) -> Result { - match s { - "" => Ok(SubdiagnosticSuggestionKind::Normal), - "_short" => Ok(SubdiagnosticSuggestionKind::Short), - "_hidden" => Ok(SubdiagnosticSuggestionKind::Hidden), - "_verbose" => Ok(SubdiagnosticSuggestionKind::Verbose), - _ => Err(()), - } - } -} - -impl SubdiagnosticSuggestionKind { - pub fn to_suggestion_style(&self) -> TokenStream { - match self { - SubdiagnosticSuggestionKind::Normal => { - quote! { rustc_errors::SuggestionStyle::ShowCode } - } - SubdiagnosticSuggestionKind::Short => { - quote! { rustc_errors::SuggestionStyle::HideCodeInline } - } - SubdiagnosticSuggestionKind::Hidden => { - quote! { rustc_errors::SuggestionStyle::HideCodeAlways } - } - SubdiagnosticSuggestionKind::Verbose => { - quote! { rustc_errors::SuggestionStyle::ShowAlways } - } - } - } -} - -/// Which kind of subdiagnostic is being created from a variant? -#[derive(Clone)] -enum SubdiagnosticKind { - /// `#[label(...)]` - Label, - /// `#[note(...)]` - Note, - /// `#[help(...)]` - Help, - /// `#[warning(...)]` - Warn, - /// `#[suggestion{,_short,_hidden,_verbose}]` - Suggestion { suggestion_kind: SubdiagnosticSuggestionKind, code: TokenStream }, - /// `#[multipart_suggestion{,_short,_hidden,_verbose}]` - MultipartSuggestion { suggestion_kind: SubdiagnosticSuggestionKind }, -} - -impl quote::IdentFragment for SubdiagnosticKind { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - SubdiagnosticKind::Label => write!(f, "label"), - SubdiagnosticKind::Note => write!(f, "note"), - SubdiagnosticKind::Help => write!(f, "help"), - SubdiagnosticKind::Warn => write!(f, "warn"), - SubdiagnosticKind::Suggestion { .. } => write!(f, "suggestion_with_style"), - SubdiagnosticKind::MultipartSuggestion { .. } => { - write!(f, "multipart_suggestion_with_style") - } - } - } - - fn span(&self) -> Option { - None - } -} +use super::utils::{SpannedOption, SubdiagnosticKind}; /// The central struct for constructing the `add_to_diagnostic` method from an annotated struct. pub(crate) struct SubdiagnosticDerive<'a> { @@ -198,8 +114,8 @@ struct SubdiagnosticDeriveBuilder<'a> { /// Identifier for the binding to the `#[primary_span]` field. span_field: SpannedOption, - /// If a suggestion, the identifier for the binding to the `#[applicability]` field or a - /// `rustc_errors::Applicability::*` variant directly. + + /// The binding to the `#[applicability]` field, if present. applicability: SpannedOption, /// Set to true when a `#[suggestion_part]` field is encountered, used to generate an error @@ -219,6 +135,7 @@ struct KindsStatistics { has_multipart_suggestion: bool, all_multipart_suggestions: bool, has_normal_suggestion: bool, + all_applicabilities_static: bool, } impl<'a> FromIterator<&'a SubdiagnosticKind> for KindsStatistics { @@ -227,8 +144,15 @@ impl<'a> FromIterator<&'a SubdiagnosticKind> for KindsStatistics { has_multipart_suggestion: false, all_multipart_suggestions: true, has_normal_suggestion: false, + all_applicabilities_static: true, }; + for kind in kinds { + if let SubdiagnosticKind::MultipartSuggestion { applicability: None, .. } + | SubdiagnosticKind::Suggestion { applicability: None, .. } = kind + { + ret.all_applicabilities_static = false; + } if let SubdiagnosticKind::MultipartSuggestion { .. } = kind { ret.has_multipart_suggestion = true; } else { @@ -248,129 +172,14 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { let mut kind_slugs = vec![]; for attr in self.variant.ast().attrs { - let span = attr.span().unwrap(); - - let name = attr.path.segments.last().unwrap().ident.to_string(); - let name = name.as_str(); - - let meta = attr.parse_meta()?; - let Meta::List(MetaList { ref nested, .. }) = meta else { - throw_invalid_attr!(attr, &meta); - }; - - let mut kind = match name { - "label" => SubdiagnosticKind::Label, - "note" => SubdiagnosticKind::Note, - "help" => SubdiagnosticKind::Help, - "warning" => SubdiagnosticKind::Warn, - _ => { - if let Some(suggestion_kind) = - name.strip_prefix("suggestion").and_then(|s| s.parse().ok()) - { - SubdiagnosticKind::Suggestion { suggestion_kind, code: TokenStream::new() } - } else if let Some(suggestion_kind) = - name.strip_prefix("multipart_suggestion").and_then(|s| s.parse().ok()) - { - SubdiagnosticKind::MultipartSuggestion { suggestion_kind } - } else { - throw_invalid_attr!(attr, &meta); - } - } - }; - - let mut slug = None; - let mut code = None; - - let mut nested_iter = nested.into_iter(); - if let Some(nested_attr) = nested_iter.next() { - match nested_attr { - NestedMeta::Meta(Meta::Path(path)) => { - slug.set_once(path.clone(), span); - } - NestedMeta::Meta(meta @ Meta::NameValue(_)) - if matches!( - meta.path().segments.last().unwrap().ident.to_string().as_str(), - "code" | "applicability" - ) => - { - // Don't error for valid follow-up attributes. - } - nested_attr => { - throw_invalid_nested_attr!(attr, &nested_attr, |diag| { - diag.help( - "first argument of the attribute should be the diagnostic \ - slug", - ) - }) - } - }; - } + let (kind, slug) = SubdiagnosticKind::from_attr(attr, self)?; - for nested_attr in nested_iter { - let meta = match nested_attr { - NestedMeta::Meta(ref meta) => meta, - _ => throw_invalid_nested_attr!(attr, &nested_attr), - }; - - let span = meta.span().unwrap(); - let nested_name = meta.path().segments.last().unwrap().ident.to_string(); - let nested_name = nested_name.as_str(); - - let value = match meta { - Meta::NameValue(MetaNameValue { lit: syn::Lit::Str(value), .. }) => value, - Meta::Path(_) => throw_invalid_nested_attr!(attr, &nested_attr, |diag| { - diag.help("a diagnostic slug must be the first argument to the attribute") - }), - _ => throw_invalid_nested_attr!(attr, &nested_attr), - }; - - match nested_name { - "code" => { - if matches!(kind, SubdiagnosticKind::Suggestion { .. }) { - let formatted_str = self.build_format(&value.value(), value.span()); - code.set_once(formatted_str, span); - } else { - span_err( - span, - &format!( - "`code` is not a valid nested attribute of a `{}` attribute", - name - ), - ) - .emit(); - } - } - "applicability" => { - if matches!( - kind, - SubdiagnosticKind::Suggestion { .. } - | SubdiagnosticKind::MultipartSuggestion { .. } - ) { - let value = - Applicability::from_str(&value.value()).unwrap_or_else(|()| { - span_err(span, "invalid applicability").emit(); - Applicability::Unspecified - }); - self.applicability.set_once(quote! { #value }, span); - } else { - span_err( - span, - &format!( - "`applicability` is not a valid nested attribute of a `{}` attribute", - name - ) - ).emit(); - } - } - _ => throw_invalid_nested_attr!(attr, &nested_attr, |diag| { - diag.help("only `code` and `applicability` are valid nested attributes") - }), - } - } + let Some(slug) = slug else { + let name = attr.path.segments.last().unwrap().ident.to_string(); + let name = name.as_str(); - let Some((slug, _)) = slug else { throw_span_err!( - span, + attr.span().unwrap(), &format!( "diagnostic slug must be first argument of a `#[{}(...)]` attribute", name @@ -378,21 +187,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { ); }; - match kind { - SubdiagnosticKind::Suggestion { code: ref mut code_field, .. } => { - let Some((code, _)) = code else { - throw_span_err!(span, "suggestion without `code = \"...\"`"); - }; - *code_field = code; - } - SubdiagnosticKind::Label - | SubdiagnosticKind::Note - | SubdiagnosticKind::Help - | SubdiagnosticKind::Warn - | SubdiagnosticKind::MultipartSuggestion { .. } => {} - } - - kind_slugs.push((kind, slug)) + kind_slugs.push((kind, slug)); } Ok(kind_slugs) @@ -510,6 +305,15 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { if kind_stats.has_multipart_suggestion || kind_stats.has_normal_suggestion { report_error_if_not_applied_to_applicability(attr, &info)?; + if kind_stats.all_applicabilities_static { + span_err( + span, + "`#[applicability]` has no effect if all `#[suggestion]`/\ + `#[multipart_suggestion]` attributes have a static \ + `applicability = \"...\"`", + ) + .emit(); + } let binding = info.binding.binding.clone(); self.applicability.set_once(quote! { #binding }, span); } else { @@ -638,11 +442,6 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { .collect(); let span_field = self.span_field.value_ref(); - let applicability = self - .applicability - .take() - .value() - .unwrap_or_else(|| quote! { rustc_errors::Applicability::Unspecified }); let diag = &self.diag; let mut calls = TokenStream::new(); @@ -650,7 +449,13 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind); let message = quote! { rustc_errors::fluent::#slug }; let call = match kind { - SubdiagnosticKind::Suggestion { suggestion_kind, code } => { + SubdiagnosticKind::Suggestion { suggestion_kind, applicability, code } => { + let applicability = applicability + .value() + .map(|a| quote! { #a }) + .or_else(|| self.applicability.take().value()) + .unwrap_or_else(|| quote! { rustc_errors::Applicability::Unspecified }); + if let Some(span) = span_field { let style = suggestion_kind.to_suggestion_style(); @@ -660,7 +465,13 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { quote! { unreachable!(); } } } - SubdiagnosticKind::MultipartSuggestion { suggestion_kind } => { + SubdiagnosticKind::MultipartSuggestion { suggestion_kind, applicability } => { + let applicability = applicability + .value() + .map(|a| quote! { #a }) + .or_else(|| self.applicability.take().value()) + .unwrap_or_else(|| quote! { rustc_errors::Applicability::Unspecified }); + if !self.has_suggestion_parts { span_err( self.span, diff --git a/compiler/rustc_macros/src/diagnostics/utils.rs b/compiler/rustc_macros/src/diagnostics/utils.rs index 3efcd216d1931..a31bda9ca0def 100644 --- a/compiler/rustc_macros/src/diagnostics/utils.rs +++ b/compiler/rustc_macros/src/diagnostics/utils.rs @@ -1,12 +1,18 @@ -use crate::diagnostics::error::{span_err, throw_span_err, DiagnosticDeriveError}; +use crate::diagnostics::error::{ + span_err, throw_invalid_attr, throw_invalid_nested_attr, throw_span_err, DiagnosticDeriveError, +}; use proc_macro::Span; use proc_macro2::TokenStream; use quote::{format_ident, quote, ToTokens}; use std::collections::{BTreeSet, HashMap}; +use std::fmt; use std::str::FromStr; use syn::{spanned::Spanned, Attribute, Meta, Type, TypeTuple}; +use syn::{MetaList, MetaNameValue, NestedMeta, Path}; use synstructure::{BindingInfo, Structure}; +use super::error::invalid_nested_attr; + /// Checks whether the type name of `ty` matches `name`. /// /// Given some struct at `a::b::c::Foo`, this will return true for `c::Foo`, `b::c::Foo`, or @@ -311,6 +317,7 @@ pub(crate) trait HasFieldMap { /// `Applicability` of a suggestion - mirrors `rustc_errors::Applicability` - and used to represent /// the user's selection of applicability if specified in an attribute. +#[derive(Clone, Copy)] pub(crate) enum Applicability { MachineApplicable, MaybeIncorrect, @@ -367,3 +374,250 @@ pub(crate) fn build_field_mapping<'a>(structure: &Structure<'a>) -> HashMap Result { + match s { + "" => Ok(SuggestionKind::Normal), + "_short" => Ok(SuggestionKind::Short), + "_hidden" => Ok(SuggestionKind::Hidden), + "_verbose" => Ok(SuggestionKind::Verbose), + _ => Err(()), + } + } +} + +impl SuggestionKind { + pub fn to_suggestion_style(&self) -> TokenStream { + match self { + SuggestionKind::Normal => { + quote! { rustc_errors::SuggestionStyle::ShowCode } + } + SuggestionKind::Short => { + quote! { rustc_errors::SuggestionStyle::HideCodeInline } + } + SuggestionKind::Hidden => { + quote! { rustc_errors::SuggestionStyle::HideCodeAlways } + } + SuggestionKind::Verbose => { + quote! { rustc_errors::SuggestionStyle::ShowAlways } + } + } + } +} + +/// Types of subdiagnostics that can be created using attributes +#[derive(Clone)] +pub(super) enum SubdiagnosticKind { + /// `#[label(...)]` + Label, + /// `#[note(...)]` + Note, + /// `#[help(...)]` + Help, + /// `#[warning(...)]` + Warn, + /// `#[suggestion{,_short,_hidden,_verbose}]` + Suggestion { + suggestion_kind: SuggestionKind, + applicability: SpannedOption, + code: TokenStream, + }, + /// `#[multipart_suggestion{,_short,_hidden,_verbose}]` + MultipartSuggestion { + suggestion_kind: SuggestionKind, + applicability: SpannedOption, + }, +} + +impl SubdiagnosticKind { + /// Constructs a `SubdiagnosticKind` from a field or type attribute such as `#[note]`, + /// `#[error(parser::add_paren)]` or `#[suggestion(code = "...")]`. Returns the + /// `SubdiagnosticKind` and the diagnostic slug, if specified. + pub(super) fn from_attr( + attr: &Attribute, + fields: &impl HasFieldMap, + ) -> Result<(SubdiagnosticKind, Option), DiagnosticDeriveError> { + let span = attr.span().unwrap(); + + let name = attr.path.segments.last().unwrap().ident.to_string(); + let name = name.as_str(); + + let meta = attr.parse_meta()?; + let mut kind = match name { + "label" => SubdiagnosticKind::Label, + "note" => SubdiagnosticKind::Note, + "help" => SubdiagnosticKind::Help, + "warning" => SubdiagnosticKind::Warn, + _ => { + if let Some(suggestion_kind) = + name.strip_prefix("suggestion").and_then(|s| s.parse().ok()) + { + SubdiagnosticKind::Suggestion { + suggestion_kind, + applicability: None, + code: TokenStream::new(), + } + } else if let Some(suggestion_kind) = + name.strip_prefix("multipart_suggestion").and_then(|s| s.parse().ok()) + { + SubdiagnosticKind::MultipartSuggestion { suggestion_kind, applicability: None } + } else { + throw_invalid_attr!(attr, &meta); + } + } + }; + + let nested = match meta { + Meta::List(MetaList { ref nested, .. }) => { + // An attribute with properties, such as `#[suggestion(code = "...")]` or + // `#[error(some::slug)]` + nested + } + Meta::Path(_) => { + // An attribute without a slug or other properties, such as `#[note]` - return + // without further processing. + // + // Only allow this if there are no mandatory properties, such as `code = "..."` in + // `#[suggestion(...)]` + match kind { + SubdiagnosticKind::Label + | SubdiagnosticKind::Note + | SubdiagnosticKind::Help + | SubdiagnosticKind::Warn + | SubdiagnosticKind::MultipartSuggestion { .. } => return Ok((kind, None)), + SubdiagnosticKind::Suggestion { .. } => { + throw_span_err!(span, "suggestion without `code = \"...\"`") + } + } + } + _ => { + throw_invalid_attr!(attr, &meta) + } + }; + + let mut code = None; + + let mut nested_iter = nested.into_iter().peekable(); + + // Peek at the first nested attribute: if it's a slug path, consume it. + let slug = if let Some(NestedMeta::Meta(Meta::Path(path))) = nested_iter.peek() { + let path = path.clone(); + // Advance the iterator. + nested_iter.next(); + Some(path) + } else { + None + }; + + for nested_attr in nested_iter { + let meta = match nested_attr { + NestedMeta::Meta(ref meta) => meta, + NestedMeta::Lit(_) => { + invalid_nested_attr(attr, &nested_attr).emit(); + continue; + } + }; + + let span = meta.span().unwrap(); + let nested_name = meta.path().segments.last().unwrap().ident.to_string(); + let nested_name = nested_name.as_str(); + + let value = match meta { + Meta::NameValue(MetaNameValue { lit: syn::Lit::Str(value), .. }) => value, + Meta::Path(_) => throw_invalid_nested_attr!(attr, &nested_attr, |diag| { + diag.help("a diagnostic slug must be the first argument to the attribute") + }), + _ => { + invalid_nested_attr(attr, &nested_attr).emit(); + continue; + } + }; + + match (nested_name, &mut kind) { + ("code", SubdiagnosticKind::Suggestion { .. }) => { + let formatted_str = fields.build_format(&value.value(), value.span()); + code.set_once(formatted_str, span); + } + ( + "applicability", + SubdiagnosticKind::Suggestion { ref mut applicability, .. } + | SubdiagnosticKind::MultipartSuggestion { ref mut applicability, .. }, + ) => { + let value = Applicability::from_str(&value.value()).unwrap_or_else(|()| { + span_err(span, "invalid applicability").emit(); + Applicability::Unspecified + }); + applicability.set_once(value, span); + } + + // Invalid nested attribute + (_, SubdiagnosticKind::Suggestion { .. }) => { + invalid_nested_attr(attr, &nested_attr) + .help("only `code` and `applicability` are valid nested attributes") + .emit(); + } + (_, SubdiagnosticKind::MultipartSuggestion { .. }) => { + invalid_nested_attr(attr, &nested_attr) + .help("only `applicability` is a valid nested attributes") + .emit() + } + _ => { + invalid_nested_attr(attr, &nested_attr).emit(); + } + } + } + + match kind { + SubdiagnosticKind::Suggestion { code: ref mut code_field, .. } => { + *code_field = if let Some((code, _)) = code { + code + } else { + span_err(span, "suggestion without `code = \"...\"`").emit(); + quote! { "" } + } + } + SubdiagnosticKind::Label + | SubdiagnosticKind::Note + | SubdiagnosticKind::Help + | SubdiagnosticKind::Warn + | SubdiagnosticKind::MultipartSuggestion { .. } => {} + } + + Ok((kind, slug)) + } +} + +impl quote::IdentFragment for SubdiagnosticKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + SubdiagnosticKind::Label => write!(f, "label"), + SubdiagnosticKind::Note => write!(f, "note"), + SubdiagnosticKind::Help => write!(f, "help"), + SubdiagnosticKind::Warn => write!(f, "warn"), + SubdiagnosticKind::Suggestion { .. } => write!(f, "suggestion_with_style"), + SubdiagnosticKind::MultipartSuggestion { .. } => { + write!(f, "multipart_suggestion_with_style") + } + } + } + + fn span(&self) -> Option { + None + } +} diff --git a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs index 9fbe7b1f4c859..606b3b5e5ebca 100644 --- a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs @@ -52,7 +52,7 @@ struct C { #[derive(Subdiagnostic)] #[label] -//~^ ERROR `#[label]` is not a valid attribute +//~^ ERROR diagnostic slug must be first argument struct D { #[primary_span] span: Span, @@ -81,6 +81,7 @@ struct F { #[derive(Subdiagnostic)] #[label(bug = "...")] //~^ ERROR `#[label(bug = ...)]` is not a valid attribute +//~| ERROR diagnostic slug must be first argument struct G { #[primary_span] span: Span, @@ -90,6 +91,7 @@ struct G { #[derive(Subdiagnostic)] #[label("...")] //~^ ERROR `#[label("...")]` is not a valid attribute +//~| ERROR diagnostic slug must be first argument struct H { #[primary_span] span: Span, @@ -99,6 +101,7 @@ struct H { #[derive(Subdiagnostic)] #[label(slug = 4)] //~^ ERROR `#[label(slug = ...)]` is not a valid attribute +//~| ERROR diagnostic slug must be first argument struct J { #[primary_span] span: Span, @@ -108,6 +111,7 @@ struct J { #[derive(Subdiagnostic)] #[label(slug("..."))] //~^ ERROR `#[label(slug(...))]` is not a valid attribute +//~| ERROR diagnostic slug must be first argument struct K { #[primary_span] span: Span, @@ -135,7 +139,7 @@ struct M { #[derive(Subdiagnostic)] #[label(parser::add_paren, code = "...")] -//~^ ERROR `code` is not a valid nested attribute of a `label` attribute +//~^ ERROR `#[label(code = ...)]` is not a valid attribute struct N { #[primary_span] span: Span, @@ -144,7 +148,7 @@ struct N { #[derive(Subdiagnostic)] #[label(parser::add_paren, applicability = "machine-applicable")] -//~^ ERROR `applicability` is not a valid nested attribute of a `label` attribute +//~^ ERROR `#[label(applicability = ...)]` is not a valid attribute struct O { #[primary_span] span: Span, @@ -216,6 +220,7 @@ enum T { enum U { #[label(code = "...")] //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute + //~| ERROR `#[label(code = ...)]` is not a valid attribute A { #[primary_span] span: Span, @@ -531,7 +536,7 @@ struct BA { #[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")] //~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields -//~| ERROR `code` is not a valid nested attribute of a `multipart_suggestion` attribute +//~| ERROR `#[multipart_suggestion(code = ...)]` is not a valid attribute struct BBa { var: String, } @@ -612,10 +617,9 @@ struct BG { #[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] -//~^ NOTE previously specified here struct BH { #[applicability] - //~^ ERROR specified multiple times + //~^ ERROR `#[applicability]` has no effect appl: Applicability, #[suggestion_part(code = "(")] first: Span, diff --git a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr index 0a0247e898088..171b89e657d81 100644 --- a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr @@ -8,7 +8,7 @@ LL | | var: String, LL | | } | |_^ -error: `#[label]` is not a valid attribute +error: diagnostic slug must be first argument of a `#[label(...)]` attribute --> $DIR/subdiagnostic-derive.rs:54:1 | LL | #[label] @@ -31,101 +31,123 @@ error: `#[label(bug = ...)]` is not a valid attribute | LL | #[label(bug = "...")] | ^^^^^^^^^^^ + +error: diagnostic slug must be first argument of a `#[label(...)]` attribute + --> $DIR/subdiagnostic-derive.rs:82:1 | - = help: first argument of the attribute should be the diagnostic slug +LL | #[label(bug = "...")] + | ^^^^^^^^^^^^^^^^^^^^^ error: `#[label("...")]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:91:9 + --> $DIR/subdiagnostic-derive.rs:92:9 | LL | #[label("...")] | ^^^^^ + +error: diagnostic slug must be first argument of a `#[label(...)]` attribute + --> $DIR/subdiagnostic-derive.rs:92:1 | - = help: first argument of the attribute should be the diagnostic slug +LL | #[label("...")] + | ^^^^^^^^^^^^^^^ error: `#[label(slug = ...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:100:9 + --> $DIR/subdiagnostic-derive.rs:102:9 | LL | #[label(slug = 4)] | ^^^^^^^^ + +error: diagnostic slug must be first argument of a `#[label(...)]` attribute + --> $DIR/subdiagnostic-derive.rs:102:1 | - = help: first argument of the attribute should be the diagnostic slug +LL | #[label(slug = 4)] + | ^^^^^^^^^^^^^^^^^^ error: `#[label(slug(...))]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:109:9 + --> $DIR/subdiagnostic-derive.rs:112:9 | LL | #[label(slug("..."))] | ^^^^^^^^^^^ + +error: diagnostic slug must be first argument of a `#[label(...)]` attribute + --> $DIR/subdiagnostic-derive.rs:112:1 | - = help: first argument of the attribute should be the diagnostic slug +LL | #[label(slug("..."))] + | ^^^^^^^^^^^^^^^^^^^^^ error: diagnostic slug must be first argument of a `#[label(...)]` attribute - --> $DIR/subdiagnostic-derive.rs:128:1 + --> $DIR/subdiagnostic-derive.rs:132:1 | LL | #[label()] | ^^^^^^^^^^ -error: `code` is not a valid nested attribute of a `label` attribute - --> $DIR/subdiagnostic-derive.rs:137:28 +error: `#[label(code = ...)]` is not a valid attribute + --> $DIR/subdiagnostic-derive.rs:141:28 | LL | #[label(parser::add_paren, code = "...")] | ^^^^^^^^^^^^ -error: `applicability` is not a valid nested attribute of a `label` attribute - --> $DIR/subdiagnostic-derive.rs:146:28 +error: `#[label(applicability = ...)]` is not a valid attribute + --> $DIR/subdiagnostic-derive.rs:150:28 | LL | #[label(parser::add_paren, applicability = "machine-applicable")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsupported type attribute for subdiagnostic enum - --> $DIR/subdiagnostic-derive.rs:155:1 + --> $DIR/subdiagnostic-derive.rs:159:1 | LL | #[foo] | ^^^^^^ error: `#[bar]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:169:5 + --> $DIR/subdiagnostic-derive.rs:173:5 | LL | #[bar] | ^^^^^^ error: `#[bar = ...]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:181:5 + --> $DIR/subdiagnostic-derive.rs:185:5 | LL | #[bar = "..."] | ^^^^^^^^^^^^^^ error: `#[bar = ...]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:193:5 + --> $DIR/subdiagnostic-derive.rs:197:5 | LL | #[bar = 4] | ^^^^^^^^^^ error: `#[bar(...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:205:5 + --> $DIR/subdiagnostic-derive.rs:209:5 | LL | #[bar("...")] | ^^^^^^^^^^^^^ +error: `#[label(code = ...)]` is not a valid attribute + --> $DIR/subdiagnostic-derive.rs:221:13 + | +LL | #[label(code = "...")] + | ^^^^^^^^^^^^ + error: diagnostic slug must be first argument of a `#[label(...)]` attribute - --> $DIR/subdiagnostic-derive.rs:217:5 + --> $DIR/subdiagnostic-derive.rs:221:5 | LL | #[label(code = "...")] | ^^^^^^^^^^^^^^^^^^^^^^ error: subdiagnostic kind not specified - --> $DIR/subdiagnostic-derive.rs:234:5 + --> $DIR/subdiagnostic-derive.rs:239:5 | LL | B { | ^ error: the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/subdiagnostic-derive.rs:246:5 + --> $DIR/subdiagnostic-derive.rs:251:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ error: label without `#[primary_span]` field - --> $DIR/subdiagnostic-derive.rs:243:1 + --> $DIR/subdiagnostic-derive.rs:248:1 | LL | / #[label(parser::add_paren)] LL | | @@ -137,13 +159,13 @@ LL | | } | |_^ error: `#[applicability]` is only valid on suggestions - --> $DIR/subdiagnostic-derive.rs:256:5 + --> $DIR/subdiagnostic-derive.rs:261:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ error: `#[bar]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:266:5 + --> $DIR/subdiagnostic-derive.rs:271:5 | LL | #[bar] | ^^^^^^ @@ -151,13 +173,13 @@ LL | #[bar] = help: only `primary_span`, `applicability` and `skip_arg` are valid field attributes error: `#[bar = ...]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:277:5 + --> $DIR/subdiagnostic-derive.rs:282:5 | LL | #[bar = "..."] | ^^^^^^^^^^^^^^ error: `#[bar(...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:288:5 + --> $DIR/subdiagnostic-derive.rs:293:5 | LL | #[bar("...")] | ^^^^^^^^^^^^^ @@ -165,7 +187,7 @@ LL | #[bar("...")] = help: only `primary_span`, `applicability` and `skip_arg` are valid field attributes error: unexpected unsupported untagged union - --> $DIR/subdiagnostic-derive.rs:304:1 + --> $DIR/subdiagnostic-derive.rs:309:1 | LL | / union AC { LL | | @@ -175,7 +197,7 @@ LL | | } | |_^ error: `#[label(parser::add_paren)]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:319:28 + --> $DIR/subdiagnostic-derive.rs:324:28 | LL | #[label(parser::add_paren, parser::add_paren)] | ^^^^^^^^^^^^^^^^^ @@ -183,67 +205,67 @@ LL | #[label(parser::add_paren, parser::add_paren)] = help: a diagnostic slug must be the first argument to the attribute error: specified multiple times - --> $DIR/subdiagnostic-derive.rs:332:5 + --> $DIR/subdiagnostic-derive.rs:337:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ | note: previously specified here - --> $DIR/subdiagnostic-derive.rs:329:5 + --> $DIR/subdiagnostic-derive.rs:334:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ error: subdiagnostic kind not specified - --> $DIR/subdiagnostic-derive.rs:338:8 + --> $DIR/subdiagnostic-derive.rs:343:8 | LL | struct AG { | ^^ error: specified multiple times - --> $DIR/subdiagnostic-derive.rs:375:47 + --> $DIR/subdiagnostic-derive.rs:380:47 | LL | #[suggestion(parser::add_paren, code = "...", code = "...")] | ^^^^^^^^^^^^ | note: previously specified here - --> $DIR/subdiagnostic-derive.rs:375:33 + --> $DIR/subdiagnostic-derive.rs:380:33 | LL | #[suggestion(parser::add_paren, code = "...", code = "...")] | ^^^^^^^^^^^^ error: specified multiple times - --> $DIR/subdiagnostic-derive.rs:393:5 + --> $DIR/subdiagnostic-derive.rs:398:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ | note: previously specified here - --> $DIR/subdiagnostic-derive.rs:390:5 + --> $DIR/subdiagnostic-derive.rs:395:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ error: the `#[applicability]` attribute can only be applied to fields of type `Applicability` - --> $DIR/subdiagnostic-derive.rs:403:5 + --> $DIR/subdiagnostic-derive.rs:408:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ error: suggestion without `code = "..."` - --> $DIR/subdiagnostic-derive.rs:416:1 + --> $DIR/subdiagnostic-derive.rs:421:1 | LL | #[suggestion(parser::add_paren)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: invalid applicability - --> $DIR/subdiagnostic-derive.rs:426:46 + --> $DIR/subdiagnostic-derive.rs:431:46 | LL | #[suggestion(parser::add_paren, code ="...", applicability = "foo")] | ^^^^^^^^^^^^^^^^^^^^^ error: suggestion without `#[primary_span]` field - --> $DIR/subdiagnostic-derive.rs:444:1 + --> $DIR/subdiagnostic-derive.rs:449:1 | LL | / #[suggestion(parser::add_paren, code = "...")] LL | | @@ -253,25 +275,25 @@ LL | | } | |_^ error: unsupported type attribute for subdiagnostic enum - --> $DIR/subdiagnostic-derive.rs:458:1 + --> $DIR/subdiagnostic-derive.rs:463:1 | LL | #[label] | ^^^^^^^^ error: `var` doesn't refer to a field on this type - --> $DIR/subdiagnostic-derive.rs:478:39 + --> $DIR/subdiagnostic-derive.rs:483:39 | LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")] | ^^^^^^^ error: `var` doesn't refer to a field on this type - --> $DIR/subdiagnostic-derive.rs:497:43 + --> $DIR/subdiagnostic-derive.rs:502:43 | LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")] | ^^^^^^^ error: `#[suggestion_part]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:520:5 + --> $DIR/subdiagnostic-derive.rs:525:5 | LL | #[suggestion_part] | ^^^^^^^^^^^^^^^^^^ @@ -279,7 +301,7 @@ LL | #[suggestion_part] = help: `#[suggestion_part(...)]` is only valid in multipart suggestions, use `#[primary_span]` instead error: `#[suggestion_part(...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:523:5 + --> $DIR/subdiagnostic-derive.rs:528:5 | LL | #[suggestion_part(code = "...")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -287,7 +309,7 @@ LL | #[suggestion_part(code = "...")] = help: `#[suggestion_part(...)]` is only valid in multipart suggestions error: suggestion without `#[primary_span]` field - --> $DIR/subdiagnostic-derive.rs:517:1 + --> $DIR/subdiagnostic-derive.rs:522:1 | LL | / #[suggestion(parser::add_paren, code = "...")] LL | | @@ -298,14 +320,16 @@ LL | | var: String, LL | | } | |_^ -error: `code` is not a valid nested attribute of a `multipart_suggestion` attribute - --> $DIR/subdiagnostic-derive.rs:532:43 +error: `#[multipart_suggestion(code = ...)]` is not a valid attribute + --> $DIR/subdiagnostic-derive.rs:537:43 | LL | #[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")] | ^^^^^^^^^^^^ + | + = help: only `applicability` is a valid nested attributes error: multipart suggestion without any `#[suggestion_part(...)]` fields - --> $DIR/subdiagnostic-derive.rs:532:1 + --> $DIR/subdiagnostic-derive.rs:537:1 | LL | / #[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")] LL | | @@ -316,19 +340,19 @@ LL | | } | |_^ error: `#[suggestion_part(...)]` attribute without `code = "..."` - --> $DIR/subdiagnostic-derive.rs:542:5 + --> $DIR/subdiagnostic-derive.rs:547:5 | LL | #[suggestion_part] | ^^^^^^^^^^^^^^^^^^ error: `#[suggestion_part(...)]` attribute without `code = "..."` - --> $DIR/subdiagnostic-derive.rs:550:5 + --> $DIR/subdiagnostic-derive.rs:555:5 | LL | #[suggestion_part()] | ^^^^^^^^^^^^^^^^^^^^ error: `#[primary_span]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:559:5 + --> $DIR/subdiagnostic-derive.rs:564:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ @@ -336,7 +360,7 @@ LL | #[primary_span] = help: multipart suggestions use one or more `#[suggestion_part]`s rather than one `#[primary_span]` error: multipart suggestion without any `#[suggestion_part(...)]` fields - --> $DIR/subdiagnostic-derive.rs:556:1 + --> $DIR/subdiagnostic-derive.rs:561:1 | LL | / #[multipart_suggestion(parser::add_paren)] LL | | @@ -348,19 +372,19 @@ LL | | } | |_^ error: `#[suggestion_part(...)]` attribute without `code = "..."` - --> $DIR/subdiagnostic-derive.rs:567:5 + --> $DIR/subdiagnostic-derive.rs:572:5 | LL | #[suggestion_part] | ^^^^^^^^^^^^^^^^^^ error: `#[suggestion_part(...)]` attribute without `code = "..."` - --> $DIR/subdiagnostic-derive.rs:570:5 + --> $DIR/subdiagnostic-derive.rs:575:5 | LL | #[suggestion_part()] | ^^^^^^^^^^^^^^^^^^^^ error: `#[suggestion_part(foo = ...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:573:23 + --> $DIR/subdiagnostic-derive.rs:578:23 | LL | #[suggestion_part(foo = "bar")] | ^^^^^^^^^^^ @@ -368,40 +392,34 @@ LL | #[suggestion_part(foo = "bar")] = help: `code` is the only valid nested attribute error: the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/subdiagnostic-derive.rs:576:5 + --> $DIR/subdiagnostic-derive.rs:581:5 | LL | #[suggestion_part(code = "...")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/subdiagnostic-derive.rs:579:5 + --> $DIR/subdiagnostic-derive.rs:584:5 | LL | #[suggestion_part()] | ^^^^^^^^^^^^^^^^^^^^ error: specified multiple times - --> $DIR/subdiagnostic-derive.rs:587:37 + --> $DIR/subdiagnostic-derive.rs:592:37 | LL | #[suggestion_part(code = "...", code = ",,,")] | ^^^^^^^^^^^^ | note: previously specified here - --> $DIR/subdiagnostic-derive.rs:587:23 + --> $DIR/subdiagnostic-derive.rs:592:23 | LL | #[suggestion_part(code = "...", code = ",,,")] | ^^^^^^^^^^^^ -error: specified multiple times - --> $DIR/subdiagnostic-derive.rs:617:5 +error: `#[applicability]` has no effect if all `#[suggestion]`/`#[multipart_suggestion]` attributes have a static `applicability = "..."` + --> $DIR/subdiagnostic-derive.rs:621:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ - | -note: previously specified here - --> $DIR/subdiagnostic-derive.rs:614:43 - | -LL | #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: cannot find attribute `foo` in this scope --> $DIR/subdiagnostic-derive.rs:63:3 @@ -410,59 +428,59 @@ LL | #[foo] | ^^^ error: cannot find attribute `foo` in this scope - --> $DIR/subdiagnostic-derive.rs:155:3 + --> $DIR/subdiagnostic-derive.rs:159:3 | LL | #[foo] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:169:7 + --> $DIR/subdiagnostic-derive.rs:173:7 | LL | #[bar] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:181:7 + --> $DIR/subdiagnostic-derive.rs:185:7 | LL | #[bar = "..."] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:193:7 + --> $DIR/subdiagnostic-derive.rs:197:7 | LL | #[bar = 4] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:205:7 + --> $DIR/subdiagnostic-derive.rs:209:7 | LL | #[bar("...")] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:266:7 + --> $DIR/subdiagnostic-derive.rs:271:7 | LL | #[bar] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:277:7 + --> $DIR/subdiagnostic-derive.rs:282:7 | LL | #[bar = "..."] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:288:7 + --> $DIR/subdiagnostic-derive.rs:293:7 | LL | #[bar("...")] | ^^^ error[E0425]: cannot find value `slug` in module `rustc_errors::fluent` - --> $DIR/subdiagnostic-derive.rs:118:9 + --> $DIR/subdiagnostic-derive.rs:122:9 | LL | #[label(slug)] | ^^^^ not found in `rustc_errors::fluent` -error: aborting due to 63 previous errors +error: aborting due to 68 previous errors For more information about this error, try `rustc --explain E0425`. From 57679fb1c5daf402b86763a546ffbfe64621fc2f Mon Sep 17 00:00:00 2001 From: Xiretza Date: Mon, 12 Sep 2022 21:11:49 +0200 Subject: [PATCH 07/15] Better error recovery in Subdiagnostic derive --- .../src/diagnostics/subdiagnostic.rs | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index 9ea03e186e72a..6545ae086b158 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -13,6 +13,7 @@ use std::collections::HashMap; use syn::{spanned::Spanned, Attribute, Meta, MetaList, MetaNameValue, NestedMeta, Path}; use synstructure::{BindingInfo, Structure, VariantInfo}; +use super::error::invalid_attr; use super::utils::{SpannedOption, SubdiagnosticKind}; /// The central struct for constructing the `add_to_diagnostic` method from an annotated struct. @@ -271,18 +272,18 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { "skip_arg" => Ok(quote! {}), "primary_span" => { if kind_stats.has_multipart_suggestion { - throw_invalid_attr!(attr, &Meta::Path(path), |diag| { - diag.help( + invalid_attr(attr, &Meta::Path(path)) + .help( "multipart suggestions use one or more `#[suggestion_part]`s rather \ than one `#[primary_span]`", ) - }) - } - - report_error_if_not_applied_to_span(attr, &info)?; + .emit(); + } else { + report_error_if_not_applied_to_span(attr, &info)?; - let binding = info.binding.binding.clone(); - self.span_field.set_once(binding, span); + let binding = info.binding.binding.clone(); + self.span_field.set_once(binding, span); + } Ok(quote! {}) } @@ -292,14 +293,16 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { if kind_stats.has_multipart_suggestion { span_err(span, "`#[suggestion_part(...)]` attribute without `code = \"...\"`") .emit(); - Ok(quote! {}) } else { - throw_invalid_attr!(attr, &Meta::Path(path), |diag| { - diag.help( - "`#[suggestion_part(...)]` is only valid in multipart suggestions, use `#[primary_span]` instead", - ) - }); + invalid_attr(attr, &Meta::Path(path)) + .help( + "`#[suggestion_part(...)]` is only valid in multipart suggestions, \ + use `#[primary_span]` instead", + ) + .emit(); } + + Ok(quote! {}) } "applicability" => { if kind_stats.has_multipart_suggestion || kind_stats.has_normal_suggestion { @@ -322,7 +325,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { Ok(quote! {}) } - _ => throw_invalid_attr!(attr, &Meta::Path(path), |diag| { + _ => { let mut span_attrs = vec![]; if kind_stats.has_multipart_suggestion { span_attrs.push("suggestion_part"); @@ -330,11 +333,16 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> { if !kind_stats.all_multipart_suggestions { span_attrs.push("primary_span") } - diag.help(format!( - "only `{}`, `applicability` and `skip_arg` are valid field attributes", - span_attrs.join(", ") - )) - }), + + invalid_attr(attr, &Meta::Path(path)) + .help(format!( + "only `{}`, `applicability` and `skip_arg` are valid field attributes", + span_attrs.join(", ") + )) + .emit(); + + Ok(quote! {}) + } } } From ae56d2a118a780d0ad1de606ad659a95c655b1b2 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 14 Sep 2022 11:38:31 +0200 Subject: [PATCH 08/15] Add missing code="" attributes to suggestion subdiagnostics --- compiler/rustc_parse/src/parser/diagnostics.rs | 8 ++++---- compiler/rustc_passes/src/errors.rs | 4 ++-- .../ui-fulldeps/session-diagnostic/diagnostic-derive.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index dcea11eadcbf1..0a81cde93be9c 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -289,7 +289,7 @@ pub enum BadTypePlusSub { #[diag(parser::maybe_recover_from_bad_qpath_stage_2)] struct BadQPathStage2 { #[primary_span] - #[suggestion(applicability = "maybe-incorrect")] + #[suggestion(code = "", applicability = "maybe-incorrect")] span: Span, ty: String, } @@ -298,7 +298,7 @@ struct BadQPathStage2 { #[diag(parser::incorrect_semicolon)] struct IncorrectSemicolon<'a> { #[primary_span] - #[suggestion_short(applicability = "machine-applicable")] + #[suggestion_short(code = "", applicability = "machine-applicable")] span: Span, #[help] opt_help: Option<()>, @@ -309,7 +309,7 @@ struct IncorrectSemicolon<'a> { #[diag(parser::incorrect_use_of_await)] struct IncorrectUseOfAwait { #[primary_span] - #[suggestion(parser::parentheses_suggestion, applicability = "machine-applicable")] + #[suggestion(parser::parentheses_suggestion, code = "", applicability = "machine-applicable")] span: Span, } @@ -329,7 +329,7 @@ struct IncorrectAwait { struct InInTypo { #[primary_span] span: Span, - #[suggestion(applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable")] sugg_span: Span, } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index be67c9e3b82d9..de11bb8901013 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -462,7 +462,7 @@ pub struct LinkSection { pub struct NoMangleForeign { #[label] pub span: Span, - #[suggestion(applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable")] pub attr_span: Span, pub foreign_item_kind: &'static str, } @@ -596,7 +596,7 @@ pub enum UnusedNote { #[derive(LintDiagnostic)] #[diag(passes::unused)] pub struct Unused { - #[suggestion(applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable")] pub attr_span: Span, #[subdiagnostic] pub note: UnusedNote, diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index c3d3c23fe5bad..eb63a7e52e5fd 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -294,7 +294,7 @@ struct WrongKindOfAnnotation { struct OptionsInErrors { #[label(typeck::label)] label: Option, - #[suggestion(typeck::suggestion)] + #[suggestion(typeck::suggestion, code = "...")] opt_sugg: Option<(Span, Applicability)>, } From 336a72a8daea236a89787f16931611310315340c Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 14 Sep 2022 17:19:40 +0200 Subject: [PATCH 09/15] Unify subdiagnostic attribute parsing --- .../src/diagnostics/diagnostic_builder.rs | 414 ++++++------------ .../session-diagnostic/diagnostic-derive.rs | 56 ++- .../diagnostic-derive.stderr | 250 +++++++---- 3 files changed, 360 insertions(+), 360 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 72f20efc8346b..2aa292bbce2b6 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -1,25 +1,23 @@ #![deny(unused_must_use)] +use super::error::throw_invalid_nested_attr; +use super::utils::{SpannedOption, SubdiagnosticKind}; use crate::diagnostics::error::{ - invalid_nested_attr, span_err, throw_invalid_attr, throw_invalid_nested_attr, throw_span_err, - DiagnosticDeriveError, + invalid_nested_attr, span_err, throw_invalid_attr, throw_span_err, DiagnosticDeriveError, }; use crate::diagnostics::utils::{ report_error_if_not_applied_to_span, report_type_error, type_is_unit, type_matches_path, - Applicability, FieldInfo, FieldInnerTy, HasFieldMap, SetOnce, + FieldInfo, FieldInnerTy, HasFieldMap, SetOnce, }; use proc_macro2::{Ident, Span, TokenStream}; use quote::{format_ident, quote}; use std::collections::HashMap; -use std::str::FromStr; use syn::{ parse_quote, spanned::Spanned, Attribute, Field, Meta, MetaList, MetaNameValue, NestedMeta, Path, Type, }; use synstructure::{BindingInfo, Structure}; -use super::utils::SpannedOption; - /// What kind of diagnostic is being derived - a fatal/error/warning or a lint? #[derive(Copy, Clone, PartialEq, Eq)] pub(crate) enum DiagnosticDeriveKind { @@ -45,7 +43,7 @@ pub(crate) struct DiagnosticDeriveBuilder { pub slug: SpannedOption, /// Error codes are a optional part of the struct attribute - this is only set to detect /// multiple specifications. - pub code: SpannedOption, + pub code: SpannedOption<()>, } impl HasFieldMap for DiagnosticDeriveBuilder { @@ -129,6 +127,30 @@ impl DiagnosticDeriveBuilder { || is_subdiagnostic } + fn parse_subdiag_attribute( + &self, + attr: &Attribute, + ) -> Result<(SubdiagnosticKind, Path), DiagnosticDeriveError> { + let (subdiag, slug) = SubdiagnosticKind::from_attr(attr, self)?; + + if let SubdiagnosticKind::MultipartSuggestion { .. } = subdiag { + let meta = attr.parse_meta()?; + throw_invalid_attr!(attr, &meta, |diag| diag + .help("consider creating a `Subdiagnostic` instead")); + } + + let slug = slug.unwrap_or_else(|| match subdiag { + SubdiagnosticKind::Label => parse_quote! { _subdiag::label }, + SubdiagnosticKind::Note => parse_quote! { _subdiag::note }, + SubdiagnosticKind::Help => parse_quote! { _subdiag::help }, + SubdiagnosticKind::Warn => parse_quote! { _subdiag::warn }, + SubdiagnosticKind::Suggestion { .. } => parse_quote! { _subdiag::suggestion }, + SubdiagnosticKind::MultipartSuggestion { .. } => unreachable!(), + }); + + Ok((subdiag, slug)) + } + /// Establishes state in the `DiagnosticDeriveBuilder` resulting from the struct /// attributes like `#[diag(..)]`, such as the slug and error code. Generates /// diagnostic builder calls for setting error code and creating note/help messages. @@ -137,98 +159,64 @@ impl DiagnosticDeriveBuilder { attr: &Attribute, ) -> Result { let diag = &self.diag; - let span = attr.span().unwrap(); let name = attr.path.segments.last().unwrap().ident.to_string(); let name = name.as_str(); let meta = attr.parse_meta()?; - let is_diag = name == "diag"; - - let nested = match meta { - // Most attributes are lists, like `#[diag(..)]` for most cases or - // `#[help(..)]`/`#[note(..)]` when the user is specifying a alternative slug. - Meta::List(MetaList { ref nested, .. }) => nested, - // Subdiagnostics without spans can be applied to the type too, and these are just - // paths: `#[help]`, `#[note]` and `#[warning]` - Meta::Path(_) if !is_diag => { - let fn_name = if name == "warning" { - Ident::new("warn", attr.span()) - } else { - Ident::new(name, attr.span()) - }; - return Ok(self.add_subdiagnostic(&fn_name, parse_quote! { _subdiag::#fn_name })); - } - _ => throw_invalid_attr!(attr, &meta), - }; - - // Check the kind before doing any further processing so that there aren't misleading - // "no kind specified" errors if there are failures later. - match name { - "error" | "lint" => throw_invalid_attr!(attr, &meta, |diag| { - diag.help("`error` and `lint` have been replaced by `diag`") - }), - "warn_" => throw_invalid_attr!(attr, &meta, |diag| { - diag.help("`warn_` have been replaced by `warning`") - }), - "diag" | "help" | "note" | "warning" => (), - _ => throw_invalid_attr!(attr, &meta, |diag| { - diag.help("only `diag`, `help`, `note` and `warning` are valid attributes") - }), - } + if name == "diag" { + let Meta::List(MetaList { ref nested, .. }) = meta else { + throw_invalid_attr!( + attr, + &meta + ); + }; - // First nested element should always be the path, e.g. `#[diag(typeck::invalid)]` or - // `#[help(typeck::another_help)]`. - let mut nested_iter = nested.into_iter(); - if let Some(nested_attr) = nested_iter.next() { - // Report an error if there are any other list items after the path. - if !is_diag && nested_iter.next().is_some() { - throw_invalid_nested_attr!(attr, &nested_attr, |diag| { - diag.help( - "`help`, `note` and `warning` struct attributes can only have one argument", - ) - }); - } + let mut nested_iter = nested.into_iter().peekable(); - match nested_attr { - NestedMeta::Meta(Meta::Path(path)) => { - if is_diag { - self.slug.set_once(path.clone(), span); - } else { - let fn_name = proc_macro2::Ident::new(name, attr.span()); - return Ok(quote! { #diag.#fn_name(rustc_errors::fluent::#path); }); - } + match nested_iter.peek() { + Some(NestedMeta::Meta(Meta::Path(slug))) => { + self.slug.set_once(slug.clone(), slug.span().unwrap()); + nested_iter.next(); } - NestedMeta::Meta(meta @ Meta::NameValue(_)) - if is_diag && meta.path().segments.last().unwrap().ident == "code" => - { - // don't error for valid follow-up attributes - } - nested_attr => throw_invalid_nested_attr!(attr, &nested_attr, |diag| { - diag.help("first argument of the attribute should be the diagnostic slug") - }), + Some(NestedMeta::Meta(Meta::NameValue { .. })) => {} + Some(nested_attr) => throw_invalid_nested_attr!(attr, &nested_attr, |diag| diag + .help("a diagnostic slug is required as the first argument")), + None => throw_invalid_attr!(attr, &meta, |diag| diag + .help("a diagnostic slug is required as the first argument")), }; - } - // Remaining attributes are optional, only `code = ".."` at the moment. - let mut tokens = Vec::new(); - for nested_attr in nested_iter { - let meta = match nested_attr { - syn::NestedMeta::Meta(meta) => meta, - _ => throw_invalid_nested_attr!(attr, &nested_attr), - }; + // Remaining attributes are optional, only `code = ".."` at the moment. + let mut tokens = TokenStream::new(); + for nested_attr in nested_iter { + let (value, path) = match nested_attr { + NestedMeta::Meta(Meta::NameValue(MetaNameValue { + lit: syn::Lit::Str(value), + path, + .. + })) => (value, path), + NestedMeta::Meta(Meta::Path(_)) => { + invalid_nested_attr(attr, &nested_attr) + .help("diagnostic slug must be the first argument") + .emit(); + continue; + } + _ => { + invalid_nested_attr(attr, &nested_attr).emit(); + continue; + } + }; - let path = meta.path(); - let nested_name = path.segments.last().unwrap().ident.to_string(); - // Struct attributes are only allowed to be applied once, and the diagnostic - // changes will be set in the initialisation code. - if let Meta::NameValue(MetaNameValue { lit: syn::Lit::Str(s), .. }) = &meta { - let span = s.span().unwrap(); + let nested_name = path.segments.last().unwrap().ident.to_string(); + // Struct attributes are only allowed to be applied once, and the diagnostic + // changes will be set in the initialisation code. + let span = value.span().unwrap(); match nested_name.as_str() { "code" => { - self.code.set_once(s.value(), span); - let code = &self.code.value_ref(); - tokens.push(quote! { + self.code.set_once((), span); + + let code = value.value(); + tokens.extend(quote! { #diag.code(rustc_errors::DiagnosticId::Error(#code.to_string())); }); } @@ -236,12 +224,22 @@ impl DiagnosticDeriveBuilder { .help("only `code` is a valid nested attributes following the slug") .emit(), } - } else { - invalid_nested_attr(attr, &nested_attr).emit() } + return Ok(tokens); } - Ok(tokens.into_iter().collect()) + let (subdiag, slug) = self.parse_subdiag_attribute(attr)?; + let fn_ident = format_ident!("{}", subdiag); + match subdiag { + SubdiagnosticKind::Note | SubdiagnosticKind::Help | SubdiagnosticKind::Warn => { + Ok(self.add_subdiagnostic(&fn_ident, slug)) + } + SubdiagnosticKind::Label | SubdiagnosticKind::Suggestion { .. } => { + throw_invalid_attr!(attr, &meta, |diag| diag + .help("`#[label]` and `#[suggestion]` can only be applied to fields")); + } + SubdiagnosticKind::MultipartSuggestion { .. } => unreachable!(), + } } fn generate_field_attrs_code(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream { @@ -305,217 +303,83 @@ impl DiagnosticDeriveBuilder { info: FieldInfo<'_>, binding: TokenStream, ) -> Result { - let meta = attr.parse_meta()?; - match meta { - Meta::Path(_) => self.generate_inner_field_code_path(attr, info, binding), - Meta::List(MetaList { .. }) => self.generate_inner_field_code_list(attr, info, binding), - _ => throw_invalid_attr!(attr, &meta), - } - } - - fn generate_inner_field_code_path( - &mut self, - attr: &Attribute, - info: FieldInfo<'_>, - binding: TokenStream, - ) -> Result { - assert!(matches!(attr.parse_meta()?, Meta::Path(_))); let diag = &self.diag; - let meta = attr.parse_meta()?; - let ident = &attr.path.segments.last().unwrap().ident; - let name = ident.to_string(); - let name = name.as_str(); - match name { - "skip_arg" => { - // Don't need to do anything - by virtue of the attribute existing, the - // `set_arg` call will not be generated. - Ok(quote! {}) - } - "primary_span" => { - match self.kind { + if let Meta::Path(_) = meta { + let ident = &attr.path.segments.last().unwrap().ident; + let name = ident.to_string(); + let name = name.as_str(); + match name { + "skip_arg" => { + // Don't need to do anything - by virtue of the attribute existing, the + // `set_arg` call will not be generated. + return Ok(quote! {}); + } + "primary_span" => match self.kind { DiagnosticDeriveKind::Diagnostic => { report_error_if_not_applied_to_span(attr, &info)?; - Ok(quote! { + return Ok(quote! { #diag.set_span(#binding); - }) + }); } DiagnosticDeriveKind::LintDiagnostic => { throw_invalid_attr!(attr, &meta, |diag| { diag.help("the `primary_span` field attribute is not valid for lint diagnostics") }) } - } + }, + "subdiagnostic" => return Ok(quote! { #diag.subdiagnostic(#binding); }), + _ => {} } - "label" => { + } + + let (subdiag, slug) = self.parse_subdiag_attribute(attr)?; + + let fn_ident = format_ident!("{}", subdiag); + match subdiag { + SubdiagnosticKind::Label => { report_error_if_not_applied_to_span(attr, &info)?; - Ok(self.add_spanned_subdiagnostic(binding, ident, parse_quote! { _subdiag::label })) + Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, slug)) } - "note" | "help" | "warning" => { - let warn_ident = Ident::new("warn", Span::call_site()); - let (ident, path) = match name { - "note" => (ident, parse_quote! { _subdiag::note }), - "help" => (ident, parse_quote! { _subdiag::help }), - "warning" => (&warn_ident, parse_quote! { _subdiag::warn }), - _ => unreachable!(), - }; + SubdiagnosticKind::Note | SubdiagnosticKind::Help | SubdiagnosticKind::Warn => { if type_matches_path(&info.ty, &["rustc_span", "Span"]) { - Ok(self.add_spanned_subdiagnostic(binding, ident, path)) + Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, slug)) } else if type_is_unit(&info.ty) { - Ok(self.add_subdiagnostic(ident, path)) + Ok(self.add_subdiagnostic(&fn_ident, slug)) } else { report_type_error(attr, "`Span` or `()`")? } } - "subdiagnostic" => Ok(quote! { #diag.subdiagnostic(#binding); }), - _ => throw_invalid_attr!(attr, &meta, |diag| { - diag.help( - "only `skip_arg`, `primary_span`, `label`, `note`, `help` and `subdiagnostic` \ - are valid field attributes", - ) - }), - } - } - - fn generate_inner_field_code_list( - &mut self, - attr: &Attribute, - info: FieldInfo<'_>, - binding: TokenStream, - ) -> Result { - let meta = attr.parse_meta()?; - let Meta::List(MetaList { ref path, ref nested, .. }) = meta else { unreachable!() }; - - let ident = &attr.path.segments.last().unwrap().ident; - let name = path.segments.last().unwrap().ident.to_string(); - let name = name.as_ref(); - match name { - "suggestion" | "suggestion_short" | "suggestion_hidden" | "suggestion_verbose" => { - return self.generate_inner_field_code_suggestion(attr, info); - } - "label" | "help" | "note" | "warning" => (), - _ => throw_invalid_attr!(attr, &meta, |diag| { - diag.help( - "only `label`, `help`, `note`, `warn` or `suggestion{,_short,_hidden,_verbose}` are \ - valid field attributes", - ) - }), - } - - // For `#[label(..)]`, `#[note(..)]` and `#[help(..)]`, the first nested element must be a - // path, e.g. `#[label(typeck::label)]`. - let mut nested_iter = nested.into_iter(); - let msg = match nested_iter.next() { - Some(NestedMeta::Meta(Meta::Path(path))) => path.clone(), - Some(nested_attr) => throw_invalid_nested_attr!(attr, &nested_attr), - None => throw_invalid_attr!(attr, &meta), - }; - - // None of these attributes should have anything following the slug. - if nested_iter.next().is_some() { - throw_invalid_attr!(attr, &meta); - } - - match name { - "label" => { - report_error_if_not_applied_to_span(attr, &info)?; - Ok(self.add_spanned_subdiagnostic(binding, ident, msg)) - } - "note" | "help" if type_matches_path(&info.ty, &["rustc_span", "Span"]) => { - Ok(self.add_spanned_subdiagnostic(binding, ident, msg)) - } - "note" | "help" if type_is_unit(&info.ty) => Ok(self.add_subdiagnostic(ident, msg)), - // `warning` must be special-cased because the attribute `warn` already has meaning and - // so isn't used, despite the diagnostic API being named `warn`. - "warning" if type_matches_path(&info.ty, &["rustc_span", "Span"]) => Ok(self - .add_spanned_subdiagnostic(binding, &Ident::new("warn", Span::call_site()), msg)), - "warning" if type_is_unit(&info.ty) => { - Ok(self.add_subdiagnostic(&Ident::new("warn", Span::call_site()), msg)) - } - "note" | "help" | "warning" => report_type_error(attr, "`Span` or `()`")?, - _ => unreachable!(), - } - } - - fn generate_inner_field_code_suggestion( - &mut self, - attr: &Attribute, - info: FieldInfo<'_>, - ) -> Result { - let diag = &self.diag; - - let mut meta = attr.parse_meta()?; - let Meta::List(MetaList { ref path, ref mut nested, .. }) = meta else { unreachable!() }; - - let (span_field, mut applicability) = self.span_and_applicability_of_ty(info)?; - - let mut code = None; - - let mut nested_iter = nested.into_iter().peekable(); - let msg = if let Some(NestedMeta::Meta(Meta::Path(path))) = nested_iter.peek() { - let path = path.clone(); - // Move the iterator forward if a path was found (don't otherwise so that - // code/applicability can be found or an error emitted). - nested_iter.next(); - Some(path) - } else { - None - }; - - for nested_attr in nested_iter { - let meta = match nested_attr { - syn::NestedMeta::Meta(ref meta) => meta, - syn::NestedMeta::Lit(_) => throw_invalid_nested_attr!(attr, &nested_attr), - }; - - let nested_name = meta.path().segments.last().unwrap().ident.to_string(); - let nested_name = nested_name.as_str(); - match meta { - Meta::NameValue(MetaNameValue { lit: syn::Lit::Str(s), .. }) => { - let span = meta.span().unwrap(); - match nested_name { - "code" => { - let formatted_str = self.build_format(&s.value(), s.span()); - code.set_once(formatted_str, span); - } - "applicability" => match Applicability::from_str(&s.value()) { - Ok(v) => applicability.set_once(quote! { #v }, span), - Err(()) => { - span_err(span, "invalid applicability").emit(); - } - }, - _ => throw_invalid_nested_attr!(attr, &nested_attr, |diag| { - diag.help( - "only `message`, `code` and `applicability` are valid field \ - attributes", - ) - }), - } + SubdiagnosticKind::Suggestion { + suggestion_kind, + applicability: static_applicability, + code, + } => { + let (span_field, mut applicability) = self.span_and_applicability_of_ty(info)?; + + if let Some((static_applicability, span)) = static_applicability { + applicability.set_once(quote! { #static_applicability }, span); } - _ => throw_invalid_nested_attr!(attr, &nested_attr, |diag| { - if matches!(meta, Meta::Path(_)) { - diag.help("a diagnostic slug must be the first argument to the attribute") - } else { - diag - } - }), + + let applicability = applicability + .value() + .unwrap_or_else(|| quote! { rustc_errors::Applicability::Unspecified }); + let style = suggestion_kind.to_suggestion_style(); + + Ok(quote! { + #diag.span_suggestion_with_style( + #span_field, + rustc_errors::fluent::#slug, + #code, + #applicability, + #style + ); + }) } + SubdiagnosticKind::MultipartSuggestion { .. } => unreachable!(), } - - let applicability = applicability - .value() - .unwrap_or_else(|| quote!(rustc_errors::Applicability::Unspecified)); - - let name = path.segments.last().unwrap().ident.to_string(); - let method = format_ident!("span_{}", name); - - let msg = msg.unwrap_or_else(|| parse_quote! { _subdiag::suggestion }); - let msg = quote! { rustc_errors::fluent::#msg }; - let code = code.value().unwrap_or_else(|| quote! { String::new() }); - - Ok(quote! { #diag.#method(#span_field, #msg, #code, #applicability); }) } /// Adds a spanned subdiagnostic by generating a `diag.span_$kind` call with the current slug diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index eb63a7e52e5fd..ad481c14bab8d 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -76,13 +76,15 @@ struct InvalidNestedStructAttr1 {} #[derive(Diagnostic)] #[diag(nonsense = "...", code = "E0123", slug = "foo")] //~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute -//~^^ ERROR diagnostic slug not specified +//~| ERROR `#[diag(slug = ...)]` is not a valid attribute +//~| ERROR diagnostic slug not specified struct InvalidNestedStructAttr2 {} #[derive(Diagnostic)] #[diag(nonsense = 4, code = "E0123", slug = "foo")] //~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute -//~^^ ERROR diagnostic slug not specified +//~| ERROR `#[diag(slug = ...)]` is not a valid attribute +//~| ERROR diagnostic slug not specified struct InvalidNestedStructAttr3 {} #[derive(Diagnostic)] @@ -217,6 +219,7 @@ struct Suggest { #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithoutCode { #[suggestion(typeck::suggestion)] + //~^ ERROR suggestion without `code = "..."` suggestion: (Span, Applicability), } @@ -225,6 +228,7 @@ struct SuggestWithoutCode { struct SuggestWithBadKey { #[suggestion(nonsense = "bar")] //~^ ERROR `#[suggestion(nonsense = ...)]` is not a valid attribute + //~| ERROR suggestion without `code = "..."` suggestion: (Span, Applicability), } @@ -233,6 +237,7 @@ struct SuggestWithBadKey { struct SuggestWithShorthandMsg { #[suggestion(msg = "bar")] //~^ ERROR `#[suggestion(msg = ...)]` is not a valid attribute + //~| ERROR suggestion without `code = "..."` suggestion: (Span, Applicability), } @@ -507,7 +512,7 @@ struct OptUnitField { #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelWithTrailingPath { #[label(typeck::label, foo)] - //~^ ERROR `#[label(...)]` is not a valid attribute + //~^ ERROR `#[label(foo)]` is not a valid attribute span: Span, } @@ -515,7 +520,7 @@ struct LabelWithTrailingPath { #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelWithTrailingNameValue { #[label(typeck::label, foo = "...")] - //~^ ERROR `#[label(...)]` is not a valid attribute + //~^ ERROR `#[label(foo = ...)]` is not a valid attribute span: Span, } @@ -523,7 +528,7 @@ struct LabelWithTrailingNameValue { #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelWithTrailingList { #[label(typeck::label, foo("..."))] - //~^ ERROR `#[label(...)]` is not a valid attribute + //~^ ERROR `#[label(foo(...))]` is not a valid attribute span: Span, } @@ -605,3 +610,44 @@ struct MissingApplicabilityInSuggestionTuple { suggestion: (Span,), //~^ ERROR wrong types for suggestion } + +#[derive(Diagnostic)] +#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] +struct MissingCodeInSuggestion { + #[suggestion(typeck::suggestion)] + //~^ ERROR suggestion without `code = "..."` + suggestion: Span, +} + +#[derive(Diagnostic)] +#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] +#[multipart_suggestion(typeck::suggestion)] +//~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute +//~| ERROR cannot find attribute `multipart_suggestion` in this scope +#[multipart_suggestion()] +//~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute +//~| ERROR cannot find attribute `multipart_suggestion` in this scope +struct MultipartSuggestion { + #[multipart_suggestion(typeck::suggestion)] + //~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute + //~| ERROR cannot find attribute `multipart_suggestion` in this scope + suggestion: Span, +} + +#[derive(Diagnostic)] +#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] +#[suggestion(typeck::suggestion, code = "...")] +//~^ ERROR `#[suggestion(...)]` is not a valid attribute +struct SuggestionOnStruct { + #[primary_span] + suggestion: Span, +} + +#[derive(Diagnostic)] +#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] +#[label] +//~^ ERROR `#[label]` is not a valid attribute +struct LabelOnStruct { + #[primary_span] + suggestion: Span, +} diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index f5432b0bf6561..9919b12beaf0a 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -20,8 +20,6 @@ error: `#[nonsense(...)]` is not a valid attribute | LL | #[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: only `diag`, `help`, `note` and `warning` are valid attributes error: diagnostic slug not specified --> $DIR/diagnostic-derive.rs:53:1 @@ -41,7 +39,7 @@ error: `#[diag("...")]` is not a valid attribute LL | #[diag("E0123")] | ^^^^^^^ | - = help: first argument of the attribute should be the diagnostic slug + = help: a diagnostic slug is required as the first argument error: diagnostic slug not specified --> $DIR/diagnostic-derive.rs:60:1 @@ -60,7 +58,7 @@ error: `#[diag(nonsense(...))]` is not a valid attribute LL | #[diag(nonsense("foo"), code = "E0123", slug = "foo")] | ^^^^^^^^^^^^^^^ | - = help: first argument of the attribute should be the diagnostic slug + = help: a diagnostic slug is required as the first argument error: diagnostic slug not specified --> $DIR/diagnostic-derive.rs:71:1 @@ -79,7 +77,15 @@ error: `#[diag(nonsense = ...)]` is not a valid attribute LL | #[diag(nonsense = "...", code = "E0123", slug = "foo")] | ^^^^^^^^^^^^^^^^ | - = help: first argument of the attribute should be the diagnostic slug + = help: only `code` is a valid nested attributes following the slug + +error: `#[diag(slug = ...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:77:42 + | +LL | #[diag(nonsense = "...", code = "E0123", slug = "foo")] + | ^^^^^^^^^^^^ + | + = help: only `code` is a valid nested attributes following the slug error: diagnostic slug not specified --> $DIR/diagnostic-derive.rs:77:1 @@ -87,32 +93,40 @@ error: diagnostic slug not specified LL | / #[diag(nonsense = "...", code = "E0123", slug = "foo")] LL | | LL | | +LL | | LL | | struct InvalidNestedStructAttr2 {} | |__________________________________^ | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]` error: `#[diag(nonsense = ...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:83:8 + --> $DIR/diagnostic-derive.rs:84:8 | LL | #[diag(nonsense = 4, code = "E0123", slug = "foo")] | ^^^^^^^^^^^^ + +error: `#[diag(slug = ...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:84:38 | - = help: first argument of the attribute should be the diagnostic slug +LL | #[diag(nonsense = 4, code = "E0123", slug = "foo")] + | ^^^^^^^^^^^^ + | + = help: only `code` is a valid nested attributes following the slug error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:83:1 + --> $DIR/diagnostic-derive.rs:84:1 | LL | / #[diag(nonsense = 4, code = "E0123", slug = "foo")] LL | | LL | | +LL | | LL | | struct InvalidNestedStructAttr3 {} | |__________________________________^ | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]` error: `#[diag(slug = ...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:89:58 + --> $DIR/diagnostic-derive.rs:91:58 | LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0123", slug = "foo")] | ^^^^^^^^^^^^ @@ -120,55 +134,57 @@ LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0123", slug = "foo")] = help: only `code` is a valid nested attributes following the slug error: `#[suggestion = ...]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:96:5 + --> $DIR/diagnostic-derive.rs:98:5 | LL | #[suggestion = "bar"] | ^^^^^^^^^^^^^^^^^^^^^ error: specified multiple times - --> $DIR/diagnostic-derive.rs:103:1 + --> $DIR/diagnostic-derive.rs:105:8 | LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0456")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:102:1 + --> $DIR/diagnostic-derive.rs:104:8 | LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: specified multiple times - --> $DIR/diagnostic-derive.rs:103:49 + --> $DIR/diagnostic-derive.rs:105:49 | LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0456")] | ^^^^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:102:49 + --> $DIR/diagnostic-derive.rs:104:49 | LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^^^^ error: specified multiple times - --> $DIR/diagnostic-derive.rs:109:65 + --> $DIR/diagnostic-derive.rs:111:65 | LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0456", code = "E0457")] | ^^^^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:109:49 + --> $DIR/diagnostic-derive.rs:111:49 | LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0456", code = "E0457")] | ^^^^^^^ error: `#[diag(typeck::ambiguous_lifetime_bound)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:114:42 + --> $DIR/diagnostic-derive.rs:116:42 | LL | #[diag(typeck::ambiguous_lifetime_bound, typeck::ambiguous_lifetime_bound, code = "E0456")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: diagnostic slug must be the first argument error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:119:1 + --> $DIR/diagnostic-derive.rs:121:1 | LL | struct KindNotProvided {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -176,7 +192,7 @@ LL | struct KindNotProvided {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]` error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:122:1 + --> $DIR/diagnostic-derive.rs:124:1 | LL | / #[diag(code = "E0456")] LL | | @@ -186,33 +202,31 @@ LL | | struct SlugNotProvided {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]` error: the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/diagnostic-derive.rs:133:5 + --> $DIR/diagnostic-derive.rs:135:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ error: `#[nonsense]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:141:5 + --> $DIR/diagnostic-derive.rs:143:5 | LL | #[nonsense] | ^^^^^^^^^^^ - | - = help: only `skip_arg`, `primary_span`, `label`, `note`, `help` and `subdiagnostic` are valid field attributes error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/diagnostic-derive.rs:158:5 + --> $DIR/diagnostic-derive.rs:160:5 | LL | #[label(typeck::label)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: `name` doesn't refer to a field on this type - --> $DIR/diagnostic-derive.rs:166:45 + --> $DIR/diagnostic-derive.rs:168:45 | LL | #[suggestion(typeck::suggestion, code = "{name}")] | ^^^^^^^^ error: invalid format string: expected `'}'` but string was terminated - --> $DIR/diagnostic-derive.rs:171:16 + --> $DIR/diagnostic-derive.rs:173:16 | LL | #[derive(Diagnostic)] | - ^ expected `'}'` in format string @@ -223,7 +237,7 @@ LL | #[derive(Diagnostic)] = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) error: invalid format string: unmatched `}` found - --> $DIR/diagnostic-derive.rs:181:15 + --> $DIR/diagnostic-derive.rs:183:15 | LL | #[derive(Diagnostic)] | ^ unmatched `}` in format string @@ -232,29 +246,47 @@ LL | #[derive(Diagnostic)] = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/diagnostic-derive.rs:201:5 + --> $DIR/diagnostic-derive.rs:203:5 | LL | #[label(typeck::label)] | ^^^^^^^^^^^^^^^^^^^^^^^ +error: suggestion without `code = "..."` + --> $DIR/diagnostic-derive.rs:221:5 + | +LL | #[suggestion(typeck::suggestion)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: `#[suggestion(nonsense = ...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:226:18 + --> $DIR/diagnostic-derive.rs:229:18 | LL | #[suggestion(nonsense = "bar")] | ^^^^^^^^^^^^^^^^ | - = help: only `message`, `code` and `applicability` are valid field attributes + = help: only `code` and `applicability` are valid nested attributes + +error: suggestion without `code = "..."` + --> $DIR/diagnostic-derive.rs:229:5 + | +LL | #[suggestion(nonsense = "bar")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `#[suggestion(msg = ...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:234:18 + --> $DIR/diagnostic-derive.rs:238:18 | LL | #[suggestion(msg = "bar")] | ^^^^^^^^^^^ | - = help: only `message`, `code` and `applicability` are valid field attributes + = help: only `code` and `applicability` are valid nested attributes + +error: suggestion without `code = "..."` + --> $DIR/diagnostic-derive.rs:238:5 + | +LL | #[suggestion(msg = "bar")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: wrong field type for suggestion - --> $DIR/diagnostic-derive.rs:256:5 + --> $DIR/diagnostic-derive.rs:261:5 | LL | / #[suggestion(typeck::suggestion, code = "This is suggested code")] LL | | @@ -264,73 +296,75 @@ LL | | suggestion: Applicability, = help: `#[suggestion(...)]` should be applied to fields of type `Span` or `(Span, Applicability)` error: specified multiple times - --> $DIR/diagnostic-derive.rs:272:24 + --> $DIR/diagnostic-derive.rs:277:24 | LL | suggestion: (Span, Span, Applicability), | ^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:272:18 + --> $DIR/diagnostic-derive.rs:277:18 | LL | suggestion: (Span, Span, Applicability), | ^^^^ error: specified multiple times - --> $DIR/diagnostic-derive.rs:280:33 + --> $DIR/diagnostic-derive.rs:285:33 | LL | suggestion: (Applicability, Applicability, Span), | ^^^^^^^^^^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:280:18 + --> $DIR/diagnostic-derive.rs:285:18 | LL | suggestion: (Applicability, Applicability, Span), | ^^^^^^^^^^^^^ error: `#[label = ...]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:287:5 + --> $DIR/diagnostic-derive.rs:292:5 | LL | #[label = "bar"] | ^^^^^^^^^^^^^^^^ error: specified multiple times - --> $DIR/diagnostic-derive.rs:438:52 + --> $DIR/diagnostic-derive.rs:443:52 | LL | #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:440:24 + --> $DIR/diagnostic-derive.rs:445:24 | LL | suggestion: (Span, Applicability), | ^^^^^^^^^^^^^ error: invalid applicability - --> $DIR/diagnostic-derive.rs:446:52 + --> $DIR/diagnostic-derive.rs:451:52 | LL | #[suggestion(typeck::suggestion, code = "...", applicability = "batman")] | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: `#[label(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:509:5 +error: `#[label(foo)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:514:28 | LL | #[label(typeck::label, foo)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ + | + = help: a diagnostic slug must be the first argument to the attribute -error: `#[label(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:517:5 +error: `#[label(foo = ...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:522:28 | LL | #[label(typeck::label, foo = "...")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^ -error: `#[label(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:525:5 +error: `#[label(foo(...))]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:530:28 | LL | #[label(typeck::label, foo("..."))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ error: `#[primary_span]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:538:5 + --> $DIR/diagnostic-derive.rs:543:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ @@ -338,15 +372,13 @@ LL | #[primary_span] = help: the `primary_span` field attribute is not valid for lint diagnostics error: `#[error(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:558:1 + --> $DIR/diagnostic-derive.rs:563:1 | LL | #[error(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: `error` and `lint` have been replaced by `diag` error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:558:1 + --> $DIR/diagnostic-derive.rs:563:1 | LL | / #[error(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | | @@ -358,15 +390,13 @@ LL | | struct ErrorAttribute {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]` error: `#[warn_(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:565:1 + --> $DIR/diagnostic-derive.rs:570:1 | LL | #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: `warn_` have been replaced by `warning` error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:565:1 + --> $DIR/diagnostic-derive.rs:570:1 | LL | / #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | | @@ -378,15 +408,13 @@ LL | | struct WarnAttribute {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]` error: `#[lint(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:572:1 + --> $DIR/diagnostic-derive.rs:577:1 | LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: `error` and `lint` have been replaced by `diag` error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:572:1 + --> $DIR/diagnostic-derive.rs:577:1 | LL | / #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | | @@ -398,15 +426,13 @@ LL | | struct LintAttributeOnSessionDiag {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]` error: `#[lint(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:579:1 + --> $DIR/diagnostic-derive.rs:584:1 | LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: `error` and `lint` have been replaced by `diag` error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:579:1 + --> $DIR/diagnostic-derive.rs:584:1 | LL | / #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | | @@ -418,19 +444,19 @@ LL | | struct LintAttributeOnLintDiag {} = help: specify the slug as the first argument to the attribute, such as `#[diag(typeck::example_error)]` error: specified multiple times - --> $DIR/diagnostic-derive.rs:588:52 + --> $DIR/diagnostic-derive.rs:593:52 | LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")] | ^^^^^^^^^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:588:38 + --> $DIR/diagnostic-derive.rs:593:38 | LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")] | ^^^^^^^^^^^^ error: wrong types for suggestion - --> $DIR/diagnostic-derive.rs:597:24 + --> $DIR/diagnostic-derive.rs:602:24 | LL | suggestion: (Span, usize), | ^^^^^ @@ -438,13 +464,59 @@ LL | suggestion: (Span, usize), = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` error: wrong types for suggestion - --> $DIR/diagnostic-derive.rs:605:17 + --> $DIR/diagnostic-derive.rs:610:17 | LL | suggestion: (Span,), | ^^^^^^^ | = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` +error: suggestion without `code = "..."` + --> $DIR/diagnostic-derive.rs:617:5 + | +LL | #[suggestion(typeck::suggestion)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: `#[multipart_suggestion(...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:624:1 + | +LL | #[multipart_suggestion(typeck::suggestion)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider creating a `Subdiagnostic` instead + +error: `#[multipart_suggestion(...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:627:1 + | +LL | #[multipart_suggestion()] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider creating a `Subdiagnostic` instead + +error: `#[multipart_suggestion(...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:631:5 + | +LL | #[multipart_suggestion(typeck::suggestion)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider creating a `Subdiagnostic` instead + +error: `#[suggestion(...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:639:1 + | +LL | #[suggestion(typeck::suggestion, code = "...")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[label]` and `#[suggestion]` can only be applied to fields + +error: `#[label]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:648:1 + | +LL | #[label] + | ^^^^^^^^ + | + = help: `#[label]` and `#[suggestion]` can only be applied to fields + error: cannot find attribute `nonsense` in this scope --> $DIR/diagnostic-derive.rs:53:3 | @@ -452,35 +524,53 @@ LL | #[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^^^^^ error: cannot find attribute `nonsense` in this scope - --> $DIR/diagnostic-derive.rs:141:7 + --> $DIR/diagnostic-derive.rs:143:7 | LL | #[nonsense] | ^^^^^^^^ error: cannot find attribute `error` in this scope - --> $DIR/diagnostic-derive.rs:558:3 + --> $DIR/diagnostic-derive.rs:563:3 | LL | #[error(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^^ error: cannot find attribute `warn_` in this scope - --> $DIR/diagnostic-derive.rs:565:3 + --> $DIR/diagnostic-derive.rs:570:3 | LL | #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^^ help: a built-in attribute with a similar name exists: `warn` error: cannot find attribute `lint` in this scope - --> $DIR/diagnostic-derive.rs:572:3 + --> $DIR/diagnostic-derive.rs:577:3 | LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^ help: a built-in attribute with a similar name exists: `link` error: cannot find attribute `lint` in this scope - --> $DIR/diagnostic-derive.rs:579:3 + --> $DIR/diagnostic-derive.rs:584:3 | LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^ help: a built-in attribute with a similar name exists: `link` +error: cannot find attribute `multipart_suggestion` in this scope + --> $DIR/diagnostic-derive.rs:624:3 + | +LL | #[multipart_suggestion(typeck::suggestion)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: cannot find attribute `multipart_suggestion` in this scope + --> $DIR/diagnostic-derive.rs:627:3 + | +LL | #[multipart_suggestion()] + | ^^^^^^^^^^^^^^^^^^^^ + +error: cannot find attribute `multipart_suggestion` in this scope + --> $DIR/diagnostic-derive.rs:631:7 + | +LL | #[multipart_suggestion(typeck::suggestion)] + | ^^^^^^^^^^^^^^^^^^^^ + error[E0425]: cannot find value `nonsense` in module `rustc_errors::fluent` --> $DIR/diagnostic-derive.rs:66:8 | @@ -488,7 +578,7 @@ LL | #[diag(nonsense, code = "E0123")] | ^^^^^^^^ not found in `rustc_errors::fluent` error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied - --> $DIR/diagnostic-derive.rs:331:10 + --> $DIR/diagnostic-derive.rs:336:10 | LL | #[derive(Diagnostic)] | ^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` @@ -501,7 +591,7 @@ LL | arg: impl IntoDiagnosticArg, | ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg` = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 58 previous errors +error: aborting due to 72 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. From a20672c91910461ff1a9e89118631029297ddd37 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 Sep 2022 14:09:41 +0200 Subject: [PATCH 10/15] Clarify Iterator::rposition code example --- library/core/src/iter/traits/iterator.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 45be7bdd8dba5..e26920b25ccf6 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -2906,14 +2906,14 @@ pub trait Iterator { /// Stopping at the first `true`: /// /// ``` - /// let a = [1, 2, 3]; + /// let a = [-1, 2, 3, 4]; /// /// let mut iter = a.iter(); /// - /// assert_eq!(iter.rposition(|&x| x == 2), Some(1)); + /// assert_eq!(iter.rposition(|&x| x >= 2), Some(3)); /// /// // we can still use `iter`, as there are more elements. - /// assert_eq!(iter.next(), Some(&1)); + /// assert_eq!(iter.next(), Some(&-1)); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] From a7c25b29575c17434406b69773f8c2961af343b3 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 25 Sep 2022 13:09:22 -0700 Subject: [PATCH 11/15] rustdoc: clean up `.out-of-band`/`.in-band` CSS * Remove the `float: right` fallback from the main header, which hasn't been needed since IE11 support was dropped. * Remove `in-band` from low-level headers, which hasn't been needed since `.rightside` switched to `float: right` in 593d6d1cb15c55c88319470dabb40126c7b7f1e2 * Remove unreachable `.in-band > code, .in-band > .code-header` CSS, since the `in-band` class was attached to the `code-header` itself, not nested directly below it. * Use `rem` instead of `em` for code header margins. * This results in a slight change in spacing around impls and item-info, but since it makes it more consistent with the way methods are presented, it's probably fine. --- src/librustdoc/html/render/mod.rs | 2 +- src/librustdoc/html/static/css/rustdoc.css | 19 +++++++------------ src/librustdoc/html/static/js/main.js | 1 - src/test/rustdoc-gui/headers-color.goml | 6 +++--- src/test/rustdoc-gui/implementors.goml | 8 ++++---- src/test/rustdoc-gui/src-font-size.goml | 2 +- 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 1c4e666cd94af..75ac11a3a886e 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1790,7 +1790,7 @@ pub(crate) fn render_impl_summary( write!(w, "
", id, aliases); render_rightside(w, cx, &i.impl_item, containing_item, RenderMode::Normal); write!(w, "", id); - write!(w, "

"); + write!(w, "

"); if let Some(use_absolute) = use_absolute { write!(w, "{}", inner_impl.print(use_absolute, cx)); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index c4da1e4600955..28dc4bf30108e 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -176,8 +176,8 @@ h4.code-header { border-bottom-style: none; margin: 0; padding: 0; - margin-top: 0.6em; - margin-bottom: 0.4em; + margin-top: 0.6rem; + margin-bottom: 0.4rem; } .impl, .impl-items .method, @@ -658,18 +658,17 @@ h2.location a { overflow-x: auto; } -.content .out-of-band { +.out-of-band { flex-grow: 0; font-size: 1.125rem; font-weight: normal; - float: right; } .method > .code-header, .trait-impl > .code-header { display: block; } -.content .in-band { +.in-band { flex-grow: 1; margin: 0px; padding: 0px; @@ -682,10 +681,6 @@ h2.location a { background-color: var(--main-background-color); } -.in-band > code, .in-band > .code-header { - display: inline-block; -} - .docblock code, .docblock-short code, pre, .rustdoc.source .example-wrap { background-color: var(--code-block-background-color); @@ -1731,13 +1726,13 @@ in storage.js plus the media query with (min-width: 701px) flex-direction: column; } - .content .out-of-band { + .out-of-band { text-align: left; margin-left: initial; padding: initial; } - .content .out-of-band .since::before { + .out-of-band .since::before { content: "Since "; } @@ -1969,7 +1964,7 @@ in storage.js plus the media query with (min-width: 701px) } @media print { - nav.sidebar, nav.sub, .content .out-of-band, a.srclink, #copy-path, + nav.sidebar, nav.sub, .out-of-band, a.srclink, #copy-path, details.rustdoc-toggle[open] > summary::before, details.rustdoc-toggle > summary::before, details.rustdoc-toggle.top-doc > summary { display: none; diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 5fbe540c32045..c9674f11a5ecf 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -555,7 +555,6 @@ function loadCss(cssFileName) { const code = document.createElement("h3"); code.innerHTML = struct[TEXT_IDX]; addClass(code, "code-header"); - addClass(code, "in-band"); onEachLazy(code.getElementsByTagName("a"), elem => { const href = elem.getAttribute("href"); diff --git a/src/test/rustdoc-gui/headers-color.goml b/src/test/rustdoc-gui/headers-color.goml index a47a9c8a14c1f..4f01f1a162457 100644 --- a/src/test/rustdoc-gui/headers-color.goml +++ b/src/test/rustdoc-gui/headers-color.goml @@ -19,7 +19,7 @@ assert-css: ( ) assert-css: ( ".impl .code-header", - {"color": "rgb(230, 225, 207)", "background-color": "rgb(15, 20, 25)"}, + {"color": "rgb(230, 225, 207)", "background-color": "rgba(0, 0, 0, 0)"}, ALL, ) @@ -58,7 +58,7 @@ assert-css: ( ) assert-css: ( ".impl .code-header", - {"color": "rgb(221, 221, 221)", "background-color": "rgb(53, 53, 53)"}, + {"color": "rgb(221, 221, 221)", "background-color": "rgba(0, 0, 0, 0)"}, ALL, ) @@ -95,7 +95,7 @@ assert-css: ( ) assert-css: ( ".impl .code-header", - {"color": "rgb(0, 0, 0)", "background-color": "rgb(255, 255, 255)"}, + {"color": "rgb(0, 0, 0)", "background-color": "rgba(0, 0, 0, 0)"}, ALL, ) diff --git a/src/test/rustdoc-gui/implementors.goml b/src/test/rustdoc-gui/implementors.goml index 666a6e1253d9d..dc3b2e122680c 100644 --- a/src/test/rustdoc-gui/implementors.goml +++ b/src/test/rustdoc-gui/implementors.goml @@ -8,23 +8,23 @@ assert-count: ("#implementors-list .impl", 2) assert: ("#implementors-list .impl:nth-child(1) > a.anchor") assert-attribute: ("#implementors-list .impl:nth-child(1)", {"id": "impl-Whatever-for-Struct"}) assert-attribute: ("#implementors-list .impl:nth-child(1) > a.anchor", {"href": "#impl-Whatever-for-Struct"}) -assert: "#implementors-list .impl:nth-child(1) > .code-header.in-band" +assert: "#implementors-list .impl:nth-child(1) > .code-header" assert: ("#implementors-list .impl:nth-child(2) > a.anchor") assert-attribute: ("#implementors-list .impl:nth-child(2)", {"id": "impl-Whatever-1"}) assert-attribute: ("#implementors-list .impl:nth-child(2) > a.anchor", {"href": "#impl-Whatever-1"}) -assert: "#implementors-list .impl:nth-child(2) > .code-header.in-band" +assert: "#implementors-list .impl:nth-child(2) > .code-header" goto: file://|DOC_PATH|/test_docs/struct.HasEmptyTraits.html compare-elements-position-near-false: ( "#impl-EmptyTrait1-for-HasEmptyTraits", "#impl-EmptyTrait2-for-HasEmptyTraits", - {"y": 30}, + {"y": 34.1875}, ) compare-elements-position-near: ( "#impl-EmptyTrait3-for-HasEmptyTraits h3", "#impl-EmptyTrait3-for-HasEmptyTraits .item-info", - {"y": 30}, + {"y": 34.1875}, ) // Now check that re-exports work correctly. diff --git a/src/test/rustdoc-gui/src-font-size.goml b/src/test/rustdoc-gui/src-font-size.goml index 0c01e25455486..9797f196c5545 100644 --- a/src/test/rustdoc-gui/src-font-size.goml +++ b/src/test/rustdoc-gui/src-font-size.goml @@ -5,7 +5,7 @@ goto: file://|DOC_PATH|/test_docs/struct.Foo.html show-text: true // Check the impl headers. assert-css: (".impl.has-srclink .srclink", {"font-size": "16px"}, ALL) -assert-css: (".impl.has-srclink .code-header.in-band", {"font-size": "18px"}, ALL) +assert-css: (".impl.has-srclink .code-header", {"font-size": "18px"}, ALL) // Check the impl items. assert-css: (".impl-items .has-srclink .srclink", {"font-size": "16px"}, ALL) assert-css: (".impl-items .has-srclink .code-header", {"font-size": "16px"}, ALL) From 4ba40314e1a28e6230c6f404ee3b23de3efb7709 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 25 Sep 2022 13:52:26 -0700 Subject: [PATCH 12/15] rustdoc: update test cases now that code-header is used without in-band --- src/test/rustdoc/anonymous-lifetime.rs | 2 +- src/test/rustdoc/assoc-consts.rs | 4 ++-- src/test/rustdoc/blanket-reexport-item.rs | 2 +- src/test/rustdoc/const-generics/add-impl.rs | 2 +- .../const-generics/const-generics-docs.rs | 12 +++++------ src/test/rustdoc/const-generics/const-impl.rs | 10 +++++----- .../const-equate-pred.rs | 2 +- .../rustdoc/duplicate_impls/issue-33054.rs | 6 +++--- src/test/rustdoc/empty-impl-block.rs | 2 +- src/test/rustdoc/extern-impl.rs | 6 +++--- src/test/rustdoc/fn-bound.rs | 2 +- src/test/rustdoc/generic-impl.rs | 2 +- .../rustdoc/higher-ranked-trait-bounds.rs | 2 +- src/test/rustdoc/impl-disambiguation.rs | 10 +++++----- src/test/rustdoc/impl-parts.rs | 4 ++-- .../rustdoc/inline_cross/issue-31948-1.rs | 20 +++++++++---------- .../rustdoc/inline_cross/issue-31948-2.rs | 12 +++++------ src/test/rustdoc/inline_cross/issue-31948.rs | 20 +++++++++---------- src/test/rustdoc/inline_cross/issue-32881.rs | 4 ++-- src/test/rustdoc/inline_cross/issue-33113.rs | 4 ++-- src/test/rustdoc/inline_cross/trait-vis.rs | 2 +- src/test/rustdoc/inline_local/trait-vis.rs | 4 ++-- src/test/rustdoc/issue-29503.rs | 2 +- src/test/rustdoc/issue-33592.rs | 4 ++-- src/test/rustdoc/issue-46727.rs | 2 +- src/test/rustdoc/issue-50159.rs | 4 ++-- src/test/rustdoc/issue-51236.rs | 2 +- src/test/rustdoc/issue-54705.rs | 4 ++-- src/test/rustdoc/issue-55321.rs | 8 ++++---- src/test/rustdoc/issue-56822.rs | 2 +- src/test/rustdoc/issue-60726.rs | 4 ++-- src/test/rustdoc/issue-75588.rs | 4 ++-- .../issue-80233-normalize-auto-trait.rs | 2 +- .../issue-82465-asref-for-and-of-local.rs | 4 ++-- src/test/rustdoc/issue-98697.rs | 4 ++-- src/test/rustdoc/negative-impl.rs | 4 ++-- src/test/rustdoc/primitive-reference.rs | 2 +- .../primitive/primitive-generic-impl.rs | 2 +- src/test/rustdoc/recursive-deref.rs | 18 ++++++++--------- src/test/rustdoc/rfc-2632-const-trait-impl.rs | 8 ++++---- .../rustdoc/sidebar-links-to-foreign-impl.rs | 4 ++-- src/test/rustdoc/sized_trait.rs | 2 +- src/test/rustdoc/src-links-auto-impls.rs | 6 +++--- src/test/rustdoc/synthetic_auto/basic.rs | 4 ++-- src/test/rustdoc/synthetic_auto/complex.rs | 2 +- .../rustdoc/synthetic_auto/crate-local.rs | 6 +++--- src/test/rustdoc/synthetic_auto/lifetimes.rs | 4 ++-- src/test/rustdoc/synthetic_auto/manual.rs | 4 ++-- src/test/rustdoc/synthetic_auto/negative.rs | 4 ++-- src/test/rustdoc/synthetic_auto/nested.rs | 4 ++-- .../rustdoc/synthetic_auto/no-redundancy.rs | 2 +- src/test/rustdoc/synthetic_auto/overflow.rs | 2 +- src/test/rustdoc/synthetic_auto/project.rs | 4 ++-- .../synthetic_auto/self-referential.rs | 2 +- .../rustdoc/synthetic_auto/static-region.rs | 2 +- src/test/rustdoc/traits-in-bodies.rs | 6 +++--- src/test/rustdoc/typedef.rs | 4 ++-- src/test/rustdoc/where.rs | 10 +++++----- 58 files changed, 143 insertions(+), 143 deletions(-) diff --git a/src/test/rustdoc/anonymous-lifetime.rs b/src/test/rustdoc/anonymous-lifetime.rs index f5a7d225847c4..390ed5a1f938b 100644 --- a/src/test/rustdoc/anonymous-lifetime.rs +++ b/src/test/rustdoc/anonymous-lifetime.rs @@ -12,7 +12,7 @@ pub trait Stream { } // @has 'foo/trait.Stream.html' -// @has - '//*[@class="code-header in-band"]' 'impl Stream for &mut S' +// @has - '//*[@class="code-header"]' 'impl Stream for &mut S' impl Stream for &mut S { type Item = S::Item; diff --git a/src/test/rustdoc/assoc-consts.rs b/src/test/rustdoc/assoc-consts.rs index 97b7739b4c975..a3e10ee5555a0 100644 --- a/src/test/rustdoc/assoc-consts.rs +++ b/src/test/rustdoc/assoc-consts.rs @@ -13,7 +13,7 @@ pub trait Foo { pub struct Bar; impl Foo for Bar { - // @has assoc_consts/struct.Bar.html '//h3[@class="code-header in-band"]' 'impl Foo for Bar' + // @has assoc_consts/struct.Bar.html '//h3[@class="code-header"]' 'impl Foo for Bar' // @has - '//*[@id="associatedconstant.FOO"]' 'const FOO: usize' const FOO: usize = 12; // @has - '//*[@id="associatedconstant.FOO_NO_DEFAULT"]' 'const FOO_NO_DEFAULT: bool' @@ -81,7 +81,7 @@ pub trait Qux { const QUX_DEFAULT2: u32 = 3; } -// @has assoc_consts/struct.Bar.html '//h3[@class="code-header in-band"]' 'impl Qux for Bar' +// @has assoc_consts/struct.Bar.html '//h3[@class="code-header"]' 'impl Qux for Bar' impl Qux for Bar { // @has - '//*[@id="associatedconstant.QUX0"]' 'const QUX0: u8' // @has - '//*[@class="docblock"]' "Docs for QUX0 in trait." diff --git a/src/test/rustdoc/blanket-reexport-item.rs b/src/test/rustdoc/blanket-reexport-item.rs index 676d656dabf47..437f0001fcfc4 100644 --- a/src/test/rustdoc/blanket-reexport-item.rs +++ b/src/test/rustdoc/blanket-reexport-item.rs @@ -1,6 +1,6 @@ #![crate_name = "foo"] -// @has foo/struct.S.html '//*[@id="impl-Into%3CU%3E-for-S"]//h3[@class="code-header in-band"]' 'impl Into for T' +// @has foo/struct.S.html '//*[@id="impl-Into%3CU%3E-for-S"]//h3[@class="code-header"]' 'impl Into for T' pub struct S2 {} mod m { pub struct S {} diff --git a/src/test/rustdoc/const-generics/add-impl.rs b/src/test/rustdoc/const-generics/add-impl.rs index 591139523456e..6cbae9abebb73 100644 --- a/src/test/rustdoc/const-generics/add-impl.rs +++ b/src/test/rustdoc/const-generics/add-impl.rs @@ -7,7 +7,7 @@ pub struct Simd { inner: T, } -// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl Add> for Simd' +// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl Add> for Simd' impl Add for Simd { type Output = Self; diff --git a/src/test/rustdoc/const-generics/const-generics-docs.rs b/src/test/rustdoc/const-generics/const-generics-docs.rs index 87d2f29e26055..5bf76e3c46908 100644 --- a/src/test/rustdoc/const-generics/const-generics-docs.rs +++ b/src/test/rustdoc/const-generics/const-generics-docs.rs @@ -19,10 +19,10 @@ pub use extern_crate::WTrait; // @has foo/trait.Trait.html '//pre[@class="rust trait"]' \ // 'pub trait Trait' -// @has - '//*[@id="impl-Trait%3C1%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<1> for u8' -// @has - '//*[@id="impl-Trait%3C2%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<2> for u8' -// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<{1 + 2}> for u8' -// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="impl-Trait%3C1%3E-for-u8"]//h3[@class="code-header"]' 'impl Trait<1> for u8' +// @has - '//*[@id="impl-Trait%3C2%3E-for-u8"]//h3[@class="code-header"]' 'impl Trait<2> for u8' +// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//h3[@class="code-header"]' 'impl Trait<{1 + 2}> for u8' +// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//h3[@class="code-header"]' \ // 'impl Trait for [u8; N]' pub trait Trait {} impl Trait<1> for u8 {} @@ -36,7 +36,7 @@ pub struct Foo where u8: Trait; // @has foo/struct.Bar.html '//pre[@class="rust struct"]' 'pub struct Bar(_)' pub struct Bar([T; N]); -// @has foo/struct.Foo.html '//*[@id="impl-Foo%3CM%3E"]/h3[@class="code-header in-band"]' 'impl Foowhere u8: Trait' +// @has foo/struct.Foo.html '//*[@id="impl-Foo%3CM%3E"]/h3[@class="code-header"]' 'impl Foowhere u8: Trait' impl Foo where u8: Trait { // @has - '//*[@id="associatedconstant.FOO_ASSOC"]' 'pub const FOO_ASSOC: usize' pub const FOO_ASSOC: usize = M + 13; @@ -47,7 +47,7 @@ impl Foo where u8: Trait { } } -// @has foo/struct.Bar.html '//*[@id="impl-Bar%3Cu8%2C%20M%3E"]/h3[@class="code-header in-band"]' 'impl Bar' +// @has foo/struct.Bar.html '//*[@id="impl-Bar%3Cu8%2C%20M%3E"]/h3[@class="code-header"]' 'impl Bar' impl Bar { // @has - '//*[@id="method.hey"]' \ // 'pub fn hey(&self) -> Foowhere u8: Trait' diff --git a/src/test/rustdoc/const-generics/const-impl.rs b/src/test/rustdoc/const-generics/const-impl.rs index f1181d54ac87f..75ee84279be3c 100644 --- a/src/test/rustdoc/const-generics/const-impl.rs +++ b/src/test/rustdoc/const-generics/const-impl.rs @@ -9,20 +9,20 @@ pub enum Order { } // @has foo/struct.VSet.html '//pre[@class="rust struct"]' 'pub struct VSet' -// @has foo/struct.VSet.html '//*[@id="impl-Send-for-VSet%3CT%2C%20ORDER%3E"]/h3[@class="code-header in-band"]' 'impl Send for VSet' -// @has foo/struct.VSet.html '//*[@id="impl-Sync-for-VSet%3CT%2C%20ORDER%3E"]/h3[@class="code-header in-band"]' 'impl Sync for VSet' +// @has foo/struct.VSet.html '//*[@id="impl-Send-for-VSet%3CT%2C%20ORDER%3E"]/h3[@class="code-header"]' 'impl Send for VSet' +// @has foo/struct.VSet.html '//*[@id="impl-Sync-for-VSet%3CT%2C%20ORDER%3E"]/h3[@class="code-header"]' 'impl Sync for VSet' pub struct VSet { inner: Vec, } -// @has foo/struct.VSet.html '//*[@id="impl-VSet%3CT%2C%20{%20Order%3A%3ASorted%20}%3E"]/h3[@class="code-header in-band"]' 'impl VSet' +// @has foo/struct.VSet.html '//*[@id="impl-VSet%3CT%2C%20{%20Order%3A%3ASorted%20}%3E"]/h3[@class="code-header"]' 'impl VSet' impl VSet { pub fn new() -> Self { Self { inner: Vec::new() } } } -// @has foo/struct.VSet.html '//*[@id="impl-VSet%3CT%2C%20{%20Order%3A%3AUnsorted%20}%3E"]/h3[@class="code-header in-band"]' 'impl VSet' +// @has foo/struct.VSet.html '//*[@id="impl-VSet%3CT%2C%20{%20Order%3A%3AUnsorted%20}%3E"]/h3[@class="code-header"]' 'impl VSet' impl VSet { pub fn new() -> Self { Self { inner: Vec::new() } @@ -31,7 +31,7 @@ impl VSet { pub struct Escape; -// @has foo/struct.Escape.html '//*[@id="impl-Escape%3Cr#%22%3Cscript%3Ealert(%22Escape%22)%3B%3C/script%3E%22#%3E"]/h3[@class="code-header in-band"]' 'impl Escapealert("Escape");"#>' +// @has foo/struct.Escape.html '//*[@id="impl-Escape%3Cr#%22%3Cscript%3Ealert(%22Escape%22)%3B%3C/script%3E%22#%3E"]/h3[@class="code-header"]' 'impl Escapealert("Escape");"#>' impl Escapealert("Escape");"#> { pub fn f() {} } diff --git a/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs b/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs index 4eac8e31e4529..310e89a35c4a9 100644 --- a/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs +++ b/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs @@ -12,7 +12,7 @@ pub struct Hasher { unsafe impl Send for Hasher {} // @has foo/struct.Foo.html -// @has - '//h3[@class="code-header in-band"]' 'impl Send for Foo' +// @has - '//h3[@class="code-header"]' 'impl Send for Foo' pub struct Foo { hasher: Hasher<[u8; 3]>, } diff --git a/src/test/rustdoc/duplicate_impls/issue-33054.rs b/src/test/rustdoc/duplicate_impls/issue-33054.rs index 84c9e4ac0cd84..c1f95ac91c394 100644 --- a/src/test/rustdoc/duplicate_impls/issue-33054.rs +++ b/src/test/rustdoc/duplicate_impls/issue-33054.rs @@ -1,12 +1,12 @@ // ignore-tidy-linelength // @has issue_33054/impls/struct.Foo.html -// @has - '//h3[@class="code-header in-band"]' 'impl Foo' -// @has - '//h3[@class="code-header in-band"]' 'impl Bar for Foo' +// @has - '//h3[@class="code-header"]' 'impl Foo' +// @has - '//h3[@class="code-header"]' 'impl Bar for Foo' // @count - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]' 1 // @count - '//*[@id="main-content"]/div[@id="implementations-list"]/details/summary/*[@class="impl has-srclink"]' 1 // @has issue_33054/impls/bar/trait.Bar.html -// @has - '//h3[@class="code-header in-band"]' 'impl Bar for Foo' +// @has - '//h3[@class="code-header"]' 'impl Bar for Foo' // @count - '//*[@class="struct"]' 1 pub mod impls; diff --git a/src/test/rustdoc/empty-impl-block.rs b/src/test/rustdoc/empty-impl-block.rs index 6a2a254f63a7f..95d4db06b3171 100644 --- a/src/test/rustdoc/empty-impl-block.rs +++ b/src/test/rustdoc/empty-impl-block.rs @@ -16,5 +16,5 @@ pub struct Another; pub trait Bar {} // @has 'foo/struct.Another.html' -// @has - '//h3[@class="code-header in-band"]' 'impl Bar for Another' +// @has - '//h3[@class="code-header"]' 'impl Bar for Another' impl Bar for Another {} diff --git a/src/test/rustdoc/extern-impl.rs b/src/test/rustdoc/extern-impl.rs index f357d65df94be..fd1bc21400837 100644 --- a/src/test/rustdoc/extern-impl.rs +++ b/src/test/rustdoc/extern-impl.rs @@ -19,9 +19,9 @@ impl Foo { // @has foo/trait.Bar.html pub trait Bar {} -// @has - '//h3[@class="code-header in-band"]' 'impl Bar for fn()' +// @has - '//h3[@class="code-header"]' 'impl Bar for fn()' impl Bar for fn() {} -// @has - '//h3[@class="code-header in-band"]' 'impl Bar for extern "C" fn()' +// @has - '//h3[@class="code-header"]' 'impl Bar for extern "C" fn()' impl Bar for extern fn() {} -// @has - '//h3[@class="code-header in-band"]' 'impl Bar for extern "system" fn()' +// @has - '//h3[@class="code-header"]' 'impl Bar for extern "system" fn()' impl Bar for extern "system" fn() {} diff --git a/src/test/rustdoc/fn-bound.rs b/src/test/rustdoc/fn-bound.rs index 4c4ffddc8a648..9e060ff2026f6 100644 --- a/src/test/rustdoc/fn-bound.rs +++ b/src/test/rustdoc/fn-bound.rs @@ -11,7 +11,7 @@ pub struct ConditionalIterator { } -// @has 'fn_bound/struct.ConditionalIterator.html' '//h3[@class="code-header in-band"]' 'impl Iterator for ConditionalIterator' +// @has 'fn_bound/struct.ConditionalIterator.html' '//h3[@class="code-header"]' 'impl Iterator for ConditionalIterator' impl Iterator for ConditionalIterator { type Item = (); diff --git a/src/test/rustdoc/generic-impl.rs b/src/test/rustdoc/generic-impl.rs index c6beed70abeb1..6f68b1574992b 100644 --- a/src/test/rustdoc/generic-impl.rs +++ b/src/test/rustdoc/generic-impl.rs @@ -5,7 +5,7 @@ use std::fmt; // @!has foo/struct.Bar.html '//*[@id="impl-ToString-for-Bar"]' '' pub struct Bar; -// @has foo/struct.Foo.html '//*[@id="impl-ToString-for-Foo"]//h3[@class="code-header in-band"]' 'impl ToString for T' +// @has foo/struct.Foo.html '//*[@id="impl-ToString-for-Foo"]//h3[@class="code-header"]' 'impl ToString for T' pub struct Foo; // @has foo/struct.Foo.html '//*[@class="sidebar-elems"]//section//a[@href="#impl-ToString-for-Foo"]' 'ToString' diff --git a/src/test/rustdoc/higher-ranked-trait-bounds.rs b/src/test/rustdoc/higher-ranked-trait-bounds.rs index 59b5b6e5797cc..3493ae6d2bbb5 100644 --- a/src/test/rustdoc/higher-ranked-trait-bounds.rs +++ b/src/test/rustdoc/higher-ranked-trait-bounds.rs @@ -49,7 +49,7 @@ impl<'a> Foo<'a> { // @has foo/trait.B.html pub trait B<'x> {} -// @has - '//h3[@class="code-header in-band"]' "impl<'a> B<'a> for dyn for<'b> Trait<'b>" +// @has - '//h3[@class="code-header"]' "impl<'a> B<'a> for dyn for<'b> Trait<'b>" impl<'a> B<'a> for dyn for<'b> Trait<'b> {} // @has foo/struct.Bar.html diff --git a/src/test/rustdoc/impl-disambiguation.rs b/src/test/rustdoc/impl-disambiguation.rs index d1d39ccff328f..bb978dc0f3ec8 100644 --- a/src/test/rustdoc/impl-disambiguation.rs +++ b/src/test/rustdoc/impl-disambiguation.rs @@ -4,13 +4,13 @@ pub trait Foo {} pub struct Bar { field: T } -// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \ +// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header"]' \ // "impl Foo for Bar" impl Foo for Bar {} -// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \ +// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header"]' \ // "impl Foo for Bar" impl Foo for Bar {} -// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \ +// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header"]' \ // "impl<'a> Foo for &'a Bar" impl<'a> Foo for &'a Bar {} @@ -22,9 +22,9 @@ pub mod mod2 { pub enum Baz {} } -// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \ +// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header"]' \ // "impl Foo for foo::mod1::Baz" impl Foo for mod1::Baz {} -// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \ +// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header"]' \ // "impl<'a> Foo for &'a foo::mod2::Baz" impl<'a> Foo for &'a mod2::Baz {} diff --git a/src/test/rustdoc/impl-parts.rs b/src/test/rustdoc/impl-parts.rs index b1481e1f27978..0a8c2c8d2a9e6 100644 --- a/src/test/rustdoc/impl-parts.rs +++ b/src/test/rustdoc/impl-parts.rs @@ -5,8 +5,8 @@ pub auto trait AnAutoTrait {} pub struct Foo { field: T } -// @has impl_parts/struct.Foo.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has impl_parts/struct.Foo.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl !AnAutoTrait for Foowhere T: Sync," -// @has impl_parts/trait.AnAutoTrait.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \ +// @has impl_parts/trait.AnAutoTrait.html '//*[@class="item-list"]//h3[@class="code-header"]' \ // "impl !AnAutoTrait for Foowhere T: Sync," impl !AnAutoTrait for Foo where T: Sync {} diff --git a/src/test/rustdoc/inline_cross/issue-31948-1.rs b/src/test/rustdoc/inline_cross/issue-31948-1.rs index be8585dd16e17..6e89167b3a451 100644 --- a/src/test/rustdoc/inline_cross/issue-31948-1.rs +++ b/src/test/rustdoc/inline_cross/issue-31948-1.rs @@ -5,22 +5,22 @@ extern crate rustdoc_nonreachable_impls; // @has issue_31948_1/struct.Wobble.html -// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Bark for' -// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Woof for' -// @!has - '//*[@class="impl"]//h3[@class="code-header in-band"]' 'Bar for' -// @!has - '//*[@class="impl"]//h3[@class="code-header in-band"]' 'Qux for' +// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Bark for' +// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Woof for' +// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'Bar for' +// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'Qux for' pub use rustdoc_nonreachable_impls::hidden::Wobble; // @has issue_31948_1/trait.Bark.html -// @has - '//h3[@class="code-header in-band"]' 'for Foo' -// @has - '//h3[@class="code-header in-band"]' 'for Wobble' -// @!has - '//h3[@class="code-header in-band"]' 'for Wibble' +// @has - '//h3[@class="code-header"]' 'for Foo' +// @has - '//h3[@class="code-header"]' 'for Wobble' +// @!has - '//h3[@class="code-header"]' 'for Wibble' pub use rustdoc_nonreachable_impls::Bark; // @has issue_31948_1/trait.Woof.html -// @has - '//h3[@class="code-header in-band"]' 'for Foo' -// @has - '//h3[@class="code-header in-band"]' 'for Wobble' -// @!has - '//h3[@class="code-header in-band"]' 'for Wibble' +// @has - '//h3[@class="code-header"]' 'for Foo' +// @has - '//h3[@class="code-header"]' 'for Wobble' +// @!has - '//h3[@class="code-header"]' 'for Wibble' pub use rustdoc_nonreachable_impls::Woof; // @!has issue_31948_1/trait.Bar.html diff --git a/src/test/rustdoc/inline_cross/issue-31948-2.rs b/src/test/rustdoc/inline_cross/issue-31948-2.rs index 7aa994f19d6f1..141e07656a09c 100644 --- a/src/test/rustdoc/inline_cross/issue-31948-2.rs +++ b/src/test/rustdoc/inline_cross/issue-31948-2.rs @@ -5,15 +5,15 @@ extern crate rustdoc_nonreachable_impls; // @has issue_31948_2/struct.Wobble.html -// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Qux for' -// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Bark for' -// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Woof for' -// @!has - '//*[@class="impl"]//h3[@class="code-header in-band"]' 'Bar for' +// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Qux for' +// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Bark for' +// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Woof for' +// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'Bar for' pub use rustdoc_nonreachable_impls::hidden::Wobble; // @has issue_31948_2/trait.Qux.html -// @has - '//h3[@class="code-header in-band"]' 'for Foo' -// @has - '//h3[@class="code-header in-band"]' 'for Wobble' +// @has - '//h3[@class="code-header"]' 'for Foo' +// @has - '//h3[@class="code-header"]' 'for Wobble' pub use rustdoc_nonreachable_impls::hidden::Qux; // @!has issue_31948_2/trait.Bar.html diff --git a/src/test/rustdoc/inline_cross/issue-31948.rs b/src/test/rustdoc/inline_cross/issue-31948.rs index 7bf4110d32ac1..96fc6ca47e7f6 100644 --- a/src/test/rustdoc/inline_cross/issue-31948.rs +++ b/src/test/rustdoc/inline_cross/issue-31948.rs @@ -5,22 +5,22 @@ extern crate rustdoc_nonreachable_impls; // @has issue_31948/struct.Foo.html -// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Bark for' -// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Woof for' -// @!has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Bar for' -// @!has - '//*[@class="impl"]//h3[@class="code-header in-band"]' 'Qux for' +// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Bark for' +// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Woof for' +// @!has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Bar for' +// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'Qux for' pub use rustdoc_nonreachable_impls::Foo; // @has issue_31948/trait.Bark.html -// @has - '//h3[@class="code-header in-band"]' 'for Foo' -// @!has - '//h3[@class="code-header in-band"]' 'for Wibble' -// @!has - '//h3[@class="code-header in-band"]' 'for Wobble' +// @has - '//h3[@class="code-header"]' 'for Foo' +// @!has - '//h3[@class="code-header"]' 'for Wibble' +// @!has - '//h3[@class="code-header"]' 'for Wobble' pub use rustdoc_nonreachable_impls::Bark; // @has issue_31948/trait.Woof.html -// @has - '//h3[@class="code-header in-band"]' 'for Foo' -// @!has - '//h3[@class="code-header in-band"]' 'for Wibble' -// @!has - '//h3[@class="code-header in-band"]' 'for Wobble' +// @has - '//h3[@class="code-header"]' 'for Foo' +// @!has - '//h3[@class="code-header"]' 'for Wibble' +// @!has - '//h3[@class="code-header"]' 'for Wobble' pub use rustdoc_nonreachable_impls::Woof; // @!has issue_31948/trait.Bar.html diff --git a/src/test/rustdoc/inline_cross/issue-32881.rs b/src/test/rustdoc/inline_cross/issue-32881.rs index 8052339a83b6d..183fd15abbe17 100644 --- a/src/test/rustdoc/inline_cross/issue-32881.rs +++ b/src/test/rustdoc/inline_cross/issue-32881.rs @@ -5,7 +5,7 @@ extern crate rustdoc_trait_object_impl; // @has issue_32881/trait.Bar.html -// @has - '//h3[@class="code-header in-band"]' "impl<'a> dyn Bar" -// @has - '//h3[@class="code-header in-band"]' "impl<'a> Debug for dyn Bar" +// @has - '//h3[@class="code-header"]' "impl<'a> dyn Bar" +// @has - '//h3[@class="code-header"]' "impl<'a> Debug for dyn Bar" pub use rustdoc_trait_object_impl::Bar; diff --git a/src/test/rustdoc/inline_cross/issue-33113.rs b/src/test/rustdoc/inline_cross/issue-33113.rs index c60859bbcea98..d954707facfe6 100644 --- a/src/test/rustdoc/inline_cross/issue-33113.rs +++ b/src/test/rustdoc/inline_cross/issue-33113.rs @@ -5,6 +5,6 @@ extern crate bar; // @has issue_33113/trait.Bar.html -// @has - '//h3[@class="code-header in-band"]' "for &'a char" -// @has - '//h3[@class="code-header in-band"]' "for Foo" +// @has - '//h3[@class="code-header"]' "for &'a char" +// @has - '//h3[@class="code-header"]' "for Foo" pub use bar::Bar; diff --git a/src/test/rustdoc/inline_cross/trait-vis.rs b/src/test/rustdoc/inline_cross/trait-vis.rs index 363c52a336e42..b646babacc5cc 100644 --- a/src/test/rustdoc/inline_cross/trait-vis.rs +++ b/src/test/rustdoc/inline_cross/trait-vis.rs @@ -3,5 +3,5 @@ extern crate inner; // @has trait_vis/struct.SomeStruct.html -// @has - '//h3[@class="code-header in-band"]' 'impl Clone for SomeStruct' +// @has - '//h3[@class="code-header"]' 'impl Clone for SomeStruct' pub use inner::SomeStruct; diff --git a/src/test/rustdoc/inline_local/trait-vis.rs b/src/test/rustdoc/inline_local/trait-vis.rs index e7b08088f4032..19b69da15138b 100644 --- a/src/test/rustdoc/inline_local/trait-vis.rs +++ b/src/test/rustdoc/inline_local/trait-vis.rs @@ -13,6 +13,6 @@ mod asdf { } // @has trait_vis/struct.SomeStruct.html -// @has - '//h3[@class="code-header in-band"]' 'impl ThisTrait for SomeStruct' -// @!has - '//h3[@class="code-header in-band"]' 'impl PrivateTrait for SomeStruct' +// @has - '//h3[@class="code-header"]' 'impl ThisTrait for SomeStruct' +// @!has - '//h3[@class="code-header"]' 'impl PrivateTrait for SomeStruct' pub use asdf::SomeStruct; diff --git a/src/test/rustdoc/issue-29503.rs b/src/test/rustdoc/issue-29503.rs index 134821e1ef3ea..01ae4438500da 100644 --- a/src/test/rustdoc/issue-29503.rs +++ b/src/test/rustdoc/issue-29503.rs @@ -5,7 +5,7 @@ pub trait MyTrait { fn my_string(&self) -> String; } -// @has - "//div[@id='implementors-list']//*[@id='impl-MyTrait-for-T']//h3[@class='code-header in-band']" "impl MyTrait for Twhere T: Debug" +// @has - "//div[@id='implementors-list']//*[@id='impl-MyTrait-for-T']//h3[@class='code-header']" "impl MyTrait for Twhere T: Debug" impl MyTrait for T where T: fmt::Debug, diff --git a/src/test/rustdoc/issue-33592.rs b/src/test/rustdoc/issue-33592.rs index 815439db9bfd2..7a128f0b897ed 100644 --- a/src/test/rustdoc/issue-33592.rs +++ b/src/test/rustdoc/issue-33592.rs @@ -6,8 +6,8 @@ pub struct Bar; pub struct Baz; -// @has foo/trait.Foo.html '//h3[@class="code-header in-band"]' 'impl Foo for Bar' +// @has foo/trait.Foo.html '//h3[@class="code-header"]' 'impl Foo for Bar' impl Foo for Bar {} -// @has foo/trait.Foo.html '//h3[@class="code-header in-band"]' 'impl Foo for Baz' +// @has foo/trait.Foo.html '//h3[@class="code-header"]' 'impl Foo for Baz' impl Foo for Baz {} diff --git a/src/test/rustdoc/issue-46727.rs b/src/test/rustdoc/issue-46727.rs index 00e9127a34d20..8cfc4827a7f4c 100644 --- a/src/test/rustdoc/issue-46727.rs +++ b/src/test/rustdoc/issue-46727.rs @@ -3,5 +3,5 @@ extern crate issue_46727; // @has issue_46727/trait.Foo.html -// @has - '//h3[@class="code-header in-band"]' 'impl Foo for Bar<[T; 3]>' +// @has - '//h3[@class="code-header"]' 'impl Foo for Bar<[T; 3]>' pub use issue_46727::{Foo, Bar}; diff --git a/src/test/rustdoc/issue-50159.rs b/src/test/rustdoc/issue-50159.rs index 43fb705f58994..04bc4f304d68a 100644 --- a/src/test/rustdoc/issue-50159.rs +++ b/src/test/rustdoc/issue-50159.rs @@ -11,8 +11,8 @@ impl Signal2 for B where B: Signal { } // @has issue_50159/struct.Switch.html -// @has - '//h3[@class="code-header in-band"]' 'impl Send for Switchwhere ::Item: Send' -// @has - '//h3[@class="code-header in-band"]' 'impl Sync for Switchwhere ::Item: Sync' +// @has - '//h3[@class="code-header"]' 'impl Send for Switchwhere ::Item: Send' +// @has - '//h3[@class="code-header"]' 'impl Sync for Switchwhere ::Item: Sync' // @count - '//*[@id="implementations-list"]//*[@class="impl"]' 0 // @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]' 5 pub struct Switch { diff --git a/src/test/rustdoc/issue-51236.rs b/src/test/rustdoc/issue-51236.rs index aa5890a84514f..1c7aa9c7eefe5 100644 --- a/src/test/rustdoc/issue-51236.rs +++ b/src/test/rustdoc/issue-51236.rs @@ -7,7 +7,7 @@ pub mod traits { } // @has issue_51236/struct.Owned.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl Send for Ownedwhere >::Reader: Send" pub struct Owned where T: for<'a> ::traits::Owned<'a> { marker: PhantomData<>::Reader>, diff --git a/src/test/rustdoc/issue-54705.rs b/src/test/rustdoc/issue-54705.rs index ce0f85d25da56..7b7290ab4b77c 100644 --- a/src/test/rustdoc/issue-54705.rs +++ b/src/test/rustdoc/issue-54705.rs @@ -1,10 +1,10 @@ pub trait ScopeHandle<'scope> {} // @has issue_54705/struct.ScopeFutureContents.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl<'scope, S> Send for ScopeFutureContents<'scope, S>where S: Sync" // -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl<'scope, S> Sync for ScopeFutureContents<'scope, S>where S: Sync" pub struct ScopeFutureContents<'scope, S> where S: ScopeHandle<'scope>, diff --git a/src/test/rustdoc/issue-55321.rs b/src/test/rustdoc/issue-55321.rs index ee2420d86d236..22a18ef90e13a 100644 --- a/src/test/rustdoc/issue-55321.rs +++ b/src/test/rustdoc/issue-55321.rs @@ -1,9 +1,9 @@ #![feature(negative_impls)] // @has issue_55321/struct.A.html -// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl !Send for A" -// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl !Sync for A" pub struct A(); @@ -11,8 +11,8 @@ impl !Send for A {} impl !Sync for A {} // @has issue_55321/struct.B.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl !Send for B" -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl !Sync for B" pub struct B(A, Box); diff --git a/src/test/rustdoc/issue-56822.rs b/src/test/rustdoc/issue-56822.rs index aef6ddd8d23bc..b4eef344b5f3b 100644 --- a/src/test/rustdoc/issue-56822.rs +++ b/src/test/rustdoc/issue-56822.rs @@ -17,7 +17,7 @@ impl<'a, T> MyTrait for Inner<'a, T> { } // @has issue_56822/struct.Parser.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl<'a> Send for Parser<'a>" pub struct Parser<'a> { field: > as MyTrait>::Output diff --git a/src/test/rustdoc/issue-60726.rs b/src/test/rustdoc/issue-60726.rs index 167f0f039c15e..fbb0f82ae3957 100644 --- a/src/test/rustdoc/issue-60726.rs +++ b/src/test/rustdoc/issue-60726.rs @@ -26,9 +26,9 @@ where {} // @has issue_60726/struct.IntoIter.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl !Send for IntoIter" -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl !Sync for IntoIter" pub struct IntoIter{ hello:DynTrait>, diff --git a/src/test/rustdoc/issue-75588.rs b/src/test/rustdoc/issue-75588.rs index ac97b94fb351b..3b11059a755d0 100644 --- a/src/test/rustdoc/issue-75588.rs +++ b/src/test/rustdoc/issue-75588.rs @@ -10,8 +10,8 @@ extern crate realcore; extern crate real_gimli; // issue #74672 -// @!has foo/trait.Deref.html '//*[@id="impl-Deref-for-EndianSlice"]//h3[@class="code-header in-band"]' 'impl Deref for EndianSlice' +// @!has foo/trait.Deref.html '//*[@id="impl-Deref-for-EndianSlice"]//h3[@class="code-header"]' 'impl Deref for EndianSlice' pub use realcore::Deref; -// @has foo/trait.Join.html '//*[@id="impl-Join-for-Foo"]//h3[@class="code-header in-band"]' 'impl Join for Foo' +// @has foo/trait.Join.html '//*[@id="impl-Join-for-Foo"]//h3[@class="code-header"]' 'impl Join for Foo' pub use realcore::Join; diff --git a/src/test/rustdoc/issue-80233-normalize-auto-trait.rs b/src/test/rustdoc/issue-80233-normalize-auto-trait.rs index 515e617b4f4ce..62fbc2444dbc2 100644 --- a/src/test/rustdoc/issue-80233-normalize-auto-trait.rs +++ b/src/test/rustdoc/issue-80233-normalize-auto-trait.rs @@ -31,7 +31,7 @@ impl Trait3 for Vec { pub struct Struct1 {} // @has issue_80233_normalize_auto_trait/struct.Question.html -// @has - '//h3[@class="code-header in-band"]' 'impl Send for Question' +// @has - '//h3[@class="code-header"]' 'impl Send for Question' pub struct Question { pub ins: < as Trait3>::Type3 as Trait2>::Type2, } diff --git a/src/test/rustdoc/issue-82465-asref-for-and-of-local.rs b/src/test/rustdoc/issue-82465-asref-for-and-of-local.rs index 8999e6a889bda..adf4d111a6cb9 100644 --- a/src/test/rustdoc/issue-82465-asref-for-and-of-local.rs +++ b/src/test/rustdoc/issue-82465-asref-for-and-of-local.rs @@ -1,14 +1,14 @@ use std::convert::AsRef; pub struct Local; -// @has issue_82465_asref_for_and_of_local/struct.Local.html '//h3[@class="code-header in-band"]' 'impl AsRef for Local' +// @has issue_82465_asref_for_and_of_local/struct.Local.html '//h3[@class="code-header"]' 'impl AsRef for Local' impl AsRef for Local { fn as_ref(&self) -> &str { todo!() } } -// @has - '//h3[@class="code-header in-band"]' 'impl AsRef for str' +// @has - '//h3[@class="code-header"]' 'impl AsRef for str' impl AsRef for str { fn as_ref(&self) -> &Local { todo!() diff --git a/src/test/rustdoc/issue-98697.rs b/src/test/rustdoc/issue-98697.rs index a8841f137fecf..d50268509b2c1 100644 --- a/src/test/rustdoc/issue-98697.rs +++ b/src/test/rustdoc/issue-98697.rs @@ -12,6 +12,6 @@ extern crate issue_98697_reexport_with_anonymous_lifetime; // @!has issue_98697/fn.repro.html '//pre[@class="rust fn"]/code' 'for<' pub use issue_98697_reexport_with_anonymous_lifetime::repro; -// @has issue_98697/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl MyTrait<&Extra> for Extra' -// @!has issue_98697/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl<' +// @has issue_98697/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl MyTrait<&Extra> for Extra' +// @!has issue_98697/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl<' pub use issue_98697_reexport_with_anonymous_lifetime::Extra; diff --git a/src/test/rustdoc/negative-impl.rs b/src/test/rustdoc/negative-impl.rs index 61a2398686230..af19c784d6d05 100644 --- a/src/test/rustdoc/negative-impl.rs +++ b/src/test/rustdoc/negative-impl.rs @@ -5,10 +5,10 @@ pub struct Alpha; // @matches negative_impl/struct.Bravo.html '//pre' "pub struct Bravo" pub struct Bravo(B); -// @matches negative_impl/struct.Alpha.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @matches negative_impl/struct.Alpha.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl !Send for Alpha" impl !Send for Alpha {} -// @matches negative_impl/struct.Bravo.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' "\ +// @matches negative_impl/struct.Bravo.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' "\ // impl !Send for Bravo" impl !Send for Bravo {} diff --git a/src/test/rustdoc/primitive-reference.rs b/src/test/rustdoc/primitive-reference.rs index 5c11934060922..431c9aa79c7f9 100644 --- a/src/test/rustdoc/primitive-reference.rs +++ b/src/test/rustdoc/primitive-reference.rs @@ -14,7 +14,7 @@ // There should be only one implementation listed. // @count - '//*[@class="impl has-srclink"]' 1 -// @has - '//*[@id="impl-Foo%3C%26A%3E-for-%26B"]/*[@class="code-header in-band"]' \ +// @has - '//*[@id="impl-Foo%3C%26A%3E-for-%26B"]/*[@class="code-header"]' \ // 'impl Foo<&A> for &B' #[doc(primitive = "reference")] /// this is a test! diff --git a/src/test/rustdoc/primitive/primitive-generic-impl.rs b/src/test/rustdoc/primitive/primitive-generic-impl.rs index eebb2cf5a355d..7b336b3981047 100644 --- a/src/test/rustdoc/primitive/primitive-generic-impl.rs +++ b/src/test/rustdoc/primitive/primitive-generic-impl.rs @@ -1,7 +1,7 @@ #![feature(rustdoc_internals)] #![crate_name = "foo"] -// @has foo/primitive.i32.html '//*[@id="impl-ToString-for-i32"]//h3[@class="code-header in-band"]' 'impl ToString for T' +// @has foo/primitive.i32.html '//*[@id="impl-ToString-for-i32"]//h3[@class="code-header"]' 'impl ToString for T' #[doc(primitive = "i32")] /// Some useless docs, wouhou! diff --git a/src/test/rustdoc/recursive-deref.rs b/src/test/rustdoc/recursive-deref.rs index 2ab9d44be6dac..aa38485c44558 100644 --- a/src/test/rustdoc/recursive-deref.rs +++ b/src/test/rustdoc/recursive-deref.rs @@ -9,7 +9,7 @@ impl C { pub fn c(&self) {} } -// @has recursive_deref/struct.A.html '//h3[@class="code-header in-band"]' 'impl Deref for A' +// @has recursive_deref/struct.A.html '//h3[@class="code-header"]' 'impl Deref for A' // @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)' impl Deref for A { type Target = B; @@ -19,7 +19,7 @@ impl Deref for A { } } -// @has recursive_deref/struct.B.html '//h3[@class="code-header in-band"]' 'impl Deref for B' +// @has recursive_deref/struct.B.html '//h3[@class="code-header"]' 'impl Deref for B' // @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)' impl Deref for B { type Target = C; @@ -29,7 +29,7 @@ impl Deref for B { } } -// @has recursive_deref/struct.C.html '//h3[@class="code-header in-band"]' 'impl Deref for C' +// @has recursive_deref/struct.C.html '//h3[@class="code-header"]' 'impl Deref for C' impl Deref for C { type Target = B; @@ -49,7 +49,7 @@ impl G { pub fn g() {} } -// @has recursive_deref/struct.D.html '//h3[@class="code-header in-band"]' 'impl Deref for D' +// @has recursive_deref/struct.D.html '//h3[@class="code-header"]' 'impl Deref for D' // We also check that `G::g` method isn't rendered because there is no `self` argument. // @!has '-' '//*[@id="deref-methods-G"]' '' impl Deref for D { @@ -60,7 +60,7 @@ impl Deref for D { } } -// @has recursive_deref/struct.E.html '//h3[@class="code-header in-band"]' 'impl Deref for E' +// @has recursive_deref/struct.E.html '//h3[@class="code-header"]' 'impl Deref for E' // We also check that `G::g` method isn't rendered because there is no `self` argument. // @!has '-' '//*[@id="deref-methods-G"]' '' impl Deref for E { @@ -71,7 +71,7 @@ impl Deref for E { } } -// @has recursive_deref/struct.F.html '//h3[@class="code-header in-band"]' 'impl Deref for F' +// @has recursive_deref/struct.F.html '//h3[@class="code-header"]' 'impl Deref for F' // We also check that `G::g` method isn't rendered because there is no `self` argument. // @!has '-' '//*[@id="deref-methods-G"]' '' impl Deref for F { @@ -82,7 +82,7 @@ impl Deref for F { } } -// @has recursive_deref/struct.G.html '//h3[@class="code-header in-band"]' 'impl Deref for G' +// @has recursive_deref/struct.G.html '//h3[@class="code-header"]' 'impl Deref for G' impl Deref for G { type Target = E; @@ -100,7 +100,7 @@ impl I { pub fn i() {} } -// @has recursive_deref/struct.H.html '//h3[@class="code-header in-band"]' 'impl Deref for H' +// @has recursive_deref/struct.H.html '//h3[@class="code-header"]' 'impl Deref for H' // @!has '-' '//*[@id="deref-methods-I"]' '' impl Deref for H { type Target = I; @@ -110,7 +110,7 @@ impl Deref for H { } } -// @has recursive_deref/struct.I.html '//h3[@class="code-header in-band"]' 'impl Deref for I' +// @has recursive_deref/struct.I.html '//h3[@class="code-header"]' 'impl Deref for I' impl Deref for I { type Target = H; diff --git a/src/test/rustdoc/rfc-2632-const-trait-impl.rs b/src/test/rustdoc/rfc-2632-const-trait-impl.rs index f3e211e301742..8bd402291aabf 100644 --- a/src/test/rustdoc/rfc-2632-const-trait-impl.rs +++ b/src/test/rustdoc/rfc-2632-const-trait-impl.rs @@ -30,10 +30,10 @@ pub trait Tr { } // @has - '//section[@id="impl-Tr%3CT%3E-for-T"]' '' -// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header in-band"]' '~const' -// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header in-band"]/a[@class="trait"]' 'Clone' -// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header in-band"]/span[@class="where"]' '~const' -// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header in-band"]/span[@class="where fmt-newline"]' ': Clone' +// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]' '~const' +// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/a[@class="trait"]' 'Clone' +// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/span[@class="where"]' '~const' +// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone' impl const Tr for T where Option: ~const Clone + ~const Destruct, diff --git a/src/test/rustdoc/sidebar-links-to-foreign-impl.rs b/src/test/rustdoc/sidebar-links-to-foreign-impl.rs index 1551503965999..6712af527a377 100644 --- a/src/test/rustdoc/sidebar-links-to-foreign-impl.rs +++ b/src/test/rustdoc/sidebar-links-to-foreign-impl.rs @@ -6,9 +6,9 @@ // @has - '//*[@class="sidebar-title"]/a[@href="#foreign-impls"]' 'Implementations on Foreign Types' // @has - '//h2[@id="foreign-impls"]' 'Implementations on Foreign Types' // @has - '//*[@class="sidebar-elems"]//section//a[@href="#impl-Foo-for-u32"]' 'u32' -// @has - '//*[@id="impl-Foo-for-u32"]//h3[@class="code-header in-band"]' 'impl Foo for u32' +// @has - '//*[@id="impl-Foo-for-u32"]//h3[@class="code-header"]' 'impl Foo for u32' // @has - '//*[@class="sidebar-elems"]//section//a[@href="#impl-Foo-for-%26%27a%20str"]' "&'a str" -// @has - '//*[@id="impl-Foo-for-%26%27a%20str"]//h3[@class="code-header in-band"]' "impl<'a> Foo for &'a str" +// @has - '//*[@id="impl-Foo-for-%26%27a%20str"]//h3[@class="code-header"]' "impl<'a> Foo for &'a str" pub trait Foo {} impl Foo for u32 {} diff --git a/src/test/rustdoc/sized_trait.rs b/src/test/rustdoc/sized_trait.rs index 36718ebe1a630..feef4de8d57fe 100644 --- a/src/test/rustdoc/sized_trait.rs +++ b/src/test/rustdoc/sized_trait.rs @@ -11,7 +11,7 @@ pub struct Bar { pub struct Foo(T); // @has foo/struct.Unsized.html -// @has - '//*[@id="impl-Sized-for-Unsized"]//h3[@class="code-header in-band"]' 'impl !Sized for Unsized' +// @has - '//*[@id="impl-Sized-for-Unsized"]//h3[@class="code-header"]' 'impl !Sized for Unsized' pub struct Unsized { data: [u8], } diff --git a/src/test/rustdoc/src-links-auto-impls.rs b/src/test/rustdoc/src-links-auto-impls.rs index 313a4b1189334..953563833c9c7 100644 --- a/src/test/rustdoc/src-links-auto-impls.rs +++ b/src/test/rustdoc/src-links-auto-impls.rs @@ -1,11 +1,11 @@ #![crate_name = "foo"] // @has foo/struct.Unsized.html -// @has - '//*[@id="impl-Sized-for-Unsized"]/h3[@class="code-header in-band"]' 'impl !Sized for Unsized' +// @has - '//*[@id="impl-Sized-for-Unsized"]/h3[@class="code-header"]' 'impl !Sized for Unsized' // @!has - '//*[@id="impl-Sized-for-Unsized"]//a[@class="srclink"]' 'source' -// @has - '//*[@id="impl-Sync-for-Unsized"]/h3[@class="code-header in-band"]' 'impl Sync for Unsized' +// @has - '//*[@id="impl-Sync-for-Unsized"]/h3[@class="code-header"]' 'impl Sync for Unsized' // @!has - '//*[@id="impl-Sync-for-Unsized"]//a[@class="srclink"]' 'source' -// @has - '//*[@id="impl-Any-for-Unsized"]/h3[@class="code-header in-band"]' 'impl Any for T' +// @has - '//*[@id="impl-Any-for-Unsized"]/h3[@class="code-header"]' 'impl Any for T' // @has - '//*[@id="impl-Any-for-Unsized"]//a[@class="srclink rightside"]' 'source' pub struct Unsized { data: [u8], diff --git a/src/test/rustdoc/synthetic_auto/basic.rs b/src/test/rustdoc/synthetic_auto/basic.rs index 19138fd1aceb2..7c6a388653c49 100644 --- a/src/test/rustdoc/synthetic_auto/basic.rs +++ b/src/test/rustdoc/synthetic_auto/basic.rs @@ -1,6 +1,6 @@ // @has basic/struct.Foo.html -// @has - '//h3[@class="code-header in-band"]' 'impl Send for Foowhere T: Send' -// @has - '//h3[@class="code-header in-band"]' 'impl Sync for Foowhere T: Sync' +// @has - '//h3[@class="code-header"]' 'impl Send for Foowhere T: Send' +// @has - '//h3[@class="code-header"]' 'impl Sync for Foowhere T: Sync' // @count - '//*[@id="implementations-list"]//*[@class="impl has-srclink"]' 0 // @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]' 5 pub struct Foo { diff --git a/src/test/rustdoc/synthetic_auto/complex.rs b/src/test/rustdoc/synthetic_auto/complex.rs index 39f78983da2b0..43393c21fddb4 100644 --- a/src/test/rustdoc/synthetic_auto/complex.rs +++ b/src/test/rustdoc/synthetic_auto/complex.rs @@ -20,7 +20,7 @@ mod foo { } // @has complex/struct.NotOuter.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl<'a, T, K: ?Sized> Send for Outer<'a, T, K>where K: for<'b> Fn((&'b bool, &'a u8)) \ // -> &'b i8, T: MyTrait<'a>, >::MyItem: Copy, 'a: 'static" diff --git a/src/test/rustdoc/synthetic_auto/crate-local.rs b/src/test/rustdoc/synthetic_auto/crate-local.rs index 58b787dfafc7c..ed01f63f998b9 100644 --- a/src/test/rustdoc/synthetic_auto/crate-local.rs +++ b/src/test/rustdoc/synthetic_auto/crate-local.rs @@ -3,7 +3,7 @@ pub auto trait Banana {} // @has crate_local/struct.Peach.html -// @has - '//h3[@class="code-header in-band"]' 'impl Banana for Peach' -// @has - '//h3[@class="code-header in-band"]' 'impl Send for Peach' -// @has - '//h3[@class="code-header in-band"]' 'impl Sync for Peach' +// @has - '//h3[@class="code-header"]' 'impl Banana for Peach' +// @has - '//h3[@class="code-header"]' 'impl Send for Peach' +// @has - '//h3[@class="code-header"]' 'impl Sync for Peach' pub struct Peach; diff --git a/src/test/rustdoc/synthetic_auto/lifetimes.rs b/src/test/rustdoc/synthetic_auto/lifetimes.rs index 0c94850e78608..33170a844359b 100644 --- a/src/test/rustdoc/synthetic_auto/lifetimes.rs +++ b/src/test/rustdoc/synthetic_auto/lifetimes.rs @@ -9,10 +9,10 @@ where {} // @has lifetimes/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl<'c, K> Send for Foo<'c, K>where K: for<'b> Fn(&'b bool) -> &'c u8, 'c: 'static" // -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl<'c, K> Sync for Foo<'c, K>where K: Sync" pub struct Foo<'c, K: 'c> { inner_field: Inner<'c, K>, diff --git a/src/test/rustdoc/synthetic_auto/manual.rs b/src/test/rustdoc/synthetic_auto/manual.rs index 35047e3e8c071..77c04ad2ad942 100644 --- a/src/test/rustdoc/synthetic_auto/manual.rs +++ b/src/test/rustdoc/synthetic_auto/manual.rs @@ -1,8 +1,8 @@ // @has manual/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // 'impl Sync for Foowhere T: Sync' // -// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // 'impl Send for Foo' // // @count - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]' 1 diff --git a/src/test/rustdoc/synthetic_auto/negative.rs b/src/test/rustdoc/synthetic_auto/negative.rs index 66e749ac38d96..2c2c848a5e0fb 100644 --- a/src/test/rustdoc/synthetic_auto/negative.rs +++ b/src/test/rustdoc/synthetic_auto/negative.rs @@ -3,10 +3,10 @@ pub struct Inner { } // @has negative/struct.Outer.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl !Send for Outer" // -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl !Sync for Outer" pub struct Outer { inner_field: Inner, diff --git a/src/test/rustdoc/synthetic_auto/nested.rs b/src/test/rustdoc/synthetic_auto/nested.rs index 09587bcc30f13..423bf115ab165 100644 --- a/src/test/rustdoc/synthetic_auto/nested.rs +++ b/src/test/rustdoc/synthetic_auto/nested.rs @@ -9,10 +9,10 @@ where } // @has nested/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // 'impl Send for Foowhere T: Copy' // -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // 'impl Sync for Foowhere T: Sync' pub struct Foo { inner_field: Inner, diff --git a/src/test/rustdoc/synthetic_auto/no-redundancy.rs b/src/test/rustdoc/synthetic_auto/no-redundancy.rs index 41375decc8a4a..59f33623322a9 100644 --- a/src/test/rustdoc/synthetic_auto/no-redundancy.rs +++ b/src/test/rustdoc/synthetic_auto/no-redundancy.rs @@ -9,7 +9,7 @@ where } // @has no_redundancy/struct.Outer.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl Send for Outerwhere T: Send + Copy" pub struct Outer { inner_field: Inner, diff --git a/src/test/rustdoc/synthetic_auto/overflow.rs b/src/test/rustdoc/synthetic_auto/overflow.rs index c132ab6fb1b3e..35a487c764dc3 100644 --- a/src/test/rustdoc/synthetic_auto/overflow.rs +++ b/src/test/rustdoc/synthetic_auto/overflow.rs @@ -21,7 +21,7 @@ enum TyData { struct VariableKind(I::InternedType); // @has overflow/struct.BoundVarsCollector.html -// @has - '//h3[@class="code-header in-band"]' "impl<'tcx> Send for BoundVarsCollector<'tcx>" +// @has - '//h3[@class="code-header"]' "impl<'tcx> Send for BoundVarsCollector<'tcx>" pub struct BoundVarsCollector<'tcx> { val: VariableKind> } diff --git a/src/test/rustdoc/synthetic_auto/project.rs b/src/test/rustdoc/synthetic_auto/project.rs index e80b1b1dc9bcf..558ff2add400c 100644 --- a/src/test/rustdoc/synthetic_auto/project.rs +++ b/src/test/rustdoc/synthetic_auto/project.rs @@ -23,10 +23,10 @@ where } // @has project/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl<'c, K> Send for Foo<'c, K>where K: MyTrait, 'c: 'static" // -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl<'c, K> Sync for Foo<'c, K>where K: MyTrait, ::MyItem: OtherTrait, \ // 'c: 'static," pub struct Foo<'c, K: 'c> { diff --git a/src/test/rustdoc/synthetic_auto/self-referential.rs b/src/test/rustdoc/synthetic_auto/self-referential.rs index d15a8de7d2fe1..c6ae96de77672 100644 --- a/src/test/rustdoc/synthetic_auto/self-referential.rs +++ b/src/test/rustdoc/synthetic_auto/self-referential.rs @@ -23,7 +23,7 @@ impl Pattern for Wrapper { // @has self_referential/struct.WriteAndThen.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl Send for WriteAndThenwhere ::Value: Send" pub struct WriteAndThen(pub P1::Value,pub > as Pattern>::Value) where P1: Pattern; diff --git a/src/test/rustdoc/synthetic_auto/static-region.rs b/src/test/rustdoc/synthetic_auto/static-region.rs index 08e9567313e22..1a76cb919c298 100644 --- a/src/test/rustdoc/synthetic_auto/static-region.rs +++ b/src/test/rustdoc/synthetic_auto/static-region.rs @@ -3,7 +3,7 @@ pub trait OwnedTrait<'a> { } // @has static_region/struct.Owned.html -// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl Send for Ownedwhere >::Reader: Send" pub struct Owned where T: OwnedTrait<'static> { marker: >::Reader, diff --git a/src/test/rustdoc/traits-in-bodies.rs b/src/test/rustdoc/traits-in-bodies.rs index 6d450a625d0bf..a65dd7a546cdc 100644 --- a/src/test/rustdoc/traits-in-bodies.rs +++ b/src/test/rustdoc/traits-in-bodies.rs @@ -4,7 +4,7 @@ pub struct Bounded(T); // @has traits_in_bodies/struct.SomeStruct.html -// @has - '//h3[@class="code-header in-band"]' 'impl Clone for SomeStruct' +// @has - '//h3[@class="code-header"]' 'impl Clone for SomeStruct' pub struct SomeStruct; fn asdf() -> Bounded { @@ -18,7 +18,7 @@ fn asdf() -> Bounded { } // @has traits_in_bodies/struct.Point.html -// @has - '//h3[@class="code-header in-band"]' 'impl Copy for Point' +// @has - '//h3[@class="code-header"]' 'impl Copy for Point' #[derive(Clone)] pub struct Point { x: i32, @@ -31,7 +31,7 @@ const _FOO: () = { }; // @has traits_in_bodies/struct.Inception.html -// @has - '//h3[@class="code-header in-band"]' 'impl Clone for Inception' +// @has - '//h3[@class="code-header"]' 'impl Clone for Inception' pub struct Inception; static _BAR: usize = { diff --git a/src/test/rustdoc/typedef.rs b/src/test/rustdoc/typedef.rs index b68ec4557ad55..d5dfa9484891a 100644 --- a/src/test/rustdoc/typedef.rs +++ b/src/test/rustdoc/typedef.rs @@ -9,8 +9,8 @@ impl MyStruct { } // @has typedef/type.MyAlias.html -// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'impl MyAlias' -// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'impl MyTrait for MyAlias' +// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'impl MyAlias' +// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'impl MyTrait for MyAlias' // @hasraw - 'Alias docstring' // @has - '//*[@class="sidebar"]//*[@class="location"]' 'MyAlias' // @has - '//*[@class="sidebar"]//a[@href="#implementations"]' 'Methods' diff --git a/src/test/rustdoc/where.rs b/src/test/rustdoc/where.rs index 68a146bfa55b8..8b5bce28f5a2a 100644 --- a/src/test/rustdoc/where.rs +++ b/src/test/rustdoc/where.rs @@ -13,7 +13,7 @@ pub fn charlie() where C: MyTrait {} pub struct Delta(D); -// @has foo/struct.Delta.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has foo/struct.Delta.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl Deltawhere D: MyTrait" impl Delta where D: MyTrait { pub fn delta() {} @@ -43,17 +43,17 @@ pub trait TraitWhere { { todo!() } } -// @has foo/struct.Echo.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has foo/struct.Echo.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl MyTrait for Echowhere E: MyTrait" -// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//h3[@class="code-header in-band"]' \ +// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//h3[@class="code-header"]' \ // "impl MyTrait for Echowhere E: MyTrait" impl MyTrait for Echowhere E: MyTrait {} pub enum Foxtrot { Foxtrot1(F) } -// @has foo/enum.Foxtrot.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \ +// @has foo/enum.Foxtrot.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' \ // "impl MyTrait for Foxtrotwhere F: MyTrait" -// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//h3[@class="code-header in-band"]' \ +// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//h3[@class="code-header"]' \ // "impl MyTrait for Foxtrotwhere F: MyTrait" impl MyTrait for Foxtrotwhere F: MyTrait {} From a50081e102c72642c87e27ab23ed07f4c9c8efc9 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 25 Sep 2022 14:58:49 -0700 Subject: [PATCH 13/15] Round offset to whole integer --- src/test/rustdoc-gui/implementors.goml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/rustdoc-gui/implementors.goml b/src/test/rustdoc-gui/implementors.goml index dc3b2e122680c..2fcbee27147e4 100644 --- a/src/test/rustdoc-gui/implementors.goml +++ b/src/test/rustdoc-gui/implementors.goml @@ -19,12 +19,12 @@ goto: file://|DOC_PATH|/test_docs/struct.HasEmptyTraits.html compare-elements-position-near-false: ( "#impl-EmptyTrait1-for-HasEmptyTraits", "#impl-EmptyTrait2-for-HasEmptyTraits", - {"y": 34.1875}, + {"y": 34}, ) compare-elements-position-near: ( "#impl-EmptyTrait3-for-HasEmptyTraits h3", "#impl-EmptyTrait3-for-HasEmptyTraits .item-info", - {"y": 34.1875}, + {"y": 34}, ) // Now check that re-exports work correctly. From 730ead80479d98de5cc1b555c558b5b0176fded8 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 24 Sep 2022 18:53:53 +0000 Subject: [PATCH 14/15] Only generate closure def id for async fns with body --- compiler/rustc_resolve/src/def_collector.rs | 10 +++++++--- src/test/ui/async-await/in-trait/issue-102219.rs | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/async-await/in-trait/issue-102219.rs diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 3f88f44ff21a3..7e83f2a722107 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -1,6 +1,5 @@ use crate::{ImplTraitContext, Resolver}; use rustc_ast::visit::{self, FnKind}; -use rustc_ast::walk_list; use rustc_ast::*; use rustc_expand::expand::AstFragment; use rustc_hir::def_id::LocalDefId; @@ -148,8 +147,13 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> { self.with_parent(return_impl_trait_id, |this| { this.visit_fn_ret_ty(&sig.decl.output) }); - let closure_def = self.create_def(closure_id, DefPathData::ClosureExpr, span); - self.with_parent(closure_def, |this| walk_list!(this, visit_block, body)); + // If this async fn has no body (i.e. it's an async fn signature in a trait) + // then the closure_def will never be used, and we should avoid generating a + // def-id for it. + if let Some(body) = body { + let closure_def = self.create_def(closure_id, DefPathData::ClosureExpr, span); + self.with_parent(closure_def, |this| this.visit_block(body)); + } return; } } diff --git a/src/test/ui/async-await/in-trait/issue-102219.rs b/src/test/ui/async-await/in-trait/issue-102219.rs new file mode 100644 index 0000000000000..9a35f6515cb1a --- /dev/null +++ b/src/test/ui/async-await/in-trait/issue-102219.rs @@ -0,0 +1,10 @@ +// compile-flags:--crate-type=lib +// edition:2021 +// check-pass + +#![feature(async_fn_in_trait)] +#![allow(incomplete_features)] + +trait T { + async fn foo(); +} From e99f6fee441dfa71d58b37a10366bf8c5c9d52ac Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 24 Sep 2022 19:22:01 +0000 Subject: [PATCH 15/15] Only lower async fn body if it actually has a body --- compiler/rustc_ast_lowering/src/item.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 1251702c1ff6b..d9b18d68e537f 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1055,9 +1055,9 @@ impl<'hir> LoweringContext<'_, 'hir> { asyncness: Async, body: Option<&Block>, ) -> hir::BodyId { - let closure_id = match asyncness { - Async::Yes { closure_id, .. } => closure_id, - Async::No => return self.lower_fn_body_block(span, decl, body), + let (closure_id, body) = match (asyncness, body) { + (Async::Yes { closure_id, .. }, Some(body)) => (closure_id, body), + _ => return self.lower_fn_body_block(span, decl, body), }; self.lower_body(|this| { @@ -1199,16 +1199,15 @@ impl<'hir> LoweringContext<'_, 'hir> { parameters.push(new_parameter); } - let body_span = body.map_or(span, |b| b.span); let async_expr = this.make_async_expr( CaptureBy::Value, closure_id, None, - body_span, + body.span, hir::AsyncGeneratorKind::Fn, |this| { // Create a block from the user's function body: - let user_body = this.lower_block_expr_opt(body_span, body); + let user_body = this.lower_block_expr(body); // Transform into `drop-temps { }`, an expression: let desugared_span = @@ -1240,7 +1239,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ( this.arena.alloc_from_iter(parameters), - this.expr(body_span, async_expr, AttrVec::new()), + this.expr(body.span, async_expr, AttrVec::new()), ) }) }