diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-06-20 14:56:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-20 14:56:41 +0200 |
| commit | 7bde23bb4f0cc74c5566e85501a43426c1be1bef (patch) | |
| tree | 632b37141c9861b86c43f8a8c6a2af0ee670c105 | |
| parent | ce1151c04c8aa529a81d124d41cc900c7da7d4ac (diff) | |
| parent | f725b97014169475d38dfe278028f06bc634728e (diff) | |
| download | rust-7bde23bb4f0cc74c5566e85501a43426c1be1bef.tar.gz rust-7bde23bb4f0cc74c5566e85501a43426c1be1bef.zip | |
Rollup merge of #98159 - PrestonFrom:issue_95665, r=petrochenkov
Include ForeignItem when visiting types for WF check Addresses Issue 95665 by including `hir::Node::ForeignItem` as a valid type to visit in `diagnostic_hir_wf_check`. Fixes #95665
| -rw-r--r-- | compiler/rustc_typeck/src/hir_wf_check.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/wf/issue-95665.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/wf/issue-95665.stderr | 15 |
3 files changed, 37 insertions, 1 deletions
diff --git a/compiler/rustc_typeck/src/hir_wf_check.rs b/compiler/rustc_typeck/src/hir_wf_check.rs index b4b438a561a..4392b9aada9 100644 --- a/compiler/rustc_typeck/src/hir_wf_check.rs +++ b/compiler/rustc_typeck/src/hir_wf_check.rs @@ -1,7 +1,7 @@ use crate::collect::ItemCtxt; use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; -use rustc_hir::HirId; +use rustc_hir::{ForeignItem, ForeignItemKind, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::TraitEngine; use rustc_infer::traits::{ObligationCause, WellFormedLoc}; @@ -141,6 +141,9 @@ fn diagnostic_hir_wf_check<'tcx>( ref item => bug!("Unexpected item {:?}", item), }, hir::Node::Field(field) => Some(field.ty), + hir::Node::ForeignItem(ForeignItem { + kind: ForeignItemKind::Static(ty, _), .. + }) => Some(*ty), ref node => bug!("Unexpected node {:?}", node), }, WellFormedLoc::Param { function: _, param_idx } => { diff --git a/src/test/ui/wf/issue-95665.rs b/src/test/ui/wf/issue-95665.rs new file mode 100644 index 00000000000..67923cbb2d6 --- /dev/null +++ b/src/test/ui/wf/issue-95665.rs @@ -0,0 +1,18 @@ +// Regression test for the ICE described in #95665. +// Ensure that the expected error is output (and thus that there is no ICE) + +pub trait Trait: {} + +pub struct Struct<T: Trait> { + member: T, +} + +// uncomment and bug goes away +// impl Trait for u8 {} + +extern "C" { + static VAR: Struct<u8>; + //~^ 14:17: 14:27: the trait bound `u8: Trait` is not satisfied [E0277] +} + +fn main() {} diff --git a/src/test/ui/wf/issue-95665.stderr b/src/test/ui/wf/issue-95665.stderr new file mode 100644 index 00000000000..b1cda59a916 --- /dev/null +++ b/src/test/ui/wf/issue-95665.stderr @@ -0,0 +1,15 @@ +error[E0277]: the trait bound `u8: Trait` is not satisfied + --> $DIR/issue-95665.rs:14:17 + | +LL | static VAR: Struct<u8>; + | ^^^^^^^^^^ the trait `Trait` is not implemented for `u8` + | +note: required by a bound in `Struct` + --> $DIR/issue-95665.rs:6:22 + | +LL | pub struct Struct<T: Trait> { + | ^^^^^ required by this bound in `Struct` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. |
