Skip to content

Commit dee12bb

Browse files
committed
Auto merge of #68506 - tmandry:rollup-kz9d33v, r=tmandry
Rollup of 7 pull requests Successful merges: - #68424 (Suggest borrowing `Vec<NonCopy>` in for loop) - #68438 (Account for non-types in substs for opaque type error messages) - #68469 (Avoid overflow in `std::iter::Skip::count`) - #68473 (Enable ASan on Fuchsia) - #68479 (Implement `unused_parens` for block return values) - #68483 (Add my (@flip1995) name to .mailmap) - #68500 (Clear out std, not std tools) Failed merges: r? @ghost
2 parents 62f227b + 7f8a61d commit dee12bb

File tree

25 files changed

+198
-39
lines changed

25 files changed

+198
-39
lines changed

.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ Peter Liniker <[email protected]>
211211
Phil Dawes <[email protected]> Phil Dawes <[email protected]>
212212
Philipp Brüschweiler <[email protected]> <[email protected]>
213213
Philipp Brüschweiler <[email protected]> <[email protected]>
214+
Philipp Krones <[email protected]> flip1995 <[email protected]>
214215
Philipp Matthias Schäfer <[email protected]>
215216
Przemysław Wesołek <[email protected]> Przemek Wesołek <[email protected]>
216217
Rafael Ávila de Espíndola <[email protected]> Rafael Avila de Espindola <espindola@dream.(none)>

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ impl<'a> Builder<'a> {
874874
//
875875
// Only clear out the directory if we're compiling std; otherwise, we
876876
// should let Cargo take care of things for us (via depdep info)
877-
if !self.config.dry_run && mode == Mode::ToolStd && cmd == "build" {
877+
if !self.config.dry_run && mode == Mode::Std && cmd == "build" {
878878
self.clear_if_dirty(&out_dir, &self.rustc(compiler));
879879
}
880880

src/bootstrap/native.rs

+18
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,24 @@ fn supported_sanitizers(out_dir: &Path, target: Interned<String>) -> Vec<Sanitiz
659659
});
660660
}
661661
}
662+
"x86_64-fuchsia" => {
663+
for s in &["asan"] {
664+
result.push(SanitizerRuntime {
665+
cmake_target: format!("clang_rt.{}-x86_64", s),
666+
path: out_dir.join(&format!("build/lib/fuchsia/libclang_rt.{}-x86_64.a", s)),
667+
name: format!("librustc_rt.{}.a", s),
668+
});
669+
}
670+
}
671+
"aarch64-fuchsia" => {
672+
for s in &["asan"] {
673+
result.push(SanitizerRuntime {
674+
cmake_target: format!("clang_rt.{}-aarch64", s),
675+
path: out_dir.join(&format!("build/lib/fuchsia/libclang_rt.{}-aarch64.a", s)),
676+
name: format!("librustc_rt.{}.a", s),
677+
});
678+
}
679+
}
662680
_ => {}
663681
}
664682
result

src/libcore/iter/adapters/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1815,8 +1815,14 @@ where
18151815
}
18161816

