-
-
Notifications
You must be signed in to change notification settings - Fork 17.5k
thread_local! doc improvements + tests for operational pedantics
#163387
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @RalfJung since you mentioned having tests for this. Admittedly, I kind of struggled to come up with anything for this that might be even remotely sensible (and these aren't that), but, please feel free to comment whether this is satisfactory.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's fair, I wasn't sure either. It just felt like something we should test for. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| use std::borrow::Cow; | ||
|
|
||
| fn main() { | ||
| let x = ""; | ||
| std::thread_local!(static A: &str = x); | ||
| //~^ ERROR attempt to use a non-constant value in a constant [E0435] | ||
| } | ||
|
|
||
| fn test<'a>(x: &'a str) { | ||
| std::thread_local!(static A: Cow<'a, str> = Cow::Borrowed("")); | ||
| //~^ ERROR can't use generic parameters from outer item [E0401] | ||
| //~| ERROR can't use generic parameters from outer item [E0401] | ||
| //~| ERROR can't use generic parameters from outer item [E0401] | ||
| //~| ERROR can't use generic parameters from outer item [E0401] | ||
| //~| ERROR can't use generic parameters from outer item [E0401] | ||
|
|
||
| // wow, aren't macros great? | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| error[E0435]: attempt to use a non-constant value in a constant | ||
| --> $DIR/non-static-lifetimes.rs:5:41 | ||
| | | ||
| LL | std::thread_local!(static A: &str = x); | ||
| | - ^ | ||
| | | | ||
| | this would need to be a `let` | ||
|
|
||
| error[E0401]: can't use generic parameters from outer item | ||
| --> $DIR/non-static-lifetimes.rs:10:38 | ||
| | | ||
| LL | fn test<'a>(x: &'a str) { | ||
| | -- lifetime parameter from outer item | ||
| LL | std::thread_local!(static A: Cow<'a, str> = Cow::Borrowed("")); | ||
| | ^^ use of generic parameter from outer item | ||
|
|
||
| error[E0401]: can't use generic parameters from outer item | ||
| --> $DIR/non-static-lifetimes.rs:10:38 | ||
| | | ||
| LL | fn test<'a>(x: &'a str) { | ||
| | -- lifetime parameter from outer item | ||
| LL | std::thread_local!(static A: Cow<'a, str> = Cow::Borrowed("")); | ||
| | ---------------------------------^^--------------------------- | ||
| | | | | ||
| | | use of generic parameter from outer item | ||
| | lifetime `'a` is missing in item created through this procedural macro | ||
|
|
||
| error[E0401]: can't use generic parameters from outer item | ||
| --> $DIR/non-static-lifetimes.rs:10:38 | ||
| | | ||
| LL | fn test<'a>(x: &'a str) { | ||
| | -- lifetime parameter from outer item | ||
| LL | std::thread_local!(static A: Cow<'a, str> = Cow::Borrowed("")); | ||
| | ^^ use of generic parameter from outer item | ||
| | | ||
| = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
|
||
| error[E0401]: can't use generic parameters from outer item | ||
| --> $DIR/non-static-lifetimes.rs:10:38 | ||
| | | ||
| LL | fn test<'a>(x: &'a str) { | ||
| | -- lifetime parameter from outer item | ||
| LL | std::thread_local!(static A: Cow<'a, str> = Cow::Borrowed("")); | ||
| | ^^ use of generic parameter from outer item | ||
| | | ||
| = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
|
||
| error[E0401]: can't use generic parameters from outer item | ||
| --> $DIR/non-static-lifetimes.rs:10:38 | ||
| | | ||
| LL | fn test<'a>(x: &'a str) { | ||
| | -- lifetime parameter from outer item | ||
| LL | std::thread_local!(static A: Cow<'a, str> = Cow::Borrowed("")); | ||
| | ^^ use of generic parameter from outer item | ||
| | | ||
| = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
|
||
| error: aborting due to 6 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0401, E0435. | ||
| For more information about an error, try `rustc --explain E0401`. |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
View changes since the review