comparison rust/hg-cpython/src/exceptions.rs @ 42609:326fdce22fb2

rust: switch hg-core and hg-cpython to rust 2018 edition Many interesting changes have happened in Rust since the Oxidation Plan was introduced, like the 2018 edition and procedural macros: - Opting in to the 2018 edition is a clear benefit in terms of future proofing, new (nice to have) syntactical sugar notwithstanding. It also has a new non-lexical, non-AST based borrow checker that has fewer bugs(!) and allows us to write correct code that in some cases would have been rejected by the old one. - Procedural macros allow us to use the PyO3 crate which maintainers have expressed the clear goal of compiling on stable, which would help in code maintainability compared to rust-cpython. In this patch are the following changes: - Removing most `extern crate` uses - Updating `use` clauses (`crate` keyword, nested `use`) - Removing `mod.rs` in favor of an aptly named module file Like discussed in the mailing list ( https://www.mercurial-scm.org/pipermail/mercurial-devel/2019-July/132316.html ), until Rust integration in Mercurial is considered to be out of the experimental phase, the maximum version of Rust allowed is whatever the latest version Debian packages. Differential Revision: https://phab.mercurial-scm.org/D6597
author Rapha?l Gom?s <rgomes@octobus.net>
date Tue, 02 Jul 2019 17:15:03 +0200
parents d26e4a434fe5
children 30320c7bf79f
comparison
equal deleted inserted replaced
42608:717686c5e461 42609:326fdce22fb2
10 //! [`GraphError`] exposes `hg::GraphError` as a subclass of `ValueError` 10 //! [`GraphError`] exposes `hg::GraphError` as a subclass of `ValueError`
11 //! but some variants of `hg::GraphError` can be converted directly to other 11 //! but some variants of `hg::GraphError` can be converted directly to other
12 //! existing Python exceptions if appropriate. 12 //! existing Python exceptions if appropriate.
13 //! 13 //!
14 //! [`GraphError`]: struct.GraphError.html 14 //! [`GraphError`]: struct.GraphError.html
15 use cpython::exc::{RuntimeError, ValueError}; 15 use cpython::{
16 use cpython::{exc, PyErr, Python}; 16 exc::{IOError, RuntimeError, ValueError},
17 py_exception, PyErr, Python,
18 };
17 use hg; 19 use hg;
18 20
19 py_exception!(rustext, GraphError, ValueError); 21 py_exception!(rustext, GraphError, ValueError);
20 22
21 impl GraphError { 23 impl GraphError {
53 impl PatternFileError { 55 impl PatternFileError {
54 pub fn pynew(py: Python, inner: hg::PatternFileError) -> PyErr { 56 pub fn pynew(py: Python, inner: hg::PatternFileError) -> PyErr {
55 match inner { 57 match inner {
56 hg::PatternFileError::IO(e) => { 58 hg::PatternFileError::IO(e) => {
57 let value = (e.raw_os_error().unwrap_or(2), e.to_string()); 59 let value = (e.raw_os_error().unwrap_or(2), e.to_string());
58 PyErr::new::<exc::IOError, _>(py, value) 60 PyErr::new::<IOError, _>(py, value)
59 } 61 }
60 hg::PatternFileError::Pattern(e, l) => match e { 62 hg::PatternFileError::Pattern(e, l) => match e {
61 hg::PatternError::UnsupportedSyntax(m) => { 63 hg::PatternError::UnsupportedSyntax(m) => {
62 PatternFileError::new(py, ("PatternFileError", m, l)) 64 PatternFileError::new(py, ("PatternFileError", m, l))
63 } 65 }