Skip to content

Commit adc24d1

Browse files
Fix compiler docs
1 parent 3416fa1 commit adc24d1

File tree

10 files changed

+32
-16
lines changed

10 files changed

+32
-16
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,12 @@ pub(super) fn check_opaque_for_cycles<'tcx>(
707707
/// check those cases in the `param_env` of that function, which may have
708708
/// bounds not on this opaque type:
709709
///
710-
/// type X<T> = impl Clone
710+
/// ```ignore (illustrative)
711+
/// type X<T> = impl Clone;
711712
/// fn f<T: Clone>(t: T) -> X<T> {
712713
/// t
713714
/// }
715+
/// ```
714716
///
715717
/// Without this check the above code is incorrectly accepted: we would ICE if
716718
/// some tried, for example, to clone an `Option<X<&mut ()>>`.

compiler/rustc_hir_analysis/src/constrained_generic_params.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ pub fn identify_constrained_generic_params<'tcx>(
114114
/// ```
115115
/// The impl's predicates are collected from left to right. Ignoring
116116
/// the implicit `Sized` bounds, these are
117-
/// * T: Debug
118-
/// * U: Iterator
119-
/// * <U as Iterator>::Item = T -- a desugared ProjectionPredicate
117+
/// * `T: Debug`
118+
/// * `U: Iterator`
119+
/// * `<U as Iterator>::Item = T` -- a desugared ProjectionPredicate
120120
///
121121
/// When we, for example, try to go over the trait-reference
122122
/// `IntoIter<u32> as Trait`, we substitute the impl parameters with fresh
@@ -132,12 +132,16 @@ pub fn identify_constrained_generic_params<'tcx>(
132132
///
133133
/// We *do* have to be somewhat careful when projection targets contain
134134
/// projections themselves, for example in
135+
///
136+
/// ```ignore (illustrative)
135137
/// impl<S,U,V,W> Trait for U where
136138
/// /* 0 */ S: Iterator<Item = U>,
137139
/// /* - */ U: Iterator,
138140
/// /* 1 */ <U as Iterator>::Item: ToOwned<Owned=(W,<V as Iterator>::Item)>
139141
/// /* 2 */ W: Iterator<Item = V>
140142
/// /* 3 */ V: Debug
143+
/// ```
144+
///
141145
/// we have to evaluate the projections in the order I wrote them:
142146
/// `V: Debug` requires `V` to be evaluated. The only projection that
143147
/// *determines* `V` is 2 (1 contains it, but *does not determine it*,

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+8
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ fn check_always_applicable(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId, impl2_node
130130
///
131131
/// Example
132132
///
133+
/// ```ignore (illustrative)
133134
/// impl<A, B> Foo<A> for B { /* impl2 */ }
134135
/// impl<C> Foo<Vec<C>> for C { /* impl1 */ }
136+
/// ```
135137
///
136138
/// Would return `S1 = [C]` and `S2 = [Vec<C>, C]`.
137139
fn get_impl_substs<'tcx>(
@@ -225,13 +227,17 @@ fn unconstrained_parent_impl_substs<'tcx>(
225227
///
226228
/// For example forbid the following:
227229
///
230+
/// ```ignore (illustrative)
228231
/// impl<A> Tr for A { }
229232
/// impl<B> Tr for (B, B) { }
233+
/// ```
230234
///
231235
/// Note that only consider the unconstrained parameters of the base impl:
232236
///
237+
/// ```ignore (illustrative)
233238
/// impl<S, I: IntoIterator<Item = S>> Tr<S> for I { }
234239
/// impl<T> Tr<T> for Vec<T> { }
240+
/// ```
235241
///
236242
/// The substs for the parent impl here are `[T, Vec<T>]`, which repeats `T`,
237243
/// but `S` is constrained in the parent impl, so `parent_substs` is only
@@ -256,8 +262,10 @@ fn check_duplicate_params<'tcx>(
256262
///
257263
/// For example forbid the following:
258264
///
265+
/// ```ignore (illustrative)
259266
/// impl<A> Tr for A { }
260267
/// impl Tr for &'static i32 { }
268+
/// ```
261269
fn check_static_lifetimes<'tcx>(
262270
tcx: TyCtxt<'tcx>,
263271
parent_substs: &Vec<GenericArg<'tcx>>,

compiler/rustc_hir_analysis/src/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
184184
/// modes #42640) may look like `Some(x)` but in fact have
185185
/// implicit deref patterns attached (e.g., it is really
186186
/// `&Some(x)`). In that case, we return the "outermost" type
187-
/// (e.g., `&Option<T>).
187+
/// (e.g., `&Option<T>`).
188188
pub(crate) fn pat_ty_adjusted(&self, pat: &hir::Pat<'_>) -> McResult<Ty<'tcx>> {
189189
// Check for implicit `&` types wrapping the pattern; note
190190
// that these are never attached to binding patterns, so

compiler/rustc_middle/src/thir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub enum StmtKind<'tcx> {
203203
/// `let pat: ty = <INIT>`
204204
initializer: Option<ExprId>,
205205

206-
/// `let pat: ty = <INIT> else { <ELSE> }
206+
/// `let pat: ty = <INIT> else { <ELSE> }`
207207
else_block: Option<BlockId>,
208208

209209
/// The lint level for this `let` statement.

compiler/rustc_middle/src/ty/adt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ impl<'tcx> AdtDef<'tcx> {
332332
self.flags().contains(AdtFlags::IS_PHANTOM_DATA)
333333
}
334334

335-
/// Returns `true` if this is Box<T>.
335+
/// Returns `true` if this is `Box<T>`.
336336
#[inline]
337337
pub fn is_box(self) -> bool {
338338
self.flags().contains(AdtFlags::IS_BOX)
339339
}
340340

341-
/// Returns `true` if this is UnsafeCell<T>.
341+
/// Returns `true` if this is `UnsafeCell<T>`.
342342
#[inline]
343343
pub fn is_unsafe_cell(self) -> bool {
344344
self.flags().contains(AdtFlags::IS_UNSAFE_CELL)

compiler/rustc_parse/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ mod errors;
3939
// uses a HOF to parse anything, and <source> includes file and
4040
// `source_str`.
4141

42-
/// A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
42+
/// A variant of 'panictry!' that works on a `Vec<Diagnostic>` instead of a single
43+
/// `DiagnosticBuilder`.
4344
macro_rules! panictry_buffer {
4445
($handler:expr, $e:expr) => {{
4546
use rustc_errors::FatalError;

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ impl<'tcx> AutoTraitFinder<'tcx> {
6666
/// struct Foo<T> { data: Box<T> }
6767
/// ```
6868
///
69-
/// then this might return that Foo<T>: Send if T: Send (encoded in the AutoTraitResult type).
70-
/// The analysis attempts to account for custom impls as well as other complex cases. This
71-
/// result is intended for use by rustdoc and other such consumers.
69+
/// then this might return that `Foo<T>: Send` if `T: Send` (encoded in the AutoTraitResult
70+
/// type). The analysis attempts to account for custom impls as well as other complex cases.
71+
/// This result is intended for use by rustdoc and other such consumers.
7272
///
7373
/// (Note that due to the coinductive nature of Send, the full and correct result is actually
7474
/// quite simple to generate. That is, when a type has no custom impl, it is Send iff its field
75-
/// types are all Send. So, in our example, we might have that Foo<T>: Send if Box<T>: Send.
75+
/// types are all Send. So, in our example, we might have that `Foo<T>: Send` if `Box<T>: Send`.
7676
/// But this is often not the best way to present to the user.)
7777
///
7878
/// Warning: The API should be considered highly unstable, and it may be refactored or removed

compiler/rustc_trait_selection/src/traits/project.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ enum ProjectionCandidate<'tcx> {
6262
/// From a where-clause in the env or object type
6363
ParamEnv(ty::PolyProjectionPredicate<'tcx>),
6464

65-
/// From the definition of `Trait` when you have something like <<A as Trait>::B as Trait2>::C
65+
/// From the definition of `Trait` when you have something like
66+
/// `<<A as Trait>::B as Trait2>::C`.
6667
TraitDef(ty::PolyProjectionPredicate<'tcx>),
6768

6869
/// Bounds specified on an object type
@@ -1367,7 +1368,7 @@ fn assemble_candidates_from_param_env<'cx, 'tcx>(
13671368
);
13681369
}
13691370

1370-
/// In the case of a nested projection like <<A as Foo>::FooT as Bar>::BarT, we may find
1371+
/// In the case of a nested projection like `<<A as Foo>::FooT as Bar>::BarT`, we may find
13711372
/// that the definition of `Foo` has some clues:
13721373
///
13731374
/// ```ignore (illustrative)

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
826826
/// must be met of course). One obvious case this comes up is
827827
/// marker traits like `Send`. Think of a linked list:
828828
///
829-
/// struct List<T> { data: T, next: Option<Box<List<T>>> }
829+
/// struct List<T> { data: T, next: Option<Box<List<T>>> }
830830
///
831831
/// `Box<List<T>>` will be `Send` if `T` is `Send` and
832832
/// `Option<Box<List<T>>>` is `Send`, and in turn

0 commit comments

Comments
 (0)