Skip to content

function type params are not checked for well-formedness #104005

Closed

Description

This unsound program shouldn't compile, but it does: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=2e0af084bc8b2ec9f440a2c5dab7992f

use std::fmt::Display;

trait Displayable {
    fn display(self) -> Box<dyn Display>;
}

impl<T: Display> Displayable for (T, Option<&'static T>) {
    fn display(self) -> Box<dyn Display> {
        Box::new(self.0)
    }
}

fn extend_lt<T, U>(val: T) -> Box<dyn Display>
where
    (T, Option<U>): Displayable,
{
    Displayable::display((val, None))
}

fn main() {
    // The type parameter `U = &'static &'temporary str` is ill-formed
    // because it does not enforce `'temporary: 'static` ...
    let val = extend_lt(&String::from("blah blah blah"));
    println!("{}", val);
}

I was shocked discovering that. I thought WellFormed(U) is part of the caller bounds of extend_lt.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

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-typesRelevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions