Skip to content

Unsoundness: Rust since 1.78 accepts invalid ? #132463

Closed
@shao-hua-li

Description

@shao-hua-li

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
%

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions