diff options
| author | kadmin <julianknodt@gmail.com> | 2022-12-30 05:09:09 +0000 |
|---|---|---|
| committer | kadmin <julianknodt@gmail.com> | 2023-01-03 23:26:57 +0000 |
| commit | 077fae94a175408d8d7624af8a9fb96ce71bf3c3 (patch) | |
| tree | 2a98c4029967cb4212063a957b6d7c382832964d /compiler/rustc_hir_analysis/src | |
| parent | 2c7536eaae59b44ff5259183ca98384129d69dd0 (diff) | |
| download | rust-077fae94a175408d8d7624af8a9fb96ce71bf3c3.tar.gz rust-077fae94a175408d8d7624af8a9fb96ce71bf3c3.zip | |
Add note about wrapping in braces
Previously it was not clear why this errored or if it was even supported, as there was no diagnostic that suggested wrapping it in braces. Thus, add a simple diagnostic that suggests wrapping enum variants in braces.
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/astconv/mod.rs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index d7ab942665b..686db67e36d 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -1199,17 +1199,26 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { (_, _) => { let got = if let Some(_) = term.ty() { "type" } else { "constant" }; let expected = def_kind.descr(assoc_item_def_id); - let reported = tcx - .sess - .struct_span_err( + let mut err = tcx.sess.struct_span_err( + binding.span, + &format!("expected {expected} bound, found {got}"), + ); + err.span_note( + tcx.def_span(assoc_item_def_id), + &format!("{expected} defined here"), + ); + + if let hir::def::DefKind::AssocConst = def_kind + && let Some(t) = term.ty() && (t.is_enum() || t.references_error()) + && tcx.features().associated_const_equality { + err.span_suggestion( binding.span, - &format!("expected {expected} bound, found {got}"), - ) - .span_note( - tcx.def_span(assoc_item_def_id), - &format!("{expected} defined here"), - ) - .emit(); + "if equating a const, try wrapping with braces", + format!("{} = {{ const }}", binding.item_name), + Applicability::HasPlaceholders, + ); + } + let reported = err.emit(); term = match def_kind { hir::def::DefKind::AssocTy => { tcx.ty_error_with_guaranteed(reported).into() |
