Skip to content

UFCS can bypass trait stability #30209

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

Open
alexcrichton opened this issue Dec 4, 2015 · 2 comments
Open

UFCS can bypass trait stability #30209

alexcrichton opened this issue Dec 4, 2015 · 2 comments
Labels
A-stability Area: `#[stable]`, `#[unstable]` etc. C-bug Category: This is a bug. F-staged_api `#![feature(staged_api)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

Right now we have a trick in the standard library where sometimes a trait is unstable but the methods are stable. This is primarily used for SliceConcatExt to make join stable on slices but you can't import the trait or rely on the fact that it's defined through a trait.

There are a few ways to bypass this, however:

// foo.rs
#![feature(staged_api)]                        
#![stable(feature = "foo", since = "1.2.0")]   

#[unstable(feature = "bar", issue = "0")]      
pub trait Foo {                                
    #[stable(feature = "foo", since = "1.2.0")]
    fn foo(&self) {}                           
}                                              

#[stable(feature = "foo", since = "1.2.0")]    
impl Foo for i32 {}                            
// bar.rs
#![allow(warnings)]               

extern crate foo;                 

// this is expected to compile and work A-OK                                  
fn test1() {                      
    use foo::*;                   
    1i32.foo();
}                                 

// this is expected to fail to compile (e.g. needs the feature)
fn test2() {                      
    use foo::Foo; //~ ERROR
}                                 

// This should *also* fail to compile, but it does not
fn test3() {                      
    foo::Foo::foo(&1) // no error
}                                 

// Like above, this should also fail to compile, but it does not
fn test4() {                      
    <i32 as foo::Foo>::foo(&1) // no error
}                                 

fn main() {}                      
$ multirust run nightly rustc foo.rs --crate-type lib
$ multirust run nightly rustc bar.rs
bar.rs:11:9: 11:17 error: use of unstable library feature 'bar' (see issue #0)
bar.rs:11     use foo::Foo;
                  ^~~~~~~~
bar.rs:11:9: 11:17 help: add #![feature(bar)] to the crate attributes to enable
error: aborting due to previous error

I thought that we crawled paths pretty meticulously, but apparently not :(

cc @petrochenkov
cc @rust-lang/libs

@alexcrichton alexcrichton added A-libs A-stability Area: `#[stable]`, `#[unstable]` etc. labels Dec 4, 2015
@steveklabnik steveklabnik added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed A-libs labels Mar 24, 2017
@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jul 24, 2017
@steveklabnik
Copy link
Member

Triage: this still reproduces, but with slightly different command line invocations, of course:

$ rustc +nightly foo.rs --crate-type lib  
$  rustc +nightly bar.rs --extern foo=./libfoo.rlib  

@kadiwa4
Copy link
Contributor

kadiwa4 commented Aug 22, 2023

Triage: Fixed.
test1 compiles and test2, test3 and test4 all fail.

error[E0658]: use of unstable library feature 'bar'
  --> bar.rs:11:9
   |
11 |     use foo::Foo; //~ ERROR
   |         ^^^^^^^^
   |
   = help: add `#![feature(bar)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'bar'
  --> bar.rs:16:5
   |
16 |     foo::Foo::foo(&1) // no error
   |     ^^^^^^^^^^^^^
   |
   = help: add `#![feature(bar)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'bar'
  --> bar.rs:21:5
   |
21 |     <i32 as foo::Foo>::foo(&1) // no error
   |     ^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: add `#![feature(bar)]` to the crate attributes to enable

error: aborting due to 3 previous errors

@fmease fmease added the F-staged_api `#![feature(staged_api)]` label Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stability Area: `#[stable]`, `#[unstable]` etc. C-bug Category: This is a bug. F-staged_api `#![feature(staged_api)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants