From 123df596c77489bd6a520b453365bc59cbd35db2 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Mon, 17 Feb 2020 18:55:41 +0100 Subject: [PATCH 1/9] Revert "Remove `checked_add` in `Layout::repeat`" This fixes a a segfault in safe code, a stable regression. Reported in \#69225. This reverts commit a983e0590a43ed8b0f60417828efd4e79b51f494. Also adds a test for the expected behaviour. --- src/libcore/alloc.rs | 12 ++++--- ...issue-69225-layout-repeated-checked-add.rs | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/issues/issue-69225-layout-repeated-checked-add.rs diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 09f743fb81e4c..2050f64512a23 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -241,11 +241,13 @@ impl Layout { #[unstable(feature = "alloc_layout_extra", issue = "55724")] #[inline] pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutErr> { - // This cannot overflow. Quoting from the invariant of Layout: - // > `size`, when rounded up to the nearest multiple of `align`, - // > must not overflow (i.e., the rounded value must be less than - // > `usize::MAX`) - let padded_size = self.size() + self.padding_needed_for(self.align()); + // Warning, removing the checked_add here led to segfaults in #67174. Further + // analysis in #69225 seems to indicate that this is an LTO-related + // miscompilation, so #67174 might be able to be reapplied in the future. + let padded_size = self + .size() + .checked_add(self.padding_needed_for(self.align())) + .ok_or(LayoutErr { private: () })?; let alloc_size = padded_size.checked_mul(n).ok_or(LayoutErr { private: () })?; unsafe { diff --git a/src/test/ui/issues/issue-69225-layout-repeated-checked-add.rs b/src/test/ui/issues/issue-69225-layout-repeated-checked-add.rs new file mode 100644 index 0000000000000..7f43e4d1a51f8 --- /dev/null +++ b/src/test/ui/issues/issue-69225-layout-repeated-checked-add.rs @@ -0,0 +1,31 @@ +// Ensure we appropriately error instead of overflowing a calculation when creating a new Alloc +// Layout + +// run-fail +// compile-flags: -C opt-level=3 +// error-pattern: index out of bounds: the len is 0 but the index is 16777216 +// ignore-wasm no panic or subprocess support +// ignore-emscripten no panic or subprocess support + +fn do_test(x: usize) { + let arr = vec![vec![0u8; 3]]; + + let mut z = Vec::new(); + for arr_ref in arr { + for y in 0..x { + for _ in 0..1 { + z.extend(std::iter::repeat(0).take(x)); + let a = y * x; + let b = (y + 1) * x - 1; + let slice = &arr_ref[a..b]; + eprintln!("{} {} {} {}", a, b, arr_ref.len(), slice.len()); + eprintln!("{:?}", slice[1 << 24]); + } + } + } +} + +fn main() { + do_test(1); + do_test(2); +} From ee392df785c2c3eac90f147495974e9d171e197a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 14 Feb 2020 17:49:16 -0800 Subject: [PATCH 2/9] Do not ICE when encountering `yield` inside `async` block --- src/librustc/hir/map/hir_id_validator.rs | 4 ++-- src/librustc/hir/map/mod.rs | 2 +- src/test/ui/generator/async-generator-issue-67158.rs | 6 ++++++ src/test/ui/generator/async-generator-issue-67158.stderr | 9 +++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/generator/async-generator-issue-67158.rs create mode 100644 src/test/ui/generator/async-generator-issue-67158.stderr diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 76e42b8af2874..ca95f87a09639 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -7,7 +7,7 @@ use rustc_hir::intravisit; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{HirId, ItemLocalId}; -pub fn check_crate(hir_map: &Map<'_>) { +pub fn check_crate(hir_map: &Map<'_>, sess: &rustc_session::Session) { hir_map.dep_graph.assert_ignored(); let errors = Lock::new(Vec::new()); @@ -24,7 +24,7 @@ pub fn check_crate(hir_map: &Map<'_>) { if !errors.is_empty() { let message = errors.iter().fold(String::new(), |s1, s2| s1 + "\n" + s2); - bug!("{}", message); + sess.delay_span_bug(rustc_span::DUMMY_SP, &message); } } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 6d7f53133a666..b5ca63a34d9fd 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -1271,7 +1271,7 @@ pub fn map_crate<'hir>( }; sess.time("validate_HIR_map", || { - hir_id_validator::check_crate(&map); + hir_id_validator::check_crate(&map, sess); }); map diff --git a/src/test/ui/generator/async-generator-issue-67158.rs b/src/test/ui/generator/async-generator-issue-67158.rs new file mode 100644 index 0000000000000..8125a7a9bb664 --- /dev/null +++ b/src/test/ui/generator/async-generator-issue-67158.rs @@ -0,0 +1,6 @@ +#![feature(generators)] +// edition:2018 +// Regression test for #67158. +fn main() { + async { yield print!(":C") }; //~ ERROR `async` generators are not yet supported +} diff --git a/src/test/ui/generator/async-generator-issue-67158.stderr b/src/test/ui/generator/async-generator-issue-67158.stderr new file mode 100644 index 0000000000000..7270d188e8b88 --- /dev/null +++ b/src/test/ui/generator/async-generator-issue-67158.stderr @@ -0,0 +1,9 @@ +error[E0727]: `async` generators are not yet supported + --> $DIR/async-generator-issue-67158.rs:5:13 + | +LL | async { yield print!(":C") }; + | ^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0727`. From e169d69d8b2a77f2f25e8392a92dcab65160a363 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Thu, 13 Feb 2020 20:29:03 +0000 Subject: [PATCH 3/9] Check `Copy` lifetimes bounds when copying from a projection --- .../borrow_check/type_check/mod.rs | 52 +++++++++---------- ...not-ignore-lifetime-bounds-in-copy-proj.rs | 12 +++++ ...ignore-lifetime-bounds-in-copy-proj.stderr | 14 +++++ 3 files changed, 51 insertions(+), 27 deletions(-) create mode 100644 src/test/ui/nll/do-not-ignore-lifetime-bounds-in-copy-proj.rs create mode 100644 src/test/ui/nll/do-not-ignore-lifetime-bounds-in-copy-proj.stderr diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index c9a1c465165d7..b81eaa6463775 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -467,33 +467,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { let mut place_ty = PlaceTy::from_ty(self.body.local_decls[place.local].ty); - if place.projection.is_empty() { - if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context { - let tcx = self.tcx(); - let trait_ref = ty::TraitRef { - def_id: tcx.lang_items().copy_trait().unwrap(), - substs: tcx.mk_substs_trait(place_ty.ty, &[]), - }; - - // To have a `Copy` operand, the type `T` of the - // value must be `Copy`. Note that we prove that `T: Copy`, - // rather than using the `is_copy_modulo_regions` - // test. This is important because - // `is_copy_modulo_regions` ignores the resulting region - // obligations and assumes they pass. This can result in - // bounds from `Copy` impls being unsoundly ignored (e.g., - // #29149). Note that we decide to use `Copy` before knowing - // whether the bounds fully apply: in effect, the rule is - // that if a value of some type could implement `Copy`, then - // it must. - self.cx.prove_trait_ref( - trait_ref, - location.to_locations(), - ConstraintCategory::CopyBound, - ); - } - } - for elem in place.projection.iter() { if place_ty.variant_index.is_none() { if place_ty.ty.references_error() { @@ -504,6 +477,31 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { place_ty = self.sanitize_projection(place_ty, elem, place, location) } + if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context { + let tcx = self.tcx(); + let trait_ref = ty::TraitRef { + def_id: tcx.lang_items().copy_trait().unwrap(), + substs: tcx.mk_substs_trait(place_ty.ty, &[]), + }; + + // To have a `Copy` operand, the type `T` of the + // value must be `Copy`. Note that we prove that `T: Copy`, + // rather than using the `is_copy_modulo_regions` + // test. This is important because + // `is_copy_modulo_regions` ignores the resulting region + // obligations and assumes they pass. This can result in + // bounds from `Copy` impls being unsoundly ignored (e.g., + // #29149). Note that we decide to use `Copy` before knowing + // whether the bounds fully apply: in effect, the rule is + // that if a value of some type could implement `Copy`, then + // it must. + self.cx.prove_trait_ref( + trait_ref, + location.to_locations(), + ConstraintCategory::CopyBound, + ); + } + place_ty } diff --git a/src/test/ui/nll/do-not-ignore-lifetime-bounds-in-copy-proj.rs b/src/test/ui/nll/do-not-ignore-lifetime-bounds-in-copy-proj.rs new file mode 100644 index 0000000000000..96c8719468f27 --- /dev/null +++ b/src/test/ui/nll/do-not-ignore-lifetime-bounds-in-copy-proj.rs @@ -0,0 +1,12 @@ +// Test that the 'static bound from the Copy impl is respected. Regression test for #29149. + +#[derive(Clone)] +struct Foo<'a>(&'a u32); +impl Copy for Foo<'static> {} + +fn main() { + let s = 2; + let a = (Foo(&s),); //~ ERROR `s` does not live long enough [E0597] + drop(a.0); + drop(a.0); +} diff --git a/src/test/ui/nll/do-not-ignore-lifetime-bounds-in-copy-proj.stderr b/src/test/ui/nll/do-not-ignore-lifetime-bounds-in-copy-proj.stderr new file mode 100644 index 0000000000000..65be3b37e0e3b --- /dev/null +++ b/src/test/ui/nll/do-not-ignore-lifetime-bounds-in-copy-proj.stderr @@ -0,0 +1,14 @@ +error[E0597]: `s` does not live long enough + --> $DIR/do-not-ignore-lifetime-bounds-in-copy-proj.rs:9:18 + | +LL | let a = (Foo(&s),); + | ^^ borrowed value does not live long enough +LL | drop(a.0); + | --- copying this value requires that `s` is borrowed for `'static` +LL | drop(a.0); +LL | } + | - `s` dropped here while still borrowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. From cff23e8a1cea4cd43465a1000205f102dfe93e0f Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Thu, 13 Feb 2020 20:29:30 +0000 Subject: [PATCH 4/9] Check types of statics in MIR typeck --- .../borrow_check/type_check/mod.rs | 18 +++++++++-- src/test/ui/nll/issue-69114-static-mut-ty.rs | 30 +++++++++++++++++++ .../ui/nll/issue-69114-static-mut-ty.stderr | 27 +++++++++++++++++ src/test/ui/nll/issue-69114-static-ty.rs | 9 ++++++ src/test/ui/nll/issue-69114-static-ty.stderr | 15 ++++++++++ 5 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/nll/issue-69114-static-mut-ty.rs create mode 100644 src/test/ui/nll/issue-69114-static-mut-ty.stderr create mode 100644 src/test/ui/nll/issue-69114-static-ty.rs create mode 100644 src/test/ui/nll/issue-69114-static-ty.stderr diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index b81eaa6463775..7d98cf90ee9b9 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -310,6 +310,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { ); } } else { + let tcx = self.tcx(); if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = constant.literal.val { if let Some(promoted) = promoted { let check_err = |verifier: &mut TypeVerifier<'a, 'b, 'tcx>, @@ -359,10 +360,23 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { ); } } + } else if let Some(static_def_id) = constant.check_static_ptr(tcx) { + let unnormalized_ty = tcx.type_of(static_def_id); + let locations = location.to_locations(); + let normalized_ty = self.cx.normalize(unnormalized_ty, locations); + let literal_ty = constant.literal.ty.builtin_deref(true).unwrap().ty; + + if let Err(terr) = self.cx.eq_types( + normalized_ty, + literal_ty, + locations, + ConstraintCategory::Boring, + ) { + span_mirbug!(self, constant, "bad static type {:?} ({:?})", constant, terr); + } } - if let ty::FnDef(def_id, substs) = constant.literal.ty.kind { - let tcx = self.tcx(); + if let ty::FnDef(def_id, substs) = constant.literal.ty.kind { let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, substs); self.cx.normalize_and_prove_instantiated_predicates( instantiated_predicates, diff --git a/src/test/ui/nll/issue-69114-static-mut-ty.rs b/src/test/ui/nll/issue-69114-static-mut-ty.rs new file mode 100644 index 0000000000000..ce37da053e371 --- /dev/null +++ b/src/test/ui/nll/issue-69114-static-mut-ty.rs @@ -0,0 +1,30 @@ +// Check that borrowck ensures that `static mut` items have the expected type. + +static FOO: u8 = 42; +static mut BAR: &'static u8 = &FOO; +static mut BAR_ELIDED: &u8 = &FOO; + +fn main() { + unsafe { + println!("{} {}", BAR, BAR_ELIDED); + set_bar(); + set_bar_elided(); + println!("{} {}", BAR, BAR_ELIDED); + } +} + +fn set_bar() { + let n = 42; + unsafe { + BAR = &n; + //~^ ERROR does not live long enough + } +} + +fn set_bar_elided() { + let n = 42; + unsafe { + BAR_ELIDED = &n; + //~^ ERROR does not live long enough + } +} diff --git a/src/test/ui/nll/issue-69114-static-mut-ty.stderr b/src/test/ui/nll/issue-69114-static-mut-ty.stderr new file mode 100644 index 0000000000000..5e55cb502caa9 --- /dev/null +++ b/src/test/ui/nll/issue-69114-static-mut-ty.stderr @@ -0,0 +1,27 @@ +error[E0597]: `n` does not live long enough + --> $DIR/issue-69114-static-mut-ty.rs:19:15 + | +LL | BAR = &n; + | ------^^ + | | | + | | borrowed value does not live long enough + | assignment requires that `n` is borrowed for `'static` +... +LL | } + | - `n` dropped here while still borrowed + +error[E0597]: `n` does not live long enough + --> $DIR/issue-69114-static-mut-ty.rs:27:22 + | +LL | BAR_ELIDED = &n; + | -------------^^ + | | | + | | borrowed value does not live long enough + | assignment requires that `n` is borrowed for `'static` +... +LL | } + | - `n` dropped here while still borrowed + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/issue-69114-static-ty.rs b/src/test/ui/nll/issue-69114-static-ty.rs new file mode 100644 index 0000000000000..3318433a1c56f --- /dev/null +++ b/src/test/ui/nll/issue-69114-static-ty.rs @@ -0,0 +1,9 @@ +// Check that borrowck ensures that `static` items have the expected type. + +static FOO: &'static (dyn Fn(&'static u8) + Send + Sync) = &drop; + +fn main() { + let n = 42; + FOO(&n); + //~^ ERROR does not live long enough +} diff --git a/src/test/ui/nll/issue-69114-static-ty.stderr b/src/test/ui/nll/issue-69114-static-ty.stderr new file mode 100644 index 0000000000000..0815e74b5537d --- /dev/null +++ b/src/test/ui/nll/issue-69114-static-ty.stderr @@ -0,0 +1,15 @@ +error[E0597]: `n` does not live long enough + --> $DIR/issue-69114-static-ty.rs:7:9 + | +LL | FOO(&n); + | ----^^- + | | | + | | borrowed value does not live long enough + | argument requires that `n` is borrowed for `'static` +LL | +LL | } + | - `n` dropped here while still borrowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. From 38bdc5fea0122bdfc69ce31ad8213198283d544b Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 13 Feb 2020 12:19:36 +0100 Subject: [PATCH 5/9] fix extra subslice lowering --- src/librustc_ast_lowering/pat.rs | 17 +++++++----- .../issue-69103-extra-binding-subslice.rs | 18 +++++++++++++ .../issue-69103-extra-binding-subslice.stderr | 26 +++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 src/test/ui/array-slice-vec/issue-69103-extra-binding-subslice.rs create mode 100644 src/test/ui/array-slice-vec/issue-69103-extra-binding-subslice.stderr diff --git a/src/librustc_ast_lowering/pat.rs b/src/librustc_ast_lowering/pat.rs index 4c3c4ddac78ee..b42b12c4dd851 100644 --- a/src/librustc_ast_lowering/pat.rs +++ b/src/librustc_ast_lowering/pat.rs @@ -128,6 +128,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let mut slice = None; let mut prev_rest_span = None; + // Lowers `$bm $ident @ ..` to `$bm $ident @ _`. + let lower_rest_sub = |this: &mut Self, pat, bm, ident, sub| { + let lower_sub = |this: &mut Self| Some(this.pat_wild_with_node_id_of(sub)); + let node = this.lower_pat_ident(pat, bm, ident, lower_sub); + this.pat_with_node_id_of(pat, node) + }; + let mut iter = pats.iter(); // Lower all the patterns until the first occurrence of a sub-slice pattern. for pat in iter.by_ref() { @@ -142,9 +149,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // Record, lower it to `$binding_mode $ident @ _`, and stop here. PatKind::Ident(ref bm, ident, Some(ref sub)) if sub.is_rest() => { prev_rest_span = Some(sub.span); - let lower_sub = |this: &mut Self| Some(this.pat_wild_with_node_id_of(sub)); - let node = self.lower_pat_ident(pat, bm, ident, lower_sub); - slice = Some(self.pat_with_node_id_of(pat, node)); + slice = Some(lower_rest_sub(self, pat, bm, ident, sub)); break; } // It was not a subslice pattern so lower it normally. @@ -157,9 +162,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // There was a previous subslice pattern; make sure we don't allow more. let rest_span = match pat.kind { PatKind::Rest => Some(pat.span), - PatKind::Ident(.., Some(ref sub)) if sub.is_rest() => { - // The `HirValidator` is merciless; add a `_` pattern to avoid ICEs. - after.push(self.pat_wild_with_node_id_of(pat)); + PatKind::Ident(ref bm, ident, Some(ref sub)) if sub.is_rest() => { + // #69103: Lower into `binding @ _` as above to avoid ICEs. + after.push(lower_rest_sub(self, pat, bm, ident, sub)); Some(sub.span) } _ => None, diff --git a/src/test/ui/array-slice-vec/issue-69103-extra-binding-subslice.rs b/src/test/ui/array-slice-vec/issue-69103-extra-binding-subslice.rs new file mode 100644 index 0000000000000..061b0d675b31f --- /dev/null +++ b/src/test/ui/array-slice-vec/issue-69103-extra-binding-subslice.rs @@ -0,0 +1,18 @@ +// We used to not lower the extra `b @ ..` into `b @ _` which meant that no type +// was registered for the binding `b` although it passed through resolve. +// This resulted in an ICE (#69103). + +fn main() { + let [a @ .., b @ ..] = &mut [1, 2]; + //~^ ERROR `..` can only be used once per slice pattern + b; + + let [.., c @ ..] = [1, 2]; + //~^ ERROR `..` can only be used once per slice pattern + c; + + // This never ICEd, but let's make sure it won't regress either. + let (.., d @ ..) = (1, 2); + //~^ ERROR `..` patterns are not allowed here + d; +} diff --git a/src/test/ui/array-slice-vec/issue-69103-extra-binding-subslice.stderr b/src/test/ui/array-slice-vec/issue-69103-extra-binding-subslice.stderr new file mode 100644 index 0000000000000..9432e2f0c9d34 --- /dev/null +++ b/src/test/ui/array-slice-vec/issue-69103-extra-binding-subslice.stderr @@ -0,0 +1,26 @@ +error: `..` can only be used once per slice pattern + --> $DIR/issue-69103-extra-binding-subslice.rs:6:22 + | +LL | let [a @ .., b @ ..] = &mut [1, 2]; + | -- ^^ can only be used once per slice pattern + | | + | previously used here + +error: `..` can only be used once per slice pattern + --> $DIR/issue-69103-extra-binding-subslice.rs:10:18 + | +LL | let [.., c @ ..] = [1, 2]; + | -- ^^ can only be used once per slice pattern + | | + | previously used here + +error: `..` patterns are not allowed here + --> $DIR/issue-69103-extra-binding-subslice.rs:15:18 + | +LL | let (.., d @ ..) = (1, 2); + | ^^ + | + = note: only allowed in tuple, tuple struct, and slice patterns + +error: aborting due to 3 previous errors + From a07f8db63c2288703d2a20b83e2d7d864c77c275 Mon Sep 17 00:00:00 2001 From: Michael Burge Date: Tue, 28 Jan 2020 10:57:03 -0800 Subject: [PATCH 6/9] Correct ICE caused by macros generating invalid spans. --- src/librustc_errors/emitter.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index bf660d188b287..7ef623807d03b 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -19,6 +19,7 @@ use crate::{ pluralize, CodeSuggestion, Diagnostic, DiagnosticId, Level, SubDiagnostic, SuggestionStyle, }; +use log::*; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; use rustc_span::hygiene::{ExpnKind, MacroKind}; @@ -2108,7 +2109,13 @@ impl<'a> Drop for WritableDst<'a> { /// Whether the original and suggested code are visually similar enough to warrant extra wording. pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool { // FIXME: this should probably be extended to also account for `FO0` → `FOO` and unicode. - let found = sm.span_to_snippet(sp).unwrap(); + let found = match sm.span_to_snippet(sp) { + Ok(snippet) => snippet, + Err(e) => { + warn!("Invalid span {:?}. Err={:?}", sp, e); + return false; + } + }; let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z']; // All the chars that differ in capitalization are confusable (above): let confusable = found From cdcf45bacf7dea68c50b87529cc3761f99d8bc13 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 28 Jan 2020 00:27:57 +0100 Subject: [PATCH 7/9] lintify conflicting_repr_hints --- src/librustc/hir/check_attr.rs | 21 +++++++++------- src/librustc_session/lint/builtin.rs | 11 ++++++++ src/test/ui/conflicting-repr-hints.rs | 2 ++ src/test/ui/conflicting-repr-hints.stderr | 25 ++++++++++++------- .../feature-gates/feature-gate-repr-simd.rs | 1 + .../feature-gate-repr-simd.stderr | 7 +++++- src/test/ui/issues/issue-47094.rs | 2 ++ src/test/ui/issues/issue-47094.stderr | 10 +++++++- 8 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 86eab3d92d366..03fa426460dab 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -14,7 +14,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::DUMMY_HIR_ID; use rustc_hir::{self, HirId, Item, ItemKind, TraitItem, TraitItemKind}; -use rustc_session::lint::builtin::UNUSED_ATTRIBUTES; +use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES}; use rustc_span::symbol::sym; use rustc_span::Span; use syntax::ast::Attribute; @@ -196,7 +196,7 @@ impl CheckAttrVisitor<'tcx> { self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id)); } - self.check_repr(attrs, span, target, item); + self.check_repr(attrs, span, target, item, hir_id); self.check_used(attrs, target); } @@ -357,6 +357,7 @@ impl CheckAttrVisitor<'tcx> { span: &Span, target: Target, item: Option<&Item<'_>>, + hir_id: HirId, ) { // Extract the names of all repr hints, e.g., [foo, bar, align] for: // ``` @@ -446,13 +447,15 @@ impl CheckAttrVisitor<'tcx> { || (is_simd && is_c) || (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item))) { - struct_span_err!( - self.tcx.sess, - hint_spans.collect::>(), - E0566, - "conflicting representation hints", - ) - .emit(); + self.tcx + .struct_span_lint_hir( + CONFLICTING_REPR_HINTS, + hir_id, + hint_spans.collect::>(), + "conflicting representation hints", + ) + .code(rustc_errors::error_code!(E0566)) + .emit(); } } diff --git a/src/librustc_session/lint/builtin.rs b/src/librustc_session/lint/builtin.rs index 3e8503ef661f0..c326061100b06 100644 --- a/src/librustc_session/lint/builtin.rs +++ b/src/librustc_session/lint/builtin.rs @@ -18,6 +18,16 @@ declare_lint! { }; } +declare_lint! { + pub CONFLICTING_REPR_HINTS, + Deny, + "conflicts between `#[repr(..)]` hints that were previously accepted and used in practice", + @future_incompatible = FutureIncompatibleInfo { + reference: "issue #68585 ", + edition: None, + }; +} + declare_lint! { pub META_VARIABLE_MISUSE, Allow, @@ -520,6 +530,7 @@ declare_lint_pass! { MACRO_USE_EXTERN_CRATE, MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS, ILL_FORMED_ATTRIBUTE_INPUT, + CONFLICTING_REPR_HINTS, META_VARIABLE_MISUSE, DEPRECATED_IN_FUTURE, AMBIGUOUS_ASSOCIATED_ITEMS, diff --git a/src/test/ui/conflicting-repr-hints.rs b/src/test/ui/conflicting-repr-hints.rs index 8e9c11690a824..09dade20992ba 100644 --- a/src/test/ui/conflicting-repr-hints.rs +++ b/src/test/ui/conflicting-repr-hints.rs @@ -11,11 +11,13 @@ enum B { } #[repr(C, u64)] //~ ERROR conflicting representation hints +//~^ WARN this was previously accepted enum C { C, } #[repr(u32, u64)] //~ ERROR conflicting representation hints +//~^ WARN this was previously accepted enum D { D, } diff --git a/src/test/ui/conflicting-repr-hints.stderr b/src/test/ui/conflicting-repr-hints.stderr index 0dfe360dbb3c4..43b76bf649778 100644 --- a/src/test/ui/conflicting-repr-hints.stderr +++ b/src/test/ui/conflicting-repr-hints.stderr @@ -3,45 +3,52 @@ error[E0566]: conflicting representation hints | LL | #[repr(C, u64)] | ^ ^^^ + | + = note: `#[deny(conflicting_repr_hints)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 error[E0566]: conflicting representation hints - --> $DIR/conflicting-repr-hints.rs:18:8 + --> $DIR/conflicting-repr-hints.rs:19:8 | LL | #[repr(u32, u64)] | ^^^ ^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:27:1 + --> $DIR/conflicting-repr-hints.rs:29:1 | LL | struct F(i32); | ^^^^^^^^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:31:1 + --> $DIR/conflicting-repr-hints.rs:33:1 | LL | struct G(i32); | ^^^^^^^^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:35:1 + --> $DIR/conflicting-repr-hints.rs:37:1 | LL | struct H(i32); | ^^^^^^^^^^^^^^ error[E0634]: type has conflicting packed representation hints - --> $DIR/conflicting-repr-hints.rs:38:1 + --> $DIR/conflicting-repr-hints.rs:40:1 | LL | struct I(i32); | ^^^^^^^^^^^^^^ error[E0634]: type has conflicting packed representation hints - --> $DIR/conflicting-repr-hints.rs:42:1 + --> $DIR/conflicting-repr-hints.rs:44:1 | LL | struct J(i32); | ^^^^^^^^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:48:1 + --> $DIR/conflicting-repr-hints.rs:50:1 | LL | / union X { LL | | @@ -50,7 +57,7 @@ LL | | } | |_^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:55:1 + --> $DIR/conflicting-repr-hints.rs:57:1 | LL | / union Y { LL | | @@ -59,7 +66,7 @@ LL | | } | |_^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:62:1 + --> $DIR/conflicting-repr-hints.rs:64:1 | LL | / union Z { LL | | diff --git a/src/test/ui/feature-gates/feature-gate-repr-simd.rs b/src/test/ui/feature-gates/feature-gate-repr-simd.rs index 1e4a404fa25a7..c527404f57270 100644 --- a/src/test/ui/feature-gates/feature-gate-repr-simd.rs +++ b/src/test/ui/feature-gates/feature-gate-repr-simd.rs @@ -2,6 +2,7 @@ struct Foo(u64, u64); #[repr(C)] //~ ERROR conflicting representation hints +//~^ WARN this was previously accepted #[repr(simd)] //~ error: SIMD types are experimental struct Bar(u64, u64); diff --git a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr index 37a7bd0b1294d..013bad069d8cd 100644 --- a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr +++ b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr @@ -8,7 +8,7 @@ LL | #[repr(simd)] = help: add `#![feature(repr_simd)]` to the crate attributes to enable error[E0658]: SIMD types are experimental and possibly buggy - --> $DIR/feature-gate-repr-simd.rs:5:1 + --> $DIR/feature-gate-repr-simd.rs:6:1 | LL | #[repr(simd)] | ^^^^^^^^^^^^^ @@ -21,8 +21,13 @@ error[E0566]: conflicting representation hints | LL | #[repr(C)] | ^ +LL | LL | #[repr(simd)] | ^^^^ + | + = note: `#[deny(conflicting_repr_hints)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/issue-47094.rs b/src/test/ui/issues/issue-47094.rs index 3258ee92a7422..c5d37feb1447f 100644 --- a/src/test/ui/issues/issue-47094.rs +++ b/src/test/ui/issues/issue-47094.rs @@ -1,10 +1,12 @@ #[repr(C, u8)] //~ ERROR conflicting representation hints +//~^ WARN this was previously accepted enum Foo { A, B, } #[repr(C)] //~ ERROR conflicting representation hints +//~^ WARN this was previously accepted #[repr(u8)] enum Bar { A, diff --git a/src/test/ui/issues/issue-47094.stderr b/src/test/ui/issues/issue-47094.stderr index c807f644fd310..e323ce660290c 100644 --- a/src/test/ui/issues/issue-47094.stderr +++ b/src/test/ui/issues/issue-47094.stderr @@ -3,14 +3,22 @@ error[E0566]: conflicting representation hints | LL | #[repr(C, u8)] | ^ ^^ + | + = note: `#[deny(conflicting_repr_hints)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 error[E0566]: conflicting representation hints - --> $DIR/issue-47094.rs:7:8 + --> $DIR/issue-47094.rs:8:8 | LL | #[repr(C)] | ^ +LL | LL | #[repr(u8)] | ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 error: aborting due to 2 previous errors From a9b95b3515f800896b1b30bdabd08ed0659bc29f Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 17 Feb 2020 19:39:38 -0500 Subject: [PATCH 8/9] Clean out some default-installed directories This helps us have enough disk space for our builders to be able to complete successfully. For now, the choices are ad-hoc and 'definitely not needed'. This should never fail the build, as everything our build needs should be inside Docker. --- src/ci/azure-pipelines/steps/run.yml | 3 +++ src/ci/scripts/clean-disk.sh | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100755 src/ci/scripts/clean-disk.sh diff --git a/src/ci/azure-pipelines/steps/run.yml b/src/ci/azure-pipelines/steps/run.yml index f536388b25b96..c39f75aba89d8 100644 --- a/src/ci/azure-pipelines/steps/run.yml +++ b/src/ci/azure-pipelines/steps/run.yml @@ -31,6 +31,9 @@ steps: - bash: src/ci/scripts/setup-environment.sh displayName: Setup environment +- bash: src/ci/scripts/clean-disk.sh + displayName: Clean disk + - bash: src/ci/scripts/should-skip-this.sh displayName: Decide whether to run this job diff --git a/src/ci/scripts/clean-disk.sh b/src/ci/scripts/clean-disk.sh new file mode 100755 index 0000000000000..c50de37c492b4 --- /dev/null +++ b/src/ci/scripts/clean-disk.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# This script deletes some of the Azure-provided artifacts. We don't use these, +# and disk space is at a premium on our builders. + +set -euo pipefail +IFS=$'\n\t' + +source "$(cd "$(dirname "$0")" && pwd)/../shared.sh" + +# All the Linux builds happen inside Docker. +if isLinux; then + # 6.7GB + sudo rm -rf /opt/ghc + # 16GB + sudo rm -rf /usr/share/dotnet +fi From e5532435d0aaf661f331431d0561c04f72b6ad27 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 23 Feb 2020 20:09:31 -0500 Subject: [PATCH 9/9] Fix stderr for test --- src/test/ui/generator/async-generator-issue-67158.stderr | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/ui/generator/async-generator-issue-67158.stderr b/src/test/ui/generator/async-generator-issue-67158.stderr index 7270d188e8b88..c2ea55c1e7203 100644 --- a/src/test/ui/generator/async-generator-issue-67158.stderr +++ b/src/test/ui/generator/async-generator-issue-67158.stderr @@ -6,4 +6,3 @@ LL | async { yield print!(":C") }; error: aborting due to previous error -For more information about this error, try `rustc --explain E0727`.