UFCS can bypass trait stability
0e4f4cd
Opened by Alex Crichton at
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
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.rlibSteve Klabnik at 2019-12-25 17:18:35
Triage: Fixed.
test1compiles andtest2,test3andtest4all 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 errorsKalle Wachsmuth at 2023-08-22 15:00:00