Skip to content

Commit

Permalink
Auto merge of rust-lang#73692 - Dylan-DPC:rollup-ehzsbfw, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - rust-lang#73638 (Remove unused crate imports in 2018 edition crates)
 - rust-lang#73639 (Change heuristic for determining range literal)
 - rust-lang#73646 (Add some regression tests)
 - rust-lang#73652 (Add re-exports to use suggestions)
 - rust-lang#73667 (Update BTreeMap::new() doc)
 - rust-lang#73675 (Update books)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Jun 24, 2020
2 parents 0b66a89 + be8f381 commit d8ed1b0
Show file tree
Hide file tree
Showing 38 changed files with 248 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/doc/book
2 changes: 1 addition & 1 deletion src/doc/rust-by-example
2 changes: 1 addition & 1 deletion src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ struct MergeIter<K, V, I: Iterator<Item = (K, V)>> {
}

impl<K: Ord, V> BTreeMap<K, V> {
/// Makes a new empty BTreeMap with a reasonable choice for B.
/// Makes a new empty BTreeMap.
///
/// Does not allocate anything on its own.
///
Expand Down
2 changes: 0 additions & 2 deletions src/liballoc/collections/vec_deque/tests.rs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/librustc_ast_pretty/pprust/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/librustc_data_structures/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
8 changes: 1 addition & 7 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 20 additions & 8 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,18 +643,18 @@ impl<'a> Resolver<'a> {
let not_local_module = crate_name.name != kw::Crate;
let mut worklist =
vec![(start_module, Vec::<ast::PathSegment>::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;
}
Expand All @@ -667,6 +667,17 @@ 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;
}

// 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
Expand Down Expand Up @@ -724,7 +735,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));
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,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() {
Expand Down
2 changes: 0 additions & 2 deletions src/libstd/os/illumos/fs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use libc;

use crate::fs::Metadata;
use crate::sys_common::AsInner;

Expand Down
3 changes: 0 additions & 3 deletions src/libstd/sys/unix/ext/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 0 additions & 1 deletion src/libstd/sys/vxworks/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/libstd/sys/vxworks/ext/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
///
Expand Down
1 change: 0 additions & 1 deletion src/libstd/sys/vxworks/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/libstd/sys/vxworks/rwlock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::cell::UnsafeCell;
use crate::sync::atomic::{AtomicUsize, Ordering};
use libc;

pub struct RWLock {
inner: UnsafeCell<libc::pthread_rwlock_t>,
Expand Down
2 changes: 0 additions & 2 deletions src/libstd/sys/vxworks/time.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -104,7 +103,6 @@ mod inner {
use crate::fmt;
use crate::sys::cvt;
use crate::time::Duration;
use libc;

use super::Timespec;

Expand Down
1 change: 0 additions & 1 deletion src/libstd/sys/wasi/alloc.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/glob-resolve1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ fn main() {
foo::<C>(); //~ ERROR: cannot find type `C` in this scope
foo::<D>(); //~ ERROR: cannot find type `D` in this scope
}

mod other {
pub fn import() {}
}
5 changes: 5 additions & 0 deletions src/test/ui/glob-resolve1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/impl-trait/issue-69840.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// check-pass

#![feature(impl_trait_in_bindings)]
#![allow(incomplete_features)]

struct A<'a>(&'a ());

trait Trait<T> {}

impl<T> Trait<T> for () {}

pub fn foo<'a>() {
let _x: impl Trait<A<'a>> = ();
}

fn main() {}
8 changes: 4 additions & 4 deletions src/test/ui/namespace/namespace-mix.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand All @@ -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`
Expand All @@ -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
Expand Down
41 changes: 41 additions & 0 deletions src/test/ui/never_type/issue-51506.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#![feature(never_type, specialization)]
#![allow(incomplete_features)]

use std::iter::{self, Empty};

trait Trait {
type Out: Iterator<Item = u32>;

fn f(&self) -> Option<Self::Out>;
}

impl<T> Trait for T {
default type Out = !; //~ ERROR: `!` is not an iterator

default fn f(&self) -> Option<Self::Out> {
None
}
}

struct X;

impl Trait for X {
type Out = Empty<u32>;

fn f(&self) -> Option<Self::Out> {
Some(iter::empty())
}
}

fn f<T: Trait>(a: T) {
if let Some(iter) = a.f() {
println!("Some");
for x in iter {
println!("x = {}", x);
}
}
}

pub fn main() {
f(10);
}
14 changes: 14 additions & 0 deletions src/test/ui/never_type/issue-51506.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0277]: `!` is not an iterator
--> $DIR/issue-51506.rs:13:5
|
LL | type Out: Iterator<Item = u32>;
| ------------------------------- 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`.
16 changes: 16 additions & 0 deletions src/test/ui/range/issue-73553-misinterp-range-literal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type Range = std::ops::Range<usize>;

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
}
27 changes: 27 additions & 0 deletions src/test/ui/range/issue-73553-misinterp-range-literal.stderr
Original file line number Diff line number Diff line change
@@ -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<usize>`
found struct `std::ops::Range<usize>`

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<usize>`
found struct `std::ops::Range<{integer}>`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
4 changes: 3 additions & 1 deletion src/test/ui/resolve/issue-21221-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
|
Expand Down
Loading

0 comments on commit d8ed1b0

Please sign in to comment.