Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,24 @@ pub(crate) fn check_static_item<'tcx>(
let is_foreign_item = tcx.is_foreign_item(item_id);

let forbid_unsized = !is_foreign_item || {
let tail = tcx.struct_tail_for_codegen(item_ty, wfcx.infcx.typing_env(wfcx.param_env));
let tail = tcx.struct_tail_raw(
item_ty,
&ObligationCause::dummy(),
|ty| match tcx
.try_normalize_erasing_regions(wfcx.infcx.typing_env(wfcx.param_env), ty)
{
Ok(ty) => ty,
Err(e) => {
tcx.dcx().span_delayed_bug(
span,
format!("could not normalize field type: {e:?}"),
);
ty
}
},
|| {},
);

!matches!(tail.kind(), ty::Foreign(_))
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
trait Trait {
type Assoc;
}

impl Trait for u8 {
type Assoc = i8;
}

struct Struct<T: Trait> {
member: T::Assoc,
}

unsafe extern "C" {
static VAR: Struct<i8>;
//~^ ERROR: the trait bound `i8: Trait` is not satisfied
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0277]: the trait bound `i8: Trait` is not satisfied
--> $DIR/extern-static-normalization_failure-issue-148161.rs:14:17
|
LL | static VAR: Struct<i8>;
| ^^^^^^^^^^ the trait `Trait` is not implemented for `i8`
|
help: the trait `Trait` is implemented for `u8`
--> $DIR/extern-static-normalization_failure-issue-148161.rs:5:1
|
LL | impl Trait for u8 {
| ^^^^^^^^^^^^^^^^^
note: required by a bound in `Struct`
--> $DIR/extern-static-normalization_failure-issue-148161.rs:9:18
|
LL | struct Struct<T: Trait> {
| ^^^^^ required by this bound in `Struct`

error: aborting due to 1 previous error

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