rust-lang/rust · error
expected `Session`
Error message
expected `Session`
What it means
lib.rs:1241: in a delayed-lint callback, the compiler downcasts a &dyn std::any::Any to rustc_session::Session via .expect("expected `Session`"). The invariant: the opaque value stored in the DelayedLint is always the compiler Session. A panic here means a delayed lint was registered with a non-Session Any value, a compiler-internal contract violation.
Source
Thrown at compiler/rustc_ast_lowering/src/lib.rs:1241
target_hir_id: HirId,
target: Target,
) -> Vec<hir::Attribute> {
let l = self.span_lowerer();
self.attribute_parser.parse_attribute_list(
attrs,
target_span,
target,
OmitDoc::Lower,
|s| l.lower(s),
|lint_id, span, kind| {
self.delayed_lints.push(DelayedLint {
lint_id,
id: target_hir_id,
span,
callback: Box::new(move |dcx, level, sess: &dyn std::any::Any| {
let sess = sess
.downcast_ref::<rustc_session::Session>()
.expect("expected `Session`");
(kind.0)(dcx, level, sess)
}),
});
},
)
}
fn alias_attrs(&mut self, id: HirId, target_id: HirId) {
assert_eq!(id.owner, self.current_hir_id_owner);
assert_eq!(target_id.owner, self.current_hir_id_owner);
if let Some(&a) = self.attrs.get(&target_id.local_id) {
assert!(!a.is_empty());
self.attrs.insert(id.local_id, a);
}
}
fn lower_delim_args(&self, args: &DelimArgs) -> DelimArgs {
args.clone()View on GitHub (pinned to 7088e4b63a)
Solutions
- File a rustc ICE report; this is a compiler-internal contract violation.
- Bisect the regression with cargo bisect-rustc.
- Try stable vs nightly to see if it is a recent regression.
- Reduce the triggering crate (often one that exercises rare lint paths) and attach it to the issue.
Defensive patterns
Strategy: fallback
Prevention
- This is an internal rustc contract violation, not user-reachable; file an ICE report.
- Bisect with cargo bisect-rustc to locate the lint-delay regression.
- Compare stable vs nightly to confirm it is a recent regression.
- Reduce the triggering crate to the minimum that exercises the affected lint path.
When it happens
Trigger: Internal compiler code that pushes a DelayedLint whose callback receives an Any that is not a Session; cannot be triggered by normal user source.
Common situations: A regression in the lint-delay mechanism during compiler development; not reachable from ordinary Rust programs.
Related errors
- alt layout should always work
- alt layout should have a niche like the regular one
- `Self` generic param is not found while expected
- must be at least one segment
- must contain self type as `SelfTy` propagation kind is speci
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/6f4bb4a963c96149.
Report an issue: GitHub.