Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit f4effec

Browse files
Fix clippy lints
1 parent 47571cb commit f4effec

File tree

22 files changed

+36
-39
lines changed

22 files changed

+36
-39
lines changed

examples/cairo_threads/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn build_ui(application: &gtk::Application) {
8787
// Draw an arc with a weirdly calculated radius
8888
image.with_surface(|surface| {
8989
let cr = Context::new(surface).expect("Can't create a Cairo context");
90-
draw_slow(&cr, delay, x, y, 1.2_f64.powi(((n as i32) << thread_num) % 32));
90+
draw_slow(&cr, delay, x, y, 1.2_f64.powi((n << thread_num) % 32));
9191
surface.flush();
9292
});
9393

examples/communication_thread/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ fn start_communication_thread(mut sender: mpsc::Sender<String>) {
4949
loop {
5050
// Instead of a counter, your application code will
5151
// block here on TCP or serial communications.
52-
let data = format!("Counter = {}!", counter);
53-
println!("Thread received data: {}", data);
52+
let data = format!("Counter = {counter}!");
53+
println!("Thread received data: {data}");
5454
match sender.try_send(data) {
5555
Ok(_) => {}
5656
Err(err) => {

examples/dialog_async/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async fn dialog<W: IsA<gtk::Window>>(window: W) {
5050
.modal(true)
5151
.buttons(gtk::ButtonsType::Close)
5252
.text("You answered")
53-
.secondary_text(&format!("Your answer: {:?}", answer))
53+
.secondary_text(&format!("Your answer: {answer:?}"))
5454
.build();
5555

5656
info_dialog.run_future().await;

examples/gtk_builder_signal/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn build_ui(application: &gtk::Application) {
3030
}),
3131
)
3232
} else {
33-
panic!("Unknown handler name {}", handler_name)
33+
panic!("Unknown handler name {handler_name}")
3434
}
3535
});
3636

examples/gtk_test/main.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ fn build_ui(application: &gtk::Application) {
3434
let scale: Scale = builder.object("scale").expect("Couldn't get scale");
3535
scale.connect_format_value(|scale, value| {
3636
let digits = scale.digits() as usize;
37-
format!("<{:.*}>", digits, value)
37+
format!("<{value:.digits$}>")
3838
});
3939

4040
let spin_button: SpinButton = builder
4141
.object("spin_button")
4242
.expect("Couldn't get spin_button");
4343
spin_button.connect_input(|spin_button| {
4444
let text = spin_button.text();
45-
println!("spin_button_input: \"{}\"", text);
45+
println!("spin_button_input: \"{text}\"");
4646
match text.parse::<f64>() {
4747
Ok(value) if value >= 90. => {
4848
println!("circular right");
@@ -72,7 +72,7 @@ fn build_ui(application: &gtk::Application) {
7272
("Custom", ResponseType::Other(0))]);
7373

7474
dialog.connect_response(glib::clone!(@weak entry => move |dialog, response| {
75-
entry.set_text(&format!("Clicked {}", response));
75+
entry.set_text(&format!("Clicked {response}"));
7676
dialog.close();
7777
}));
7878
dialog.show_all();
@@ -119,7 +119,7 @@ fn build_ui(application: &gtk::Application) {
119119
dialog.connect_response(|dialog, response| {
120120
if response == ResponseType::Ok {
121121
let files = dialog.filenames();
122-
println!("Files: {:?}", files);
122+
println!("Files: {files:?}");
123123
}
124124
dialog.close();
125125
});
@@ -159,7 +159,7 @@ fn build_ui(application: &gtk::Application) {
159159
let keyval = key.keyval();
160160
let keystate = key.state();
161161

162-
println!("key pressed: {} / {:?}", keyval, keystate);
162+
println!("key pressed: {keyval} / {keystate:?}");
163163
println!("text: {}", entry.text());
164164

165165
if keystate.intersects(gdk::ModifierType::CONTROL_MASK) {

examples/icon_view/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn create_list_store_model() -> gtk::ListStore {
8484
);
8585
}
8686
Err(err) => {
87-
println!("Error: {}", err);
87+
println!("Error: {err}");
8888
process::exit(1);
8989
}
9090
}

examples/list_box_model/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn build_ui(application: &gtk::Application) {
178178
window.add(&vbox);
179179

180180
for i in 0..10 {
181-
model.append(&RowData::new(&format!("Name {}", i), i * 10));
181+
model.append(&RowData::new(&format!("Name {i}"), i * 10));
182182
}
183183

184184
window.show_all();

examples/multi_threading_context/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn build_ui(application: &gtk::Application) {
3535
// do long work
3636
thread::sleep(Duration::from_millis(50));
3737
// send result to channel
38-
tx.send(format!("#{} Text from another thread.", i))
38+
tx.send(format!("#{i} Text from another thread."))
3939
.expect("Couldn't send data to channel");
4040
// receiver will be run on the main thread
4141
}

examples/multi_window/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ fn create_sub_window(
104104
}),
105105
);
106106

107-
let button = gtk::Button::with_label(&format!("Notify main window with id {}!", id));
107+
let button = gtk::Button::with_label(&format!("Notify main window with id {id}!"));
108108
button.connect_clicked(glib::clone!(@weak main_window_entry => move |_| {
109109
// When the button is clicked, let's write it on the main window's entry!
110-
main_window_entry.buffer().set_text(&format!("sub window {} clicked", id));
110+
main_window_entry.buffer().set_text(&format!("sub window {id} clicked"));
111111
}));
112112
window.add(&button);
113113

examples/notebook/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn build_ui(application: &gtk::Application) {
2525
let mut notebook = Notebook::new();
2626

2727
for i in 1..4 {
28-
let title = format!("sheet {}", i);
28+
let title = format!("sheet {i}");
2929
let label = gtk::Label::new(Some(&*title));
3030
notebook.create_tab(&title, label.upcast());
3131
}

examples/text_viewer/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn build_ui(application: &gtk::Application) {
3232
file_chooser.connect_response(glib::clone!(@weak text_view => move |file_chooser, response| {
3333
if response == gtk::ResponseType::Ok {
3434
let filename = file_chooser.filename().expect("Couldn't get filename");
35-
let file = File::open(&filename).expect("Couldn't open file");
35+
let file = File::open(filename).expect("Couldn't open file");
3636

3737
let mut reader = BufReader::new(file);
3838
let mut contents = String::new();

examples/tree_view/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn build_ui(application: &gtk::Application) {
3333
// insert_with_values takes a slice of tuples: column index and ToValue
3434
// trait objects. ToValue is implemented for strings, numeric types,
3535
// bool and Object descendants
36-
let iter = left_store.insert_with_values(None, None, &[(0, &format!("Hello {}", i))]);
36+
let iter = left_store.insert_with_values(None, None, &[(0, &format!("Hello {i}"))]);
3737

3838
for _ in 0..i {
3939
left_store.insert_with_values(Some(&iter), None, &[(0, &"I'm a child node")]);

gdk/src/display.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<O: IsA<Display>> DisplayExtManual for O {
6464
"GdkQuartzDisplay" => Backend::MacOS,
6565
"GdkWin32Display" => Backend::Win32,
6666
"GdkBroadwayDisplay" => Backend::Broadway,
67-
e => panic!("Unsupported display backend {}", e),
67+
e => panic!("Unsupported display backend {e}"),
6868
}
6969
}
7070
}

gdk/src/event.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl Event {
256256
self.to_glib_none().0,
257257
state.as_mut_ptr(),
258258
)) {
259-
Some(from_glib(state.assume_init() as u32))
259+
Some(from_glib(state.assume_init() as _))
260260
} else {
261261
None
262262
}

gdk/sys/build.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {} // prevent linking libraries to avoid documentation failure
1111
#[cfg(not(feature = "dox"))]
1212
fn main() {
1313
if let Err(s) = system_deps::Config::new().probe() {
14-
let _ = writeln!(io::stderr(), "{}", s);
14+
let _ = writeln!(io::stderr(), "{s}");
1515
process::exit(1);
1616
}
1717

@@ -34,9 +34,9 @@ fn check_features() {
3434
// For reference, the backend set at time of writing consists of:
3535
// x11 win32 quartz broadway wayland
3636
if let Ok(targets) = pkg_config::get_variable(PKG_CONFIG_PACKAGE, "targets") {
37-
println!("cargo:backends={}", targets);
37+
println!("cargo:backends={targets}");
3838
for target in targets.split_whitespace() {
39-
println!("cargo:rustc-cfg=gdk_backend=\"{}\"", target);
39+
println!("cargo:rustc-cfg=gdk_backend=\"{target}\"");
4040
}
4141
}
4242
}

gdk/tests/check_gir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
#[test]
44
fn check_gir_file() {
55
let res = gir_format_check::check_gir_file("Gir.toml");
6-
println!("{}", res);
6+
println!("{res}");
77
assert_eq!(res.nb_errors, 0);
88
}

gtk/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn check_features() {
1111
// x11 win32 quartz broadway wayland
1212
if let Ok(targets) = pkg_config::get_variable("gtk+-3.0", "targets") {
1313
for target in targets.split_whitespace() {
14-
println!("cargo:rustc-cfg=gdk_backend=\"{}\"", target);
14+
println!("cargo:rustc-cfg=gdk_backend=\"{target}\"");
1515
}
1616
}
1717
}

gtk/src/builder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<O: IsA<Builder>> BuilderExtManual for O {
105105
}
106106

107107
fn add_from_string(&self, buffer: &str) -> Result<(), glib::Error> {
108-
let length = buffer.len() as usize;
108+
let length = buffer.len();
109109
unsafe {
110110
let mut error = ptr::null_mut();
111111
let exit_code = ffi::gtk_builder_add_from_string(
@@ -150,7 +150,7 @@ impl<O: IsA<Builder>> BuilderExtManual for O {
150150
buffer: &str,
151151
object_ids: &[&str],
152152
) -> Result<(), glib::Error> {
153-
let length = buffer.len() as usize;
153+
let length = buffer.len();
154154
unsafe {
155155
let mut error = ptr::null_mut();
156156
let exit_code = ffi::gtk_builder_add_objects_from_string(
@@ -222,7 +222,7 @@ impl<O: IsA<Builder>> BuilderExtManual for O {
222222
template_type: glib::types::Type,
223223
buffer: &str,
224224
) -> Result<(), glib::Error> {
225-
let length = buffer.len() as usize;
225+
let length = buffer.len();
226226
unsafe {
227227
let mut error = ptr::null_mut();
228228
let exit_code = ffi::gtk_builder_extend_with_template(

gtk/src/container.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ impl<O: IsA<Container>> ContainerExtManual for O {
3434
property_name.to_glib_none().0,
3535
));
3636
let pspec = pspec.unwrap_or_else(|| {
37-
panic!("The Container property '{}' doesn't exists", property_name)
37+
panic!("The Container property '{property_name}' doesn't exists")
3838
});
3939

4040
if !pspec.flags().contains(glib::ParamFlags::READABLE)
4141
|| !pspec.flags().contains(glib::ParamFlags::READWRITE)
4242
{
43-
panic!("The Container property '{}' is not readable", property_name);
43+
panic!("The Container property '{property_name}' is not readable");
4444
}
4545

4646
let mut value = glib::Value::from_type(pspec.value_type());
@@ -79,16 +79,13 @@ impl<O: IsA<Container>> ContainerExtManual for O {
7979
property_name.to_glib_none().0,
8080
));
8181
let pspec = pspec.unwrap_or_else(|| {
82-
panic!("The Container property '{}' doesn't exists", property_name)
82+
panic!("The Container property '{property_name}' doesn't exists")
8383
});
8484

8585
if !pspec.flags().contains(glib::ParamFlags::WRITABLE)
8686
|| !pspec.flags().contains(glib::ParamFlags::READWRITE)
8787
{
88-
panic!(
89-
"The Container property '{}' is not writeable",
90-
property_name
91-
);
88+
panic!("The Container property '{property_name}' is not writeable");
9289
}
9390

9491
assert!(

gtk/src/enums.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl IconSize {
1414
impl From<IconSize> for i32 {
1515
fn from(val: IconSize) -> i32 {
1616
skip_assert_initialized!();
17-
val.into_glib() as i32
17+
val.into_glib() as _
1818
}
1919
}
2020

@@ -28,7 +28,7 @@ impl From<i32> for IconSize {
2828
impl From<ResponseType> for i32 {
2929
fn from(val: ResponseType) -> i32 {
3030
skip_assert_initialized!();
31-
val.into_glib() as i32
31+
val.into_glib() as _
3232
}
3333
}
3434

gtk/tests/check_gir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
#[test]
44
fn check_gir_file() {
55
let res = gir_format_check::check_gir_file("Gir.toml");
6-
println!("{}", res);
6+
println!("{res}");
77
assert_eq!(res.nb_errors, 0);
88
}

gtk3-macros/src/attribute_parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn parse_field_attr_meta(
144144
let ident_str = ident.to_string();
145145
let unknown_err = Err(Error::new(
146146
ident.span(),
147-
&format!("unknown attribute argument: `{}`", ident_str),
147+
format!("unknown attribute argument: `{ident_str}`"),
148148
));
149149
let value = match ty {
150150
FieldAttributeType::TemplateChild => match ident_str.as_str() {

0 commit comments

Comments
 (0)