diff --git a/compiler/rustc_resolve/src/diagnostics/impls.rs b/compiler/rustc_resolve/src/diagnostics/impls.rs index 47a05b3f65d86..cf4dce2ca9433 100644 --- a/compiler/rustc_resolve/src/diagnostics/impls.rs +++ b/compiler/rustc_resolve/src/diagnostics/impls.rs @@ -1747,9 +1747,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } if candidates.iter().all(|v: &ImportSuggestion| v.did != did) { + // Add a note about unstable features on nightly Rust. + let note = if !is_stable + && let Some(did) = did + && let Some(stab) = this.tcx.lookup_stability(did) + && let StabilityLevel::Unstable { .. } = stab.level + { + Some(format!( + "'{}' is unstable in nightly Rust \ + and is only available with the \ + `#![feature({})]` attribute", + path_names_to_string(&path), + stab.feature + )) + } // See if we're recommending TryFrom, TryInto, or FromIterator and add // a note about editions - let note = if let Some(did) = did { + else if let Some(did) = did { let requires_note = !did.is_local() && find_attr!( this.tcx, diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 0046ccdba6ec4..d81a9427fb399 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -952,17 +952,12 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { } }) .collect::>(); - // Try to filter out intrinsics candidates, as long as we have - // some other candidates to suggest. - let intrinsic_candidates: Vec<_> = candidates - .extract_if(.., |sugg| { - let path = path_names_to_string(&sugg.path); - path.starts_with("core::intrinsics::") || path.starts_with("std::intrinsics::") - }) - .collect(); - if candidates.is_empty() { - // Put them back if we have no more candidates to suggest... - candidates = intrinsic_candidates; + // Only suggest intrinsics when the `core_intrinsics` feature is already enabled + if !self.r.features.enabled(sym::core_intrinsics) { + candidates.retain(|sugg| { + let p = path_names_to_string(&sugg.path); + !(p.starts_with("core::intrinsics::") || p.starts_with("std::intrinsics::")) + }); } let crate_def_id = CRATE_DEF_ID.to_def_id(); if candidates.is_empty() && is_expected(Res::Def(DefKind::Enum, crate_def_id)) { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 6376fe032c64e..fac2936103d95 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -726,6 +726,7 @@ symbols! { copysignf64, copysignf128, core, + core_intrinsics, core_panic, core_panic_2015_macro, core_panic_macro, diff --git a/tests/ui/annotate-snippet/missing-type.stderr b/tests/ui/annotate-snippet/missing-type.stderr index ab02697a6980f..af2e887f69e3b 100644 --- a/tests/ui/annotate-snippet/missing-type.stderr +++ b/tests/ui/annotate-snippet/missing-type.stderr @@ -4,6 +4,7 @@ error[E0425]: cannot find type `Iter` in this scope LL | let x: Iter; | ^^^^ not found in this scope | + = note: 'std::sync::mpmc::Iter' is unstable in nightly Rust and is only available with the `#![feature(mpmc_channel)]` attribute help: consider importing one of these structs | LL + use std::collections::binary_heap::Iter; diff --git a/tests/ui/argument-suggestions/disjoint-spans-issue-151607.stderr b/tests/ui/argument-suggestions/disjoint-spans-issue-151607.stderr index c8eddd196de6b..cb0c339a19413 100644 --- a/tests/ui/argument-suggestions/disjoint-spans-issue-151607.stderr +++ b/tests/ui/argument-suggestions/disjoint-spans-issue-151607.stderr @@ -25,6 +25,8 @@ error[E0425]: cannot find value `E` in this scope LL | foo(B, g, D, E, F, G) | ^ not found in this scope | + = note: 'std::f128::consts::E' is unstable in nightly Rust and is only available with the `#![feature(f128)]` attribute + = note: 'std::f16::consts::E' is unstable in nightly Rust and is only available with the `#![feature(f16)]` attribute help: a local variable with a similar name exists | LL - foo(B, g, D, E, F, G) diff --git a/tests/ui/const-generics/issues/issue-82956.stderr b/tests/ui/const-generics/issues/issue-82956.stderr index a3d5572d5474d..04d2949190f30 100644 --- a/tests/ui/const-generics/issues/issue-82956.stderr +++ b/tests/ui/const-generics/issues/issue-82956.stderr @@ -4,6 +4,7 @@ error[E0433]: cannot find type `IntoIter` in this scope LL | let mut iter = IntoIter::new(self); | ^^^^^^^^ use of undeclared type `IntoIter` | + = note: 'std::sync::mpmc::IntoIter' is unstable in nightly Rust and is only available with the `#![feature(mpmc_channel)]` attribute help: consider importing one of these structs | LL + use std::array::IntoIter; diff --git a/tests/ui/feature-gates/feature-gate-autodiff.no_support.stderr b/tests/ui/feature-gates/feature-gate-autodiff.no_support.stderr index dcbaba716459b..656eb594d5473 100644 --- a/tests/ui/feature-gates/feature-gate-autodiff.no_support.stderr +++ b/tests/ui/feature-gates/feature-gate-autodiff.no_support.stderr @@ -4,6 +4,7 @@ error: cannot find attribute `autodiff_reverse` in this scope LL | #[autodiff_reverse(dfoo)] | ^^^^^^^^^^^^^^^^ | + = note: 'std::autodiff::autodiff_reverse' is unstable in nightly Rust and is only available with the `#![feature(autodiff)]` attribute help: consider importing this attribute macro | LL + use std::autodiff::autodiff_reverse; diff --git a/tests/ui/lint/use_suggestion_json.stderr b/tests/ui/lint/use_suggestion_json.stderr index 6f2d7b461f76b..1a86b1694bffe 100644 --- a/tests/ui/lint/use_suggestion_json.stderr +++ b/tests/ui/lint/use_suggestion_json.stderr @@ -90,6 +90,14 @@ current module, then it must also be declared as public (e.g., `pub fn`). } ], "children": [ + { + "message": "'std::sync::mpmc::Iter' is unstable in nightly Rust and is only available with the `#![feature(mpmc_channel)]` attribute", + "code": null, + "level": "note", + "spans": [], + "children": [], + "rendered": null + }, { "message": "consider importing one of these structs", "code": null, @@ -405,6 +413,7 @@ current module, then it must also be declared as public (e.g., `pub fn`). \u001b[1m\u001b[94mLL\u001b[0m \u001b[1m\u001b[94m|\u001b[0m let x: Iter; \u001b[1m\u001b[94m|\u001b[0m \u001b[1m\u001b[91m^^^^\u001b[0m \u001b[1m\u001b[91mnot found in this scope\u001b[0m \u001b[1m\u001b[94m|\u001b[0m + \u001b[1m\u001b[94m= \u001b[0m\u001b[1mnote\u001b[0m: 'std::sync::mpmc::Iter' is unstable in nightly Rust and is only available with the `#![feature(mpmc_channel)]` attribute \u001b[1m\u001b[96mhelp\u001b[0m: consider importing one of these structs \u001b[1m\u001b[94m|\u001b[0m \u001b[1m\u001b[94mLL\u001b[0m \u001b[92m+ use std::collections::binary_heap::Iter;\u001b[0m diff --git a/tests/ui/mir/gvn-nonsensical-coroutine-layout.stderr b/tests/ui/mir/gvn-nonsensical-coroutine-layout.stderr index c22c996160e5a..5b8595332d784 100644 --- a/tests/ui/mir/gvn-nonsensical-coroutine-layout.stderr +++ b/tests/ui/mir/gvn-nonsensical-coroutine-layout.stderr @@ -15,6 +15,7 @@ error[E0574]: expected struct, variant or union type, found enum `Request` LL | static instance: Request = Request { bar: 17 }; | ^^^^^^^ not a struct, variant or union type | + = note: 'std::error::Request' is unstable in nightly Rust and is only available with the `#![feature(error_generic_member_access)]` attribute help: consider importing this struct instead | LL + use std::error::Request; diff --git a/tests/ui/resolve/filter-intrinsics.gate_off.stderr b/tests/ui/resolve/filter-intrinsics.gate_off.stderr new file mode 100644 index 0000000000000..61a43fe37f5a0 --- /dev/null +++ b/tests/ui/resolve/filter-intrinsics.gate_off.stderr @@ -0,0 +1,20 @@ +error[E0425]: cannot find function `transmute` in this scope + --> $DIR/filter-intrinsics.rs:7:13 + | +LL | let _ = transmute::(); + | ^^^^^^^^^ not found in this scope + | +help: consider importing this function + | +LL + use std::mem::transmute; + | + +error[E0425]: cannot find function `fabs` in this scope + --> $DIR/filter-intrinsics.rs:10:13 + | +LL | let _ = fabs(1.0); + | ^^^^ not found in this scope + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/resolve/filter-intrinsics.stderr b/tests/ui/resolve/filter-intrinsics.gate_on.stderr similarity index 88% rename from tests/ui/resolve/filter-intrinsics.stderr rename to tests/ui/resolve/filter-intrinsics.gate_on.stderr index 3870cfcb1080a..9e6925ec1b6b0 100644 --- a/tests/ui/resolve/filter-intrinsics.stderr +++ b/tests/ui/resolve/filter-intrinsics.gate_on.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find function `transmute` in this scope - --> $DIR/filter-intrinsics.rs:3:13 + --> $DIR/filter-intrinsics.rs:7:13 | LL | let _ = transmute::(); | ^^^^^^^^^ not found in this scope @@ -10,7 +10,7 @@ LL + use std::mem::transmute; | error[E0425]: cannot find function `fabs` in this scope - --> $DIR/filter-intrinsics.rs:8:13 + --> $DIR/filter-intrinsics.rs:10:13 | LL | let _ = fabs(1.0); | ^^^^ not found in this scope diff --git a/tests/ui/resolve/filter-intrinsics.rs b/tests/ui/resolve/filter-intrinsics.rs index 9998bec1ad4fe..56bf549b9987d 100644 --- a/tests/ui/resolve/filter-intrinsics.rs +++ b/tests/ui/resolve/filter-intrinsics.rs @@ -1,10 +1,12 @@ +//@ revisions: gate_off gate_on +//@ dont-require-annotations: HELP + +#![cfg_attr(gate_on, feature(core_intrinsics))] fn main() { - // Should suggest only `std::mem::transmute` +//[gate_on]~^ HELP consider importing this function let _ = transmute::(); - //~^ ERROR cannot find + //~^ ERROR cannot find function `transmute` in this scope - // Should suggest `std::intrinsics::fabs`, - // since there is no non-intrinsic to suggest. let _ = fabs(1.0); - //~^ ERROR cannot find + //~^ ERROR cannot find function `fabs` in this scope } diff --git a/tests/ui/resolve/import-suggestion-unstable-feature-note.gate_off.stderr b/tests/ui/resolve/import-suggestion-unstable-feature-note.gate_off.stderr new file mode 100644 index 0000000000000..f297b9fe374ae --- /dev/null +++ b/tests/ui/resolve/import-suggestion-unstable-feature-note.gate_off.stderr @@ -0,0 +1,37 @@ +error[E0425]: cannot find type `BorrowedBuf` in this scope + --> $DIR/import-suggestion-unstable-feature-note.rs:9:12 + | +LL | let _: BorrowedBuf; + | ^^^^^^^^^^^ not found in this scope + | + = note: 'std::io::BorrowedBuf' is unstable in nightly Rust and is only available with the `#![feature(core_io_borrowed_buf)]` attribute +help: consider importing this struct + | +LL + use std::io::BorrowedBuf; + | + +error[E0425]: cannot find type `HashMap` in this scope + --> $DIR/import-suggestion-unstable-feature-note.rs:13:12 + | +LL | let _: HashMap; + | ^^^^^^^ not found in this scope + | +help: consider importing this struct + | +LL + use std::collections::HashMap; + | + +error[E0425]: cannot find type `S` in this scope + --> $DIR/import-suggestion-unstable-feature-note.rs:16:12 + | +LL | let _: S; + | ^ not found in this scope + | +help: consider importing this struct + | +LL + use extern_prelude::S; + | + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/resolve/import-suggestion-unstable-feature-note.gate_on.stderr b/tests/ui/resolve/import-suggestion-unstable-feature-note.gate_on.stderr new file mode 100644 index 0000000000000..7dc602697a6e1 --- /dev/null +++ b/tests/ui/resolve/import-suggestion-unstable-feature-note.gate_on.stderr @@ -0,0 +1,36 @@ +error[E0425]: cannot find type `BorrowedBuf` in this scope + --> $DIR/import-suggestion-unstable-feature-note.rs:9:12 + | +LL | let _: BorrowedBuf; + | ^^^^^^^^^^^ not found in this scope + | +help: consider importing this struct + | +LL + use std::io::BorrowedBuf; + | + +error[E0425]: cannot find type `HashMap` in this scope + --> $DIR/import-suggestion-unstable-feature-note.rs:13:12 + | +LL | let _: HashMap; + | ^^^^^^^ not found in this scope + | +help: consider importing this struct + | +LL + use std::collections::HashMap; + | + +error[E0425]: cannot find type `S` in this scope + --> $DIR/import-suggestion-unstable-feature-note.rs:16:12 + | +LL | let _: S; + | ^ not found in this scope + | +help: consider importing this struct + | +LL + use extern_prelude::S; + | + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/resolve/import-suggestion-unstable-feature-note.rs b/tests/ui/resolve/import-suggestion-unstable-feature-note.rs new file mode 100644 index 0000000000000..f25bc47994e00 --- /dev/null +++ b/tests/ui/resolve/import-suggestion-unstable-feature-note.rs @@ -0,0 +1,18 @@ +//@ revisions: gate_off gate_on +//@ aux-build:extern-prelude.rs +//@ dont-require-annotations: NOTE +#![cfg_attr(gate_on, feature(core_io_borrowed_buf))] + +extern crate extern_prelude; + +fn main() { + let _: BorrowedBuf; + //~^ ERROR cannot find type `BorrowedBuf` in this scope + //[gate_off]~| NOTE 'std::io::BorrowedBuf' is unstable in nightly Rust and is only available with the `#![feature(core_io_borrowed_buf)]` attribute + + let _: HashMap; + //~^ ERROR cannot find type `HashMap` in this scope + + let _: S; + //~^ ERROR cannot find type `S` in this scope +} diff --git a/tests/ui/resolve/issue-50599.stderr b/tests/ui/resolve/issue-50599.stderr index 24fb3d580b8fa..33ea912a69418 100644 --- a/tests/ui/resolve/issue-50599.stderr +++ b/tests/ui/resolve/issue-50599.stderr @@ -4,6 +4,8 @@ error[E0425]: cannot find value `LOG10_2` in module `std::f64` LL | const M: usize = (f64::from(N) * std::f64::LOG10_2) as usize; | ^^^^^^^ not found in `std::f64` | + = note: 'std::f128::consts::LOG10_2' is unstable in nightly Rust and is only available with the `#![feature(f128)]` attribute + = note: 'std::f16::consts::LOG10_2' is unstable in nightly Rust and is only available with the `#![feature(f16)]` attribute help: consider importing one of these constants | LL + use std::f128::consts::LOG10_2; diff --git a/tests/ui/resolve/issue-73427.stderr b/tests/ui/resolve/issue-73427.stderr index e5890dd41b926..c11e1b6bff34b 100644 --- a/tests/ui/resolve/issue-73427.stderr +++ b/tests/ui/resolve/issue-73427.stderr @@ -115,6 +115,8 @@ LL | / enum E { LL | | TupleWithFields(()), LL | | } | |_^ + = note: 'std::f128::consts::E' is unstable in nightly Rust and is only available with the `#![feature(f128)]` attribute + = note: 'std::f16::consts::E' is unstable in nightly Rust and is only available with the `#![feature(f16)]` attribute help: the following enum variant is available | LL - E.foo(); diff --git a/tests/ui/resolve/privacy-enum-ctor.stderr b/tests/ui/resolve/privacy-enum-ctor.stderr index 39aa3d25a08bb..20481afd24a70 100644 --- a/tests/ui/resolve/privacy-enum-ctor.stderr +++ b/tests/ui/resolve/privacy-enum-ctor.stderr @@ -79,6 +79,8 @@ note: similarly named function `f` defined here | LL | fn f() { | ^^^^^^ + = note: 'std::f128::consts::E' is unstable in nightly Rust and is only available with the `#![feature(f128)]` attribute + = note: 'std::f16::consts::E' is unstable in nightly Rust and is only available with the `#![feature(f16)]` attribute help: you might have meant to use the following enum variant | LL - let _: E = m::E; @@ -128,6 +130,8 @@ LL | | }, LL | | Unit, LL | | } | |_____^ + = note: 'std::f128::consts::E' is unstable in nightly Rust and is only available with the `#![feature(f128)]` attribute + = note: 'std::f16::consts::E' is unstable in nightly Rust and is only available with the `#![feature(f16)]` attribute help: you might have meant to use the following enum variant | LL | let _: E = E::Unit; diff --git a/tests/ui/resolve/resolve-assoc-suggestions.stderr b/tests/ui/resolve/resolve-assoc-suggestions.stderr index e6311962884f1..a6b2177136f7b 100644 --- a/tests/ui/resolve/resolve-assoc-suggestions.stderr +++ b/tests/ui/resolve/resolve-assoc-suggestions.stderr @@ -27,6 +27,7 @@ error[E0425]: cannot find type `Type` in this scope LL | let _: Type; | ^^^^ | + = note: 'std::mem::type_info::Type' is unstable in nightly Rust and is only available with the `#![feature(type_info)]` attribute help: you might have meant to use the associated type | LL | let _: Self::Type; @@ -42,6 +43,7 @@ error[E0531]: cannot find tuple struct or tuple variant `Type` in this scope LL | let Type(..); | ^^^^ not found in this scope | + = note: 'std::mem::type_info::Generic::Type' is unstable in nightly Rust and is only available with the `#![feature(type_info)]` attribute help: consider importing this tuple variant | LL + use std::mem::type_info::Generic::Type; @@ -53,6 +55,7 @@ error[E0425]: cannot find value `Type` in this scope LL | Type; | ^^^^ not found in this scope | + = note: 'std::mem::type_info::Generic::Type' is unstable in nightly Rust and is only available with the `#![feature(type_info)]` attribute help: consider importing this tuple variant | LL + use std::mem::type_info::Generic::Type; diff --git a/tests/ui/simd/portable-intrinsics-arent-exposed.stderr b/tests/ui/simd/portable-intrinsics-arent-exposed.stderr index 0f58d3eeb95cd..b67d2cec7dd66 100644 --- a/tests/ui/simd/portable-intrinsics-arent-exposed.stderr +++ b/tests/ui/simd/portable-intrinsics-arent-exposed.stderr @@ -18,6 +18,7 @@ LL | use std::simd::intrinsics; | | | no `intrinsics` in `simd` | + = note: 'std::intrinsics' is unstable in nightly Rust and is only available with the `#![feature(core_intrinsics)]` attribute help: consider importing this module instead | LL - use std::simd::intrinsics; diff --git a/tests/ui/test-attrs/inaccessible-test-modules.stderr b/tests/ui/test-attrs/inaccessible-test-modules.stderr index 246a68c14b620..7ac5724757590 100644 --- a/tests/ui/test-attrs/inaccessible-test-modules.stderr +++ b/tests/ui/test-attrs/inaccessible-test-modules.stderr @@ -14,6 +14,7 @@ LL | use test as y; | | | no `test` in the root | + = note: 'test::test' is unstable in nightly Rust and is only available with the `#![feature(test)]` attribute help: consider importing this module instead | LL | use test::test as y; diff --git a/tests/ui/traits/ignore-err-impls.stderr b/tests/ui/traits/ignore-err-impls.stderr index 46a2a7d55a2e5..919dcde99ff7e 100644 --- a/tests/ui/traits/ignore-err-impls.stderr +++ b/tests/ui/traits/ignore-err-impls.stderr @@ -4,6 +4,7 @@ error[E0425]: cannot find type `Type` in this scope LL | impl Generic for S {} | ^^^^ not found in this scope | + = note: 'std::mem::type_info::Type' is unstable in nightly Rust and is only available with the `#![feature(type_info)]` attribute help: consider importing this struct | LL + use std::mem::type_info::Type; diff --git a/tests/ui/unresolved/unresolved-candidates.stderr b/tests/ui/unresolved/unresolved-candidates.stderr index 7d8e894a55826..91a68900f013e 100644 --- a/tests/ui/unresolved/unresolved-candidates.stderr +++ b/tests/ui/unresolved/unresolved-candidates.stderr @@ -4,6 +4,7 @@ error[E0432]: unresolved import `Trait` LL | use Trait; | ^^^^^ no `Trait` in the root | + = note: 'std::mem::type_info::Trait' is unstable in nightly Rust and is only available with the `#![feature(type_info)]` attribute help: consider importing one of these items instead | LL | use std::mem::type_info::Trait; diff --git a/tests/ui/use/issue-18986.stderr b/tests/ui/use/issue-18986.stderr index 084fa80c3b6d3..a1ee221777d67 100644 --- a/tests/ui/use/issue-18986.stderr +++ b/tests/ui/use/issue-18986.stderr @@ -4,6 +4,7 @@ error[E0574]: expected struct, variant or union type, found trait `Trait` LL | Trait { x: 42 } => () | ^^^^^ not a struct, variant or union type | + = note: 'std::mem::type_info::Trait' is unstable in nightly Rust and is only available with the `#![feature(type_info)]` attribute help: consider importing this struct instead | LL + use std::mem::type_info::Trait;