Skip to content

Rollup of 7 pull requests #124295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7731135
alloc::Layout: explicitly document size invariant on the type level
RalfJung Mar 25, 2024
aa1653e
Rename coroutine_stalled_predicates
compiler-errors Apr 15, 2024
d29178c
Do check_coroutine_obligations once per typeck root
compiler-errors Apr 15, 2024
0650115
redundant ::{self}
compiler-errors Apr 15, 2024
a8c9a0b
crash -> test
compiler-errors Apr 16, 2024
f7ebad4
Emit suggestions when equality constraints are wrongly used
gurry Apr 16, 2024
c623319
Lower deref patterns to MIR
Nadrieril Mar 9, 2024
1dabacd
Don't fake borrow inside a deref pattern
Nadrieril Mar 9, 2024
5c4909b
Track mutability of deref patterns
Nadrieril Apr 3, 2024
377e095
Allow mutable bindings inside deref patterns
Nadrieril Apr 3, 2024
b55afe4
Address closure-related review
Nadrieril Apr 5, 2024
511bd78
Rework fake borrow calculation
Nadrieril Apr 6, 2024
5053180
Add a non-shallow fake borrow
Nadrieril Apr 6, 2024
436c612
Use deep fake borrows for deref patterns
Nadrieril Apr 5, 2024
217a4df
Test or-patterns inside deref patterns
Nadrieril Apr 8, 2024
726fb55
Fix documentation of `BorrowKind::Fake`
Nadrieril Apr 20, 2024
5646b65
Pass translation closure to add_to_diag_with() as reference
Xiretza Apr 18, 2024
c88bb6c
Allow nesting subdiagnostics
Xiretza Apr 20, 2024
b220b74
Fix source ordering of IntoDiagArg impls
Xiretza Apr 20, 2024
6974e9c
Move "elided lifetime in path" to subdiagnostic struct
Xiretza Apr 20, 2024
31e581e
Wrap dyn type with parentheses in suggestion
long-long-float Jan 25, 2024
4815155
Mark @RUSTC_BUILTIN search path usage as unstable
Veykril Apr 23, 2024
80f2b91
Rollup merge of #120929 - long-long-float:wrap-dyn-in-suggestion, r=f…
fmease Apr 23, 2024
68939f7
Rollup merge of #122591 - gurry:122162-impl-type-binding-suggestion, …
fmease Apr 23, 2024
332cac2
Rollup merge of #122598 - Nadrieril:full-derefpats, r=matthewjasper
fmease Apr 23, 2024
2d7d480
Rollup merge of #123048 - RalfJung:layout, r=dtolnay
fmease Apr 23, 2024
e15d6f9
Rollup merge of #123993 - compiler-errors:coroutine-obl, r=lcnr
fmease Apr 23, 2024
6e423e1
Rollup merge of #124218 - Xiretza:subsubdiagnostics, r=davidtwco
fmease Apr 23, 2024
5ff1fa9
Rollup merge of #124285 - ferrocene:unstable-L-rust-builtin, r=petroc…
fmease Apr 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow nesting subdiagnostics
  • Loading branch information
Xiretza committed Apr 21, 2024
commit c88bb6c011a034a8b29d2a61734de0d36a02a1e9
37 changes: 25 additions & 12 deletions compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl SubdiagnosticDerive {
span_field: None,
applicability: None,
has_suggestion_parts: false,
has_subdiagnostic: false,
is_enum,
};
builder.into_tokens().unwrap_or_else(|v| v.to_compile_error())
Expand Down Expand Up @@ -133,6 +134,10 @@ struct SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
/// during finalization if still `false`.
has_suggestion_parts: bool,

/// Set to true when a `#[subdiagnostic]` field is encountered, used to suppress the error
/// emitted when no subdiagnostic kinds are specified on the variant itself.
has_subdiagnostic: bool,

/// Set to true when this variant is an enum variant rather than just the body of a struct.
is_enum: bool,
}
Expand Down Expand Up @@ -373,6 +378,13 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {

Ok(quote! {})
}
"subdiagnostic" => {
let f = &self.parent.f;
let diag = &self.parent.diag;
let binding = &info.binding;
self.has_subdiagnostic = true;
Ok(quote! { #binding.add_to_diag_with(#diag, #f); })
}
_ => {
let mut span_attrs = vec![];
if kind_stats.has_multipart_suggestion {
Expand Down Expand Up @@ -480,18 +492,6 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {

pub(crate) fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveError> {
let kind_slugs = self.identify_kind()?;
if kind_slugs.is_empty() {
if self.is_enum {
// It's okay for a variant to not be a subdiagnostic at all..
return Ok(quote! {});
} else {
// ..but structs should always be _something_.
throw_span_err!(
self.variant.ast().ident.span().unwrap(),
"subdiagnostic kind not specified"
);
}
};

let kind_stats: KindsStatistics =
kind_slugs.iter().map(|(kind, _slug, _no_span)| kind).collect();
Expand All @@ -510,6 +510,19 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
.map(|binding| self.generate_field_attr_code(binding, kind_stats))
.collect();

if kind_slugs.is_empty() {
if self.is_enum {
// It's okay for a variant to not be a subdiagnostic at all..
return Ok(quote! {});
} else if !self.has_subdiagnostic {
// ..but structs should always be _something_.
throw_span_err!(
self.variant.ast().ident.span().unwrap(),
"subdiagnostic kind not specified"
);
}
};

let span_field = self.span_field.value_ref();

let diag = &self.parent.diag;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ decl_derive!(
help,
note,
warning,
subdiagnostic,
suggestion,
suggestion_short,
suggestion_hidden,
Expand Down
10 changes: 10 additions & 0 deletions tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,13 @@ struct PrimarySpanOnVec {
//~| NOTE there must be exactly one primary span
sub: Vec<Span>,
}

#[derive(Subdiagnostic)]
struct NestedParent {
#[subdiagnostic]
single_sub: A,
#[subdiagnostic]
option_sub: Option<A>,
#[subdiagnostic]
vec_sub: Vec<A>,
}