Skip to content

Commit 7bde23b

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#95665
2 parents ce1151c + f725b97 commit 7bde23b

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

compiler/rustc_typeck/src/hir_wf_check.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::collect::ItemCtxt;
22
use rustc_hir as hir;
33
use rustc_hir::intravisit::{self, Visitor};
4-
use rustc_hir::HirId;
4+
use rustc_hir::{ForeignItem, ForeignItemKind, HirId};
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_infer::traits::TraitEngine;
77
use rustc_infer::traits::{ObligationCause, WellFormedLoc};
@@ -141,6 +141,9 @@ fn diagnostic_hir_wf_check<'tcx>(
141141
ref item => bug!("Unexpected item {:?}", item),
142142
},
143143
hir::Node::Field(field) => Some(field.ty),
144+
hir::Node::ForeignItem(ForeignItem {
145+
kind: ForeignItemKind::Static(ty, _), ..
146+
}) => Some(*ty),
144147
ref node => bug!("Unexpected node {:?}", node),
145148
},
146149
WellFormedLoc::Param { function: _, param_idx } => {

src/test/ui/wf/issue-95665.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for the ICE described in #95665.
2+
// Ensure that the expected error is output (and thus that there is no ICE)
3+
4+
pub trait Trait: {}
5+
6+
pub struct Struct<T: Trait> {
7+
member: T,
8+
}
9+
10+
// uncomment and bug goes away
11+
// impl Trait for u8 {}
12+
13+
extern "C" {
14+
static VAR: Struct<u8>;
15+
//~^ 14:17: 14:27: the trait bound `u8: Trait` is not satisfied [E0277]
16+
}
17+
18+
fn main() {}

src/test/ui/wf/issue-95665.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `u8: Trait` is not satisfied
2+
--> $DIR/issue-95665.rs:14:17
3+
|
4+
LL | static VAR: Struct<u8>;
5+
| ^^^^^^^^^^ the trait `Trait` is not implemented for `u8`
6+
|
7+
note: required by a bound in `Struct`
8+
--> $DIR/issue-95665.rs:6:22
9+
|
10+
LL | pub struct Struct<T: Trait> {
11+
| ^^^^^ required by this bound in `Struct`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)