Skip to content

Unsoundness due to where clauses not checked for well-formedness #98117

@aliemjay

Description

@aliemjay

This code does pass: (playground)

trait Outlives<'a>: 'a {} // without `: 'a`, it fails as expected. fn t_is_static<T>() where &'static T: Outlives<'static>, { }

But according to RFC 1214 functions are responsible for checking the well-formedness of their own where clauses. So this should fail and require an explicit bound T: 'static.

Here is an exploit of this unsoundness: (playground)

trait Outlives<'a>: 'a {} impl<'a, T> Outlives<'a> for &'a T {} fn step2<T>(t: T) -> &'static str where &'static T: Outlives<'static>, T: AsRef<str>, { AsRef::as_ref(Box::leak(Box::new(t) as Box<dyn AsRef<str> + 'static>)) } fn step1<T>(t: T) -> &'static str where for<'a> &'a T: Outlives<'a>, T: AsRef<str>, { step2(t) } fn main() { let s: &'static str = step1(&String::from("blah blah blah")); println!("{s}"); }

@rustbot label C-bug T-compiler T-types A-lifetimes I-unsound

Metadata

Metadata

Labels

A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

Completed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions