1
Fork 0

Auto merge of #73692 - Dylan-DPC:rollup-ehzsbfw, r=Dylan-DPC

Rollup of 6 pull requests

Successful merges:

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

Failed merges:

r? @ghost
This commit is contained in:
bors 2020-06-24 15:47:22 +00:00
commit d8ed1b03c2
38 changed files with 248 additions and 51 deletions

@ -1 +1 @@
Subproject commit 30cd9dfe71c446de63826bb4472627af45acc9db
Subproject commit 4e7c00bece1544d409312ec93467beb62b5bd0cb

@ -1 +1 @@
Subproject commit 5555a97f04ad7974ac6fb8fb47c267c4274adf4a
Subproject commit 616962ad0dd80f34d8b802da038d0aed9dd691bb

@ -1 +1 @@
Subproject commit 5d40ba5c2515caffa7790cda621239dc21ef5a72
Subproject commit 04d5d5d7ba624b6f5016298451f3a63d557f3260

@ -1 +1 @@
Subproject commit 7aa82129aa23e7e181efbeb8da03a2a897ef6afc
Subproject commit 6f94ccb48da6fa4ed0031290f21411cf789f7d5e

View file

@ -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.
///

View file

@ -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) {

View file

@ -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;

View file

@ -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};

View file

@ -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 {

View file

@ -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;
}
@ -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
@ -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));
}
}
}

View file

@ -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() {

View file

@ -1,7 +1,5 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]
use libc;
use crate::fs::Metadata;
use crate::sys_common::AsInner;

View file

@ -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)]

View file

@ -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;

View file

@ -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`].
///

View file

@ -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);

View file

@ -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>,

View file

@ -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;

View file

@ -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 {

View file

@ -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() {}
}

View file

@ -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

View file

@ -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() {}

View file

@ -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

View file

@ -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);
}

View file

@ -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`.

View file

@ -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
}

View file

@ -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`.

View file

@ -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;
|

View file

@ -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

View file

@ -0,0 +1,40 @@
#![crate_type = "lib"]
#![feature(specialization)]
#![feature(unsize, coerce_unsized)]
#![allow(incomplete_features)]
use std::ops::CoerceUnsized;
pub struct SmartassPtr<A: Smartass+?Sized>(A::Data);
pub trait Smartass {
type Data;
type Data2: CoerceUnsized<*const [u8]>;
}
pub trait MaybeObjectSafe {}
impl MaybeObjectSafe for () {}
impl<T> Smartass for T {
type Data = <Self as Smartass>::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<U: Smartass+?Sized, T: Smartass+?Sized> CoerceUnsized<SmartassPtr<T>> for SmartassPtr<U>
where <U as Smartass>::Data: std::ops::CoerceUnsized<<T as Smartass>::Data>
{}
pub fn conv(s: SmartassPtr<()>) -> SmartassPtr<dyn MaybeObjectSafe> {
s
}

View file

@ -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`.

View file

@ -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: <i32 as MyTrait>::MyType = <i32 as MyTrait>::MyType::default();
}

View file

@ -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`.

View file

@ -7,7 +7,6 @@
#![deny(warnings)]
use serde::Serialize;
use toml;
use std::collections::BTreeMap;
use std::collections::HashMap;

View file

@ -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;

View file

@ -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;

View file

@ -25,7 +25,6 @@ mod imp {
#[cfg(unix)]
mod imp {
use libc;
use std::io;
use std::io::prelude::*;
use std::mem;

View file

@ -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};