Skip to content

Commit

Permalink
Remove deprecated Error::description usage and definition
Browse files Browse the repository at this point in the history
Error descriptions are soft-deprecated
since 1.27.0, and hard-deprecated since
1.42.0.

See rust-lang/rust#66919
  • Loading branch information
est31 committed Mar 6, 2020
1 parent 8925a80 commit 9c5ee2b
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 240 deletions.
13 changes: 4 additions & 9 deletions src/backend/glutin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,14 @@ impl Display {

impl fmt::Display for DisplayCreationError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(fmt, "{}", self.description())
match self {
DisplayCreationError::GlutinCreationError(err) => write!(fmt, "{}", err),
DisplayCreationError::IncompatibleOpenGl(err) => write!(fmt, "{}", err),
}
}
}

impl Error for DisplayCreationError {
#[inline]
fn description(&self) -> &str {
match *self {
DisplayCreationError::GlutinCreationError(ref err) => err.description(),
DisplayCreationError::IncompatibleOpenGl(ref err) => err.description(),
}
}

#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
Expand Down
26 changes: 10 additions & 16 deletions src/buffer/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,17 @@ pub enum ReadError {

impl fmt::Display for ReadError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.description())
}
}

impl Error for ReadError {
fn description(&self) -> &str {
use self::ReadError::*;
match *self {
let desc = match *self {
NotSupported => "The backend doesn't support reading from a buffer",
ContextLost => "The context has been lost. Reading from the buffer would return garbage data",
}
};
fmt.write_str(desc)
}
}

impl Error for ReadError {}

/// Error that can happen when copying data between buffers.
#[derive(Debug, Copy, Clone)]
pub enum CopyError {
Expand All @@ -55,19 +52,16 @@ pub enum CopyError {

impl fmt::Display for CopyError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.description())
}
}

impl Error for CopyError {
fn description(&self) -> &str {
use self::CopyError::*;
match *self {
let desc = match *self {
NotSupported => "The backend doesn't support copying between buffers",
}
};
fmt.write_str(desc)
}
}

impl Error for CopyError {}

/// A buffer in the graphics card's memory.
pub struct Alloc {
context: Rc<Context>,
Expand Down
15 changes: 6 additions & 9 deletions src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,15 @@ pub enum BufferCreationError {

impl fmt::Display for BufferCreationError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.description())
let desc = match self {
BufferCreationError::OutOfMemory => "Not enough memory to create the buffer",
BufferCreationError::BufferTypeNotSupported => "This type of buffer is not supported",
};
fmt.write_str(desc)
}
}

impl Error for BufferCreationError {
fn description(&self) -> &str {
match self {
&BufferCreationError::OutOfMemory => "Not enough memory to create the buffer",
&BufferCreationError::BufferTypeNotSupported => "This type of buffer is not supported",
}
}
}
impl Error for BufferCreationError {}

/// How the buffer is created.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand Down
26 changes: 10 additions & 16 deletions src/draw_parameters/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,16 @@ pub enum QueryCreationError {

impl fmt::Display for QueryCreationError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.description())
}
}

impl Error for QueryCreationError {
fn description(&self) -> &str {
use self::QueryCreationError::*;
match *self {
let desc = match *self {
NotSupported => "The given query type is not supported",
}
};
fmt.write_str(desc)
}
}

impl Error for QueryCreationError {}

/// Error that can happen when writing the value of a query to a buffer.
#[derive(Copy, Clone, Debug)]
pub enum ToBufferError {
Expand All @@ -89,19 +86,16 @@ pub enum ToBufferError {

impl fmt::Display for ToBufferError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.description())
}
}

impl Error for ToBufferError {
fn description(&self) -> &str {
use self::ToBufferError::*;
match *self {
let desc = match *self {
NotSupported => "Writing the result to a buffer is not supported",
}
};
fmt.write_str(desc)
}
}

impl Error for ToBufferError {}

impl RawQuery {
/// Builds a new query. Returns `None` if the backend doesn't support this type.
pub fn new<F: ?Sized>(facade: &F, ty: QueryType) -> Result<RawQuery, QueryCreationError>
Expand Down
22 changes: 9 additions & 13 deletions src/fbo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,19 +603,7 @@ pub enum ValidationError {
impl fmt::Display for ValidationError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
use self::ValidationError::*;
match *self {
TooManyColorAttachments{ ref maximum, ref obtained } =>
write!(fmt, "{}: found {}, maximum: {}", self.description(), obtained, maximum),
_ =>
write!(fmt, "{}", self.description()),
}
}
}

impl Error for ValidationError {
fn description(&self) -> &str {
use self::ValidationError::*;
match *self {
let desc = match self {
EmptyFramebufferObjectsNotSupported =>
"You requested an empty framebuffer object, but they are not supported",
EmptyFramebufferUnsupportedDimensions =>
Expand All @@ -626,10 +614,18 @@ impl Error for ValidationError {
"All attachments must have the same number of samples",
TooManyColorAttachments {..} =>
"Backends only support a certain number of color attachments",
};
match self {
TooManyColorAttachments{ ref maximum, ref obtained } =>
write!(fmt, "{}: found {}, maximum: {}", desc, obtained, maximum),
_ =>
fmt.write_str(desc),
}
}
}

impl Error for ValidationError {}

/// Data structure stored in the hashmap.
///
/// These attachments are guaranteed to be valid.
Expand Down
13 changes: 5 additions & 8 deletions src/framebuffer/render_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ pub enum CreationError {

impl fmt::Display for CreationError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.description())
}
}

