Skip to content

Correct overly broad definition of 'static kind bound. - #13113

Merged
bors merged 1 commit into
rust-lang:masterfrom
pnkfelix:correct-static-kind-doc
Mar 24, 2014
Merged

Correct overly broad definition of 'static kind bound.#13113
bors merged 1 commit into
rust-lang:masterfrom
pnkfelix:correct-static-kind-doc

Conversation

@pnkfelix

Copy link
Copy Markdown
Contributor

While double-checking my understanding of the meaning of 'static, I made the following test program:

fnfoo<X:'static>(_x:X){}#[cfg(not(acceptable))]fnbar(){let a = 3;let b = &a;foo(b);}#[cfg(acceptable)]fnbar(){static c :int = 4;;let d :&'staticint = &c;foo(d);}fnmain(){bar();}

Transcript of compiling above program, illustrating that the --cfg acceptable variant of bar compiles successfully, showing that the'static kind bound only disallows non-static references, not all references:

% rustc --version
/Users/fklock/opt/rust-dbg/bin/rustc 0.10-pre (caf17fe 2014-03-21 02:21:50 -0700)
host: x86_64-apple-darwin
% rustc /tmp/s.rs
/tmp/s.rs:7:5: 7:8 error: instantiating a type parameter with an incompatible type `&int`, which does not fulfill `'static`
/tmp/s.rs:7 foo(b);
^~~
error: aborting due to previous error
% rustc --cfg acceptable /tmp/s.rs
% ./s
%

(Note that the explicit type annotation on let d : &'static int is necessary; it did not suffice for me to just write let d = &'static c;. That might be a latent bug, I am not sure yet.)

Anyway, a fix to the documentation seemed prudent.

While double-checking my understanding of the meaning of `'static`,
I made the following test program:
```rust
fn foo<X:'static>(_x: X) { }
#[cfg(not(acceptable))]
fn bar() {
let a = 3;
let b = &a;
foo(b);
}
#[cfg(acceptable)]
fn bar() {
static c : int = 4;;
let d : &'static int = &c;
foo(d);
}
fn main() {
bar();
}
```
Transcript of compiling above program, illustrating that the `--cfg
acceptable` variant of `bar` compiles successfully, showing that the
`'static` kind bound only disallows non-`static` references, not *all*
references:
```
% rustc --version
/Users/fklock/opt/rust-dbg/bin/rustc 0.10-pre (caf17fe 2014-03-21 02:21:50 -0700)
host: x86_64-apple-darwin
% rustc /tmp/s.rs
/tmp/s.rs:7:5: 7:8 error: instantiating a type parameter with an incompatible type `&int`, which does not fulfill `'static`
/tmp/s.rs:7 foo(b);
^~~
error: aborting due to previous error
% rustc --cfg acceptable /tmp/s.rs
% ./s
%
```
(Note that the explicit type annotation on `let d : &'static int` is
necessary; it did not suffice for me to just write `let d = &'static
c;`. That might be a latent bug, I am not sure yet.)
Anyway, a fix to the documentation seemed prudent.
@flaper87

Copy link
Copy Markdown
Contributor

LGTM

@pnkfelix

Copy link
Copy Markdown
ContributorAuthor

(See also #7268, which has related discussion regarding whether &'static T should imply T: 'static.)

bors added a commit that referenced this pull request Mar 24, 2014
While double-checking my understanding of the meaning of `'static`, I made the following test program:
```rust
fn foo<X:'static>(_x: X) { }
#[cfg(not(acceptable))]
fn bar() {
let a = 3;
let b = &a;
foo(b);
}
#[cfg(acceptable)]
fn bar() {
static c : int = 4;;
let d : &'static int = &c;
foo(d);
}
fn main() {
bar();
}
```
Transcript of compiling above program, illustrating that the `--cfg acceptable` variant of `bar` compiles successfully, showing that the`'static` kind bound only disallows non-`static` references, not *all* references:
```
% rustc --version
/Users/fklock/opt/rust-dbg/bin/rustc 0.10-pre (caf17fe 2014-03-21 02:21:50 -0700)
host: x86_64-apple-darwin
% rustc /tmp/s.rs
/tmp/s.rs:7:5: 7:8 error: instantiating a type parameter with an incompatible type `&int`, which does not fulfill `'static`
/tmp/s.rs:7 foo(b);
^~~
error: aborting due to previous error
% rustc --cfg acceptable /tmp/s.rs
% ./s
%
```
(Note that the explicit type annotation on `let d : &'static int` is necessary; it did not suffice for me to just write `let d = &'static c;`. That might be a latent bug, I am not sure yet.)
Anyway, a fix to the documentation seemed prudent.
@borsbors closed this Mar 24, 2014
@bors
bors merged commit 57ac379 into rust-lang:masterMar 24, 2014
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 5, 2024
…blyxyas
Ignore underscore-prefixed args for needless_pass_by_value lint
When a user explicitly tags a param as unused (yet?), there is no need to raise another lint on it.
fixesrust-lang#7295
Note that I had to rename all `_*` params in the tests, but kept the variable name length to avoid extra changes in the expected output.
changelog: [`needless_pass_by_value`]: do not warn if the argument name starts with an `_`
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pnkfelix@flaper87@huonw@bors