Skip to content

Commit 21bb1a4

Browse files
committed
Allow for a missing adt_def in NamePrivacyVisitor.
This was caused by 72b172b in #121206. That commit removed an early return from `analysis` when there are stashed errors. As a result, it's possible to reach privacy analysis when there are stashed errors, which means more code paths can be reached. One such code path was handled in that commit, where a `span_bug` was changed to a `span_delayed_bug`. This commit handles another such code path uncovered by fuzzing, in much the same way. Fixes #121455.
1 parent c5f69bd commit 21bb1a4

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Diff for: compiler/rustc_privacy/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,10 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
988988
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
989989
if let hir::ExprKind::Struct(qpath, fields, ref base) = expr.kind {
990990
let res = self.typeck_results().qpath_res(qpath, expr.hir_id);
991-
let adt = self.typeck_results().expr_ty(expr).ty_adt_def().unwrap();
991+
let Some(adt) = self.typeck_results().expr_ty(expr).ty_adt_def() else {
992+
self.tcx.dcx().span_delayed_bug(expr.span, "no adt_def for expression");
993+
return;
994+
};
992995
let variant = adt.variant_of_res(res);
993996
if let Some(base) = *base {
994997
// If the expression uses FRU we need to make sure all the unmentioned fields

Diff for: tests/ui/privacy/unreachable-issue-121455.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn test(s: &Self::Id) {
2+
//~^ ERROR failed to resolve: `Self` is only available in impls, traits, and type definitions
3+
match &s[0..3] {}
4+
}
5+
6+
fn main() {}

Diff for: tests/ui/privacy/unreachable-issue-121455.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
2+
--> $DIR/unreachable-issue-121455.rs:1:13
3+
|
4+
LL | fn test(s: &Self::Id) {
5+
| ^^^^ `Self` is only available in impls, traits, and type definitions
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)