Open
Description
Code
(hand-reduced)
#![feature(builtin_syntax)]
trait MyTrait<'a> {}
struct S { f: MyTrait, }
fn t3() {
builtin # offset_of(S, f);
}
fn main() {}
(original)
// Tests that we still detect defining usages when
// lifetimes are used in an associated opaque type
//@ check-pass
#![feature(impl_trait_in_assoc_type)]
trait UnwrapItemsExt<'a> {
type Iter;
fn unwrap_items(self) -> Self::Iter;
}
struct MyStruct {}
trait MyTrait<'a> {}
impl<'a> MyTrait<'a> for MyStruct {}
impl<'a, I> UnwrapItemsExt<'a> for I {
type Iter = impl MyTrait<'a>;
fn unwrap_items(self) -> Self::Iter {
MyStruct {}
}
}
fn main() {}
#![feature(builtin_syntax)]
// For the exposed macro we already test these errors in the other files,
// but this test helps to make sure the builtin construct also errors.
// This has the same examples as offset-of-arg-count.rs
fn main() {
builtin # offset_of(NotEnoughArguments); //~ ERROR expected one of
}
fn t1() {
builtin # offset_of(NotEnoughArgumentsWithAComma, ); //~ ERROR expected expression
}
fn t2() {
builtin # offset_of(S, f, too many arguments); //~ ERROR expected `)`, found `too`
}
fn t3() {
builtin # offset_of(S, f); // compiles fine
}
fn t4() {
builtin # offset_of(S, f.); //~ ERROR unexpected token
}
fn t5() {
builtin # offset_of(S, f.,); //~ ERROR unexpected token
}
fn t6() {
builtin # offset_of(S, f..); //~ ERROR offset_of expects dot-separated field and variant names
}
fn t7() {
builtin # offset_of(S, f..,); //~ ERROR offset_of expects dot-separated field and variant names
}
struct S { f: MyTrait, }
Meta
rustc --version --verbose
:
rustc 1.80.0-nightly (6f3df08aa 2024-05-30)
binary: rustc
commit-hash: 6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4
commit-date: 2024-05-30
host: x86_64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6
Error output
Command: rustc
error[E0106]: missing lifetime specifier
--> r_mod_FA6845.rs:5:15
|
5 | struct S { f: MyTrait, }
| ^^^^^^^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
5 | struct S<'a> { f: MyTrait<'a>, }
| ++++ ++++
warning: trait objects without an explicit `dyn` are deprecated
--> r_mod_FA6845.rs:5:15
|
5 | struct S { f: MyTrait, }
| ^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
|
5 | struct S { f: dyn MyTrait, }
| +++
Backtrace
thread 'rustc' panicked at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/compiler/rustc_target/src/abi/mod.rs:272:13:
offset of unsized field (type dyn [Binder(Trait(MyTrait<'_>), [])] + '{erased}) cannot be computed statically
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: <rustc_target::abi::TyAndLayout<rustc_middle::ty::Ty>>::offset_of_subfield::<rustc_mir_transform::known_panics_lint::ConstPropagator, core::iter::adapters::copied::Copied<core::slice::iter::Iter<(rustc_target::abi::VariantIdx, rustc_target::abi::FieldIdx)>>>
3: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_assign
4: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_basic_block_data
5: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_body
6: <rustc_mir_transform::known_panics_lint::KnownPanicsLint as rustc_mir_transform::pass_manager::MirLint>::run_lint
7: rustc_mir_transform::pass_manager::run_passes_inner
8: rustc_mir_transform::run_analysis_to_runtime_passes
9: rustc_mir_transform::mir_drops_elaborated_and_const_checked
[... omitted 1 frame ...]
10: rustc_interface::passes::run_required_analyses
11: rustc_interface::passes::analysis
[... omitted 1 frame ...]
12: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
13: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: please make sure that you have updated to the latest nightly
note: please attach the file at `/Volumes/T7/workspace/240530_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-05-31T08_16_43-23629.txt` to your bug report
query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `t3`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0106`.
Note
- ICE location:
rustc_target/src/abi/mod.rs L272-L276
rust/compiler/rustc_target/src/abi/mod.rs
Lines 267 to 276 in 6f3df08
- ICE:
offset of unsized field (type dyn [Binder(Trait(std::fmt::Debug), [])] + '{erased}) cannot be computed statically
#125680 has identical ICE location, but has different query stack & feature.
Metadata
Metadata
Assignees
Labels
Category: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(offset_of)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.