警告:`auto-ref`(bin'auto-ref; quot;)生成1个警告

发布于 2025-02-12 19:29:15 字数 1101 浏览 0 评论 0原文

在运行以下代码时,我会从Rust Compiler那里获得此WARNIG:

fn main() {
    let test = 3;
    let bar = Bar(test);
    (&bar).foo();
}

#[derive(Debug, Copy, Clone)]
struct Bar(i32);

impl Bar {

    fn foo(self) -> () {

        println!("{:?}", self);
    }

}

我想在fn Method_name(self)上尝试自动ref规则。

我在Termux上运行货物1.61。

谁能向我解释什么是实际警告或如何显示它?

编辑: 这是术语控制台输出

~/auto-ref/src $ cargo run
warning: Hard linking files in the incremental compilation cache failed. Copying files instead. Consider moving the cache directory to a file system which supports hard linking in session dir `/data/data/com.termux/files/home/auto-ref/target/debug/incremental/auto_ref-2c1jpkoha1tv/s-gbbxgywkr4-kv6r95-working`

warning: `auto-ref` (bin "auto-ref") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 1.11s
     Running `/data/data/com.termux/files/home/auto-ref/target/debug/auto-ref`                            Bar(3)
~/auto-ref/src $

I get this warnig from the rust compiler, when running the following code:

fn main() {
    let test = 3;
    let bar = Bar(test);
    (&bar).foo();
}

#[derive(Debug, Copy, Clone)]
struct Bar(i32);

impl Bar {

    fn foo(self) -> () {

        println!("{:?}", self);
    }

}

I wanted to try out the auto-ref rule on fn method_name(self).

I run cargo 1.61 on termux.

Can anyone explain to me what the actual warning is or how I can get it to be displayed?

EDIT:
Here's the termux console output

~/auto-ref/src $ cargo run
warning: Hard linking files in the incremental compilation cache failed. Copying files instead. Consider moving the cache directory to a file system which supports hard linking in session dir `/data/data/com.termux/files/home/auto-ref/target/debug/incremental/auto_ref-2c1jpkoha1tv/s-gbbxgywkr4-kv6r95-working`

warning: `auto-ref` (bin "auto-ref") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 1.11s
     Running `/data/data/com.termux/files/home/auto-ref/target/debug/auto-ref`                            Bar(3)
~/auto-ref/src $

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你在我安 2025-02-19 19:29:15

好,我现在明白了。我认为警告只是警告摘要。我很困惑,因为我试图测试一条规则,该规则说A&自我方法参数可以在使用类型自我时自动引用。警告提到了自动REF-因此我的困惑
- 但我认为实际上是关于链接警告。

我尝试的是以下内容;

使用自动参考规则,以便您做

bar.foo()

而不是

(&bar).foo()


另外,示例代码甚至没有这样做。这将是正确的示例。

fn main() {
    let test = 3;
    let bar = Bar(test);
    bar.foo();
}

#[derive(Debug, Copy, Clone)]
struct Bar(i32);

impl Bar {

    fn foo(&self) -> () {

        println!("{:?}", self);
    }

}

Ok, I understand now. What I thought was a warning was just the warnings summary. I got confused because I tried to test a rule that says that a &self method argument can automatically be referenced when using it on type self. The warning mentions auto-ref -- hence my confusion
-- but I think is actually about the linking warning.

What I tried was the following;

use the aut ref rule such that you do

bar.foo()

instead of

(&bar).foo()

.
Also the example code doesn't even do this. Here would be the correct example.

fn main() {
    let test = 3;
    let bar = Bar(test);
    bar.foo();
}

#[derive(Debug, Copy, Clone)]
struct Bar(i32);

impl Bar {

    fn foo(&self) -> () {

        println!("{:?}", self);
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文