impl Error for CreationError {
fn description(&self) -> &str {
use self::CreationError::*;
match *self {
let desc = match *self {
FormatNotSupported => "The requested format is not supported",
}
};
fmt.write_str(desc)
}
}

impl Error for CreationError {}

impl From<image_format::FormatNotSupportedError> for CreationError {
fn from(_: image_format::FormatNotSupportedError) -> CreationError {
CreationError::FormatNotSupported
Expand Down
8 changes: 2 additions & 6 deletions src/image_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ pub struct FormatNotSupportedError;

impl fmt::Display for FormatNotSupportedError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.description())
write!(fmt, "Format is not supported by OpenGL")
}
}

impl Error for FormatNotSupportedError {
fn description(&self) -> &str {
"Format is not supported by OpenGL"
}
}
impl Error for FormatNotSupportedError {}

/// Texture format request.
#[derive(Copy, Clone, Debug)]
Expand Down
13 changes: 5 additions & 8 deletions src/index/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,20 @@ pub enum CreationError {

impl fmt::Display for CreationError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.description())
}
}

impl Error for CreationError {
fn description(&self) -> &str {
use self::CreationError::*;
match *self {
let desc = match *self {
IndexTypeNotSupported =>
"The type of index is not supported by the backend",
PrimitiveTypeNotSupported =>
"The type of primitives is not supported by the backend",
BufferCreationError(_) =>
"An error happened while creating the buffer",
}
};
fmt.write_str(desc)
}
}

impl Error for CreationError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
use self::CreationError::*;
match *self {
Expand Down
76 changes: 32 additions & 44 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,20 @@ pub enum DrawError {
}

impl Error for DrawError {
fn description(&self) -> &str {
fn source(&self) -> Option<&(dyn Error + 'static)> {
use self::DrawError::*;
match *self {
UniformBlockLayoutMismatch { ref err, .. } => Some(err),
_ => None,
}
}
}


impl fmt::Display for DrawError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use self::DrawError::*;
let desc = match self {
NoDepthBuffer =>
"A depth function has been requested but no depth buffer is available",
AttributeTypeMismatch =>
Expand Down Expand Up @@ -1013,55 +1024,40 @@ impl Error for DrawError {
"Restarting indices (multiple objects per draw call) is not supported by the backend",
ClipPlaneIndexOutOfBounds =>
"Tried to enable a clip plane that does not exist."
}
}

fn source(&self) -> Option<&(dyn Error + 'static)> {
use self::DrawError::*;
match *self {
UniformBlockLayoutMismatch { ref err, .. } => Some(err),
_ => None,
}
}
}


impl fmt::Display for DrawError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use self::DrawError::*;
match *self {
UniformTypeMismatch { ref name, ref expected } =>
};
match self {
UniformTypeMismatch { name, expected } =>
write!(
fmt,
"{}, got: {:?}, expected: {:?}",
self.description(),
desc,
name,
expected,
),
UniformBufferToValue { ref name } =>
UniformBufferToValue { name } =>
write!(
fmt,
"{}: {}",
self.description(),
desc,
name,
),
UniformValueToBlock { ref name } =>
UniformValueToBlock { name } =>
write!(
fmt,
"{}: {}",
self.description(),
desc,
name,
),
UniformBlockLayoutMismatch { ref name, ref err } =>
UniformBlockLayoutMismatch { name, err } =>
write!(
fmt,
"{}: {}, caused by {}",
self.description(),
desc,
name,
err,
),
_ =>
write!(fmt, "{}", self.description()),
fmt.write_str(desc),
}
}
}
Expand All @@ -1087,21 +1083,18 @@ pub enum SwapBuffersError {
AlreadySwapped,
}

impl Error for SwapBuffersError {
fn description(&self) -> &str {
impl Error for SwapBuffersError {}

impl fmt::Display for SwapBuffersError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use self::SwapBuffersError::*;
match *self {
let desc = match *self {
ContextLost =>
"the OpenGL context has been lost and needs to be recreated",
AlreadySwapped =>
"the buffers have already been swapped",
}
}
}

impl fmt::Display for SwapBuffersError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(fmt, "{}", self.description())
};
fmt.write_str(desc)
}
}

Expand Down Expand Up @@ -1256,16 +1249,11 @@ pub struct IncompatibleOpenGl(pub String);

impl fmt::Display for IncompatibleOpenGl {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.description())
fmt.write_str("The OpenGL implementation is too old to work with glium")
}
}

impl Error for IncompatibleOpenGl {
#[inline]
fn description(&self) -> &str {
"The OpenGL implementation is too old to work with glium"
}
}
impl Error for IncompatibleOpenGl {}

#[allow(dead_code)]
#[inline]
Expand Down
Loading

0 comments on commit 9c5ee2b

Please sign in to comment.