18171817
#[inline]
1818-
fn count(self) -> usize {
1819-
self.iter.count().saturating_sub(self.n)
1818+
fn count(mut self) -> usize {
1819+
if self.n > 0 {
1820+
// nth(n) skips n+1
1821+
if self.iter.nth(self.n - 1).is_none() {
1822+
return 0;
1823+
}
1824+
}
1825+
self.iter.count()
18201826
}
18211827

18221828
#[inline]

src/libcore/option.rs

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ use crate::{
151151

152152
/// The `Option` type. See [the module level documentation](index.html) for more.
153153
#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
154+
#[rustc_diagnostic_item = "option_type"]
154155
#[stable(feature = "rust1", since = "1.0.0")]
155156
pub enum Option<T> {
156157
/// No value

src/libcore/result.rs

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ use crate::ops::{self, Deref, DerefMut};
242242
/// [`Err`]: enum.Result.html#variant.Err
243243
#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
244244
#[must_use = "this `Result` may be an `Err` variant, which should be handled"]
245+
#[rustc_diagnostic_item = "result_type"]
245246
#[stable(feature = "rust1", since = "1.0.0")]
246247
pub enum Result<T, E> {
247248
/// Contains the success value

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,7 @@ impl<'tcx> AdtDef {
24102410

24112411
#[inline]
24122412
pub fn variant_range(&self) -> Range<VariantIdx> {
2413-
(VariantIdx::new(0)..VariantIdx::new(self.variants.len()))
2413+
VariantIdx::new(0)..VariantIdx::new(self.variants.len())
24142414
}
24152415

24162416
/// Computes the discriminant value used by a specific variant.

src/librustc/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
529529
pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> Range<VariantIdx> {
530530
// FIXME requires optimized MIR
531531
let num_variants = tcx.generator_layout(def_id).variant_fields.len();
532-
(VariantIdx::new(0)..VariantIdx::new(num_variants))
532+
VariantIdx::new(0)..VariantIdx::new(num_variants)
533533
}
534534

535535
/// The discriminant for the given variant. Panics if the `variant_index` is

src/librustc_codegen_ssa/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ fn link_sanitizer_runtime(sess: &Session, crate_type: config::CrateType, linker:
777777
linker.args(&["-Wl,-rpath".into(), "-Xlinker".into(), rpath.into()]);
778778
linker.link_dylib(Symbol::intern(&libname));
779779
}
780-
"x86_64-unknown-linux-gnu" => {
780+
"x86_64-unknown-linux-gnu" | "x86_64-fuchsia" | "aarch64-fuchsia" => {
781781
let filename = format!("librustc_rt.{}.a", name);
782782
let path = default_tlib.join(&filename);
783783
linker.link_whole_rlib(&path);

src/librustc_data_structures/sorted_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<K: Ord, V> SortedMap<K, V> {
132132
R: RangeBounds<K>,
133133
{
134134
let (start, end) = self.range_slice_indices(range);
135-
(&self.data[start..end])
135+
&self.data[start..end]
136136
}
137137

138138
#[inline]

src/librustc_lint/unused.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,20 @@ impl EarlyLintPass for UnusedParens {
544544
}
545545

546546
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
547-
if let ast::StmtKind::Local(ref local) = s.kind {
548-
self.check_unused_parens_pat(cx, &local.pat, false, false);
547+
use ast::StmtKind::*;
549548

550-
if let Some(ref value) = local.init {
551-
self.check_unused_parens_expr(cx, &value, "assigned value", false, None, None);
549+
match s.kind {
550+
Local(ref local) => {
551+
self.check_unused_parens_pat(cx, &local.pat, false, false);
552+
553+
if let Some(ref value) = local.init {
554+
self.check_unused_parens_expr(cx, &value, "assigned value", false, None, None);
555+
}
552556
}
557+
Expr(ref expr) => {
558+
self.check_unused_parens_expr(cx, &expr, "block return value", false, None, None);
559+
}
560+
_ => {}
553561
}
554562
}
555563

src/librustc_mir/borrow_check/diagnostics/move_errors.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use rustc::mir::*;
22
use rustc::ty;
33
use rustc_errors::{Applicability, DiagnosticBuilder};
4-
use rustc_span::Span;
4+
use rustc_span::source_map::DesugaringKind;
5+
use rustc_span::{Span, Symbol};
56

67
use crate::borrow_check::diagnostics::UseSpans;
78
use crate::borrow_check::prefixes::PrefixSet;
@@ -383,10 +384,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
383384
}
384385
}
385386
};
386-
let move_ty = format!("{:?}", move_place.ty(*self.body, self.infcx.tcx).ty,);
387387
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
388-
let is_option = move_ty.starts_with("std::option::Option");
389-
let is_result = move_ty.starts_with("std::result::Result");
388+
let def_id = match move_place.ty(*self.body, self.infcx.tcx).ty.kind {
389+
ty::Adt(self_def, _) => self_def.did,
390+
ty::Foreign(def_id)
391+
| ty::FnDef(def_id, _)
392+
| ty::Closure(def_id, _)
393+
| ty::Generator(def_id, ..)
394+
| ty::Opaque(def_id, _) => def_id,
395+
_ => return err,
396+
};
397+
let is_option =
398+
self.infcx.tcx.is_diagnostic_item(Symbol::intern("option_type"), def_id);
399+
let is_result =
400+
self.infcx.tcx.is_diagnostic_item(Symbol::intern("result_type"), def_id);
390401
if (is_option || is_result) && use_spans.map_or(true, |v| !v.for_closure()) {
391402
err.span_suggestion(
392403
span,
@@ -397,6 +408,16 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
397408
format!("{}.as_ref()", snippet),
398409
Applicability::MaybeIncorrect,
399410
);
411+
} else if span.is_desugaring(DesugaringKind::ForLoop)
412+
&& self.infcx.tcx.is_diagnostic_item(Symbol::intern("vec_type"), def_id)
413+
{
414+
// FIXME: suggest for anything that implements `IntoIterator`.
415+
err.span_suggestion(
416+
span,
417+
"consider iterating over a slice of the `Vec<_>`'s content",
418+
format!("&{}", snippet),
419+
Applicability::MaybeIncorrect,
420+
);
400421
}
401422
}
402423
err

src/librustc_mir_build/hair/pattern/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ impl<'tcx> IntRange<'tcx> {
15301530
// 2 -------- // 2 -------
15311531
let (lo, hi) = self.boundaries();
15321532
let (other_lo, other_hi) = other.boundaries();
1533-
(lo == other_hi || hi == other_lo)
1533+
lo == other_hi || hi == other_lo
15341534
}
15351535

15361536
fn to_pat(&self, tcx: TyCtxt<'tcx>) -> Pat<'tcx> {

src/librustc_session/session.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,12 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
11271127

11281128
// Sanitizers can only be used on some tested platforms.
11291129
if let Some(ref sanitizer) = sess.opts.debugging_opts.sanitizer {
1130-
const ASAN_SUPPORTED_TARGETS: &[&str] =
1131-
&["x86_64-unknown-linux-gnu", "x86_64-apple-darwin"];
1130+
const ASAN_SUPPORTED_TARGETS: &[&str] = &[
1131+
"x86_64-unknown-linux-gnu",
1132+
"x86_64-apple-darwin",
1133+
"x86_64-fuchsia",
1134+
"aarch64-fuchsia",
1135+
];
11321136
const TSAN_SUPPORTED_TARGETS: &[&str] =
11331137
&["x86_64-unknown-linux-gnu", "x86_64-apple-darwin"];
11341138
const LSAN_SUPPORTED_TARGETS: &[&str] =

src/librustc_span/source_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,10 @@ impl SourceMap {
774774
// searching forwards for boundaries we've got somewhere to search.
775775
let snippet = if let Some(ref src) = local_begin.sf.src {
776776
let len = src.len();
777-
(&src[start_index..len])
777+
&src[start_index..len]
778778
} else if let Some(src) = src.get_source() {
779779
let len = src.len();
780-
(&src[start_index..len])
780+
&src[start_index..len]
781781
} else {
782782
return 1;
783783
};

src/librustc_typeck/collect.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1673,8 +1673,15 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
16731673
ty::Param(_) => true,
16741674
_ => false,
16751675
};
1676-
let bad_substs: Vec<_> =
1677-
substs.types().enumerate().filter(|(_, ty)| !is_param(ty)).collect();
1676+
let bad_substs: Vec<_> = substs
1677+
.iter()
1678+
.enumerate()
1679+
.filter_map(|(i, k)| {
1680+
if let GenericArgKind::Type(ty) = k.unpack() { Some((i, ty)) } else { None }
1681+
})
1682+
.filter(|(_, ty)| !is_param(ty))
1683+
.collect();
1684+
16781685
if !bad_substs.is_empty() {
16791686
let identity_substs = InternalSubsts::identity_for_item(self.tcx, self.def_id);
16801687
for (i, bad_subst) in bad_substs {

src/libsyntax/print/pprust.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
548548
let st = match style {
549549
ast::StrStyle::Cooked => (format!("\"{}\"", st.escape_debug())),
550550
ast::StrStyle::Raw(n) => {
551-
(format!(
552-
"r{delim}\"{string}\"{delim}",
553-
delim = "#".repeat(n as usize),
554-
string = st
555-
))
551+
format!("r{delim}\"{string}\"{delim}", delim = "#".repeat(n as usize), string = st)
556552
}
557553
};
558554
self.word(st)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-pass
2+
// only-32bit too impatient for 2⁶⁴ items
3+
// compile-flags: -C overflow-checks -C opt-level=3
4+
5+
fn main() {
6+
let i = (0..usize::max_value()).chain(0..10).skip(usize::max_value());
7+
assert_eq!(i.count(), 10);
8+
}

src/test/ui/lint/lint-unnecessary-parens.rs

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ fn unused_parens_around_return_type() -> (u32) { //~ ERROR unnecessary parenthes
1717
panic!()
1818
}
1919

20+
fn unused_parens_around_block_return() -> u32 {
21+
let foo = {
22+
(5) //~ ERROR unnecessary parentheses around block return value
23+
};
24+
(5) //~ ERROR unnecessary parentheses around block return value
25+
}
26+
2027
trait Trait {
2128
fn test(&self);
2229
}

src/test/ui/lint/lint-unnecessary-parens.stderr

+24-12
Original file line numberDiff line numberDiff line change
@@ -22,73 +22,85 @@ error: unnecessary parentheses around type
2222
LL | fn unused_parens_around_return_type() -> (u32) {
2323
| ^^^^^ help: remove these parentheses
2424

25+
error: unnecessary parentheses around block return value
26+
--> $DIR/lint-unnecessary-parens.rs:22:9
27+
|
28+
LL | (5)
29+
| ^^^ help: remove these parentheses
30+
31+
error: unnecessary parentheses around block return value
32+
--> $DIR/lint-unnecessary-parens.rs:24:5
33+
|
34+
LL | (5)
35+
| ^^^ help: remove these parentheses
36+
2537
error: unnecessary parentheses around function argument
26-
--> $DIR/lint-unnecessary-parens.rs:36:9
38+
--> $DIR/lint-unnecessary-parens.rs:43:9
2739
|
2840
LL | bar((true));
2941
| ^^^^^^ help: remove these parentheses
3042

3143
error: unnecessary parentheses around `if` condition
32-
--> $DIR/lint-unnecessary-parens.rs:38:8
44+
--> $DIR/lint-unnecessary-parens.rs:45:8
3345
|
3446
LL | if (true) {}
3547
| ^^^^^^ help: remove these parentheses
3648

3749
error: unnecessary parentheses around `while` condition
38-
--> $DIR/lint-unnecessary-parens.rs:39:11
50+
--> $DIR/lint-unnecessary-parens.rs:46:11
3951
|
4052
LL | while (true) {}
4153
| ^^^^^^ help: remove these parentheses
4254

4355
warning: denote infinite loops with `loop { ... }`
44-
--> $DIR/lint-unnecessary-parens.rs:39:5
56+
--> $DIR/lint-unnecessary-parens.rs:46:5
4557
|
4658
LL | while (true) {}
4759
| ^^^^^^^^^^^^ help: use `loop`
4860
|
4961
= note: `#[warn(while_true)]` on by default
5062

5163
error: unnecessary parentheses around `match` head expression
52-
--> $DIR/lint-unnecessary-parens.rs:41:11
64+
--> $DIR/lint-unnecessary-parens.rs:48:11
5365
|
5466
LL | match (true) {
5567
| ^^^^^^ help: remove these parentheses
5668

5769
error: unnecessary parentheses around `let` head expression
58-
--> $DIR/lint-unnecessary-parens.rs:44:16
70+
--> $DIR/lint-unnecessary-parens.rs:51:16
5971
|
6072
LL | if let 1 = (1) {}
6173
| ^^^ help: remove these parentheses
6274

6375
error: unnecessary parentheses around `let` head expression
64-
--> $DIR/lint-unnecessary-parens.rs:45:19
76+
--> $DIR/lint-unnecessary-parens.rs:52:19
6577
|
6678
LL | while let 1 = (2) {}
6779
| ^^^ help: remove these parentheses
6880

6981
error: unnecessary parentheses around method argument
70-
--> $DIR/lint-unnecessary-parens.rs:59:24
82+
--> $DIR/lint-unnecessary-parens.rs:66:24
7183
|
7284
LL | X { y: false }.foo((true));
7385
| ^^^^^^ help: remove these parentheses
7486

7587
error: unnecessary parentheses around assigned value
76-
--> $DIR/lint-unnecessary-parens.rs:61:18
88+
--> $DIR/lint-unnecessary-parens.rs:68:18
7789
|
7890
LL | let mut _a = (0);
7991
| ^^^ help: remove these parentheses
8092

8193
error: unnecessary parentheses around assigned value
82-
--> $DIR/lint-unnecessary-parens.rs:62:10
94+
--> $DIR/lint-unnecessary-parens.rs:69:10
8395
|
8496
LL | _a = (0);
8597
| ^^^ help: remove these parentheses
8698

8799
error: unnecessary parentheses around assigned value
88-
--> $DIR/lint-unnecessary-parens.rs:63:11
100+
--> $DIR/lint-unnecessary-parens.rs:70:11
89101
|
90102
LL | _a += (1);
91103
| ^^^ help: remove these parentheses
92104

93-
error: aborting due to 13 previous errors
105+
error: aborting due to 15 previous errors
94106

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-rustfix
2+
#![allow(dead_code)]
3+
4+
struct Foo {
5+
v: Vec<u32>,
6+
}
7+
8+
impl Foo {
9+
fn bar(&self) {
10+
for _ in &self.v { //~ ERROR cannot move out of `self.v` which is behind a shared reference
11+
}
12+
}
13+
}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)