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

Unsoundness: Rust since 1.78 accepts invalid ? #132463

Closed
shao-hua-li opened this issue Nov 1, 2024 · 1 comment
Closed

Unsoundness: Rust since 1.78 accepts invalid ? #132463

shao-hua-li opened this issue Nov 1, 2024 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@shao-hua-li
Copy link

Code

I tried this code:

pub trait Frob<T: ?Frob> {}

I expected to see this happen: rustc rejects this code

Instead, this happened: rustc since 1.78 accepts the code

Version it worked on

It most recently worked on: Rust 1.77

% rustc -Awarnings --crate-type=lib test.rs
error[E0107]: missing generics for trait `Frob`
 --> src/lib.rs:1:20
  |
1 | pub trait Frob<T: ?Frob> {}
  |                    ^^^^ expected 1 generic argument
  |
note: trait defined here, with 1 generic parameter: `T`
 --> src/lib.rs:1:11
  |
1 | pub trait Frob<T: ?Frob> {}
  |           ^^^^ -
help: add missing generic argument
  |
1 | pub trait Frob<T: ?Frob<T>> {}
  |                        +++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0107`.
%
% rustc --version --verbose
rustc 1.77.0-nightly (e51e98dde 2023-12-31)
binary: rustc
commit-hash: e51e98dde6a60637b6a71b8105245b629ac3fe77
commit-date: 2023-12-31
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6
%

Version with regression

% rustc -Awarnings --crate-type=lib test.rs
%
% rustc --version --verbose
rustc 1.84.0-nightly (a0d98ff0e 2024-10-31)
binary: rustc
commit-hash: a0d98ff0e5b6e1f2c63fd26f68484792621b235c
commit-date: 2024-10-31
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1
%
@shao-hua-li shao-hua-li added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Nov 1, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 1, 2024
@compiler-errors
Copy link
Member

This is not unsound. This is just nonsense code being accepted by the compiler. There is no meaning to ? on arbitrary traits, so ignoring the bound outright is obviously not desirable, but totally fine for the compiler to do.

I fixed this in #132209.

@jieyouxu jieyouxu removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-untriaged Untriaged performance or correctness regression. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 1, 2024
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.
Projects
None yet
Development

No branches or pull requests

4 participants