commit d354d9afe923eb08f7ee89128b38ddb6415de01d
Author: Knut Petersen <Knut_Petersen@t-online.de>
Date: Sat Jan 7 10:22:04 2006 +0100
[PATCH] fbcon: don<B4>t call set_par() in fbcon_init() if vc_mode == KD_GRAPHICS
Nothing prevents a user to modprobe a framebuffer driver from e.g. the
xterm prompt. As a result, the set_par() function of the driver will be
called from fbcon_init().
This is fatal as a lot of X / framebuffer combinations are unable to
recover from set_par() reprogramming the graphics controller in
KD_GRAPHICS mode.
It is also unnecessary as the set_par() function will be called during a
switch to KD_TEXT anyway. Because of this no side effects are possible.
Signed-off-by: Knut Petersen <Knut_Petersen@t-online.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Commit log messages are typically encoded in UTF-8, but other extended ASCII encodings are also supported. This includes ISO-8859-x, CP125x and many others, but not UTF-16/32, EBCDIC and CJK multi-byte encodings (GBK, Shift-JIS, Big5, EUC-x, CP9xx etc.).
fn main() {
let a = 3;
let b = 5;
println!("(a, b) = ({a:?}, {b:?})");
core::mem::swap(&mut a, &mut b);
println!("(a, b) = ({a:?}, {b:?})");
}
こたえ
$ cargo --quiet run --example q1
error[E0596]: cannot borrow `a` as mutable, as it is not declared as mutable
--> examples/q1.rs:5:21
|
5 | core::mem::swap(&mut a, &mut b);
| ^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
2 | let mut a = 3;
| +++
error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable
--> examples/q1.rs:5:29
|
5 | core::mem::swap(&mut a, &mut b);
| ^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
3 | let mut b = 5;
| +++
For more information about this error, try `rustc --explain E0596`.
error: could not compile `pinquiz` (example "q1") due to 2 previous errors
fn main() {
let mut a = 3;
let mut b = 5;
println!("(a, b) @ ({0:p}, {1:p}) = ({0:?}, {1:?})", &mut a, &mut b);
core::mem::swap(&mut a, &mut b);
println!("(a, b) @ ({0:p}, {1:p}) = ({0:?}, {1:?})", &mut a, &mut b);
}
こたえ
$ cargo --quiet run --example q3
(a, b) @ (0x7ffc101d53d0, 0x7ffc101d53d4) = (3, 5)
(a, b) @ (0x7ffc101d53d0, 0x7ffc101d53d4) = (5, 3)
fn main() {
let mut a = 3;
let mut b = 5;
let a = &mut a;
let b = &mut b;
println!("(a, b) @ ({0:p}, {1:p}) = ({0:?}, {1:?})", a, b);
core::mem::swap(a, b);
println!("(a, b) @ ({0:p}, {1:p}) = ({0:?}, {1:?})", a, b);
}
こたえ
$ cargo --quiet run --example q4
(a, b) @ (0x7ffee3f429c0, 0x7ffee3f429c4) = (3, 5)
(a, b) @ (0x7ffee3f429c0, 0x7ffee3f429c4) = (5, 3)
fn main() {
let mut a = 3;
let mut b = 5;
let a = &mut a;
let b = &mut b;
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap(a, b);
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
}
こたえ
$ cargo --quiet run --example q5
(a, b) @ (0x7ffc887a82b0, 0x7ffc887a82b4) = (3, 5)
(a, b) @ (0x7ffc887a82b0, 0x7ffc887a82b4) = (5, 3)
use std::any::type_name_of_val;
fn main() {
let mut a = 3u8;
let mut b = 5u8;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = &mut a;
let b = &mut b;
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap(a, b);
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
}
こたえ
$ cargo --quiet run --example q6
a: u8
b: u8
(a, b) @ (0x7ffe385b3086, 0x7ffe385b3087) = (3, 5)
(a, b) @ (0x7ffe385b3086, 0x7ffe385b3087) = (5, 3)
use std::any::type_name_of_val;
use std::pin::Pin;
fn main() {
let mut a = 3u8;
let mut b = 5u8;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = &mut a;
let b = &mut b;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = Pin::new(a);
let b = Pin::new(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap(a, b);
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
こたえ
$ cargo --quiet run --example q8
error[E0308]: arguments to this function are incorrect
--> examples/q8.rs:18:5
|
18 | core::mem::swap(a, b);
| ^^^^^^^^^^^^^^^
|
note: expected `&mut _`, found `Pin<&mut u8>`
--> examples/q8.rs:18:21
|
18 | core::mem::swap(a, b);
| ^
= note: expected mutable reference `&mut _`
found struct `Pin<&mut u8>`
note: expected `&mut _`, found `Pin<&mut u8>`
--> examples/q8.rs:18:24
|
18 | core::mem::swap(a, b);
| ^
= note: expected mutable reference `&mut _`
found struct `Pin<&mut u8>`
note: function defined here
--> /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/core/src/mem/mod.rs:732:14
help: consider mutably borrowing here
|
18 | core::mem::swap(&mut a, b);
| ++++
help: consider mutably borrowing here
|
18 | core::mem::swap(a, &mut b);
| ++++
For more information about this error, try `rustc --explain E0308`.
error: could not compile `pinquiz` (example "q8") due to 1 previous error
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::pin::Pin;
fn main() {
let mut a = 3u8;
let mut b = 5u8;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = &mut a;
let b = &mut b;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = Pin::new(a);
let b = Pin::new(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
こたえ
$ cargo --quiet run --example q9
error[E0596]: cannot borrow `a` as mutable, as it is not declared as mutable
--> examples/q9.rs:19:21
|
19 | core::mem::swap(a.borrow_mut(), b.borrow_mut());
| ^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
14 | let mut a = Pin::new(a);
| +++
error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable
--> examples/q9.rs:19:37
|
19 | core::mem::swap(a.borrow_mut(), b.borrow_mut());
| ^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
15 | let mut b = Pin::new(b);
| +++
For more information about this error, try `rustc --explain E0596`.
error: could not compile `pinquiz` (example "q9") due to 2 previous errors
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::pin::Pin;
fn main() {
let mut a = 3u8;
let mut b = 5u8;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = &mut a;
let b = &mut b;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = Pin::new(a);
let mut b = Pin::new(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::pin::Pin;
fn main() {
let mut a = 3u8;
let mut b = 5u8;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = &mut a;
let b = &mut b;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = Pin::new(a);
let mut b = Pin::new(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<u8>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::pin::Pin;
fn main() {
let mut a = 3u8;
let mut b = 5u8;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = &mut a;
let b = &mut b;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = Pin::new(a);
let mut b = Pin::new(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<Pin<&mut u8>>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::pin::Pin;
fn main() {
let mut a = (3u8, ());
let mut b = (5u8, ());
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = &mut a;
let b = &mut b;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = Pin::new(a);
let mut b = Pin::new(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<(u8, ())>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::pin::Pin;
fn main() {
let mut a = (3u8, Default::default());
let mut b = (5u8, Default::default());
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = &mut a;
let b = &mut b;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = Pin::new(a);
let mut b = Pin::new(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<(u8, ())>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
ここは小休止、Default::default()っていう便利なやつの紹介です。これは、Defaultトレイトのdefaultメソッドを呼び出すという意味になるので、書いた場所の型がDefaultを実装していたら、めでたくデフォルトの値を入れてくれるという便利な子です。ジェネリクスとかと相性がいいですよ。
unit typeの()のデフォルト値は()ですから(いいですか、前者が型の()で、後者が値の()です…よく見てください(大丈夫、同じ文字列です))
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::pin::Pin;
fn main() {
type T = (u8, ());
let mut a = (3u8, Default::default());
let mut b = (5u8, Default::default());
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = &mut a;
let b = &mut b;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = Pin::new(a);
let mut b = Pin::new(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::marker::PhantomPinned;
use std::pin::Pin;
fn main() {
type T = (u8, PhantomPinned);
let mut a = (3u8, Default::default());
let mut b = (5u8, Default::default());
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = &mut a;
let b = &mut b;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = Pin::new(a);
let mut b = Pin::new(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
こたえ
$ cargo --quiet run --example q16
error[E0277]: `PhantomPinned` cannot be unpinned
--> examples/q16.rs:16:26
|
16 | let mut a = Pin::new(a);
| -------- ^ within `(u8, PhantomPinned)`, the trait `Unpin` is not implemented for `PhantomPinned`
| |
| required by a bound introduced by this call
|
= note: consider using the `pin!` macro
consider using `Box::pin` if you need to access the pinned value outside of the current scope
= note: required because it appears within the type `(u8, PhantomPinned)`
note: required by a bound in `Pin::<Ptr>::new`
--> /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/core/src/pin.rs:1191:5
error[E0277]: `PhantomPinned` cannot be unpinned
--> examples/q16.rs:17:26
|
17 | let mut b = Pin::new(b);
| -------- ^ within `(u8, PhantomPinned)`, the trait `Unpin` is not implemented for `PhantomPinned`
| |
| required by a bound introduced by this call
|
= note: consider using the `pin!` macro
consider using `Box::pin` if you need to access the pinned value outside of the current scope
= note: required because it appears within the type `(u8, PhantomPinned)`
note: required by a bound in `Pin::<Ptr>::new`
--> /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/core/src/pin.rs:1191:5
For more information about this error, try `rustc --explain E0277`.
error: could not compile `pinquiz` (example "q16") due to 2 previous errors
impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
...
pub const fn new(pointer: Ptr) -> Pin<Ptr> {
// SAFETY: the value pointed to is `Unpin`, and so has no requirements
// around pinning.
unsafe { Pin::new_unchecked(pointer) }
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::marker::PhantomPinned;
use std::pin::pin;
fn main() {
type T = (u8, PhantomPinned);
let mut a = (3u8, Default::default());
let mut b = (5u8, Default::default());
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = &mut a;
let b = &mut b;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = pin!(a);
let mut b = pin!(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::marker::PhantomPinned;
use std::pin::pin;
fn main() {
type T = (u8, PhantomPinned);
let a = (3u8, Default::default());
let b = (5u8, Default::default());
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = pin!(a);
let mut b = pin!(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
こたえ
$ cargo --quiet run --example q18
error[E0596]: cannot borrow data in dereference of `Pin<&mut (u8, PhantomPinned)>` as mutable
--> examples/q18.rs:17:26
|
17 | core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
| ^^^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<&mut (u8, PhantomPinned)>`
error[E0596]: cannot borrow data in dereference of `Pin<&mut (u8, PhantomPinned)>` as mutable
--> examples/q18.rs:17:42
|
17 | core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
| ^^^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<&mut (u8, PhantomPinned)>`
For more information about this error, try `rustc --explain E0596`.
error: could not compile `pinquiz` (example "q18") due to 2 previous errors
use std::any::type_name_of_val;
use std::marker::PhantomPinned;
use std::pin::pin;
fn main() {
type T = (u8, PhantomPinned);
let a: T = (3u8, Default::default());
let b: T = (5u8, Default::default());
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let a = pin!(a);
let b = pin!(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
//core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::marker::PhantomPinned;
use std::pin::pin;
fn main() {
type T = (u8, PhantomPinned);
let a: T = (3u8, Default::default());
let b: T = (5u8, Default::default());
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = pin!(a);
let mut b = pin!(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
こたえ
$ cargo --quiet run --example q20
error[E0596]: cannot borrow data in dereference of `Pin<&mut (u8, PhantomPinned)>` as mutable
--> examples/q20.rs:17:26
|
17 | core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
| ^^^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<&mut (u8, PhantomPinned)>`
error[E0596]: cannot borrow data in dereference of `Pin<&mut (u8, PhantomPinned)>` as mutable
--> examples/q20.rs:17:42
|
17 | core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
| ^^^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<&mut (u8, PhantomPinned)>`
For more information about this error, try `rustc --explain E0596`.
error: could not compile `pinquiz` (example "q20") due to 2 previous errors
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::pin::pin;
fn main() {
type T = (u8, ());
let a: T = (3u8, Default::default());
let b: T = (5u8, Default::default());
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = pin!(a);
let mut b = pin!(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::pin::pin;
fn main() {
type T = u8;
let a: T = 3u8;
let b: T = 5u8;
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = pin!(a);
let mut b = pin!(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::pin::pin;
fn main() {
type T = Box<u8>;
let a: T = Box::new(3u8);
let b: T = Box::new(5u8);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = pin!(a);
let mut b = pin!(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::marker::PhantomPinned;
use std::pin::pin;
fn main() {
type T = Box<(u8, PhantomPinned)>;
let a: T = Box::new((3u8, Default::default()));
let b: T = Box::new((5u8, Default::default()));
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
let mut a = pin!(a);
let mut b = pin!(b);
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::marker::PhantomPinned;
use std::pin::Pin;
fn main() {
type T = (u8, PhantomPinned);
let mut a: Pin<Box<T>> = Box::pin((3u8, Default::default()));
let mut b: Pin<Box<T>> = Box::pin((5u8, Default::default()));
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
こたえ
$ cargo --quiet run --example q25
error[E0596]: cannot borrow data in dereference of `Pin<Box<(u8, PhantomPinned)>>` as mutable
--> examples/q25.rs:13:26
|
13 | core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
| ^^^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<(u8, PhantomPinned)>>`
error[E0596]: cannot borrow data in dereference of `Pin<Box<(u8, PhantomPinned)>>` as mutable
--> examples/q25.rs:13:42
|
13 | core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
| ^^^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<(u8, PhantomPinned)>>`
For more information about this error, try `rustc --explain E0596`.
error: could not compile `pinquiz` (example "q25") due to 2 previous errors
use std::any::type_name_of_val;
use std::borrow::BorrowMut;
use std::marker::PhantomPinned;
use std::ops::Drop;
use std::pin::Pin;
#[derive(Debug)]
#[allow(unused)]
struct Wrapper(u8, PhantomPinned);
impl Drop for Wrapper {
fn drop(&mut self) {
println!("dropped: {self:?} @ {self:p}")
}
}
fn main() {
type T = Wrapper;
let mut a: Pin<Box<T>> = Box::pin(Wrapper(3u8, Default::default()));
let mut b: Pin<Box<T>> = Box::pin(Wrapper(5u8, Default::default()));
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
println!("(a, b) @ ({a:p}, {b:p}) = ({a:?}, {b:?})");
println!("a: {}", type_name_of_val(&a));
println!("b: {}", type_name_of_val(&b));
}
こたえ
$ cargo --quiet run --example q29
error[E0596]: cannot borrow data in dereference of `Pin<Box<Wrapper>>` as mutable
--> examples/q29.rs:23:26
|
23 | core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
| ^^^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<Wrapper>>`
error[E0596]: cannot borrow data in dereference of `Pin<Box<Wrapper>>` as mutable
--> examples/q29.rs:23:42
|
23 | core::mem::swap::<T>(a.borrow_mut(), b.borrow_mut());
| ^^^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<Wrapper>>`
For more information about this error, try `rustc --explain E0596`.
error: could not compile `pinquiz` (example "q29") due to 2 previous errors
"Don't forget why you got into this business in the first place: Science is fun. Minimize the noise that causes anxiety"
> 13. Don't forget why you got into this business in the first place: Science is fun. Minimize the noise that causes anxiety. これがめっちゃ突き刺さっている(ScienceをComputersに置き換えると私にダイレクトに刺さる) https://t.co/LdsCEG608h
/// This function prints the addr of itself for debug purpose.
#[no_mangle]
pub fn print_kernel_debug_metadata() {
// Note: This log message is used by the e2etest and dbgutil
// so please do not edit if you are unsure!
info!(
"DEBUG_METADATA: print_kernel_debug_metadata = {:#018p}",
print_kernel_debug_metadata as *const ()
);
}
この関数はOS起動時の比較的初期に呼ばれ、シリアルポートに関数の実際のアドレスが出力されます。
make runを実行した際には、QEMUのシリアルポート出力をファイルに保存するよう、QEMUの引数で指定しているので、あとはそこからいい感じにこの数値を切り出してあげれば、
PEファイル中に書かれているアドレスと、実際のメモリ上のアドレスの差が判明します。
The domain "invalid." and any names falling within ".invalid." are special in the ways listed below.
Users MAY assume that queries for "invalid" names will always return NXDOMAIN responses.
Name resolution APIs and libraries SHOULD recognize "invalid" names as special and SHOULD always return immediate negative responses.
WasabiではEnd-to-end test (e2etest) にも力を入れていて、e2etestディレクトリ配下にコードが格納されています。
make run_e2e_testと実行すれば、QEMUを画面無しで起動して、ネットワーク周りの機能やキー入力、アプリのロードと実行が正しく動作しているかを、ユーザーと同様の外部入出力レベルでテストすることができます。実装コストや実行時間はかかりますが、これが通れば一通りの機能は動く、という安心感をもって作業を進められるのは、とても心強かったです!
> The deterioration of Google's culture will eventually become irreversible, because the kinds of people whom you need to act as moral compass are the same kinds of people who don't join an organisation without a moral compass.https://t.co/5RqrbP018i