Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion compiler/rustc_resolve/src/diagnostics/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 6 additions & 11 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,17 +952,12 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
}
})
.collect::<Vec<_>>();
// 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)) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ symbols! {
copysignf64,
copysignf128,
core,
core_intrinsics,
core_panic,
core_panic_2015_macro,
core_panic_macro,
Expand Down
1 change: 1 addition & 0 deletions tests/ui/annotate-snippet/missing-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/ui/const-generics/issues/issue-82956.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/lint/use_suggestion_json.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/ui/mir/gvn-nonsensical-coroutine-layout.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/resolve/filter-intrinsics.gate_off.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0425]: cannot find function `transmute` in this scope
--> $DIR/filter-intrinsics.rs:7:13
|
LL | let _ = transmute::<usize>();
| ^^^^^^^^^ 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`.
Original file line number Diff line number Diff line change
@@ -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::<usize>();
| ^^^^^^^^^ not found in this scope
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions tests/ui/resolve/filter-intrinsics.rs
Original file line number Diff line number Diff line change
@@ -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::<usize>();
//~^ 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
}
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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`.
18 changes: 18 additions & 0 deletions tests/ui/resolve/import-suggestion-unstable-feature-note.rs
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions tests/ui/resolve/issue-50599.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/resolve/issue-73427.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/resolve/privacy-enum-ctor.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/resolve/resolve-assoc-suggestions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/simd/portable-intrinsics-arent-exposed.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/test-attrs/inaccessible-test-modules.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/traits/ignore-err-impls.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0425]: cannot find type `Type` in this scope
LL | impl Generic<Type> 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;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/unresolved/unresolved-candidates.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/use/issue-18986.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading