summary refs log tree commit diff
path: root/src/test/ui/pattern
AgeCommit message (Collapse)AuthorLines
2020-12-22Add some testsNadrieril-28/+71
2020-12-22Auto merge of #78242 - Nadrieril:rename-overlapping_endpoints-lint, r=varkorbors-86/+103
Rename `overlapping_patterns` lint As discussed in https://github.com/rust-lang/rust/issues/65477. I also tweaked a few things along the way. r? `@varkor` `@rustbot` modify labels: +A-exhaustiveness-checking
2020-12-20Fix pretty printing an AST representing `&(mut ident)`Thomas Bahn-0/+19
`PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..), ..)` is an AST representing `&(mut ident)`. It was errorneously printed as `&mut ident` which reparsed into a syntactically different AST. This affected help diagnostics in the parser.
2020-12-20Auto merge of #80100 - mark-i-m:pattORns-2, r=petrochenkovbors-0/+44
or_patterns: implement :pat edition-specific behavior cc #54883 `@joshtriplett` This PR implements the edition-specific behavior of `:pat` wrt or-patterns, as determined by the crater runs and T-lang consensus in https://github.com/rust-lang/rust/issues/54883#issuecomment-745509090. I believe this can unblock stabilization of or_patterns. r? `@petrochenkov`
2020-12-19Tweak diagnosticsNadrieril-8/+8
2020-12-19implement edition-specific :pat behavior for 2015/18mark-0/+44
2020-12-18Keep all witnesses of non-exhaustivenessNadrieril-12/+14
2020-12-18Add testsNadrieril-14/+47
2020-11-29`overlapping_range_endpoints` does not belong in the `unused` lint groupNadrieril-37/+39
2020-11-29Improve error messageNadrieril-17/+32
2020-11-29Be consistent about linting singletonsNadrieril-19/+3
2020-11-29Rename the `overlapping_patterns` lint to `overlapping_range_endpoints`Nadrieril-33/+33
2020-11-29Add testsNadrieril-3/+19
2020-11-28Correctly detect `usize`/`isize` range overlapsNadrieril-2/+8
2020-11-21Improve integer range testsNadrieril-655/+892
2020-11-19Regroup many usefulness-related test in the same folderNadrieril-0/+686
2020-11-18Auto merge of #78995 - Nadrieril:clean-empty-match, r=varkorbors-55/+162
Handle empty matches cleanly in exhaustiveness checking This removes the special-casing of empty matches that was done in `check_match`. This fixes most of https://github.com/rust-lang/rust/issues/55123. Somewhat unrelatedly, I also made `_match.rs` more self-contained, because I think it's cleaner. r? `@varkor` `@rustbot` modify labels: +A-exhaustiveness-checking
2020-11-17Fix exhaustiveness in case a byte string literal is used at slice typeoli-2/+2
2020-11-16Add a test for foreign empty enumsNadrieril-48/+102
2020-11-12Handle empty matches cleanlyNadrieril-36/+43
2020-11-12Add testsNadrieril-42/+88
2020-11-05Auto merge of #78638 - vn-ki:bindigs-after-at-issue-69971, r=oli-obkbors-595/+524
reverse binding order in matches to allow the subbinding of copyable fields in bindings after @ Fixes #69971 ### TODO - [x] Regression tests r? `@oli-obk`
2020-11-03review commentsVishnunarayan K I-1/+4
2020-11-03add testsVishnunarayan K I-0/+49
2020-11-03preserve bindings order for SomeVishnunarayan K I-201/+159
2020-11-02new fix method and update testsVishnunarayan K I-57/+57
2020-11-02update some ui tests and update move ref drop semantics outputVishnunarayan K I-1/+1
2020-11-02reverse binding order in matches ...Vishnunarayan K I-708/+627
... to allow the subbinding of copyable fields in bindings after `@` Fixes #69971
2020-11-01Fix #78549Nadrieril-0/+25
Before #78430, string literals worked because `specialize_constructor` didn't actually care too much which constructor was passed to it unless needed. Since then, string literals are special cased and a bit hacky. I did not anticipate patterns for the `&str` type other than string literals, hence this bug. This makes string literals less hacky.
2020-10-24Rollup merge of #78072 - Nadrieril:cleanup-constant-matching, r=varkorJonas Schievink-2/+274
Cleanup constant matching in exhaustiveness checking This supercedes https://github.com/rust-lang/rust/pull/77390. I made the `Opaque` constructor work. I have opened two issues https://github.com/rust-lang/rust/issues/78071 and https://github.com/rust-lang/rust/issues/78057 from the discussion we had on the previous PR. They are not regressions nor directly related to the current PR so I thought we'd deal with them separately. I left a FIXME somewhere because I didn't know how to compare string constants for equality. There might even be some unicode things that need to happen there. In the meantime I preserved previous behavior. EDIT: I accidentally fixed #78071
2020-10-20Accidentally fixed #78071Nadrieril-24/+36
2020-10-18The only remaining constant patterns are opaqueNadrieril-9/+2
2020-10-18Destructure byte array constants to array patterns instead of keeping them ↵Oliver Scherer-2/+2
opaque
2020-10-18Add some testsNadrieril-0/+267
2020-10-17Improve wording of "cannot multiply" type errorCamelid-2/+2
For example, if you had this code: fn foo(x: i32, y: f32) -> f32 { x * y } You would get this error: error[E0277]: cannot multiply `f32` to `i32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32` However, that's not usually how people describe multiplication. People usually describe multiplication like how the division error words it: error[E0277]: cannot divide `i32` by `f32` --> src/lib.rs:2:7 | 2 | x / y | ^ no implementation for `i32 / f32` | = help: the trait `Div<f32>` is not implemented for `i32` So that's what this change does. It changes this: error[E0277]: cannot multiply `f32` to `i32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32` To this: error[E0277]: cannot multiply `i32` by `f32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32`
2020-10-16Rollup merge of #76119 - Amjad50:stabilizing-move_ref_pattern, r=nikomatsakisDylan DPC-364/+246
Stabilize move_ref_pattern # Implementation - Initially the rule was added in the run-up to 1.0. The AST-based borrow checker was having difficulty correctly enforcing match expressions that combined ref and move bindings, and so it was decided to simplify forbid the combination out right. - The move to MIR-based borrow checking made it possible to enforce the rules in a finer-grained level, but we kept the rule in place in an effort to be conservative in our changes. - In #68376, @Centril lifted the restriction but required a feature-gate. - This PR removes the feature-gate. Tracking issue: #68354. # Description This PR is to stabilize the feature `move_ref_pattern`, which allows patterns containing both `by-ref` and `by-move` bindings at the same time. For example: `Foo(ref x, y)`, where `x` is `by-ref`, and `y` is `by-move`. The rules of moving a variable also apply here when moving *part* of a variable, such as it can't be referenced or moved before. If this pattern is used, it would result in *partial move*, which means that part of the variable is moved. The variable that was partially moved from cannot be used as a whole in this case, only the parts that are still not moved can be used. ## Documentation - The reference (rust-lang/reference#881) - Rust by example (rust-lang/rust-by-example#1377) ## Tests There are many tests, but I think one of the comperhensive ones: - [borrowck-move-ref-pattern-pass.rs](https://github.com/Centril/rust/blob/85fbf49ce0e2274d0acf798f6e703747674feec3/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern-pass.rs) - [borrowck-move-ref-pattern.rs](https://github.com/Centril/rust/blob/85fbf49ce0e2274d0acf798f6e703747674feec3/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.rs) # Examples ```rust #[derive(PartialEq, Eq)] struct Finished {} #[derive(PartialEq, Eq)] struct Processing { status: ProcessStatus, } #[derive(PartialEq, Eq)] enum ProcessStatus { One, Two, Three, } #[derive(PartialEq, Eq)] enum Status { Finished(Finished), Processing(Processing), } fn check_result(_url: &str) -> Status { // fetch status from some server Status::Processing(Processing { status: ProcessStatus::One, }) } fn wait_for_result(url: &str) -> Finished { let mut previous_status = None; loop { match check_result(url) { Status::Finished(f) => return f, Status::Processing(p) => { match (&mut previous_status, p.status) { (None, status) => previous_status = Some(status), // first status (Some(previous), status) if *previous == status => {} // no change, ignore (Some(previous), status) => { // Now it can be used // new status *previous = status; } } } } } } ``` Before, we would have used: ```rust match (&previous_status, p.status) { (Some(previous), status) if *previous == status => {} // no change, ignore (_, status) => { // new status previous_status = Some(status); } } ``` Demonstrating *partial move* ```rust fn main() { #[derive(Debug)] struct Person { name: String, age: u8, } let person = Person { name: String::from("Alice"), age: 20, }; // `name` is moved out of person, but `age` is referenced let Person { name, ref age } = person; println!("The person's age is {}", age); println!("The person's name is {}", name); // Error! borrow of partially moved value: `person` partial move occurs //println!("The person struct is {:?}", person); // `person` cannot be used but `person.age` can be used as it is not moved println!("The person's age from person struct is {}", person.age); } ```
2020-10-01Add a regression test for issue-72565Yuki Okushi-0/+16
2020-10-01Add a regression test for issue-66501Yuki Okushi-0/+12
2020-09-26`char` not charvarkor-2/+2
2020-09-24Revert a test change to make sure it's still testing the original issueOliver Scherer-2/+2
2020-09-23Deduplicate errors in const to pat conversionOliver Scherer-8/+1
2020-09-20Use precise errors during const to pat conversion instead of a catch-all on ↵Oliver Scherer-4/+12
the main constant
2020-09-20Implement destructuring for all aggregates and for referencesOliver Scherer-61/+144
2020-09-15Stabilize move_ref_patternAmjad Alsharafi-364/+246
2020-09-09Rollup merge of #75984 - kornelski:typeormodule, r=matthewjasperTyler Mandry-3/+3
Improve unresolved use error message "use of undeclared type or module `foo`" doesn't mention that it could be a crate. This error can happen when users forget to add a dependency to `Cargo.toml`, so I think it's important to mention that it could be a missing crate. I've used a heuristic based on Rust's naming conventions. It complains about an unknown type if the ident starts with an upper-case letter, and crate or module otherwise. It seems to work very well. The expanded error help covers both an unknown type and a missing crate case.
2020-09-02pretty: trim paths of unique symbolsDan Aloni-132/+132
If a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path and print only the name. This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere. This adds a new '-Z trim-diagnostic-paths=false' option to control this feature. On the good path, with no diagnosis printed, we should try to avoid issuing this query, so we need to prevent trimmed_def_paths query on several cases. This change also relies on a previous commit that differentiates between `Debug` and `Display` on various rustc types, where the latter is trimmed and presented to the user and the former is not.
2020-09-01Clarify message about unresolved useKornel-3/+3
2020-08-30mv compiler to compiler/mark-1/+1
2020-08-02Auto merge of #74963 - JohnTitor:ptn-ice, r=petrochenkovbors-0/+95
Fix ICEs with `@ ..` binding This reverts #74557 and introduces an alternative fix while ensuring that #74954 is not broken. The diagnostics are verbose though, it fixes three related issues. cc #74954, #74539, and #74702
2020-07-31Rename HAIR to THIR (Typed HIR).Valentin Lazureanu-2/+2