Skip to content

Commit 613efe8

Browse files
Merge pull request #336 from Havvy/warning-css
Warning css
2 parents 0f63519 + a84b5aa commit 613efe8

File tree

5 files changed

+80
-24
lines changed

5 files changed

+80
-24
lines changed

src/expressions/method-call-expr.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,17 @@ generic methods or traits are considered the same, then it is a compiler
8181
error. These cases require a [disambiguating function call syntax] for method
8282
and function invocation.
8383
84-
> Warning: For [trait objects], if there is an inherent method of the same name
85-
> as a trait method, it will give a compiler error when trying to call the
86-
> method in a method call expression. Instead, you can call the method using
87-
> [disambiguating function call syntax], in which case it calls the trait
88-
> method, not the inherent method. There is no way to call the inherent method.
89-
> Just don't define inherent methods on trait objects with the same name a trait
90-
> method and you'll be fine.
84+
<div class="warning">
85+
86+
***Warning:*** For [trait objects], if there is an inherent method of the same
87+
name as a trait method, it will give a compiler error when trying to call the
88+
method in a method call expression. Instead, you can call the method using
89+
[disambiguating function call syntax], in which case it calls the trait
90+
method, not the inherent method. There is no way to call the inherent method.
91+
Just don't define inherent methods on trait objects with the same name a trait
92+
method and you'll be fine.
93+
94+
</div>
9195
9296
[IDENTIFIER]: identifiers.html
9397
[visible]: visibility-and-privacy.html

src/theme/reference.css

+44
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,47 @@ the parenthetical. So for this example, you'd use
7777
.parenthetical {
7878
white-space: nowrap;
7979
}
80+
81+
/*
82+
Warnings and notes:
83+
84+
Write the <div>s on their own line. E.g.
85+
86+
<div class="warning">
87+
88+
Warning: This is bad!
89+
90+
</div>
91+
*/
92+
main .warning p {
93+
padding: 10px 20px;
94+
margin: 20px 0;
95+
}
96+
97+
main .warning p::before {
98+
content: "⚠️ ";
99+
}
100+
101+
.light main .warning p,
102+
.rust main .warning p {
103+
border: 2px solid red;
104+
background: #ffcece;
105+
}
106+
107+
.rust main .warning p {
108+
/* overrides previous declaration */
109+
border-color: #961717;
110+
}
111+
112+
.coal main .warning p,
113+
.navy main .warning p,
114+
.ayu main .warning p {
115+
background: #542626
116+
}
117+
118+
/* Make the links higher contrast on dark themes */
119+
.coal main .warning p a,
120+
.navy main .warning p a,
121+
.ayu main .warning p a {
122+
color: #80d0d0
123+
}

src/trait-bounds.md

-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ fn call_on_ref_zero<F>(f: F) where F: for<'a> Fn(&'a i32) {
134134
}
135135
```
136136

137-
> Warning: lifetime bounds are allowed on lifetimes in a `for` binder, but have
138-
> no effect: `for<'a, 'b: 'a>` is no different to `for<'a, 'b>`.
139-
140137
[LIFETIME_OR_LABEL]: tokens.html#lifetimes-and-loop-labels
141138
[_TraitPath_]: paths.html
142139
[`Sized`]: special-types-and-traits.html#sized

src/type-layout.md

+18-10
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,17 @@ the default `enum` size and alignment for the target platform's C ABI.
233233
> really a "best guess". In particular, this may be incorrect when the C code
234234
> of interest is compiled with certain flags.
235235
236-
> Warning: There are crucial differences between an `enum` in the C language and
237-
> Rust's C-like enumerations with this representation. An `enum` in C is
238-
> mostly a `typedef` plus some named constants; in other words, an object of an
239-
> `enum` type can hold any integer value. For example, this is often used for
240-
> bitflags in `C`. In contrast, Rust’s C-like enumerations can only legally hold
241-
> the discriminant values, everything else is undefined behaviour. Therefore,
242-
> using a C-like enumeration in FFI to model a C `enum` is often wrong.
236+
<div class="warning">
237+
238+
Warning: There are crucial differences between an `enum` in the C language and
239+
Rust's C-like enumerations with this representation. An `enum` in C is
240+
mostly a `typedef` plus some named constants; in other words, an object of an
241+
`enum` type can hold any integer value. For example, this is often used for
242+
bitflags in `C`. In contrast, Rust’s C-like enumerations can only legally hold
243+
the discriminant values, everything else is undefined behaviour. Therefore,
244+
using a C-like enumeration in FFI to model a C `enum` is often wrong.
245+
246+
</div>
243247

244248
It is an error for [zero-variant enumerations] to have the `C` representation.
245249

@@ -290,9 +294,13 @@ padding bytes and forcing the alignment of the type to `1`.
290294
The `align` and `packed` representations cannot be applied on the same type and
291295
a `packed` type cannot transitively contain another `align`ed type.
292296

293-
> Warning: Dereferencing an unaligned pointer is [undefined behaviour] and it is
294-
> possible to [safely create unaligned pointers to `packed` fields][27060].
295-
> Like all ways to create undefined behavior in safe Rust, this is a bug.
297+
<div class="warning">
298+
299+
***Warning:*** Dereferencing an unaligned pointer is [undefined behaviour] and
300+
it is possible to [safely create unaligned pointers to `packed` fields][27060].
301+
Like all ways to create undefined behavior in safe Rust, this is a bug.
302+
303+
</div>
296304

297305
[`align_of_val`]: ../std/mem/fn.align_of_val.html
298306
[`size_of_val`]: ../std/mem/fn.size_of_val.html

src/types.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,13 @@ if the sets of auto traits are the same and the lifetime bounds are the same.
580580
For example, `dyn Trait + Send + UnwindSafe` is the same as
581581
`dyn Trait + Unwindsafe + Send`.
582582

583-
> Warning: With two trait object types, even when the complete set of traits is
584-
> the same, if the base traits differ, the type is different. For example,
585-
> `dyn Send + Sync` is a different type from `dyn Sync + Send`. See
586-
> [issue 33140].
583+
<div class="warning">
584+
585+
***Warning:*** With two trait object types, even when the complete set of traits
586+
is the same, if the base traits differ, the type is different. For example,
587+
`dyn Send + Sync` is a different type from `dyn Sync + Send`. See [issue 33140].
588+
589+
</div>
587590

588591
Due to the opaqueness of which concrete type the value is of, trait objects are
589592
[dynamically sized types]. Like all

0 commit comments

Comments
 (0)