Auto merge of #90358 - DevinR528:omitted-field-fix, r=jackh726
Fix exposing fields marked unstable or doc hidden Closes https://github.com/rust-lang/rust/issues/89837 Work towards https://github.com/rust-lang/rust/issues/89554 Filter fields that are marked `doc(hidden)` or are unstable with that feature turned off. This brings structs and enums into alignment behavior-wise when emitting warning/errors about pattern exhaustiveness/reachability. cc `@Nadrieril`
This commit is contained in:
commit
bbbd48fa6d
21 changed files with 422 additions and 79 deletions
|
@ -692,11 +692,11 @@ impl<'tcx> Constructor<'tcx> {
|
|||
}
|
||||
|
||||
/// Checks if the `Constructor` is a `Constructor::Variant` with a `#[doc(hidden)]`
|
||||
/// attribute.
|
||||
/// attribute from a type not local to the current crate.
|
||||
pub(super) fn is_doc_hidden_variant(&self, pcx: PatCtxt<'_, '_, 'tcx>) -> bool {
|
||||
if let Constructor::Variant(idx) = self && let ty::Adt(adt, _) = pcx.ty.kind() {
|
||||
let variant_def_id = adt.variant(*idx).def_id;
|
||||
return pcx.cx.tcx.is_doc_hidden(variant_def_id);
|
||||
let variant_def_id = adt.variants()[*idx].def_id;
|
||||
return pcx.cx.tcx.is_doc_hidden(variant_def_id) && !variant_def_id.is_local();
|
||||
}
|
||||
false
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator;
|
|||
use rustc_hir::{HirId, Pat, PatKind};
|
||||
use rustc_infer::infer;
|
||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use rustc_middle::middle::stability::EvalResult;
|
||||
use rustc_middle::ty::{self, Adt, BindingMode, Ty, TypeFoldable};
|
||||
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
|
||||
use rustc_span::hygiene::DesugaringKind;
|
||||
|
@ -1308,6 +1309,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
.copied()
|
||||
.filter(|(field, _)| {
|
||||
field.vis.is_accessible_from(tcx.parent_module(pat.hir_id).to_def_id(), tcx)
|
||||
&& !matches!(
|
||||
tcx.eval_stability(field.did, None, DUMMY_SP, None),
|
||||
EvalResult::Deny { .. }
|
||||
)
|
||||
// We only want to report the error if it is hidden and not local
|
||||
&& !(tcx.is_doc_hidden(field.did) && !field.did.is_local())
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue