Skip to content

Commit 9c5ee2b

Browse files
committed
Remove deprecated Error::description usage and definition
Error descriptions are soft-deprecated since 1.27.0, and hard-deprecated since 1.42.0. See rust-lang/rust#66919
1 parent 8925a80 commit 9c5ee2b

File tree

17 files changed

+156
-240
lines changed

17 files changed

+156
-240
lines changed

src/backend/glutin/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,14 @@ impl Display {
188188

189189
impl fmt::Display for DisplayCreationError {
190190
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
191-
write!(fmt, "{}", self.description())
191+
match self {
192+
DisplayCreationError::GlutinCreationError(err) => write!(fmt, "{}", err),
193+
DisplayCreationError::IncompatibleOpenGl(err) => write!(fmt, "{}", err),
194+
}
192195
}
193196
}
194197

195198
impl Error for DisplayCreationError {
196-
#[inline]
197-
fn description(&self) -> &str {
198-
match *self {
199-
DisplayCreationError::GlutinCreationError(ref err) => err.description(),
200-
DisplayCreationError::IncompatibleOpenGl(ref err) => err.description(),
201-
}
202-
}
203-
204199
#[inline]
205200
fn source(&self) -> Option<&(dyn Error + 'static)> {
206201
match *self {

src/buffer/alloc.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,17 @@ pub enum ReadError {
3232

3333
impl fmt::Display for ReadError {
3434
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
35-
write!(fmt, "{}", self.description())
36-
}
37-
}
38-
39-
impl Error for ReadError {
40-
fn description(&self) -> &str {
4135
use self::ReadError::*;
42-
match *self {
36+
let desc = match *self {
4337
NotSupported => "The backend doesn't support reading from a buffer",
4438
ContextLost => "The context has been lost. Reading from the buffer would return garbage data",
45-
}
39+
};
40+
fmt.write_str(desc)
4641
}
4742
}
4843

44+
impl Error for ReadError {}
45+
4946
/// Error that can happen when copying data between buffers.
5047
#[derive(Debug, Copy, Clone)]
5148
pub enum CopyError {
@@ -55,19 +52,16 @@ pub enum CopyError {
5552

5653
impl fmt::Display for CopyError {
5754
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
58-
write!(fmt, "{}", self.description())
59-
}
60-
}
61-
62-
impl Error for CopyError {
63-
fn description(&self) -> &str {
6455
use self::CopyError::*;
65-
match *self {
56+
let desc = match *self {
6657
NotSupported => "The backend doesn't support copying between buffers",
67-
}
58+
};
59+
fmt.write_str(desc)
6860
}
6961
}
7062

63+
impl Error for CopyError {}
64+
7165
/// A buffer in the graphics card's memory.
7266
pub struct Alloc {
7367
context: Rc<Context>,

src/buffer/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,15 @@ pub enum BufferCreationError {
192192

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

199-
impl Error for BufferCreationError {
200-
fn description(&self) -> &str {
201-
match self {
202-
&BufferCreationError::OutOfMemory => "Not enough memory to create the buffer",
203-
&BufferCreationError::BufferTypeNotSupported => "This type of buffer is not supported",
204-
}
205-
}
206-
}
203+
impl Error for BufferCreationError {}
207204

208205
/// How the buffer is created.
209206
#[derive(Debug, Copy, Clone, PartialEq, Eq)]

src/draw_parameters/query.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,16 @@ pub enum QueryCreationError {
6767

6868
impl fmt::Display for QueryCreationError {
6969
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
70-
write!(fmt, "{}", self.description())
71-
}
72-
}
73-
74-
impl Error for QueryCreationError {
75-
fn description(&self) -> &str {
7670
use self::QueryCreationError::*;
77-
match *self {
71+
let desc = match *self {
7872
NotSupported => "The given query type is not supported",
79-
}
73+
};
74+
fmt.write_str(desc)
8075
}
8176
}
8277

78+
impl Error for QueryCreationError {}
79+
8380
/// Error that can happen when writing the value of a query to a buffer.
8481
#[derive(Copy, Clone, Debug)]
8582
pub enum ToBufferError {
@@ -89,19 +86,16 @@ pub enum ToBufferError {
8986

9087
impl fmt::Display for ToBufferError {
9188
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
92-
write!(fmt, "{}", self.description())
93-
}
94-
}
95-
96-
impl Error for ToBufferError {
97-
fn description(&self) -> &str {
9889
use self::ToBufferError::*;
99-
match *self {
90+
let desc = match *self {
10091
NotSupported => "Writing the result to a buffer is not supported",
101-
}
92+
};
93+
fmt.write_str(desc)
10294
}
10395
}
10496

97+
impl Error for ToBufferError {}
98+
10599
impl RawQuery {
106100
/// Builds a new query. Returns `None` if the backend doesn't support this type.
107101
pub fn new<F: ?Sized>(facade: &F, ty: QueryType) -> Result<RawQuery, QueryCreationError>

src/fbo.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -603,19 +603,7 @@ pub enum ValidationError {
603603
impl fmt::Display for ValidationError {
604604
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
605605
use self::ValidationError::*;
606-
match *self {
607-
TooManyColorAttachments{ ref maximum, ref obtained } =>
608-
write!(fmt, "{}: found {}, maximum: {}", self.description(), obtained, maximum),
609-
_ =>
610-
write!(fmt, "{}", self.description()),
611-
}
612-
}
613-
}
614-
615-
impl Error for ValidationError {
616-
fn description(&self) -> &str {
617-
use self::ValidationError::*;
618-
match *self {
606+
let desc = match self {
619607
EmptyFramebufferObjectsNotSupported =>
620608
"You requested an empty framebuffer object, but they are not supported",
621609
EmptyFramebufferUnsupportedDimensions =>
@@ -626,10 +614,18 @@ impl Error for ValidationError {
626614
"All attachments must have the same number of samples",
627615
TooManyColorAttachments {..} =>
628616
"Backends only support a certain number of color attachments",
617+
};
618+
match self {
619+
TooManyColorAttachments{ ref maximum, ref obtained } =>
620+
write!(fmt, "{}: found {}, maximum: {}", desc, obtained, maximum),
621+
_ =>
622+
fmt.write_str(desc),
629623
}
630624
}
631625
}
632626

627+
impl Error for ValidationError {}
628+
633629
/// Data structure stored in the hashmap.
634630
///
635631
/// These attachments are guaranteed to be valid.

src/framebuffer/render_buffer.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,16 @@ pub enum CreationError {
3838

3939
impl fmt::Display for CreationError {
4040
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
41-
write!(fmt, "{}", self.description())
42-
}
43-
}
44-
45-
impl Error for CreationError {
46-
fn description(&self) -> &str {
4741
use self::CreationError::*;
48-
match *self {
42+
let desc = match *self {
4943
FormatNotSupported => "The requested format is not supported",
50-
}
44+
};
45+
fmt.write_str(desc)
5146
}
5247
}
5348

49+
impl Error for CreationError {}
50+
5451
impl From<image_format::FormatNotSupportedError> for CreationError {
5552
fn from(_: image_format::FormatNotSupportedError) -> CreationError {
5653
CreationError::FormatNotSupported

src/image_format.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ pub struct FormatNotSupportedError;
1818

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

25-
impl Error for FormatNotSupportedError {
26-
fn description(&self) -> &str {
27-
"Format is not supported by OpenGL"
28-
}
29-
}
25+
impl Error for FormatNotSupportedError {}
3026

3127
/// Texture format request.
3228
#[derive(Copy, Clone, Debug)]

src/index/buffer.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,20 @@ pub enum CreationError {
3030

3131
impl fmt::Display for CreationError {
3232
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
33-
write!(fmt, "{}", self.description())
34-
}
35-
}
36-
37-
impl Error for CreationError {
38-
fn description(&self) -> &str {
3933
use self::CreationError::*;
40-
match *self {
34+
let desc = match *self {
4135
IndexTypeNotSupported =>
4236
"The type of index is not supported by the backend",
4337
PrimitiveTypeNotSupported =>
4438
"The type of primitives is not supported by the backend",
4539
BufferCreationError(_) =>
4640
"An error happened while creating the buffer",
47-
}
41+
};
42+
fmt.write_str(desc)
4843
}
44+
}
4945

46+
impl Error for CreationError {
5047
fn source(&self) -> Option<&(dyn Error + 'static)> {
5148
use self::CreationError::*;
5249
match *self {

src/lib.rs

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -956,9 +956,20 @@ pub enum DrawError {
956956
}
957957

958958
impl Error for DrawError {
959-
fn description(&self) -> &str {
959+
fn source(&self) -> Option<&(dyn Error + 'static)> {
960960
use self::DrawError::*;
961961
match *self {
962+
UniformBlockLayoutMismatch { ref err, .. } => Some(err),
963+
_ => None,
964+
}
965+
}
966+
}
967+
968+
969+
impl fmt::Display for DrawError {
970+
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
971+
use self::DrawError::*;
972+
let desc = match self {
962973
NoDepthBuffer =>
963974
"A depth function has been requested but no depth buffer is available",
964975
AttributeTypeMismatch =>
@@ -1013,55 +1024,40 @@ impl Error for DrawError {
10131024
"Restarting indices (multiple objects per draw call) is not supported by the backend",
10141025
ClipPlaneIndexOutOfBounds =>
10151026
"Tried to enable a clip plane that does not exist."
1016-
}
1017-
}
1018-
1019-
fn source(&self) -> Option<&(dyn Error + 'static)> {
1020-
use self::DrawError::*;
1021-
match *self {
1022-
UniformBlockLayoutMismatch { ref err, .. } => Some(err),
1023-
_ => None,
1024-
}
1025-
}
1026-
}
1027-
1028-
1029-
impl fmt::Display for DrawError {
1030-
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
1031-
use self::DrawError::*;
1032-
match *self {
1033-
UniformTypeMismatch { ref name, ref expected } =>
1027+
};
1028+
match self {
1029+
UniformTypeMismatch { name, expected } =>
10341030
write!(
10351031
fmt,
10361032
"{}, got: {:?}, expected: {:?}",
1037-
self.description(),
1033+
desc,
10381034
name,
10391035
expected,
10401036
),
1041-
UniformBufferToValue { ref name } =>
1037+
UniformBufferToValue { name } =>
10421038
write!(
10431039
fmt,
10441040
"{}: {}",
1045-
self.description(),
1041+
desc,
10461042
name,
10471043
),
1048-
UniformValueToBlock { ref name } =>
1044+
UniformValueToBlock { name } =>
10491045
write!(
10501046
fmt,
10511047
"{}: {}",
1052-
self.description(),
1048+
desc,
10531049
name,
10541050
),
1055-
UniformBlockLayoutMismatch { ref name, ref err } =>
1051+
UniformBlockLayoutMismatch { name, err } =>
10561052
write!(
10571053
fmt,
10581054
"{}: {}, caused by {}",
1059-
self.description(),
1055+
desc,
10601056
name,
10611057
err,
10621058
),
10631059
_ =>
1064-
write!(fmt, "{}", self.description()),
1060+
fmt.write_str(desc),
10651061
}
10661062
}
10671063
}
@@ -1087,21 +1083,18 @@ pub enum SwapBuffersError {
10871083
AlreadySwapped,
10881084
}
10891085

1090-
impl Error for SwapBuffersError {
1091-
fn description(&self) -> &str {
1086+
impl Error for SwapBuffersError {}
1087+
1088+
impl fmt::Display for SwapBuffersError {
1089+
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
10921090
use self::SwapBuffersError::*;
1093-
match *self {
1091+
let desc = match *self {
10941092
ContextLost =>
10951093
"the OpenGL context has been lost and needs to be recreated",
10961094
AlreadySwapped =>
10971095
"the buffers have already been swapped",
1098-
}
1099-
}
1100-
}
1101-
1102-
impl fmt::Display for SwapBuffersError {
1103-
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
1104-
write!(fmt, "{}", self.description())
1096+
};
1097+
fmt.write_str(desc)
11051098
}
11061099
}
11071100

@@ -1256,16 +1249,11 @@ pub struct IncompatibleOpenGl(pub String);
12561249

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

1263-
impl Error for IncompatibleOpenGl {
1264-
#[inline]
1265-
fn description(&self) -> &str {
1266-
"The OpenGL implementation is too old to work with glium"
1267-
}
1268-
}
1256+
impl Error for IncompatibleOpenGl {}
12691257

12701258
#[allow(dead_code)]
12711259
#[inline]

0 commit comments

Comments
 (0)