Skip to content

UFCS can bypass trait stability #30209

Open
@alexcrichton

Description

@alexcrichton

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-stabilityArea: `#[stable]`, `#[unstable]` etc.C-bugCategory: This is a bug.F-staged_api`#![feature(staged_api)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions