From 9267b4f6120ff137f2ba8649e07ff093c9428340 Mon Sep 17 00:00:00 2001 From: yuqio Date: Tue, 23 Jun 2020 05:01:20 +0200 Subject: [PATCH 01/10] Remove unused crate imports in 2018 edition crates --- src/liballoc/collections/vec_deque/tests.rs | 2 -- src/librustc_ast_pretty/pprust/tests.rs | 1 - src/librustc_data_structures/sync.rs | 1 - src/libstd/os/illumos/fs.rs | 2 -- src/libstd/sys/unix/ext/net.rs | 3 --- src/libstd/sys/vxworks/args.rs | 1 - src/libstd/sys/vxworks/ext/fs.rs | 1 - src/libstd/sys/vxworks/rand.rs | 1 - src/libstd/sys/vxworks/rwlock.rs | 1 - src/libstd/sys/vxworks/time.rs | 2 -- src/libstd/sys/wasi/alloc.rs | 1 - src/tools/build-manifest/src/main.rs | 1 - src/tools/compiletest/src/json.rs | 1 - src/tools/compiletest/src/main.rs | 2 -- src/tools/compiletest/src/read2.rs | 1 - src/tools/compiletest/src/runtest.rs | 1 - 16 files changed, 22 deletions(-) diff --git a/src/liballoc/collections/vec_deque/tests.rs b/src/liballoc/collections/vec_deque/tests.rs index fc2ec7908e823..960af4bfda053 100644 --- a/src/liballoc/collections/vec_deque/tests.rs +++ b/src/liballoc/collections/vec_deque/tests.rs @@ -1,7 +1,5 @@ use super::*; -use test; - #[bench] #[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks fn bench_push_back_100(b: &mut test::Bencher) { diff --git a/src/librustc_ast_pretty/pprust/tests.rs b/src/librustc_ast_pretty/pprust/tests.rs index f51439f89ffbe..f92e40ed6ffab 100644 --- a/src/librustc_ast_pretty/pprust/tests.rs +++ b/src/librustc_ast_pretty/pprust/tests.rs @@ -2,7 +2,6 @@ use super::*; use rustc_ast::ast; use rustc_ast::with_default_globals; -use rustc_span; use rustc_span::source_map::respan; use rustc_span::symbol::Ident; diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs index 39afb3d82ff5a..53d831749ceb7 100644 --- a/src/librustc_data_structures/sync.rs +++ b/src/librustc_data_structures/sync.rs @@ -358,7 +358,6 @@ cfg_if! { use parking_lot::Mutex as InnerLock; use parking_lot::RwLock as InnerRwLock; - use std; use std::thread; pub use rayon::{join, scope}; diff --git a/src/libstd/os/illumos/fs.rs b/src/libstd/os/illumos/fs.rs index 2abbf1fa9fa16..b668aa2595d67 100644 --- a/src/libstd/os/illumos/fs.rs +++ b/src/libstd/os/illumos/fs.rs @@ -1,7 +1,5 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] -use libc; - use crate::fs::Metadata; use crate::sys_common::AsInner; diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index cd24605ec7ab7..ada8eaa1c9745 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -2,9 +2,6 @@ //! Unix-specific networking functionality -#[cfg(unix)] -use libc; - // FIXME(#43348): Make libc adapt #[doc(cfg(...))] so we don't need these fake definitions here? #[cfg(not(unix))] #[allow(non_camel_case_types)] diff --git a/src/libstd/sys/vxworks/args.rs b/src/libstd/sys/vxworks/args.rs index efd615f404db6..adff6c489bbc9 100644 --- a/src/libstd/sys/vxworks/args.rs +++ b/src/libstd/sys/vxworks/args.rs @@ -56,7 +56,6 @@ mod imp { use crate::ffi::{CStr, OsString}; use crate::marker::PhantomData; use crate::ptr; - use libc; use crate::sys_common::mutex::Mutex; diff --git a/src/libstd/sys/vxworks/ext/fs.rs b/src/libstd/sys/vxworks/ext/fs.rs index 9864a855df738..7cc64658ee1a9 100644 --- a/src/libstd/sys/vxworks/ext/fs.rs +++ b/src/libstd/sys/vxworks/ext/fs.rs @@ -6,7 +6,6 @@ use crate::path::Path; use crate::sys; use crate::sys::platform::fs::MetadataExt as UnixMetadataExt; use crate::sys_common::{AsInner, AsInnerMut, FromInner}; -use libc; /// Unix-specific extensions to [`File`]. /// diff --git a/src/libstd/sys/vxworks/rand.rs b/src/libstd/sys/vxworks/rand.rs index 87ebd2c9593fc..3a1ff5fd3b9c6 100644 --- a/src/libstd/sys/vxworks/rand.rs +++ b/src/libstd/sys/vxworks/rand.rs @@ -13,7 +13,6 @@ pub fn hashmap_random_keys() -> (u64, u64) { mod imp { use crate::io; use core::sync::atomic::{AtomicBool, Ordering::Relaxed}; - use libc; pub fn fill_bytes(v: &mut [u8]) { static RNG_INIT: AtomicBool = AtomicBool::new(false); diff --git a/src/libstd/sys/vxworks/rwlock.rs b/src/libstd/sys/vxworks/rwlock.rs index fd2e1a6e7bcfb..c90304c2b4a6a 100644 --- a/src/libstd/sys/vxworks/rwlock.rs +++ b/src/libstd/sys/vxworks/rwlock.rs @@ -1,6 +1,5 @@ use crate::cell::UnsafeCell; use crate::sync::atomic::{AtomicUsize, Ordering}; -use libc; pub struct RWLock { inner: UnsafeCell, diff --git a/src/libstd/sys/vxworks/time.rs b/src/libstd/sys/vxworks/time.rs index 8ebbf89213f32..8365c9ee9c995 100644 --- a/src/libstd/sys/vxworks/time.rs +++ b/src/libstd/sys/vxworks/time.rs @@ -1,7 +1,6 @@ use crate::cmp::Ordering; use crate::time::Duration; use ::core::hash::{Hash, Hasher}; -use libc; pub use self::inner::{Instant, SystemTime, UNIX_EPOCH}; use crate::convert::TryInto; @@ -104,7 +103,6 @@ mod inner { use crate::fmt; use crate::sys::cvt; use crate::time::Duration; - use libc; use super::Timespec; diff --git a/src/libstd/sys/wasi/alloc.rs b/src/libstd/sys/wasi/alloc.rs index bc61416278401..57187851a14e3 100644 --- a/src/libstd/sys/wasi/alloc.rs +++ b/src/libstd/sys/wasi/alloc.rs @@ -1,7 +1,6 @@ use crate::alloc::{GlobalAlloc, Layout, System}; use crate::ptr; use crate::sys_common::alloc::{realloc_fallback, MIN_ALIGN}; -use libc; #[stable(feature = "alloc_system_type", since = "1.28.0")] unsafe impl GlobalAlloc for System { diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 39baa6b8540df..9eb43eb2df43f 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -7,7 +7,6 @@ #![deny(warnings)] use serde::Serialize; -use toml; use std::collections::BTreeMap; use std::collections::HashMap; diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index 52d0cbd4bfd7a..6ac7c3b9b474a 100644 --- a/src/tools/compiletest/src/json.rs +++ b/src/tools/compiletest/src/json.rs @@ -4,7 +4,6 @@ use crate::errors::{Error, ErrorKind}; use crate::runtest::ProcRes; use serde::Deserialize; -use serde_json; use std::path::{Path, PathBuf}; use std::str::FromStr; diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index c00b0f02c3a90..134ac66b7d15b 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -9,8 +9,6 @@ extern crate test; use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS}; use crate::common::{CompareMode, Config, Debugger, Mode, PassMode, Pretty, TestPaths}; use crate::util::logv; -use env_logger; -use getopts; use getopts::Options; use log::*; use std::env; diff --git a/src/tools/compiletest/src/read2.rs b/src/tools/compiletest/src/read2.rs index da1d3db49d70e..30a922057eb20 100644 --- a/src/tools/compiletest/src/read2.rs +++ b/src/tools/compiletest/src/read2.rs @@ -25,7 +25,6 @@ mod imp { #[cfg(unix)] mod imp { - use libc; use std::io; use std::io::prelude::*; use std::mem; diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 95ea4fb078955..dd0c68ecd4965 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -13,7 +13,6 @@ use crate::header::TestProps; use crate::json; use crate::util::get_pointer_width; use crate::util::{logv, PathBufExt}; -use diff; use regex::{Captures, Regex}; use rustfix::{apply_suggestions, get_suggestions_from_json, Filter}; From 7930f9a368c055db249a0378c1533aaedc7b037b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 22 Jun 2020 20:52:44 -0700 Subject: [PATCH 02/10] Change heuristic for determining range literal Currently, rustc uses a heuristic to determine if a range expression is not a literal based on whether the expression looks like a function call or struct initialization. This fails for range literals whose lower/upper bounds are the results of function calls. A possibly-better heuristic is to check if the expression contains `..`, required in range literals. Of course, this is also not perfect; for example, if the range expression is a struct which includes some text with `..` this will fail, but in general I believe it is a better heuristic. A better alternative altogether is to add the `QPath::LangItem` enum variant suggested in #60607. I would be happy to do this as a precursor to this patch if someone is able to provide general suggestions on how usages of `QPath` need to be changed later in the compiler with the `LangItem` variant. Closes #73553 --- src/librustc_hir/hir.rs | 8 +----- .../issue-73553-misinterp-range-literal.rs | 16 +++++++++++ ...issue-73553-misinterp-range-literal.stderr | 27 +++++++++++++++++++ 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/range/issue-73553-misinterp-range-literal.rs create mode 100644 src/test/ui/range/issue-73553-misinterp-range-literal.stderr diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs index 7d1cb7738c35e..f3dfec7ca7215 100644 --- a/src/librustc_hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -1511,13 +1511,7 @@ pub fn is_range_literal(sm: &SourceMap, expr: &Expr<'_>) -> bool { // Check whether a span corresponding to a range expression is a // range literal, rather than an explicit struct or `new()` call. fn is_lit(sm: &SourceMap, span: &Span) -> bool { - let end_point = sm.end_point(*span); - - if let Ok(end_string) = sm.span_to_snippet(end_point) { - !(end_string.ends_with('}') || end_string.ends_with(')')) - } else { - false - } + sm.span_to_snippet(*span).map(|range_src| range_src.contains("..")).unwrap_or(false) }; match expr.kind { diff --git a/src/test/ui/range/issue-73553-misinterp-range-literal.rs b/src/test/ui/range/issue-73553-misinterp-range-literal.rs new file mode 100644 index 0000000000000..e65dba0a03821 --- /dev/null +++ b/src/test/ui/range/issue-73553-misinterp-range-literal.rs @@ -0,0 +1,16 @@ +type Range = std::ops::Range; + +fn demo(r: &Range) { + println!("{:?}", r); +} + +fn tell(x: usize) -> usize { + x +} + +fn main() { + demo(tell(1)..tell(10)); + //~^ ERROR mismatched types + demo(1..10); + //~^ ERROR mismatched types +} diff --git a/src/test/ui/range/issue-73553-misinterp-range-literal.stderr b/src/test/ui/range/issue-73553-misinterp-range-literal.stderr new file mode 100644 index 0000000000000..5167b87fd27b8 --- /dev/null +++ b/src/test/ui/range/issue-73553-misinterp-range-literal.stderr @@ -0,0 +1,27 @@ +error[E0308]: mismatched types + --> $DIR/issue-73553-misinterp-range-literal.rs:12:10 + | +LL | demo(tell(1)..tell(10)); + | ^^^^^^^^^^^^^^^^^ + | | + | expected reference, found struct `std::ops::Range` + | help: consider borrowing here: `&(tell(1)..tell(10))` + | + = note: expected reference `&std::ops::Range` + found struct `std::ops::Range` + +error[E0308]: mismatched types + --> $DIR/issue-73553-misinterp-range-literal.rs:14:10 + | +LL | demo(1..10); + | ^^^^^ + | | + | expected reference, found struct `std::ops::Range` + | help: consider borrowing here: `&(1..10)` + | + = note: expected reference `&std::ops::Range` + found struct `std::ops::Range<{integer}>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. From bb882d74bd00477395e8d302463148f0a5f8cfe6 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 23 Jun 2020 17:52:01 +0900 Subject: [PATCH 03/10] Add test for issue-44861 --- src/test/ui/specialization/issue-44861.rs | 40 +++++++++++++++++++ src/test/ui/specialization/issue-44861.stderr | 12 ++++++ 2 files changed, 52 insertions(+) create mode 100644 src/test/ui/specialization/issue-44861.rs create mode 100644 src/test/ui/specialization/issue-44861.stderr diff --git a/src/test/ui/specialization/issue-44861.rs b/src/test/ui/specialization/issue-44861.rs new file mode 100644 index 0000000000000..c37a6273de366 --- /dev/null +++ b/src/test/ui/specialization/issue-44861.rs @@ -0,0 +1,40 @@ +#![crate_type = "lib"] +#![feature(specialization)] +#![feature(unsize, coerce_unsized)] +#![allow(incomplete_features)] + +use std::ops::CoerceUnsized; + +pub struct SmartassPtr(A::Data); + +pub trait Smartass { + type Data; + type Data2: CoerceUnsized<*const [u8]>; +} + +pub trait MaybeObjectSafe {} + +impl MaybeObjectSafe for () {} + +impl Smartass for T { + type Data = ::Data2; + default type Data2 = (); + //~^ ERROR: the trait bound `(): std::ops::CoerceUnsized<*const [u8]>` is not satisfied +} + +impl Smartass for () { + type Data2 = *const [u8; 1]; +} + +impl Smartass for dyn MaybeObjectSafe { + type Data = *const [u8]; + type Data2 = *const [u8; 0]; +} + +impl CoerceUnsized> for SmartassPtr + where ::Data: std::ops::CoerceUnsized<::Data> +{} + +pub fn conv(s: SmartassPtr<()>) -> SmartassPtr { + s +} diff --git a/src/test/ui/specialization/issue-44861.stderr b/src/test/ui/specialization/issue-44861.stderr new file mode 100644 index 0000000000000..b41b17e76a6ab --- /dev/null +++ b/src/test/ui/specialization/issue-44861.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `(): std::ops::CoerceUnsized<*const [u8]>` is not satisfied + --> $DIR/issue-44861.rs:21:5 + | +LL | type Data2: CoerceUnsized<*const [u8]>; + | --------------------------------------- required by `Smartass::Data2` +... +LL | default type Data2 = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::ops::CoerceUnsized<*const [u8]>` is not implemented for `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From 43ef554b6ab72c4cc3c56dab8e9b61021c63b3b7 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 23 Jun 2020 17:52:26 +0900 Subject: [PATCH 04/10] Add test for issue-51506 --- src/test/ui/never_type/issue-51506.rs | 41 +++++++++++++++++++++++ src/test/ui/never_type/issue-51506.stderr | 14 ++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/test/ui/never_type/issue-51506.rs create mode 100644 src/test/ui/never_type/issue-51506.stderr diff --git a/src/test/ui/never_type/issue-51506.rs b/src/test/ui/never_type/issue-51506.rs new file mode 100644 index 0000000000000..d0fe6a0f59a87 --- /dev/null +++ b/src/test/ui/never_type/issue-51506.rs @@ -0,0 +1,41 @@ +#![feature(never_type, specialization)] +#![allow(incomplete_features)] + +use std::iter::{self, Empty}; + +trait Trait { + type Out: Iterator; + + fn f(&self) -> Option; +} + +impl Trait for T { + default type Out = !; //~ ERROR: `!` is not an iterator + + default fn f(&self) -> Option { + None + } +} + +struct X; + +impl Trait for X { + type Out = Empty; + + fn f(&self) -> Option { + Some(iter::empty()) + } +} + +fn f(a: T) { + if let Some(iter) = a.f() { + println!("Some"); + for x in iter { + println!("x = {}", x); + } + } +} + +pub fn main() { + f(10); +} diff --git a/src/test/ui/never_type/issue-51506.stderr b/src/test/ui/never_type/issue-51506.stderr new file mode 100644 index 0000000000000..73865a9b5a02c --- /dev/null +++ b/src/test/ui/never_type/issue-51506.stderr @@ -0,0 +1,14 @@ +error[E0277]: `!` is not an iterator + --> $DIR/issue-51506.rs:13:5 + | +LL | type Out: Iterator; + | ------------------------------- required by `Trait::Out` +... +LL | default type Out = !; + | ^^^^^^^^^^^^^^^^^^^^^ `!` is not an iterator + | + = help: the trait `std::iter::Iterator` is not implemented for `!` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From e817cd2a6e499eebf9674e558b762fd98581f13a Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 23 Jun 2020 17:52:42 +0900 Subject: [PATCH 05/10] Add test for issue-59435 --- src/test/ui/specialization/issue-59435.rs | 17 +++++++++++++++++ src/test/ui/specialization/issue-59435.stderr | 12 ++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/test/ui/specialization/issue-59435.rs create mode 100644 src/test/ui/specialization/issue-59435.stderr diff --git a/src/test/ui/specialization/issue-59435.rs b/src/test/ui/specialization/issue-59435.rs new file mode 100644 index 0000000000000..47323d3096f3d --- /dev/null +++ b/src/test/ui/specialization/issue-59435.rs @@ -0,0 +1,17 @@ +#![feature(specialization)] +#![allow(incomplete_features)] + +struct MyStruct {} + +trait MyTrait { + type MyType: Default; +} + +impl MyTrait for i32 { + default type MyType = MyStruct; + //~^ ERROR: the trait bound `MyStruct: std::default::Default` is not satisfied +} + +fn main() { + let _x: ::MyType = ::MyType::default(); +} diff --git a/src/test/ui/specialization/issue-59435.stderr b/src/test/ui/specialization/issue-59435.stderr new file mode 100644 index 0000000000000..fd512a539a3ee --- /dev/null +++ b/src/test/ui/specialization/issue-59435.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `MyStruct: std::default::Default` is not satisfied + --> $DIR/issue-59435.rs:11:5 + | +LL | type MyType: Default; + | --------------------- required by `MyTrait::MyType` +... +LL | default type MyType = MyStruct; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::default::Default` is not implemented for `MyStruct` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From 814782b4c6bd773d47dfce5614d4bbea935f5d85 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 23 Jun 2020 17:52:51 +0900 Subject: [PATCH 06/10] Add test for issue-69840 --- src/test/ui/impl-trait/issue-69840.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/ui/impl-trait/issue-69840.rs diff --git a/src/test/ui/impl-trait/issue-69840.rs b/src/test/ui/impl-trait/issue-69840.rs new file mode 100644 index 0000000000000..b270f88b6886e --- /dev/null +++ b/src/test/ui/impl-trait/issue-69840.rs @@ -0,0 +1,16 @@ +// check-pass + +#![feature(impl_trait_in_bindings)] +#![allow(incomplete_features)] + +struct A<'a>(&'a ()); + +trait Trait {} + +impl Trait for () {} + +pub fn foo<'a>() { + let _x: impl Trait> = (); +} + +fn main() {} From 404df1cbbfac0126d256f99a12a175d9ce96fd0f Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sun, 21 Jun 2020 19:31:49 +0300 Subject: [PATCH 07/10] Add re-exports to use suggestions In the following example, an inaccessible path is suggested via `use foo::bar::X;` whereas an accessible public exported path can be suggested instead. ``` mod foo { mod bar { pub struct X; } pub use self::bar::X; } fn main() { X; } ``` This fixes the issue. --- src/librustc_resolve/diagnostics.rs | 23 +++++++++++++------- src/librustc_resolve/lib.rs | 7 ++++++ src/test/ui/glob-resolve1.rs | 4 ++++ src/test/ui/glob-resolve1.stderr | 5 +++++ src/test/ui/namespace/namespace-mix.stderr | 8 +++---- src/test/ui/resolve/issue-21221-2.stderr | 4 +++- src/test/ui/resolve/privacy-enum-ctor.stderr | 8 +++---- 7 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index bb88b8191f1ad..ea4a84a9c3bd4 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -643,22 +643,24 @@ impl<'a> Resolver<'a> { let not_local_module = crate_name.name != kw::Crate; let mut worklist = vec![(start_module, Vec::::new(), true, not_local_module)]; + let mut worklist_via_import = vec![]; - while let Some((in_module, path_segments, accessible, in_module_is_extern)) = worklist.pop() + while let Some((in_module, path_segments, accessible, in_module_is_extern)) = + match worklist.pop() { + None => worklist_via_import.pop(), + Some(x) => Some(x), + } { // We have to visit module children in deterministic order to avoid // instabilities in reported imports (#43552). in_module.for_each_child(self, |this, ident, ns, name_binding| { - // avoid imports entirely - if name_binding.is_import() && !name_binding.is_extern_crate() { - return; - } - - // avoid non-importable candidates as well + // avoid non-importable candidates if !name_binding.is_importable() { return; } + let via_import = name_binding.is_import() && !name_binding.is_extern_crate(); + let child_accessible = accessible && this.is_accessible_from(name_binding.vis, parent_scope.module); @@ -667,6 +669,10 @@ impl<'a> Resolver<'a> { return; } + if via_import && name_binding.is_possibly_imported_variant() { + return; + } + // collect results based on the filter function // avoid suggesting anything from the same module in which we are resolving if ident.name == lookup_ident.name @@ -724,7 +730,8 @@ impl<'a> Resolver<'a> { let is_extern = in_module_is_extern || name_binding.is_extern_crate(); // add the module to the lookup if seen_modules.insert(module.def_id().unwrap()) { - worklist.push((module, path_segments, child_accessible, is_extern)); + if via_import { &mut worklist_via_import } else { &mut worklist } + .push((module, path_segments, child_accessible, is_extern)); } } } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 91bd155614178..9aa0be0a71e1f 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -711,6 +711,13 @@ impl<'a> NameBinding<'a> { } } + fn is_possibly_imported_variant(&self) -> bool { + match self.kind { + NameBindingKind::Import { binding, .. } => binding.is_possibly_imported_variant(), + _ => self.is_variant(), + } + } + // We sometimes need to treat variants as `pub` for backwards compatibility. fn pseudo_vis(&self) -> ty::Visibility { if self.is_variant() && self.res().def_id().is_local() { diff --git a/src/test/ui/glob-resolve1.rs b/src/test/ui/glob-resolve1.rs index 63c435cc20641..32660fdb41876 100644 --- a/src/test/ui/glob-resolve1.rs +++ b/src/test/ui/glob-resolve1.rs @@ -29,3 +29,7 @@ fn main() { foo::(); //~ ERROR: cannot find type `C` in this scope foo::(); //~ ERROR: cannot find type `D` in this scope } + +mod other { + pub fn import() {} +} diff --git a/src/test/ui/glob-resolve1.stderr b/src/test/ui/glob-resolve1.stderr index 995da6cc1f975..3c818f3ae48ea 100644 --- a/src/test/ui/glob-resolve1.stderr +++ b/src/test/ui/glob-resolve1.stderr @@ -42,6 +42,11 @@ error[E0425]: cannot find function `import` in this scope | LL | import(); | ^^^^^^ not found in this scope + | +help: consider importing this function + | +LL | use other::import; + | error[E0412]: cannot find type `A` in this scope --> $DIR/glob-resolve1.rs:28:11 diff --git a/src/test/ui/namespace/namespace-mix.stderr b/src/test/ui/namespace/namespace-mix.stderr index c80055f00d7d9..ee730910ee441 100644 --- a/src/test/ui/namespace/namespace-mix.stderr +++ b/src/test/ui/namespace/namespace-mix.stderr @@ -16,7 +16,7 @@ help: consider importing one of these items instead | LL | use m2::S; | -LL | use namespace_mix::xm2::S; +LL | use xm2::S; | error[E0423]: expected value, found type alias `xm1::S` @@ -39,7 +39,7 @@ help: consider importing one of these items instead | LL | use m2::S; | -LL | use namespace_mix::xm2::S; +LL | use xm2::S; | error[E0423]: expected value, found struct variant `m7::V` @@ -61,7 +61,7 @@ help: consider importing one of these items instead | LL | use m8::V; | -LL | use namespace_mix::xm8::V; +LL | use xm8::V; | error[E0423]: expected value, found struct variant `xm7::V` @@ -83,7 +83,7 @@ help: consider importing one of these items instead | LL | use m8::V; | -LL | use namespace_mix::xm8::V; +LL | use xm8::V; | error[E0277]: the trait bound `c::Item: Impossible` is not satisfied diff --git a/src/test/ui/resolve/issue-21221-2.stderr b/src/test/ui/resolve/issue-21221-2.stderr index f9263d2af5026..d4fd7cb1257e0 100644 --- a/src/test/ui/resolve/issue-21221-2.stderr +++ b/src/test/ui/resolve/issue-21221-2.stderr @@ -4,7 +4,9 @@ error[E0405]: cannot find trait `T` in this scope LL | impl T for Foo { } | ^ not found in this scope | -help: consider importing this trait +help: consider importing one of these items + | +LL | use baz::T; | LL | use foo::bar::T; | diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr index d9b1b9c59558a..16baa6c9b6233 100644 --- a/src/test/ui/resolve/privacy-enum-ctor.stderr +++ b/src/test/ui/resolve/privacy-enum-ctor.stderr @@ -132,7 +132,7 @@ LL | let _: E = m::n::Z; | ^ help: consider importing this enum | -LL | use m::n::Z; +LL | use m::Z; | error[E0423]: expected value, found enum `m::n::Z` @@ -165,7 +165,7 @@ LL | let _: E = m::n::Z::Fn; | ^ help: consider importing this enum | -LL | use m::n::Z; +LL | use m::Z; | error[E0412]: cannot find type `Z` in this scope @@ -183,7 +183,7 @@ LL | let _: E = m::n::Z::Struct; | ^ help: consider importing this enum | -LL | use m::n::Z; +LL | use m::Z; | error[E0423]: expected value, found struct variant `m::n::Z::Struct` @@ -212,7 +212,7 @@ LL | let _: E = m::n::Z::Unit {}; | ^ help: consider importing this enum | -LL | use m::n::Z; +LL | use m::Z; | error[E0603]: enum `Z` is private From f37c157f2ca1b56d17389cacb4287aebc44edc45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Tue, 23 Jun 2020 20:06:44 +0200 Subject: [PATCH 08/10] Update map.rs --- src/liballoc/collections/btree/map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs index 2fcc8cc98737d..88a8aa19b5718 100644 --- a/src/liballoc/collections/btree/map.rs +++ b/src/liballoc/collections/btree/map.rs @@ -488,7 +488,7 @@ struct MergeIter> { } impl BTreeMap { - /// Makes a new empty BTreeMap with a reasonable choice for B. + /// Makes a new empty BTreeMap. /// /// # Examples /// From 037e930df7983577a2093732de0bd2c1252a4e37 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Tue, 23 Jun 2020 22:25:23 +0300 Subject: [PATCH 09/10] Review fixes --- src/librustc_resolve/diagnostics.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index ea4a84a9c3bd4..268974384a8d3 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -659,8 +659,6 @@ impl<'a> Resolver<'a> { return; } - let via_import = name_binding.is_import() && !name_binding.is_extern_crate(); - let child_accessible = accessible && this.is_accessible_from(name_binding.vis, parent_scope.module); @@ -669,6 +667,13 @@ impl<'a> Resolver<'a> { return; } + let via_import = name_binding.is_import() && !name_binding.is_extern_crate(); + + // There is an assumption elsewhere that paths of variants are in the enum's + // declaration and not imported. With this assumption, the variant component is + // chopped and the rest of the path is assumed to be the enum's own path. For + // errors where a variant is used as the type instead of the enum, this causes + // funny looking invalid suggestions, i.e `foo` instead of `foo::MyEnum`. if via_import && name_binding.is_possibly_imported_variant() { return; } From e02dafcaaaf4c9f32e549f643721b7e43ab86516 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 23 Jun 2020 17:56:33 -0700 Subject: [PATCH 10/10] Update books --- src/doc/book | 2 +- src/doc/embedded-book | 2 +- src/doc/reference | 2 +- src/doc/rust-by-example | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/book b/src/doc/book index 30cd9dfe71c44..4e7c00bece154 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 30cd9dfe71c446de63826bb4472627af45acc9db +Subproject commit 4e7c00bece1544d409312ec93467beb62b5bd0cb diff --git a/src/doc/embedded-book b/src/doc/embedded-book index 5555a97f04ad7..616962ad0dd80 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit 5555a97f04ad7974ac6fb8fb47c267c4274adf4a +Subproject commit 616962ad0dd80f34d8b802da038d0aed9dd691bb diff --git a/src/doc/reference b/src/doc/reference index 5d40ba5c2515c..04d5d5d7ba624 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 5d40ba5c2515caffa7790cda621239dc21ef5a72 +Subproject commit 04d5d5d7ba624b6f5016298451f3a63d557f3260 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 7aa82129aa23e..6f94ccb48da6f 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 7aa82129aa23e7e181efbeb8da03a2a897ef6afc +Subproject commit 6f94ccb48da6fa4ed0031290f21411cf789f7d5e