Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#![feature(trivial_bounds)] allows invalid code to compile #67801

Closed
Aaron1011 opened this issue Jan 2, 2020 · 5 comments
Closed

#![feature(trivial_bounds)] allows invalid code to compile #67801

Aaron1011 opened this issue Jan 2, 2020 · 5 comments
Labels
C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

Aaron1011 commented Jan 2, 2020

The following code compiles:

#![feature(trivial_bounds)]

struct NotCopy;

fn weird() -> NotCopy where NotCopy: Copy {
    *&NotCopy // Should not compile
}

despite the fact that we are moving out of a reference to a !Copy type.

I don't think this can actually lead to unsoundness, since it's impossible to actually call weird. However, I would still expect type-checking to not attempt to assume that trivially false bounds are actually true.

@Aaron1011
Copy link
Member Author

In #67696, this leads to the const evaluator getting confused, since it's attempting to evaluate code that should never have actually compiled.

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jan 2, 2020
@cramertj
Copy link
Member

cramertj commented Jan 2, 2020

FWIW I wouldn't have considered this example a bug-- it's exactly what I thought the trivial_bounds feature was supposed to allow. I'd have expected this to compile just fine, but for weird to be uncallable.

@Aaron1011
Copy link
Member Author

Aaron1011 commented Jan 3, 2020

I thought trivial_bounds was just supposed to allow writing trivially true or trivially false where clauses. Whether or not something like NotCopy: Copy holds is a global property of the program, so it seems very surprising that you can 'pretend' that it does within a particular function.

@cramertj
Copy link
Member

cramertj commented Jan 3, 2020

Inside the body of the function, all where clauses and other bounds on that function should be considered true. This is crucial to trivial_bounds being useful for one of its primary intended purposes: using the trivial bounds as guards on generated code.

@joshtriplett
Copy link
Member

Just discovered this issue. I agree that this is exactly how trivial_bounds should work: it should assume the bound is true within the function, and then the function should only be callable if the bound is true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants