Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark constant functions with const #1521

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/allocator/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ macro_rules! format_tables {
}
}

fn _impl_formats() -> &'static [$crate::backend::allocator::Fourcc] {
const fn _impl_formats() -> &'static [$crate::backend::allocator::Fourcc] {
&[
$(
$crate::backend::allocator::Fourcc::$fourcc,
Expand Down
6 changes: 3 additions & 3 deletions src/backend/drm/compositor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ pub mod gbm;
use elements::*;

impl RenderElementState {
pub(crate) fn zero_copy(visible_area: usize) -> Self {
pub(crate) const fn zero_copy(visible_area: usize) -> Self {
RenderElementState {
visible_area,
presentation_state: RenderElementPresentationState::ZeroCopy,
}
}

pub(crate) fn rendering_with_reason(reason: RenderingReason) -> Self {
pub(crate) const fn rendering_with_reason(reason: RenderingReason) -> Self {
RenderElementState {
visible_area: 0,
presentation_state: RenderElementPresentationState::Rendering { reason: Some(reason) },
Expand Down Expand Up @@ -4205,7 +4205,7 @@ fn apply_underlying_storage_transform(
}

#[inline]
fn apply_output_transform(transform: Transform, output_transform: Transform) -> Transform {
const fn apply_output_transform(transform: Transform, output_transform: Transform) -> Transform {
match (transform, output_transform) {
(Transform::Normal, output_transform) => output_transform,

Expand Down
2 changes: 1 addition & 1 deletion src/backend/drm/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl DrmDevice {
}

/// Claim a plane so that it won't be used by a different crtc
///
///
/// Returns `None` if the plane could not be claimed
pub fn claim_plane(&self, plane: plane::Handle, crtc: crtc::Handle) -> Option<PlaneClaim> {
self.plane_claim_storage.claim(plane, crtc)
Expand Down
6 changes: 3 additions & 3 deletions src/backend/drm/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ impl DrmNode {
}

/// Returns the type of the DRM node.
pub fn ty(&self) -> NodeType {
pub const fn ty(&self) -> NodeType {
self.ty
}

/// Returns the device_id of the underlying DRM node.
pub fn dev_id(&self) -> dev_t {
pub const fn dev_id(&self) -> dev_t {
self.dev
}

Expand Down Expand Up @@ -148,7 +148,7 @@ impl NodeType {
/// Returns a string representing the prefix of a minor device's name.
///
/// For example, on Linux with a primary node, the returned string would be `card`.
pub fn minor_name_prefix(&self) -> &str {
pub const fn minor_name_prefix(&self) -> &str {
match self {
NodeType::Primary => PRIMARY_NAME,
NodeType::Control => CONTROL_NAME,
Expand Down
8 changes: 4 additions & 4 deletions src/backend/drm/surface/gbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ where
}

/// Tries to mark a [`connector`](drm::control::connector)
/// for removal on the next commit.
/// for removal on the next commit.
pub fn remove_connector(&self, connector: connector::Handle) -> Result<(), Error<A::Error>> {
self.drm.remove_connector(connector).map_err(Error::DrmError)
}
Expand All @@ -470,19 +470,19 @@ where
/// Fails if one new `connector` is not compatible with the underlying [`crtc`](drm::control::crtc)
/// (e.g. no suitable [`encoder`](drm::control::encoder) may be found)
/// or is not compatible with the currently pending
/// [`Mode`](drm::control::Mode).
/// [`Mode`](drm::control::Mode).
pub fn set_connectors(&self, connectors: &[connector::Handle]) -> Result<(), Error<A::Error>> {
self.drm.set_connectors(connectors).map_err(Error::DrmError)
}

/// Returns the currently active [`Mode`](drm::control::Mode)
/// of the underlying [`crtc`](drm::control::crtc)
/// of the underlying [`crtc`](drm::control::crtc)
pub fn current_mode(&self) -> Mode {
self.drm.current_mode()
}

/// Returns the currently pending [`Mode`](drm::control::Mode)
/// to be used after the next commit.
/// to be used after the next commit.
pub fn pending_mode(&self) -> Mode {
self.drm.pending_mode()
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/drm/surface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl DrmSurface {
}

/// Claim a plane so that it won't be used by a different crtc
///
///
/// Returns `None` if the plane could not be claimed
pub fn claim_plane(&self, plane: plane::Handle) -> Option<PlaneClaim> {
// Validate that we are called with an plane that belongs to us
Expand Down
6 changes: 3 additions & 3 deletions src/backend/egl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ pub struct PixelFormatRequirements {

impl PixelFormatRequirements {
/// Format selection to get a 8-bit color format with alpha, depth and stencil bits
pub fn _8_bit() -> Self {
pub const fn _8_bit() -> Self {
PixelFormatRequirements {
hardware_accelerated: Some(true),
color_bits: Some(24),
Expand All @@ -558,7 +558,7 @@ impl PixelFormatRequirements {
}

/// Format selection to get a 10-bit color format with alpha, depth and stencil bits
pub fn _10_bit() -> Self {
pub const fn _10_bit() -> Self {
PixelFormatRequirements {
hardware_accelerated: Some(true),
color_bits: Some(30),
Expand All @@ -571,7 +571,7 @@ impl PixelFormatRequirements {
}

/// Format selection to get a 10-bit color format based on floating point values with alpha, depth and stencil bits
pub fn _10f_bit() -> Self {
pub const fn _10f_bit() -> Self {
PixelFormatRequirements {
hardware_accelerated: Some(true),
color_bits: Some(48),
Expand Down
2 changes: 1 addition & 1 deletion src/backend/egl/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub type NativeDisplayType = *const c_void;
pub type NativePixmapType = *const c_void;
pub type NativeWindowType = *const c_void;

fn error_str(error: egl::types::EGLenum) -> &'static str {
const fn error_str(error: egl::types::EGLenum) -> &'static str {
match error {
egl::SUCCESS => "SUCCESS",
egl::NOT_INITIALIZED => "NOT_INITIALIZED",
Expand Down
2 changes: 1 addition & 1 deletion src/backend/egl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub enum Format {
impl Format {
/// Amount of planes this format uses
#[inline]
pub fn num_planes(&self) -> usize {
pub const fn num_planes(&self) -> usize {
match *self {
Format::RGB | Format::RGBA | Format::External => 1,
Format::Y_UV | Format::Y_XUXV => 2,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ pub enum InputEvent<B: InputBackend> {
///
/// Taken from https://sources.debian.org/src/xserver-xorg-input-libinput/1.1.0-1/src/xf86libinput.c/?hl=1508#L236-L252
#[cfg(any(feature = "backend_winit", feature = "backend_x11"))]
pub(crate) fn xorg_mouse_to_libinput(xorg: u32) -> u32 {
pub(crate) const fn xorg_mouse_to_libinput(xorg: u32) -> u32 {
match xorg {
0 => 0,
1 => 0x110, // BTN_LEFT
Expand Down
10 changes: 5 additions & 5 deletions src/backend/renderer/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ impl Color32F {
impl Color32F {
/// Red color component
#[inline]
pub fn r(&self) -> f32 {
pub const fn r(&self) -> f32 {
self.0[0]
}

/// Green color component
#[inline]
pub fn g(&self) -> f32 {
pub const fn g(&self) -> f32 {
self.0[1]
}

/// Blue color component
#[inline]
pub fn b(&self) -> f32 {
pub const fn b(&self) -> f32 {
self.0[2]
}

/// Alpha color component
#[inline]
pub fn a(&self) -> f32 {
pub const fn a(&self) -> f32 {
self.0[3]
}

/// Color components
#[inline]
pub fn components(self) -> [f32; 4] {
pub const fn components(self) -> [f32; 4] {
self.0
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/renderer/damage/shaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ enum DamageSplitAxis {

impl DamageSplitAxis {
/// Invert the split direction.
fn invert(self) -> Self {
const fn invert(self) -> Self {
match self {
DamageSplitAxis::X => DamageSplitAxis::Y,
DamageSplitAxis::Y => DamageSplitAxis::X,
Expand Down
4 changes: 2 additions & 2 deletions src/backend/renderer/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub enum RenderElementPresentationState {
#[derive(Debug, Clone, Copy)]
pub struct RenderElementState {
/// Holds the physical visible area of the element on the output in pixels.
///
///
/// Note: If the presentation_state is [`RenderElementPresentationState::Skipped`] this will be zero.
pub visible_area: usize,
/// Holds the presentation state of the element on the output
Expand All @@ -154,7 +154,7 @@ impl RenderElementState {
}
}

pub(crate) fn rendered(visible_area: usize) -> Self {
pub(crate) const fn rendered(visible_area: usize) -> Self {
RenderElementState {
visible_area,
presentation_state: RenderElementPresentationState::Rendering { reason: None },
Expand Down
2 changes: 1 addition & 1 deletion src/backend/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub enum TextureFilter {
impl Transform {
/// A projection matrix to apply this transformation
#[inline]
pub fn matrix(&self) -> Matrix3<f32> {
pub const fn matrix(&self) -> Matrix3<f32> {
match self {
Transform::Normal => Matrix3::new(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0),
Transform::_90 => Matrix3::new(0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0),
Expand Down
2 changes: 1 addition & 1 deletion src/backend/winit/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ pub(crate) struct RelativePosition {
}

impl RelativePosition {
pub(crate) fn new(x: f64, y: f64) -> Self {
pub(crate) const fn new(x: f64, y: f64) -> Self {
Self { x, y }
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/backend/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,15 @@ pub struct WindowBuilder<'a> {
impl<'a> WindowBuilder<'a> {
#[allow(clippy::new_without_default)]
/// Returns a new builder.
pub fn new() -> WindowBuilder<'a> {
pub const fn new() -> WindowBuilder<'a> {
WindowBuilder {
name: None,
size: None,
}
}

/// Sets the title of the window that will be created by the builder.
pub fn title(self, name: &'a str) -> Self {
pub const fn title(self, name: &'a str) -> Self {
Self {
name: Some(name),
..self
Expand All @@ -454,7 +454,7 @@ impl<'a> WindowBuilder<'a> {
///
/// There is no guarantee the size specified here will be the actual size of the window when it is
/// presented.
pub fn size(self, size: Size<u16, Logical>) -> Self {
pub const fn size(self, size: Size<u16, Logical>) -> Self {
Self {
size: Some(size),
..self
Expand Down
2 changes: 1 addition & 1 deletion src/input/pointer/cursor_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct CursorImageAttributes {
pub hotspot: Point<i32, Logical>,
}

/// Data associated with XDG toplevel surface
/// Data associated with XDG toplevel surface
///
/// ```no_run
/// # #[cfg(feature = "wayland_frontend")]
Expand Down
8 changes: 4 additions & 4 deletions src/input/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ pub struct GestureHoldEndEvent {

impl AxisFrame {
/// Create a new frame of axis events
pub fn new(time: u32) -> Self {
pub const fn new(time: u32) -> Self {
AxisFrame {
source: None,
relative_direction: (AxisRelativeDirection::Identical, AxisRelativeDirection::Identical),
Expand All @@ -1081,13 +1081,13 @@ impl AxisFrame {
///
/// Using the [`AxisSource::Finger`] requires a stop event to be send,
/// when the user lifts off the finger (not necessarily in the same frame).
pub fn source(mut self, source: AxisSource) -> Self {
pub const fn source(mut self, source: AxisSource) -> Self {
self.source = Some(source);
self
}

/// Specify the direction of the physical motion, relative to axis direction
pub fn relative_direction(mut self, axis: Axis, relative_direction: AxisRelativeDirection) -> Self {
pub const fn relative_direction(mut self, axis: Axis, relative_direction: AxisRelativeDirection) -> Self {
match axis {
Axis::Horizontal => {
self.relative_direction.0 = relative_direction;
Expand Down Expand Up @@ -1135,7 +1135,7 @@ impl AxisFrame {
///
/// This event is required for sources of the [`AxisSource::Finger`] type
/// and otherwise optional.
pub fn stop(mut self, axis: Axis) -> Self {
pub const fn stop(mut self, axis: Axis) -> Self {
match axis {
Axis::Horizontal => {
self.stop.0 = true;
Expand Down
2 changes: 1 addition & 1 deletion src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl Scale {
}

/// Returns the fractional scale (calculated if necessary)
pub fn fractional_scale(&self) -> f64 {
pub const fn fractional_scale(&self) -> f64 {
match self {
Scale::Integer(scale) => *scale as f64,
Scale::Fractional(scale) => *scale,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct Clock<Kind: ClockSource> {
impl<Kind: ClockSource> Clock<Kind> {
/// Initialize a new clock
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
pub const fn new() -> Self {
Clock { _kind: PhantomData }
}

Expand All @@ -47,7 +47,7 @@ impl<Kind: ClockSource> Clock<Kind> {
}

/// Gets the id of the clock
pub fn id(&self) -> ClockId {
pub const fn id(&self) -> ClockId {
Kind::ID
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ pub struct Size<N, Kind> {
impl<N: Coordinate, Kind> Size<N, Kind> {
/// Convert this [`Size`] to a [`Point`] with the same coordinates
#[inline]
pub fn to_point(self) -> Point<N, Kind> {
pub const fn to_point(self) -> Point<N, Kind> {
Point {
x: self.w,
y: self.h,
Expand Down Expand Up @@ -1526,7 +1526,7 @@ impl Transform {
///
/// Flipping is preserved and 180/Normal transformation are uneffected.
#[inline]
pub fn invert(&self) -> Transform {
pub const fn invert(&self) -> Transform {
match self {
Transform::Normal => Transform::Normal,
Transform::Flipped => Transform::Flipped,
Expand Down Expand Up @@ -1601,7 +1601,7 @@ impl Transform {
}

/// Returns true if the transformation would flip contents
pub fn flipped(&self) -> bool {
pub const fn flipped(&self) -> bool {
!matches!(
self,
Transform::Normal | Transform::_90 | Transform::_180 | Transform::_270
Expand All @@ -1610,7 +1610,7 @@ impl Transform {

/// Returns the angle (in degrees) of the transformation
#[inline]
pub fn degrees(&self) -> u32 {
pub const fn degrees(&self) -> u32 {
match self {
Transform::Normal | Transform::Flipped => 0,
Transform::_90 | Transform::Flipped90 => 90,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sealed_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl SealedFile {
}

// Only used in KeymapFile which is under the wayland_frontend feature
pub fn size(&self) -> usize {
pub const fn size(&self) -> usize {
self.size
}
}
Expand Down
Loading