Skip to content

Commit d8ed1b0

Browse files
committed
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
2 parents 0b66a89 + be8f381 commit d8ed1b0

38 files changed

+248
-51
lines changed

src/liballoc/collections/btree/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ struct MergeIter<K, V, I: Iterator<Item = (K, V)>> {
488488
}
489489

490490
impl<K: Ord, V> BTreeMap<K, V> {
491-
/// Makes a new empty BTreeMap with a reasonable choice for B.
491+
/// Makes a new empty BTreeMap.
492492
///
493493
/// Does not allocate anything on its own.
494494
///

src/liballoc/collections/vec_deque/tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use super::*;
22

3-
use test;
4-
53
#[bench]
64
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
75
fn bench_push_back_100(b: &mut test::Bencher) {

src/librustc_ast_pretty/pprust/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::*;
22

33
use rustc_ast::ast;
44
use rustc_ast::with_default_globals;
5-
use rustc_span;
65
use rustc_span::source_map::respan;
76
use rustc_span::symbol::Ident;
87

src/librustc_data_structures/sync.rs

-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ cfg_if! {
358358
use parking_lot::Mutex as InnerLock;
359359
use parking_lot::RwLock as InnerRwLock;
360360

361-
use std;
362361
use std::thread;
363362
pub use rayon::{join, scope};
364363

src/librustc_hir/hir.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1511,13 +1511,7 @@ pub fn is_range_literal(sm: &SourceMap, expr: &Expr<'_>) -> bool {
15111511
// Check whether a span corresponding to a range expression is a
15121512
// range literal, rather than an explicit struct or `new()` call.
15131513
fn is_lit(sm: &SourceMap, span: &Span) -> bool {
1514-
let end_point = sm.end_point(*span);
1515-
1516-
if let Ok(end_string) = sm.span_to_snippet(end_point) {
1517-
!(end_string.ends_with('}') || end_string.ends_with(')'))
1518-
} else {
1519-
false
1520-
}
1514+
sm.span_to_snippet(*span).map(|range_src| range_src.contains("..")).unwrap_or(false)
15211515
};
15221516

15231517
match expr.kind {

src/librustc_resolve/diagnostics.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -643,18 +643,18 @@ impl<'a> Resolver<'a> {
643643
let not_local_module = crate_name.name != kw::Crate;
644644
let mut worklist =
645645
vec![(start_module, Vec::<ast::PathSegment>::new(), true, not_local_module)];
646+
let mut worklist_via_import = vec![];
646647

647-
while let Some((in_module, path_segments, accessible, in_module_is_extern)) = worklist.pop()
648+
while let Some((in_module, path_segments, accessible, in_module_is_extern)) =
649+
match worklist.pop() {
650+
None => worklist_via_import.pop(),
651+
Some(x) => Some(x),
652+
}
648653
{
649654
// We have to visit module children in deterministic order to avoid
650655
// instabilities in reported imports (#43552).
651656
in_module.for_each_child(self, |this, ident, ns, name_binding| {
652-
// avoid imports entirely
653-
if name_binding.is_import() && !name_binding.is_extern_crate() {
654-
return;
655-
}
656-
657-
// avoid non-importable candidates as well
657+
// avoid non-importable candidates
658658
if !name_binding.is_importable() {
659659
return;
660660
}
@@ -667,6 +667,17 @@ impl<'a> Resolver<'a> {
667667
return;
668668
}
669669

670+
let via_import = name_binding.is_import() && !name_binding.is_extern_crate();
671+
672+
// There is an assumption elsewhere that paths of variants are in the enum's
673+
// declaration and not imported. With this assumption, the variant component is
674+
// chopped and the rest of the path is assumed to be the enum's own path. For
675+
// errors where a variant is used as the type instead of the enum, this causes
676+
// funny looking invalid suggestions, i.e `foo` instead of `foo::MyEnum`.
677+
if via_import && name_binding.is_possibly_imported_variant() {
678+
return;
679+
}
680+
670681
// collect results based on the filter function
671682
// avoid suggesting anything from the same module in which we are resolving
672683
if ident.name == lookup_ident.name
@@ -724,7 +735,8 @@ impl<'a> Resolver<'a> {
724735
let is_extern = in_module_is_extern || name_binding.is_extern_crate();
725736
// add the module to the lookup
726737
if seen_modules.insert(module.def_id().unwrap()) {
727-
worklist.push((module, path_segments, child_accessible, is_extern));
738+
if via_import { &mut worklist_via_import } else { &mut worklist }
739+
.push((module, path_segments, child_accessible, is_extern));
728740
}
729741
}
730742
}

src/librustc_resolve/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,13 @@ impl<'a> NameBinding<'a> {
703703
}
704704
}
705705

706+
fn is_possibly_imported_variant(&self) -> bool {
707+
match self.kind {
708+
NameBindingKind::Import { binding, .. } => binding.is_possibly_imported_variant(),
709+
_ => self.is_variant(),
710+
}
711+
}
712+
706713
// We sometimes need to treat variants as `pub` for backwards compatibility.
707714
fn pseudo_vis(&self) -> ty::Visibility {
708715
if self.is_variant() && self.res().def_id().is_local() {

src/libstd/os/illumos/fs.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![stable(feature = "metadata_ext", since = "1.1.0")]
22

3-
use libc;
4-
53
use crate::fs::Metadata;
64
use crate::sys_common::AsInner;
75

src/libstd/sys/unix/ext/net.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
//! Unix-specific networking functionality
44
5-
#[cfg(unix)]
6-
use libc;
7-
85
// FIXME(#43348): Make libc adapt #[doc(cfg(...))] so we don't need these fake definitions here?
96
#[cfg(not(unix))]
107
#[allow(non_camel_case_types)]

src/libstd/sys/vxworks/args.rs

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ mod imp {
5656
use crate::ffi::{CStr, OsString};
5757
use crate::marker::PhantomData;
5858
use crate::ptr;
59-
use libc;
6059

6160
use crate::sys_common::mutex::Mutex;
6261

src/libstd/sys/vxworks/ext/fs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::path::Path;
66
use crate::sys;
77
use crate::sys::platform::fs::MetadataExt as UnixMetadataExt;
88
use crate::sys_common::{AsInner, AsInnerMut, FromInner};
9-
use libc;
109

1110
/// Unix-specific extensions to [`File`].
1211
///

src/libstd/sys/vxworks/rand.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub fn hashmap_random_keys() -> (u64, u64) {
1313
mod imp {
1414
use crate::io;
1515
use core::sync::atomic::{AtomicBool, Ordering::Relaxed};
16-
use libc;
1716

1817
pub fn fill_bytes(v: &mut [u8]) {
1918
static RNG_INIT: AtomicBool = AtomicBool::new(false);

src/libstd/sys/vxworks/rwlock.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::cell::UnsafeCell;
22
use crate::sync::atomic::{AtomicUsize, Ordering};
3-
use libc;
43

54
pub struct RWLock {
65
inner: UnsafeCell<libc::pthread_rwlock_t>,

src/libstd/sys/vxworks/time.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::cmp::Ordering;
22
use crate::time::Duration;
33
use ::core::hash::{Hash, Hasher};
4-
use libc;
54

65
pub use self::inner::{Instant, SystemTime, UNIX_EPOCH};
76
use crate::convert::TryInto;
@@ -104,7 +103,6 @@ mod inner {
104103
use crate::fmt;
105104
use crate::sys::cvt;
106105
use crate::time::Duration;
107-
use libc;
108106

109107
use super::Timespec;
110108

src/libstd/sys/wasi/alloc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::alloc::{GlobalAlloc, Layout, System};
22
use crate::ptr;
33
use crate::sys_common::alloc::{realloc_fallback, MIN_ALIGN};
4-
use libc;
54

65
#[stable(feature = "alloc_system_type", since = "1.28.0")]
76
unsafe impl GlobalAlloc for System {

src/test/ui/glob-resolve1.rs

+4
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ fn main() {
2929
foo::<C>(); //~ ERROR: cannot find type `C` in this scope
3030
foo::<D>(); //~ ERROR: cannot find type `D` in this scope
3131
}
32+
33+
mod other {
34+
pub fn import() {}
35+
}

src/test/ui/glob-resolve1.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ error[E0425]: cannot find function `import` in this scope
4242
|
4343
LL | import();
4444
| ^^^^^^ not found in this scope
45+
|
46+
help: consider importing this function
47+
|
48+
LL | use other::import;
49+
|
4550

4651
error[E0412]: cannot find type `A` in this scope
4752
--> $DIR/glob-resolve1.rs:28:11

src/test/ui/impl-trait/issue-69840.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
3+
#![feature(impl_trait_in_bindings)]
4+
#![allow(incomplete_features)]
5+
6+
struct A<'a>(&'a ());
7+
8+
trait Trait<T> {}
9+
10+
impl<T> Trait<T> for () {}
11+
12+
pub fn foo<'a>() {
13+
let _x: impl Trait<A<'a>> = ();
14+
}
15+
16+
fn main() {}

src/test/ui/namespace/namespace-mix.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ help: consider importing one of these items instead
1616
|
1717
LL | use m2::S;
1818
|
19-
LL | use namespace_mix::xm2::S;
19+
LL | use xm2::S;
2020
|
2121

2222
error[E0423]: expected value, found type alias `xm1::S`
@@ -39,7 +39,7 @@ help: consider importing one of these items instead
3939
|
4040
LL | use m2::S;
4141
|
42-
LL | use namespace_mix::xm2::S;
42+
LL | use xm2::S;
4343
|
4444

4545
error[E0423]: expected value, found struct variant `m7::V`
@@ -61,7 +61,7 @@ help: consider importing one of these items instead
6161
|
6262
LL | use m8::V;
6363
|
64-
LL | use namespace_mix::xm8::V;
64+
LL | use xm8::V;
6565
|
6666

6767
error[E0423]: expected value, found struct variant `xm7::V`
@@ -83,7 +83,7 @@ help: consider importing one of these items instead
8383
|
8484
LL | use m8::V;
8585
|
86-
LL | use namespace_mix::xm8::V;
86+
LL | use xm8::V;
8787
|
8888

8989
error[E0277]: the trait bound `c::Item: Impossible` is not satisfied

src/test/ui/never_type/issue-51506.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![feature(never_type, specialization)]
2+
#![allow(incomplete_features)]
3+
4+
use std::iter::{self, Empty};
5+
6+
trait Trait {
7+
type Out: Iterator<Item = u32>;
8+
9+
fn f(&self) -> Option<Self::Out>;
10+
}
11+
12+
impl<T> Trait for T {
13+
default type Out = !; //~ ERROR: `!` is not an iterator
14+
15+
default fn f(&self) -> Option<Self::Out> {
16+
None
17+
}
18+
}
19+
20+
struct X;
21+
22+
impl Trait for X {
23+
type Out = Empty<u32>;
24+
25+
fn f(&self) -> Option<Self::Out> {
26+
Some(iter::empty())
27+
}
28+
}
29+
30+
fn f<T: Trait>(a: T) {
31+
if let Some(iter) = a.f() {
32+
println!("Some");
33+
for x in iter {
34+
println!("x = {}", x);
35+
}
36+
}
37+
}
38+
39+
pub fn main() {
40+
f(10);
41+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: `!` is not an iterator
2+
--> $DIR/issue-51506.rs:13:5
3+
|
4+
LL | type Out: Iterator<Item = u32>;
5+
| ------------------------------- required by `Trait::Out`
6+
...
7+
LL | default type Out = !;
8+
| ^^^^^^^^^^^^^^^^^^^^^ `!` is not an iterator
9+
|
10+
= help: the trait `std::iter::Iterator` is not implemented for `!`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
type Range = std::ops::Range<usize>;
2+
3+
fn demo(r: &Range) {
4+
println!("{:?}", r);
5+
}
6+
7+
fn tell(x: usize) -> usize {
8+
x
9+
}
10+
11+
fn main() {
12+
demo(tell(1)..tell(10));
13+
//~^ ERROR mismatched types
14+
demo(1..10);
15+
//~^ ERROR mismatched types
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-73553-misinterp-range-literal.rs:12:10
3+
|
4+
LL | demo(tell(1)..tell(10));
5+
| ^^^^^^^^^^^^^^^^^
6+
| |
7+
| expected reference, found struct `std::ops::Range`
8+
| help: consider borrowing here: `&(tell(1)..tell(10))`
9+
|
10+
= note: expected reference `&std::ops::Range<usize>`
11+
found struct `std::ops::Range<usize>`
12+
13+
error[E0308]: mismatched types
14+
--> $DIR/issue-73553-misinterp-range-literal.rs:14:10
15+
|
16+
LL | demo(1..10);
17+
| ^^^^^
18+
| |
19+
| expected reference, found struct `std::ops::Range`
20+
| help: consider borrowing here: `&(1..10)`
21+
|
22+
= note: expected reference `&std::ops::Range<usize>`
23+
found struct `std::ops::Range<{integer}>`
24+
25+
error: aborting due to 2 previous errors
26+
27+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/resolve/issue-21221-2.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ error[E0405]: cannot find trait `T` in this scope
44
LL | impl T for Foo { }
55
| ^ not found in this scope
66
|
7-
help: consider importing this trait
7+
help: consider importing one of these items
8+
|
9+
LL | use baz::T;
810
|
911
LL | use foo::bar::T;
1012
|

0 commit comments

Comments
 (0)