From 8062c7ae4b6201b3728baae37fb04215dcc5fcd4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 1 Oct 2018 00:55:00 +0200 Subject: Add test for crate filtering --- src/test/rustdoc-js/filter-crate.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/test/rustdoc-js/filter-crate.js (limited to 'src/test') diff --git a/src/test/rustdoc-js/filter-crate.js b/src/test/rustdoc-js/filter-crate.js new file mode 100644 index 00000000000..69c959a6ef2 --- /dev/null +++ b/src/test/rustdoc-js/filter-crate.js @@ -0,0 +1,20 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// should-fail + +const QUERY = 'string'; +const FILTER_CRATE = 'core'; + +const EXPECTED = { + 'others': [ + { 'path': 'std::collections', 'name': 'VecDeque' }, + ], +}; -- cgit 1.4.1-3-g733a5 From f1f6d87eab20f62a4fbb16b327f16fa69dbbaf99 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 30 Nov 2018 10:40:59 +0000 Subject: Stabilise exhaustive_integer_patterns --- src/librustc_mir/hair/pattern/_match.rs | 36 +++++++++++++----------------- src/libsyntax/feature_gate.rs | 4 ++-- src/test/ui/exhaustive_integer_patterns.rs | 2 +- 3 files changed, 19 insertions(+), 23 deletions(-) (limited to 'src/test') diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index fd869d6c334..82e368198f2 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -622,7 +622,6 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, -> Vec> { debug!("all_constructors({:?})", pcx.ty); - let exhaustive_integer_patterns = cx.tcx.features().exhaustive_integer_patterns; let ctors = match pcx.ty.sty { ty::Bool => { [true, false].iter().map(|&b| { @@ -652,7 +651,7 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, .map(|v| Variant(v.did)) .collect() } - ty::Char if exhaustive_integer_patterns => { + ty::Char => { vec![ // The valid Unicode Scalar Value ranges. ConstantRange('\u{0000}' as u128, @@ -667,14 +666,14 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, ), ] } - ty::Int(ity) if exhaustive_integer_patterns => { + ty::Int(ity) => { // FIXME(49937): refactor these bit manipulations into interpret. let bits = Integer::from_attr(&cx.tcx, SignedInt(ity)).size().bits() as u128; let min = 1u128 << (bits - 1); let max = (1u128 << (bits - 1)) - 1; vec![ConstantRange(min, max, pcx.ty, RangeEnd::Included)] } - ty::Uint(uty) if exhaustive_integer_patterns => { + ty::Uint(uty) => { // FIXME(49937): refactor these bit manipulations into interpret. let bits = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size().bits() as u128; let max = !0u128 >> (128 - bits); @@ -971,12 +970,10 @@ fn compute_missing_ctors<'a, 'tcx: 'a>( // If a constructor appears in a `match` arm, we can // eliminate it straight away. refined_ctors = vec![] - } else if tcx.features().exhaustive_integer_patterns { - if let Some(interval) = IntRange::from_ctor(tcx, used_ctor) { - // Refine the required constructors for the type by subtracting - // the range defined by the current constructor pattern. - refined_ctors = interval.subtract_from(tcx, refined_ctors); - } + } else if let Some(interval) = IntRange::from_ctor(tcx, used_ctor) { + // Refine the required constructors for the type by subtracting + // the range defined by the current constructor pattern. + refined_ctors = interval.subtract_from(tcx, refined_ctors); } // If the constructor patterns that have been considered so far @@ -1433,17 +1430,16 @@ fn slice_pat_covered_by_constructor<'tcx>( // Whether to evaluate a constructor using exhaustive integer matching. This is true if the // constructor is a range or constant with an integer type. fn should_treat_range_exhaustively(tcx: TyCtxt<'_, 'tcx, 'tcx>, ctor: &Constructor<'tcx>) -> bool { - if tcx.features().exhaustive_integer_patterns { - let ty = match ctor { - ConstantValue(value) => value.ty, - ConstantRange(_, _, ty, _) => ty, - _ => return false, - }; - if let ty::Char | ty::Int(_) | ty::Uint(_) = ty.sty { - return true; - } + let ty = match ctor { + ConstantValue(value) => value.ty, + ConstantRange(_, _, ty, _) => ty, + _ => return false, + }; + if let ty::Char | ty::Int(_) | ty::Uint(_) = ty.sty { + true + } else { + false } - false } /// For exhaustive integer matching, some constructors are grouped within other constructors diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 3bc34917051..53faf04f278 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -439,8 +439,6 @@ declare_features! ( // 'a: { break 'a; } (active, label_break_value, "1.28.0", Some(48594), None), - // Integer match exhaustiveness checking - (active, exhaustive_integer_patterns, "1.30.0", Some(50907), None), // #[doc(keyword = "...")] (active, doc_keyword, "1.28.0", Some(51315), None), @@ -686,6 +684,8 @@ declare_features! ( (accepted, extern_crate_item_prelude, "1.31.0", Some(55599), None), // Allows use of the :literal macro fragment specifier (RFC 1576) (accepted, macro_literal_matcher, "1.31.0", Some(35625), None), + // Integer match exhaustiveness checking (RFC 2591) + (accepted, exhaustive_integer_patterns, "1.32.0", Some(50907), None), // Use `?` as the Kleene "at most one" operator (accepted, macro_at_most_once_rep, "1.32.0", Some(48075), None), ); diff --git a/src/test/ui/exhaustive_integer_patterns.rs b/src/test/ui/exhaustive_integer_patterns.rs index 7825aaa2912..cddb301dbdf 100644 --- a/src/test/ui/exhaustive_integer_patterns.rs +++ b/src/test/ui/exhaustive_integer_patterns.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(exhaustive_integer_patterns)] #![feature(exclusive_range_pattern)] + #![deny(unreachable_patterns)] use std::{char, usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128}; -- cgit 1.4.1-3-g733a5 From e018268ffad0e3d2704705cb3337b6195b5cba08 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 30 Nov 2018 00:44:33 +0000 Subject: Add precise_pointer_size_matching feature --- src/librustc/ty/sty.rs | 7 +++++++ src/librustc_mir/hair/pattern/_match.rs | 5 +++-- src/libsyntax/feature_gate.rs | 2 ++ src/test/ui/exhaustive_integer_patterns.rs | 1 + .../feature-gate-precise_pointer_size_matching.rs | 14 ++++++++++++++ .../feature-gate-precise_pointer_size_matching.stderr | 15 +++++++++++++++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.rs create mode 100644 src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.stderr (limited to 'src/test') diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index a18e3a27546..fbc98696574 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -1780,6 +1780,13 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> { } } + pub fn is_pointer_sized(&self) -> bool { + match self.sty { + Int(ast::IntTy::Isize) | Uint(ast::UintTy::Usize) => true, + _ => false, + } + } + pub fn is_machine(&self) -> bool { match self.sty { Int(ast::IntTy::Isize) | Uint(ast::UintTy::Usize) => false, diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 82e368198f2..a2fbfd70a65 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -1129,7 +1129,8 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, // For privately empty and non-exhaustive enums, we work as if there were an "extra" // `_` constructor for the type, so we can never match over all constructors. - let is_non_exhaustive = is_privately_empty || is_declared_nonexhaustive; + let is_non_exhaustive = is_privately_empty || is_declared_nonexhaustive || + (pcx.ty.is_pointer_sized() && !cx.tcx.features().precise_pointer_size_matching); if cheap_missing_ctors == MissingCtors::Empty && !is_non_exhaustive { split_grouped_constructors(cx.tcx, all_ctors, matrix, pcx.ty).into_iter().map(|c| { @@ -1436,7 +1437,7 @@ fn should_treat_range_exhaustively(tcx: TyCtxt<'_, 'tcx, 'tcx>, ctor: &Construct _ => return false, }; if let ty::Char | ty::Int(_) | ty::Uint(_) = ty.sty { - true + !ty.is_pointer_sized() || tcx.features().precise_pointer_size_matching } else { false } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 53faf04f278..15679322663 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -439,6 +439,8 @@ declare_features! ( // 'a: { break 'a; } (active, label_break_value, "1.28.0", Some(48594), None), + // Exhaustive pattern matching on `usize` and `isize`. + (active, precise_pointer_size_matching, "1.32.0", Some(56354), None), // #[doc(keyword = "...")] (active, doc_keyword, "1.28.0", Some(51315), None), diff --git a/src/test/ui/exhaustive_integer_patterns.rs b/src/test/ui/exhaustive_integer_patterns.rs index cddb301dbdf..ad955fbe05d 100644 --- a/src/test/ui/exhaustive_integer_patterns.rs +++ b/src/test/ui/exhaustive_integer_patterns.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(precise_pointer_size_matching)] #![feature(exclusive_range_pattern)] #![deny(unreachable_patterns)] diff --git a/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.rs b/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.rs new file mode 100644 index 00000000000..1208552d256 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.rs @@ -0,0 +1,14 @@ +#![feature(exclusive_range_pattern)] + +use std::usize::MAX; + +fn main() { + match 0usize { //~ERROR non-exhaustive patterns: `_` not covered + 0..=MAX => {} + } + + match 0isize { //~ERROR non-exhaustive patterns: `_` not covered + 1..=20 => {} + -5..3 => {} + } +} diff --git a/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.stderr b/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.stderr new file mode 100644 index 00000000000..5806f6f0391 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.stderr @@ -0,0 +1,15 @@ +error[E0004]: non-exhaustive patterns: `_` not covered + --> $DIR/feature-gate-precise_pointer_size_matching.rs:6:11 + | +LL | match 0usize { //~ERROR non-exhaustive patterns: `_` not covered + | ^^^^^^ pattern `_` not covered + +error[E0004]: non-exhaustive patterns: `_` not covered + --> $DIR/feature-gate-precise_pointer_size_matching.rs:10:11 + | +LL | match 0isize { //~ERROR non-exhaustive patterns: `_` not covered + | ^^^^^^ pattern `_` not covered + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0004`. -- cgit 1.4.1-3-g733a5 From 4fc5758a67e38b21e975fc9efe071dd58f4b98c6 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 30 Nov 2018 13:53:15 +0000 Subject: Update existing tests with more precise error messages --- .../array-slice-vec/vec-matching-autoslice.stderr | 8 +++++++ src/test/run-pass/binding/match-range.stderr | 20 ++++++++++++++++ .../issue-15881-model-lexer-dotdotdot.stderr | 8 +++++++ src/test/run-pass/issues/issue-7222.stderr | 8 +++++++ src/test/ui/consts/const-match-check.eval1.stderr | 4 ++-- src/test/ui/consts/const-match-check.eval2.stderr | 4 ++-- .../ui/consts/const-match-check.matchck.stderr | 16 ++++++------- src/test/ui/consts/const-pattern-irrefutable.rs | 6 ++--- .../ui/consts/const-pattern-irrefutable.stderr | 12 +++++----- src/test/ui/exhaustive_integer_patterns.stderr | 28 +++++++++++----------- .../ui/feature-gate-exhaustive_integer_patterns.rs | 16 ------------- ...feature-gate-exhaustive_integer_patterns.stderr | 9 ------- ...for-loop-refutable-pattern-error-message.stderr | 4 ++-- src/test/ui/match/match-non-exhaustive.stderr | 4 ++-- src/test/ui/match/match-range-fail-dominate.stderr | 8 ++++++- src/test/ui/non-exhaustive/non-exhaustive-match.rs | 3 ++- .../ui/non-exhaustive/non-exhaustive-match.stderr | 14 +++++------ src/test/ui/refutable-pattern-errors.rs | 2 +- src/test/ui/refutable-pattern-errors.stderr | 4 ++-- 19 files changed, 102 insertions(+), 76 deletions(-) create mode 100644 src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr create mode 100644 src/test/run-pass/binding/match-range.stderr create mode 100644 src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr create mode 100644 src/test/run-pass/issues/issue-7222.stderr delete mode 100644 src/test/ui/feature-gate-exhaustive_integer_patterns.rs delete mode 100644 src/test/ui/feature-gate-exhaustive_integer_patterns.stderr (limited to 'src/test') diff --git a/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr b/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr new file mode 100644 index 00000000000..fd811e8083c --- /dev/null +++ b/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr @@ -0,0 +1,8 @@ +warning: unreachable pattern + --> $DIR/vec-matching-autoslice.rs:31:9 + | +LL | ([_, _], _) => panic!(), + | ^^^^^^^^^^^ + | + = note: #[warn(unreachable_patterns)] on by default + diff --git a/src/test/run-pass/binding/match-range.stderr b/src/test/run-pass/binding/match-range.stderr new file mode 100644 index 00000000000..f402a98af49 --- /dev/null +++ b/src/test/run-pass/binding/match-range.stderr @@ -0,0 +1,20 @@ +warning: unreachable pattern + --> $DIR/match-range.rs:47:7 + | +LL | _ => panic!("should match float range") + | ^ + | + = note: #[warn(unreachable_patterns)] on by default + +warning: unreachable pattern + --> $DIR/match-range.rs:55:9 + | +LL | _ => {}, + | ^ + +warning: unreachable pattern + --> $DIR/match-range.rs:59:9 + | +LL | _ => panic!("should match the range start"), + | ^ + diff --git a/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr b/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr new file mode 100644 index 00000000000..41b4130acf4 --- /dev/null +++ b/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr @@ -0,0 +1,8 @@ +warning: unreachable pattern + --> $DIR/issue-15881-model-lexer-dotdotdot.rs:41:7 + | +LL | _ => panic!("should match float range") + | ^ + | + = note: #[warn(unreachable_patterns)] on by default + diff --git a/src/test/run-pass/issues/issue-7222.stderr b/src/test/run-pass/issues/issue-7222.stderr new file mode 100644 index 00000000000..1b231f2da39 --- /dev/null +++ b/src/test/run-pass/issues/issue-7222.stderr @@ -0,0 +1,8 @@ +warning: unreachable pattern + --> $DIR/issue-7222.rs:20:9 + | +LL | _ => () + | ^ + | + = note: #[warn(unreachable_patterns)] on by default + diff --git a/src/test/ui/consts/const-match-check.eval1.stderr b/src/test/ui/consts/const-match-check.eval1.stderr index 3caf1491aba..703453e6bdd 100644 --- a/src/test/ui/consts/const-match-check.eval1.stderr +++ b/src/test/ui/consts/const-match-check.eval1.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:35:15 | LL | A = { let 0 = 0; 0 }, - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered error: aborting due to previous error diff --git a/src/test/ui/consts/const-match-check.eval2.stderr b/src/test/ui/consts/const-match-check.eval2.stderr index de85d4d73db..6caff93e642 100644 --- a/src/test/ui/consts/const-match-check.eval2.stderr +++ b/src/test/ui/consts/const-match-check.eval2.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:41:24 | LL | let x: [i32; { let 0 = 0; 0 }] = []; - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered error: aborting due to previous error diff --git a/src/test/ui/consts/const-match-check.matchck.stderr b/src/test/ui/consts/const-match-check.matchck.stderr index bbf1169c577..9e45045d27e 100644 --- a/src/test/ui/consts/const-match-check.matchck.stderr +++ b/src/test/ui/consts/const-match-check.matchck.stderr @@ -1,26 +1,26 @@ -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:14:22 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:18:23 | LL | static Y: i32 = { let 0 = 0; 0 }; - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:23:26 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `-2147483648i32..=-1i32` not covered --> $DIR/const-match-check.rs:29:26 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ pattern `_` not covered + | ^ pattern `-2147483648i32..=-1i32` not covered error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/const-pattern-irrefutable.rs b/src/test/ui/consts/const-pattern-irrefutable.rs index af0b95e002d..278864d6de9 100644 --- a/src/test/ui/consts/const-pattern-irrefutable.rs +++ b/src/test/ui/consts/const-pattern-irrefutable.rs @@ -19,8 +19,8 @@ use foo::d; const a: u8 = 2; fn main() { - let a = 4; //~ ERROR refutable pattern in local binding: `_` not covered - let c = 4; //~ ERROR refutable pattern in local binding: `_` not covered - let d = 4; //~ ERROR refutable pattern in local binding: `_` not covered + let a = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered + let c = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered + let d = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered fn f() {} // Check that the `NOTE`s still work with an item here (c.f. issue #35115). } diff --git a/src/test/ui/consts/const-pattern-irrefutable.stderr b/src/test/ui/consts/const-pattern-irrefutable.stderr index 6d5738f3328..d9ad16cd0e8 100644 --- a/src/test/ui/consts/const-pattern-irrefutable.stderr +++ b/src/test/ui/consts/const-pattern-irrefutable.stderr @@ -1,19 +1,19 @@ -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `0u8..=1u8` not covered --> $DIR/const-pattern-irrefutable.rs:22:9 | -LL | let a = 4; //~ ERROR refutable pattern in local binding: `_` not covered +LL | let a = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered | ^ interpreted as a constant pattern, not new variable -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `0u8..=1u8` not covered --> $DIR/const-pattern-irrefutable.rs:23:9 | -LL | let c = 4; //~ ERROR refutable pattern in local binding: `_` not covered +LL | let c = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered | ^ interpreted as a constant pattern, not new variable -error[E0005]: refutable pattern in local binding: `_` not covered +error[E0005]: refutable pattern in local binding: `0u8..=1u8` not covered --> $DIR/const-pattern-irrefutable.rs:24:9 | -LL | let d = 4; //~ ERROR refutable pattern in local binding: `_` not covered +LL | let d = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` not covered | ^ interpreted as a constant pattern, not new variable error: aborting due to 3 previous errors diff --git a/src/test/ui/exhaustive_integer_patterns.stderr b/src/test/ui/exhaustive_integer_patterns.stderr index 44b05a12aeb..c9b669aefd1 100644 --- a/src/test/ui/exhaustive_integer_patterns.stderr +++ b/src/test/ui/exhaustive_integer_patterns.stderr @@ -1,83 +1,83 @@ error: unreachable pattern - --> $DIR/exhaustive_integer_patterns.rs:32:9 + --> $DIR/exhaustive_integer_patterns.rs:33:9 | LL | 200 => {} //~ ERROR unreachable pattern | ^^^ | note: lint level defined here - --> $DIR/exhaustive_integer_patterns.rs:13:9 + --> $DIR/exhaustive_integer_patterns.rs:14:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error[E0004]: non-exhaustive patterns: `128u8..=255u8` not covered - --> $DIR/exhaustive_integer_patterns.rs:37:11 + --> $DIR/exhaustive_integer_patterns.rs:38:11 | LL | match x { //~ ERROR non-exhaustive patterns | ^ pattern `128u8..=255u8` not covered error[E0004]: non-exhaustive patterns: `11u8..=19u8`, `31u8..=34u8`, `36u8..=69u8` and 1 more not covered - --> $DIR/exhaustive_integer_patterns.rs:42:11 + --> $DIR/exhaustive_integer_patterns.rs:43:11 | LL | match x { //~ ERROR non-exhaustive patterns | ^ patterns `11u8..=19u8`, `31u8..=34u8`, `36u8..=69u8` and 1 more not covered error: unreachable pattern - --> $DIR/exhaustive_integer_patterns.rs:53:9 + --> $DIR/exhaustive_integer_patterns.rs:54:9 | LL | -2..=20 => {} //~ ERROR unreachable pattern | ^^^^^^^ error[E0004]: non-exhaustive patterns: `-128i8..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered - --> $DIR/exhaustive_integer_patterns.rs:50:11 + --> $DIR/exhaustive_integer_patterns.rs:51:11 | LL | match x { //~ ERROR non-exhaustive patterns | ^ patterns `-128i8..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered error[E0004]: non-exhaustive patterns: `-128i8` not covered - --> $DIR/exhaustive_integer_patterns.rs:99:11 + --> $DIR/exhaustive_integer_patterns.rs:100:11 | LL | match 0i8 { //~ ERROR non-exhaustive patterns | ^^^ pattern `-128i8` not covered error[E0004]: non-exhaustive patterns: `0i16` not covered - --> $DIR/exhaustive_integer_patterns.rs:107:11 + --> $DIR/exhaustive_integer_patterns.rs:108:11 | LL | match 0i16 { //~ ERROR non-exhaustive patterns | ^^^^ pattern `0i16` not covered error[E0004]: non-exhaustive patterns: `128u8..=255u8` not covered - --> $DIR/exhaustive_integer_patterns.rs:125:11 + --> $DIR/exhaustive_integer_patterns.rs:126:11 | LL | match 0u8 { //~ ERROR non-exhaustive patterns | ^^^ pattern `128u8..=255u8` not covered error[E0004]: non-exhaustive patterns: `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered - --> $DIR/exhaustive_integer_patterns.rs:137:11 + --> $DIR/exhaustive_integer_patterns.rs:138:11 | LL | match (0u8, Some(())) { //~ ERROR non-exhaustive patterns | ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered error[E0004]: non-exhaustive patterns: `(126u8..=127u8, false)` not covered - --> $DIR/exhaustive_integer_patterns.rs:142:11 + --> $DIR/exhaustive_integer_patterns.rs:143:11 | LL | match (0u8, true) { //~ ERROR non-exhaustive patterns | ^^^^^^^^^^^ pattern `(126u8..=127u8, false)` not covered error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211455u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:162:11 + --> $DIR/exhaustive_integer_patterns.rs:163:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `340282366920938463463374607431768211455u128` not covered error[E0004]: non-exhaustive patterns: `5u128..=340282366920938463463374607431768211455u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:166:11 + --> $DIR/exhaustive_integer_patterns.rs:167:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `5u128..=340282366920938463463374607431768211455u128` not covered error[E0004]: non-exhaustive patterns: `0u128..=3u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:170:11 + --> $DIR/exhaustive_integer_patterns.rs:171:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `0u128..=3u128` not covered diff --git a/src/test/ui/feature-gate-exhaustive_integer_patterns.rs b/src/test/ui/feature-gate-exhaustive_integer_patterns.rs deleted file mode 100644 index 3aa15229455..00000000000 --- a/src/test/ui/feature-gate-exhaustive_integer_patterns.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let x: u8 = 0; - match x { //~ ERROR non-exhaustive patterns: `_` not covered - 0 ..= 255 => {} - } -} diff --git a/src/test/ui/feature-gate-exhaustive_integer_patterns.stderr b/src/test/ui/feature-gate-exhaustive_integer_patterns.stderr deleted file mode 100644 index 63d98f6b5eb..00000000000 --- a/src/test/ui/feature-gate-exhaustive_integer_patterns.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0004]: non-exhaustive patterns: `_` not covered - --> $DIR/feature-gate-exhaustive_integer_patterns.rs:13:11 - | -LL | match x { //~ ERROR non-exhaustive patterns: `_` not covered - | ^ pattern `_` not covered - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0004`. diff --git a/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr b/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr index b76c2ffc240..9b19fc80e2b 100644 --- a/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr +++ b/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in `for` loop binding: `&_` not covered +error[E0005]: refutable pattern in `for` loop binding: `&-2147483648i32..=0i32` not covered --> $DIR/for-loop-refutable-pattern-error-message.rs:12:9 | LL | for &1 in [1].iter() {} //~ ERROR refutable pattern in `for` loop binding - | ^^ pattern `&_` not covered + | ^^ pattern `&-2147483648i32..=0i32` not covered error: aborting due to previous error diff --git a/src/test/ui/match/match-non-exhaustive.stderr b/src/test/ui/match/match-non-exhaustive.stderr index 04f09caceed..ad895b448dd 100644 --- a/src/test/ui/match/match-non-exhaustive.stderr +++ b/src/test/ui/match/match-non-exhaustive.stderr @@ -1,8 +1,8 @@ -error[E0004]: non-exhaustive patterns: `_` not covered +error[E0004]: non-exhaustive patterns: `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered --> $DIR/match-non-exhaustive.rs:12:11 | LL | match 0 { 1 => () } //~ ERROR non-exhaustive patterns - | ^ pattern `_` not covered + | ^ patterns `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered error[E0004]: non-exhaustive patterns: `_` not covered --> $DIR/match-non-exhaustive.rs:13:11 diff --git a/src/test/ui/match/match-range-fail-dominate.stderr b/src/test/ui/match/match-range-fail-dominate.stderr index d75630e09c5..99f65042d85 100644 --- a/src/test/ui/match/match-range-fail-dominate.stderr +++ b/src/test/ui/match/match-range-fail-dominate.stderr @@ -62,5 +62,11 @@ error: unreachable pattern LL | 0.02f64 => {} | ^^^^^^^ -error: aborting due to 5 previous errors +error: unreachable pattern + --> $DIR/match-range-fail-dominate.rs:47:7 + | +LL | _ => {} + | ^ + +error: aborting due to 6 previous errors diff --git a/src/test/ui/non-exhaustive/non-exhaustive-match.rs b/src/test/ui/non-exhaustive/non-exhaustive-match.rs index 13b62429f46..99a0c5d6626 100644 --- a/src/test/ui/non-exhaustive/non-exhaustive-match.rs +++ b/src/test/ui/non-exhaustive/non-exhaustive-match.rs @@ -22,7 +22,8 @@ fn main() { match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered None => {} } - match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, _)` not covered + match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)` + // and `(_, _, 5i32..=2147483647i32)` not covered (_, _, 4) => {} } match (t::a, t::a) { //~ ERROR non-exhaustive patterns: `(a, a)` not covered diff --git a/src/test/ui/non-exhaustive/non-exhaustive-match.stderr b/src/test/ui/non-exhaustive/non-exhaustive-match.stderr index f48a0bc15eb..d3703a44454 100644 --- a/src/test/ui/non-exhaustive/non-exhaustive-match.stderr +++ b/src/test/ui/non-exhaustive/non-exhaustive-match.stderr @@ -16,32 +16,32 @@ error[E0004]: non-exhaustive patterns: `Some(_)` not covered LL | match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered | ^^^^^^^^ pattern `Some(_)` not covered -error[E0004]: non-exhaustive patterns: `(_, _, _)` not covered +error[E0004]: non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)` and `(_, _, 5i32..=2147483647i32)` not covered --> $DIR/non-exhaustive-match.rs:25:11 | -LL | match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, _)` not covered - | ^^^^^^^^^ pattern `(_, _, _)` not covered +LL | match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, -2147483648i32..=3i32)` + | ^^^^^^^^^ patterns `(_, _, -2147483648i32..=3i32)` and `(_, _, 5i32..=2147483647i32)` not covered error[E0004]: non-exhaustive patterns: `(a, a)` not covered - --> $DIR/non-exhaustive-match.rs:28:11 + --> $DIR/non-exhaustive-match.rs:29:11 | LL | match (t::a, t::a) { //~ ERROR non-exhaustive patterns: `(a, a)` not covered | ^^^^^^^^^^^^ pattern `(a, a)` not covered error[E0004]: non-exhaustive patterns: `b` not covered - --> $DIR/non-exhaustive-match.rs:32:11 + --> $DIR/non-exhaustive-match.rs:33:11 | LL | match t::a { //~ ERROR non-exhaustive patterns: `b` not covered | ^^^^ pattern `b` not covered error[E0004]: non-exhaustive patterns: `[]` not covered - --> $DIR/non-exhaustive-match.rs:43:11 + --> $DIR/non-exhaustive-match.rs:44:11 | LL | match *vec { //~ ERROR non-exhaustive patterns: `[]` not covered | ^^^^ pattern `[]` not covered error[E0004]: non-exhaustive patterns: `[_, _, _, _]` not covered - --> $DIR/non-exhaustive-match.rs:56:11 + --> $DIR/non-exhaustive-match.rs:57:11 | LL | match *vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _]` not covered | ^^^^ pattern `[_, _, _, _]` not covered diff --git a/src/test/ui/refutable-pattern-errors.rs b/src/test/ui/refutable-pattern-errors.rs index 7b4009481ab..a140e421a57 100644 --- a/src/test/ui/refutable-pattern-errors.rs +++ b/src/test/ui/refutable-pattern-errors.rs @@ -14,5 +14,5 @@ fn func((1, (Some(1), 2..=3)): (isize, (Option, isize))) { } fn main() { let (1, (Some(1), 2..=3)) = (1, (None, 2)); - //~^ ERROR refutable pattern in local binding: `(_, _)` not covered + //~^ ERROR refutable pattern in local binding: `(-2147483648i32..=0i32, _)` not covered } diff --git a/src/test/ui/refutable-pattern-errors.stderr b/src/test/ui/refutable-pattern-errors.stderr index c2d5fe001fc..42aa5727895 100644 --- a/src/test/ui/refutable-pattern-errors.stderr +++ b/src/test/ui/refutable-pattern-errors.stderr @@ -4,11 +4,11 @@ error[E0005]: refutable pattern in function argument: `(_, _)` not covered LL | fn func((1, (Some(1), 2..=3)): (isize, (Option, isize))) { } | ^^^^^^^^^^^^^^^^^^^^^ pattern `(_, _)` not covered -error[E0005]: refutable pattern in local binding: `(_, _)` not covered +error[E0005]: refutable pattern in local binding: `(-2147483648i32..=0i32, _)` not covered --> $DIR/refutable-pattern-errors.rs:16:9 | LL | let (1, (Some(1), 2..=3)) = (1, (None, 2)); - | ^^^^^^^^^^^^^^^^^^^^^ pattern `(_, _)` not covered + | ^^^^^^^^^^^^^^^^^^^^^ pattern `(-2147483648i32..=0i32, _)` not covered error: aborting due to 2 previous errors -- cgit 1.4.1-3-g733a5 From 0fb52fb538946600dfe76be0b943556363904136 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 30 Nov 2018 21:13:07 +0000 Subject: Separate out precise_pointer_size_matching tests from exhaustive_integer_patterns tests --- src/test/ui/exhaustive_integer_patterns.rs | 10 +-------- src/test/ui/exhaustive_integer_patterns.stderr | 16 +++++++-------- src/test/ui/precise_pointer_size_matching.rs | 26 ++++++++++++++++++++++++ src/test/ui/precise_pointer_size_matching.stderr | 15 ++++++++++++++ 4 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 src/test/ui/precise_pointer_size_matching.rs create mode 100644 src/test/ui/precise_pointer_size_matching.stderr (limited to 'src/test') diff --git a/src/test/ui/exhaustive_integer_patterns.rs b/src/test/ui/exhaustive_integer_patterns.rs index ad955fbe05d..020382d9fe1 100644 --- a/src/test/ui/exhaustive_integer_patterns.rs +++ b/src/test/ui/exhaustive_integer_patterns.rs @@ -13,7 +13,7 @@ #![deny(unreachable_patterns)] -use std::{char, usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128}; +use std::{char, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128}; fn main() { let x: u8 = 0; @@ -69,10 +69,6 @@ fn main() { '\u{E000}' ..= '\u{10_FFFF}' => {} } - match 0usize { - 0 ..= usize::MAX => {} // ok - } - match 0u16 { 0 ..= u16::MAX => {} // ok } @@ -89,10 +85,6 @@ fn main() { 0 ..= u128::MAX => {} // ok } - match 0isize { - isize::MIN ..= isize::MAX => {} // ok - } - match 0i8 { -128 ..= 127 => {} // ok } diff --git a/src/test/ui/exhaustive_integer_patterns.stderr b/src/test/ui/exhaustive_integer_patterns.stderr index c9b669aefd1..011e93683fb 100644 --- a/src/test/ui/exhaustive_integer_patterns.stderr +++ b/src/test/ui/exhaustive_integer_patterns.stderr @@ -35,49 +35,49 @@ LL | match x { //~ ERROR non-exhaustive patterns | ^ patterns `-128i8..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered error[E0004]: non-exhaustive patterns: `-128i8` not covered - --> $DIR/exhaustive_integer_patterns.rs:100:11 + --> $DIR/exhaustive_integer_patterns.rs:92:11 | LL | match 0i8 { //~ ERROR non-exhaustive patterns | ^^^ pattern `-128i8` not covered error[E0004]: non-exhaustive patterns: `0i16` not covered - --> $DIR/exhaustive_integer_patterns.rs:108:11 + --> $DIR/exhaustive_integer_patterns.rs:100:11 | LL | match 0i16 { //~ ERROR non-exhaustive patterns | ^^^^ pattern `0i16` not covered error[E0004]: non-exhaustive patterns: `128u8..=255u8` not covered - --> $DIR/exhaustive_integer_patterns.rs:126:11 + --> $DIR/exhaustive_integer_patterns.rs:118:11 | LL | match 0u8 { //~ ERROR non-exhaustive patterns | ^^^ pattern `128u8..=255u8` not covered error[E0004]: non-exhaustive patterns: `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered - --> $DIR/exhaustive_integer_patterns.rs:138:11 + --> $DIR/exhaustive_integer_patterns.rs:130:11 | LL | match (0u8, Some(())) { //~ ERROR non-exhaustive patterns | ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=255u8, Some(_))` not covered error[E0004]: non-exhaustive patterns: `(126u8..=127u8, false)` not covered - --> $DIR/exhaustive_integer_patterns.rs:143:11 + --> $DIR/exhaustive_integer_patterns.rs:135:11 | LL | match (0u8, true) { //~ ERROR non-exhaustive patterns | ^^^^^^^^^^^ pattern `(126u8..=127u8, false)` not covered error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211455u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:163:11 + --> $DIR/exhaustive_integer_patterns.rs:155:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `340282366920938463463374607431768211455u128` not covered error[E0004]: non-exhaustive patterns: `5u128..=340282366920938463463374607431768211455u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:167:11 + --> $DIR/exhaustive_integer_patterns.rs:159:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `5u128..=340282366920938463463374607431768211455u128` not covered error[E0004]: non-exhaustive patterns: `0u128..=3u128` not covered - --> $DIR/exhaustive_integer_patterns.rs:171:11 + --> $DIR/exhaustive_integer_patterns.rs:163:11 | LL | match 0u128 { //~ ERROR non-exhaustive patterns | ^^^^^ pattern `0u128..=3u128` not covered diff --git a/src/test/ui/precise_pointer_size_matching.rs b/src/test/ui/precise_pointer_size_matching.rs new file mode 100644 index 00000000000..31b202fd6aa --- /dev/null +++ b/src/test/ui/precise_pointer_size_matching.rs @@ -0,0 +1,26 @@ +#![feature(precise_pointer_size_matching)] +#![feature(exclusive_range_pattern)] + +#![deny(unreachable_patterns)] + +use std::{usize, isize}; + +fn main() { + match 0isize { + isize::MIN ..= isize::MAX => {} // ok + } + + match 0usize { + 0 ..= usize::MAX => {} // ok + } + + match 0isize { //~ ERROR non-exhaustive patterns + 1 ..= 8 => {} + -5 ..= 20 => {} + } + + match 0usize { //~ ERROR non-exhaustive patterns + 1 ..= 8 => {} + 5 ..= 20 => {} + } +} diff --git a/src/test/ui/precise_pointer_size_matching.stderr b/src/test/ui/precise_pointer_size_matching.stderr new file mode 100644 index 00000000000..8e13be0ae0c --- /dev/null +++ b/src/test/ui/precise_pointer_size_matching.stderr @@ -0,0 +1,15 @@ +error[E0004]: non-exhaustive patterns: `-9223372036854775808isize..=-6isize` and `21isize..=9223372036854775807isize` not covered + --> $DIR/precise_pointer_size_matching.rs:17:11 + | +LL | match 0isize { //~ ERROR non-exhaustive patterns + | ^^^^^^ patterns `-9223372036854775808isize..=-6isize` and `21isize..=9223372036854775807isize` not covered + +error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=18446744073709551615usize` not covered + --> $DIR/precise_pointer_size_matching.rs:22:11 + | +LL | match 0usize { //~ ERROR non-exhaustive patterns + | ^^^^^^ patterns `0usize` and `21usize..=18446744073709551615usize` not covered + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0004`. -- cgit 1.4.1-3-g733a5 From 4406391cdce37dfd8142cc49e3760c606da8913c Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 30 Nov 2018 21:13:16 +0000 Subject: Fix bug in matching on floating-point ranges --- src/librustc_mir/hair/pattern/_match.rs | 17 ++++++++++++----- .../array-slice-vec/vec-matching-autoslice.stderr | 8 -------- src/test/run-pass/binding/match-range.stderr | 20 -------------------- .../issues/issue-15881-model-lexer-dotdotdot.stderr | 8 -------- src/test/run-pass/issues/issue-7222.stderr | 8 -------- src/test/ui/match/match-range-fail-dominate.stderr | 8 +------- .../non-exhaustive-float-range-match.rs | 13 +++++++++++++ .../non-exhaustive-float-range-match.stderr | 9 +++++++++ 8 files changed, 35 insertions(+), 56 deletions(-) delete mode 100644 src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr delete mode 100644 src/test/run-pass/binding/match-range.stderr delete mode 100644 src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr delete mode 100644 src/test/run-pass/issues/issue-7222.stderr create mode 100644 src/test/ui/non-exhaustive/non-exhaustive-float-range-match.rs create mode 100644 src/test/ui/non-exhaustive/non-exhaustive-float-range-match.stderr (limited to 'src/test') diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index a2fbfd70a65..f7e034df1da 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -812,8 +812,17 @@ impl<'tcx> IntRange<'tcx> { fn from_ctor(tcx: TyCtxt<'_, 'tcx, 'tcx>, ctor: &Constructor<'tcx>) -> Option> { + // Floating-point ranges are permitted and we don't want + // to consider them when constructing integer ranges. + fn is_integral<'tcx>(ty: Ty<'tcx>) -> bool { + match ty.sty { + ty::Char | ty::Int(_) | ty::Uint(_) => true, + _ => false, + } + } + match ctor { - ConstantRange(lo, hi, ty, end) => { + ConstantRange(lo, hi, ty, end) if is_integral(ty) => { // Perform a shift if the underlying types are signed, // which makes the interval arithmetic simpler. let bias = IntRange::signed_bias(tcx, ty); @@ -826,7 +835,7 @@ impl<'tcx> IntRange<'tcx> { Some(IntRange { range: lo..=(hi - offset), ty }) } } - ConstantValue(val) => { + ConstantValue(val) if is_integral(val.ty) => { let ty = val.ty; if let Some(val) = val.assert_bits(tcx, ty::ParamEnv::empty().and(ty)) { let bias = IntRange::signed_bias(tcx, ty); @@ -836,9 +845,7 @@ impl<'tcx> IntRange<'tcx> { None } } - Single | Variant(_) | Slice(_) => { - None - } + _ => None, } } diff --git a/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr b/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr deleted file mode 100644 index fd811e8083c..00000000000 --- a/src/test/run-pass/array-slice-vec/vec-matching-autoslice.stderr +++ /dev/null @@ -1,8 +0,0 @@ -warning: unreachable pattern - --> $DIR/vec-matching-autoslice.rs:31:9 - | -LL | ([_, _], _) => panic!(), - | ^^^^^^^^^^^ - | - = note: #[warn(unreachable_patterns)] on by default - diff --git a/src/test/run-pass/binding/match-range.stderr b/src/test/run-pass/binding/match-range.stderr deleted file mode 100644 index f402a98af49..00000000000 --- a/src/test/run-pass/binding/match-range.stderr +++ /dev/null @@ -1,20 +0,0 @@ -warning: unreachable pattern - --> $DIR/match-range.rs:47:7 - | -LL | _ => panic!("should match float range") - | ^ - | - = note: #[warn(unreachable_patterns)] on by default - -warning: unreachable pattern - --> $DIR/match-range.rs:55:9 - | -LL | _ => {}, - | ^ - -warning: unreachable pattern - --> $DIR/match-range.rs:59:9 - | -LL | _ => panic!("should match the range start"), - | ^ - diff --git a/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr b/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr deleted file mode 100644 index 41b4130acf4..00000000000 --- a/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.stderr +++ /dev/null @@ -1,8 +0,0 @@ -warning: unreachable pattern - --> $DIR/issue-15881-model-lexer-dotdotdot.rs:41:7 - | -LL | _ => panic!("should match float range") - | ^ - | - = note: #[warn(unreachable_patterns)] on by default - diff --git a/src/test/run-pass/issues/issue-7222.stderr b/src/test/run-pass/issues/issue-7222.stderr deleted file mode 100644 index 1b231f2da39..00000000000 --- a/src/test/run-pass/issues/issue-7222.stderr +++ /dev/null @@ -1,8 +0,0 @@ -warning: unreachable pattern - --> $DIR/issue-7222.rs:20:9 - | -LL | _ => () - | ^ - | - = note: #[warn(unreachable_patterns)] on by default - diff --git a/src/test/ui/match/match-range-fail-dominate.stderr b/src/test/ui/match/match-range-fail-dominate.stderr index 99f65042d85..d75630e09c5 100644 --- a/src/test/ui/match/match-range-fail-dominate.stderr +++ b/src/test/ui/match/match-range-fail-dominate.stderr @@ -62,11 +62,5 @@ error: unreachable pattern LL | 0.02f64 => {} | ^^^^^^^ -error: unreachable pattern - --> $DIR/match-range-fail-dominate.rs:47:7 - | -LL | _ => {} - | ^ - -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors diff --git a/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.rs b/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.rs new file mode 100644 index 00000000000..588fecbf10d --- /dev/null +++ b/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.rs @@ -0,0 +1,13 @@ +#![allow(illegal_floating_point_literal_pattern)] +#![deny(unreachable_patterns)] + +fn main() { + match 0.0 { + 0.0..=1.0 => {} + _ => {} // ok + } + + match 0.0 { //~ ERROR non-exhaustive patterns + 0.0..=1.0 => {} + } +} diff --git a/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.stderr b/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.stderr new file mode 100644 index 00000000000..2e285afb380 --- /dev/null +++ b/src/test/ui/non-exhaustive/non-exhaustive-float-range-match.stderr @@ -0,0 +1,9 @@ +error[E0004]: non-exhaustive patterns: `_` not covered + --> $DIR/non-exhaustive-float-range-match.rs:10:11 + | +LL | match 0.0 { //~ ERROR non-exhaustive patterns + | ^^^ pattern `_` not covered + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0004`. -- cgit 1.4.1-3-g733a5 From 59e9a1e75aaa971b1910fd9db98d9fce55534558 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Mon, 3 Dec 2018 00:49:12 +0200 Subject: pass the parameter environment to `traits::find_associated_item` dropping the param-env on the floor is obviously the wrong thing to do. The ICE was probably exposed by #54490 adding the problem-exposing use of `traits::find_associated_item`. Fixes #55380. --- src/librustc/traits/specialize/mod.rs | 12 ++++++++++- src/librustc/traits/structural_impls.rs | 4 ++-- src/librustc/ty/instance.rs | 5 +++-- src/test/run-pass/issue-55380.rs | 38 +++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 src/test/run-pass/issue-55380.rs (limited to 'src/test') diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 19ef3171b13..cb17246b15f 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -85,6 +85,8 @@ pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, source_substs: &'tcx Substs<'tcx>, target_node: specialization_graph::Node) -> &'tcx Substs<'tcx> { + debug!("translate_substs({:?}, {:?}, {:?}, {:?})", + param_env, source_impl, source_substs, target_node); let source_trait_ref = infcx.tcx .impl_trait_ref(source_impl) .unwrap() @@ -119,10 +121,13 @@ pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, /// whichever applies. pub fn find_associated_item<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, + param_env: ty::ParamEnv<'tcx>, item: &ty::AssociatedItem, substs: &'tcx Substs<'tcx>, impl_data: &super::VtableImplData<'tcx, ()>, ) -> (DefId, &'tcx Substs<'tcx>) { + debug!("find_associated_item({:?}, {:?}, {:?}, {:?})", + param_env, item, substs, impl_data); assert!(!substs.needs_infer()); let trait_def_id = tcx.trait_id_of_impl(impl_data.impl_def_id).unwrap(); @@ -132,7 +137,7 @@ pub fn find_associated_item<'a, 'tcx>( match ancestors.defs(tcx, item.ident, item.kind, trait_def_id).next() { Some(node_item) => { let substs = tcx.infer_ctxt().enter(|infcx| { - let param_env = ty::ParamEnv::reveal_all(); + let param_env = param_env.with_reveal_all(); let substs = substs.rebase_onto(tcx, trait_def_id, impl_data.substs); let substs = translate_substs(&infcx, param_env, impl_data.impl_def_id, substs, node_item.node); @@ -219,12 +224,17 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, source_trait_ref: ty::TraitRef<'tcx>, target_impl: DefId) -> Result<&'tcx Substs<'tcx>, ()> { + debug!("fulfill_implication({:?}, trait_ref={:?} |- {:?} applies)", + param_env, source_trait_ref, target_impl); + let selcx = &mut SelectionContext::new(&infcx); let target_substs = infcx.fresh_substs_for_item(DUMMY_SP, target_impl); let (target_trait_ref, mut obligations) = impl_trait_ref_and_oblig(selcx, param_env, target_impl, target_substs); + debug!("fulfill_implication: target_trait_ref={:?}, obligations={:?}", + target_trait_ref, obligations); // do the impls unify? If not, no specialization. match infcx.at(&ObligationCause::dummy(), param_env) diff --git a/src/librustc/traits/structural_impls.rs b/src/librustc/traits/structural_impls.rs index 36538ac0889..36e93cc7740 100644 --- a/src/librustc/traits/structural_impls.rs +++ b/src/librustc/traits/structural_impls.rs @@ -33,8 +33,8 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> { if ty::tls::with(|tcx| tcx.sess.verbose()) { write!( f, - "Obligation(predicate={:?},cause={:?},depth={})", - self.predicate, self.cause, self.recursion_depth + "Obligation(predicate={:?},cause={:?},param_env={:?},depth={})", + self.predicate, self.cause, self.param_env, self.recursion_depth ) } else { write!( diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 411a6e7e623..a24920da158 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -347,9 +347,10 @@ fn resolve_associated_item<'a, 'tcx>( ) -> Option> { let def_id = trait_item.def_id; debug!("resolve_associated_item(trait_item={:?}, \ + param_env={:?}, \ trait_id={:?}, \ rcvr_substs={:?})", - def_id, trait_id, rcvr_substs); + def_id, param_env, trait_id, rcvr_substs); let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs); let vtbl = tcx.codegen_fulfill_obligation((param_env, ty::Binder::bind(trait_ref))); @@ -359,7 +360,7 @@ fn resolve_associated_item<'a, 'tcx>( match vtbl { traits::VtableImpl(impl_data) => { let (def_id, substs) = traits::find_associated_item( - tcx, trait_item, rcvr_substs, &impl_data); + tcx, param_env, trait_item, rcvr_substs, &impl_data); let substs = tcx.erase_regions(&substs); Some(ty::Instance::new(def_id, substs)) } diff --git a/src/test/run-pass/issue-55380.rs b/src/test/run-pass/issue-55380.rs new file mode 100644 index 00000000000..29392fba8b4 --- /dev/null +++ b/src/test/run-pass/issue-55380.rs @@ -0,0 +1,38 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-pass + +#![feature(specialization)] + +pub trait Foo { + fn abc() -> u32; + fn def() -> u32; +} + +pub trait Marker {} + +impl Marker for () {} + +impl Foo for T { + default fn abc() -> u32 { 16 } + default fn def() -> u32 { 42 } +} + +impl Foo for T { + fn def() -> u32 { + Self::abc() + } +} + +fn main() { + assert_eq!(<()>::def(), 16); + assert_eq!(::def(), 42); +} -- cgit 1.4.1-3-g733a5 From 101467c152b26c44079401a712291c29cff0c9ac Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 2 Dec 2018 03:05:19 +0300 Subject: syntax: `dyn` is a used keyword now --- src/libsyntax_pos/symbol.rs | 18 +++++++++++++----- src/test/ui/rust-2018/dyn-trait-compatibility.rs | 2 +- src/test/ui/rust-2018/dyn-trait-compatibility.stderr | 6 +++--- 3 files changed, 17 insertions(+), 9 deletions(-) (limited to 'src/test') diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 741877bb4c8..8ccd123afdc 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -404,9 +404,11 @@ declare_keywords! { (49, Virtual, "virtual") (50, Yield, "yield") + // Edition-specific keywords used in the language. + (51, Dyn, "dyn") // >= 2018 Edition only + // Edition-specific keywords reserved for future use. - (51, Async, "async") // >= 2018 Edition only - (52, Dyn, "dyn") // >= 2018 Edition only + (52, Async, "async") // >= 2018 Edition only (53, Try, "try") // >= 2018 Edition only // Special lifetime names @@ -417,11 +419,15 @@ declare_keywords! { (56, Auto, "auto") (57, Catch, "catch") (58, Default, "default") - (59, Union, "union") - (60, Existential, "existential") + (59, Existential, "existential") + (60, Union, "union") } impl Symbol { + fn is_used_keyword_2018(self) -> bool { + self == keywords::Dyn.name() + } + fn is_unused_keyword_2018(self) -> bool { self >= keywords::Async.name() && self <= keywords::Try.name() } @@ -436,7 +442,9 @@ impl Ident { /// Returns `true` if the token is a keyword used in the language. pub fn is_used_keyword(self) -> bool { - self.name >= keywords::As.name() && self.name <= keywords::While.name() + // Note: `span.edition()` is relatively expensive, don't call it unless necessary. + self.name >= keywords::As.name() && self.name <= keywords::While.name() || + self.name.is_used_keyword_2018() && self.span.rust_2018() } /// Returns `true` if the token is a keyword reserved for possible future use. diff --git a/src/test/ui/rust-2018/dyn-trait-compatibility.rs b/src/test/ui/rust-2018/dyn-trait-compatibility.rs index 9548df5959b..377c85fef49 100644 --- a/src/test/ui/rust-2018/dyn-trait-compatibility.rs +++ b/src/test/ui/rust-2018/dyn-trait-compatibility.rs @@ -1,7 +1,7 @@ // edition:2018 type A0 = dyn; -type A1 = dyn::dyn; //~ERROR expected identifier, found reserved keyword +type A1 = dyn::dyn; //~ERROR expected identifier, found keyword `dyn` type A2 = dyn; //~ERROR expected identifier, found `<` type A3 = dyn<::dyn>; diff --git a/src/test/ui/rust-2018/dyn-trait-compatibility.stderr b/src/test/ui/rust-2018/dyn-trait-compatibility.stderr index ea0483394b5..bd72f9c6786 100644 --- a/src/test/ui/rust-2018/dyn-trait-compatibility.stderr +++ b/src/test/ui/rust-2018/dyn-trait-compatibility.stderr @@ -1,8 +1,8 @@ -error: expected identifier, found reserved keyword `dyn` +error: expected identifier, found keyword `dyn` --> $DIR/dyn-trait-compatibility.rs:4:16 | -LL | type A1 = dyn::dyn; //~ERROR expected identifier, found reserved keyword - | ^^^ expected identifier, found reserved keyword +LL | type A1 = dyn::dyn; //~ERROR expected identifier, found keyword `dyn` + | ^^^ expected identifier, found keyword error: expected identifier, found `<` --> $DIR/dyn-trait-compatibility.rs:5:14 -- cgit 1.4.1-3-g733a5 From 3f253f53946398199277cfb6e3af7c05b5ed3b4f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 3 Dec 2018 23:04:59 +0100 Subject: Improve filter test --- src/test/rustdoc-js/filter-crate.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/test') diff --git a/src/test/rustdoc-js/filter-crate.js b/src/test/rustdoc-js/filter-crate.js index 69c959a6ef2..97ecc607f47 100644 --- a/src/test/rustdoc-js/filter-crate.js +++ b/src/test/rustdoc-js/filter-crate.js @@ -8,13 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// should-fail +// exact-check -const QUERY = 'string'; +const QUERY = 'hashmap'; const FILTER_CRATE = 'core'; const EXPECTED = { 'others': [ - { 'path': 'std::collections', 'name': 'VecDeque' }, ], }; -- cgit 1.4.1-3-g733a5 From 956b03f7db8b6b6b73bb4b2b6e0cbb1016e08f8a Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Tue, 4 Dec 2018 10:24:17 +0100 Subject: Add a test case for inlining the docs of a macro reexport --- src/test/rustdoc/inline_local/macro_by_example.rs | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/rustdoc/inline_local/macro_by_example.rs (limited to 'src/test') diff --git a/src/test/rustdoc/inline_local/macro_by_example.rs b/src/test/rustdoc/inline_local/macro_by_example.rs new file mode 100644 index 00000000000..93d55ec0798 --- /dev/null +++ b/src/test/rustdoc/inline_local/macro_by_example.rs @@ -0,0 +1,28 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +/// docs for foo +#[deprecated(since = "1.2.3", note = "text")] +#[macro_export] +macro_rules! foo { + ($($tt:tt)*) => {} +} + +// @has macro_by_example/macros/index.html +pub mod macros { + // @!has - 'pub use foo as bar;' + // @has macro_by_example/macros/macro.bar.html + // @has - '//*[@class="docblock"]' 'docs for foo' + // @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.2.3: text' + // @has - '//a/@href' 'macro_by_example.rs.html#15-17' + #[doc(inline)] + pub use foo as bar; +} -- cgit 1.4.1-3-g733a5 From ed64b1927b4e929e905f778870a9f53d75216b34 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 5 Dec 2018 23:21:56 +0100 Subject: Fix precise_pointer_size_matching tests on all platforms --- src/test/ui/precise_pointer_size_matching.rs | 7 +++++++ src/test/ui/precise_pointer_size_matching.stderr | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src/test') diff --git a/src/test/ui/precise_pointer_size_matching.rs b/src/test/ui/precise_pointer_size_matching.rs index 31b202fd6aa..759b63b188b 100644 --- a/src/test/ui/precise_pointer_size_matching.rs +++ b/src/test/ui/precise_pointer_size_matching.rs @@ -1,3 +1,10 @@ +// normalize-stderr-32bit: "-2147483648isize" -> "$$ISIZE_MIN" +// normalize-stderr-64bit: "-9223372036854775808isize" -> "$$ISIZE_MIN" +// normalize-stderr-32bit: "2147483647isize" -> "$$ISIZE_MAX" +// normalize-stderr-64bit: "9223372036854775807isize" -> "$$ISIZE_MAX" +// normalize-stderr-32bit: "4294967295usize" -> "$$USIZE_MAX" +// normalize-stderr-64bit: "18446744073709551615usize" -> "$$USIZE_MAX" + #![feature(precise_pointer_size_matching)] #![feature(exclusive_range_pattern)] diff --git a/src/test/ui/precise_pointer_size_matching.stderr b/src/test/ui/precise_pointer_size_matching.stderr index 8e13be0ae0c..4acbec6c7ff 100644 --- a/src/test/ui/precise_pointer_size_matching.stderr +++ b/src/test/ui/precise_pointer_size_matching.stderr @@ -1,14 +1,14 @@ -error[E0004]: non-exhaustive patterns: `-9223372036854775808isize..=-6isize` and `21isize..=9223372036854775807isize` not covered - --> $DIR/precise_pointer_size_matching.rs:17:11 +error[E0004]: non-exhaustive patterns: `$ISIZE_MIN..=-6isize` and `21isize..=$ISIZE_MAX` not covered + --> $DIR/precise_pointer_size_matching.rs:24:11 | LL | match 0isize { //~ ERROR non-exhaustive patterns - | ^^^^^^ patterns `-9223372036854775808isize..=-6isize` and `21isize..=9223372036854775807isize` not covered + | ^^^^^^ patterns `$ISIZE_MIN..=-6isize` and `21isize..=$ISIZE_MAX` not covered -error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=18446744073709551615usize` not covered - --> $DIR/precise_pointer_size_matching.rs:22:11 +error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=$USIZE_MAX` not covered + --> $DIR/precise_pointer_size_matching.rs:29:11 | LL | match 0usize { //~ ERROR non-exhaustive patterns - | ^^^^^^ patterns `0usize` and `21usize..=18446744073709551615usize` not covered + | ^^^^^^ patterns `0usize` and `21usize..=$USIZE_MAX` not covered error: aborting due to 2 previous errors -- cgit 1.4.1-3-g733a5