Skip to content

Commit

Permalink
Allow for a missing adt_def in NamePrivacyVisitor.
Browse files Browse the repository at this point in the history
This was caused by 72b172b in rust-lang#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 rust-lang#121455.
  • Loading branch information
nnethercote committed Feb 22, 2024
1 parent c5f69bd commit 21bb1a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,10 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
if let hir::ExprKind::Struct(qpath, fields, ref base) = expr.kind {
let res = self.typeck_results().qpath_res(qpath, expr.hir_id);
let adt = self.typeck_results().expr_ty(expr).ty_adt_def().unwrap();
let Some(adt) = self.typeck_results().expr_ty(expr).ty_adt_def() else {
self.tcx.dcx().span_delayed_bug(expr.span, "no adt_def for expression");
return;
};
let variant = adt.variant_of_res(res);
if let Some(base) = *base {
// If the expression uses FRU we need to make sure all the unmentioned fields
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/privacy/unreachable-issue-121455.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn test(s: &Self::Id) {
//~^ ERROR failed to resolve: `Self` is only available in impls, traits, and type definitions
match &s[0..3] {}
}

fn main() {}
9 changes: 9 additions & 0 deletions tests/ui/privacy/unreachable-issue-121455.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
--> $DIR/unreachable-issue-121455.rs:1:13
|
LL | fn test(s: &Self::Id) {
| ^^^^ `Self` is only available in impls, traits, and type definitions

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0433`.

0 comments on commit 21bb1a4

Please sign in to comment.