mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-27 18:26:19 +00:00
fix doc tests
This commit is contained in:
parent
bd7375a58f
commit
b19ef6b046
37 changed files with 75 additions and 61 deletions
|
|
@ -10,7 +10,6 @@ license.workspace = true
|
|||
rust-version.workspace = true
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
arrayvec.workspace = true
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@
|
|||
//!
|
||||
//! It is used like this:
|
||||
//!
|
||||
//! ```
|
||||
//! ```ignore
|
||||
//! # use hir_def::dyn_map::DynMap;
|
||||
//! # use hir_def::dyn_map::Key;
|
||||
//! // keys define submaps of a `DynMap`
|
||||
//! const STRING_TO_U32: Key<String, u32> = Key::new();
|
||||
//! const U32_TO_VEC: Key<u32, Vec<bool>> = Key::new();
|
||||
|
|
|
|||
|
|
@ -883,20 +883,20 @@ pub struct UseTree {
|
|||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum UseTreeKind {
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// use path::to::Item;
|
||||
/// use path::to::Item as Renamed;
|
||||
/// use path::to::Trait as _;
|
||||
/// ```
|
||||
Single { path: Interned<ModPath>, alias: Option<ImportAlias> },
|
||||
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// use *; // (invalid, but can occur in nested tree)
|
||||
/// use path::*;
|
||||
/// ```
|
||||
Glob { path: Option<Interned<ModPath>> },
|
||||
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// use prefix::{self, Item, ...};
|
||||
/// ```
|
||||
Prefixed { prefix: Option<Interned<ModPath>>, list: Box<[UseTree]> },
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ impl DirPath {
|
|||
/// So this is the case which doesn't really work I think if we try to be
|
||||
/// 100% platform agnostic:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// mod a {
|
||||
/// #[path="C://sad/face"]
|
||||
/// mod b { mod c; }
|
||||
|
|
|
|||
|
|
@ -532,16 +532,17 @@ impl Resolver {
|
|||
/// Note that in Rust one name can be bound to several items:
|
||||
///
|
||||
/// ```
|
||||
/// # #![allow(non_camel_case_types)]
|
||||
/// macro_rules! t { () => (()) }
|
||||
/// type t = t!();
|
||||
/// const t: t = t!()
|
||||
/// const t: t = t!();
|
||||
/// ```
|
||||
///
|
||||
/// That's why we return a multimap.
|
||||
///
|
||||
/// The shadowing is accounted for: in
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// let it = 92;
|
||||
/// {
|
||||
/// let it = 92;
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ fn dummy_gate_test_expand(
|
|||
/// somewhat inconsistently resolve derive attributes.
|
||||
///
|
||||
/// As such, we expand `#[derive(Foo, bar::Bar)]` into
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// #![Foo]
|
||||
/// #![bar::Bar]
|
||||
/// ```
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ pub struct HirFormatter<'a> {
|
|||
enum BoundsFormattingCtx {
|
||||
Entered {
|
||||
/// We can have recursive bounds like the following case:
|
||||
/// ```rust
|
||||
/// ```ignore
|
||||
/// where
|
||||
/// T: Foo,
|
||||
/// T::FooAssoc: Baz<<T::FooAssoc as Bar>::BarAssoc> + Bar
|
||||
|
|
|
|||
|
|
@ -335,7 +335,7 @@ impl Default for InternedStandardTypes {
|
|||
/// sized struct to a dynamically sized one. E.g., &[i32; 4] -> &[i32] is
|
||||
/// represented by:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// Deref(None) -> [i32; 4],
|
||||
/// Borrow(AutoBorrow::Ref) -> &[i32; 4],
|
||||
/// Unsize -> &[i32],
|
||||
|
|
@ -481,9 +481,10 @@ pub struct InferenceResult {
|
|||
/// or pattern can have multiple binding modes. For example:
|
||||
/// ```
|
||||
/// fn foo(mut slice: &[u32]) -> usize {
|
||||
/// slice = match slice {
|
||||
/// [0, rest @ ..] | rest => rest,
|
||||
/// };
|
||||
/// slice = match slice {
|
||||
/// [0, rest @ ..] | rest => rest,
|
||||
/// };
|
||||
/// 0
|
||||
/// }
|
||||
/// ```
|
||||
/// the first `rest` has implicit `ref` binding mode, but the second `rest` binding mode is `move`.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
//!
|
||||
//! This module solves the following problem:
|
||||
//!
|
||||
//! Given a piece of syntax, find the corresponding semantic definition (def).
|
||||
//! > Given a piece of syntax, find the corresponding semantic definition (def).
|
||||
//!
|
||||
//! This problem is a part of more-or-less every IDE feature implemented. Every
|
||||
//! IDE functionality (like goto to definition), conceptually starts with a
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ fn mod_item_path_str(
|
|||
/// Type tree shows how can we get from set of types to some type.
|
||||
///
|
||||
/// Consider the following code as an example
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// fn foo(x: i32, y: bool) -> Option<i32> { None }
|
||||
/// fn bar() {
|
||||
/// let a = 1;
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ fn comment_to_doc(acc: &mut Assists, comment: ast::Comment, style: CommentPlacem
|
|||
|
||||
/// Not all comments are valid candidates for conversion into doc comments. For example, the
|
||||
/// comments in the code:
|
||||
/// ```rust
|
||||
/// ```ignore
|
||||
/// // Brilliant module right here
|
||||
///
|
||||
/// // Really good right
|
||||
|
|
@ -148,7 +148,7 @@ fn comment_to_doc(acc: &mut Assists, comment: ast::Comment, style: CommentPlacem
|
|||
/// mod nice_module {}
|
||||
/// ```
|
||||
/// can be converted to doc comments. However, the comments in this example:
|
||||
/// ```rust
|
||||
/// ```ignore
|
||||
/// fn foo_bar(foo: Foo /* not bar yet */) -> Bar {
|
||||
/// foo.into_bar()
|
||||
/// // Nicely done
|
||||
|
|
@ -162,7 +162,7 @@ fn comment_to_doc(acc: &mut Assists, comment: ast::Comment, style: CommentPlacem
|
|||
/// are not allowed to become doc comments. Moreover, some comments _are_ allowed, but aren't common
|
||||
/// style in Rust. For example, the following comments are allowed to be doc comments, but it is not
|
||||
/// common style for them to be:
|
||||
/// ```rust
|
||||
/// ```ignore
|
||||
/// fn foo_bar(foo: Foo) -> Bar {
|
||||
/// // this could be an inner comment with //!
|
||||
/// foo.into_bar()
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ fn make_function_name(semantics_scope: &hir::SemanticsScope<'_>) -> ast::NameRef
|
|||
/// * We want whole node, like `loop {}`, `2 + 2`, `{ let n = 1; }` exprs.
|
||||
/// Then we can use `ast::Expr`
|
||||
/// * We want a few statements for a block. E.g.
|
||||
/// ```rust,no_run
|
||||
/// ```ignore
|
||||
/// fn foo() -> i32 {
|
||||
/// let m = 1;
|
||||
/// $0
|
||||
|
|
@ -386,7 +386,7 @@ struct ContainerInfo {
|
|||
/// Control flow that is exported from extracted function
|
||||
///
|
||||
/// E.g.:
|
||||
/// ```rust,no_run
|
||||
/// ```ignore
|
||||
/// loop {
|
||||
/// $0
|
||||
/// if 42 == 42 {
|
||||
|
|
|
|||
|
|
@ -1037,7 +1037,7 @@ fn filter_bounds_in_scope(
|
|||
|
||||
/// Makes duplicate argument names unique by appending incrementing numbers.
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// let mut names: Vec<String> =
|
||||
/// vec!["foo".into(), "foo".into(), "bar".into(), "baz".into(), "bar".into()];
|
||||
/// deduplicate_arg_names(&mut names);
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@ impl ConstAndTypeMap {
|
|||
/// 1. Map the provided instance's generic args to the type alias's generic
|
||||
/// params:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// type A<'a, const N: usize, T = u64> = &'a [T; N];
|
||||
/// ^ alias generic params
|
||||
/// let a: A<100>;
|
||||
|
|
|
|||
|
|
@ -249,8 +249,8 @@ pub(crate) enum Qualified {
|
|||
/// This would be None, if path is not solely made of
|
||||
/// `super` segments, e.g.
|
||||
///
|
||||
/// ```rust
|
||||
/// use super::foo;
|
||||
/// ```ignore
|
||||
/// use super::foo;
|
||||
/// ```
|
||||
///
|
||||
/// Otherwise it should be Some(count of `super`)
|
||||
|
|
|
|||
|
|
@ -97,7 +97,8 @@ fn token_at_offset_ignore_whitespace(file: &SyntaxNode, offset: TextSize) -> Opt
|
|||
/// We do this by recursively expanding all macros and picking the best possible match. We cannot just
|
||||
/// choose the first expansion each time because macros can expand to something that does not include
|
||||
/// our completion marker, e.g.:
|
||||
/// ```
|
||||
///
|
||||
/// ```ignore
|
||||
/// macro_rules! helper { ($v:ident) => {} }
|
||||
/// macro_rules! my_macro {
|
||||
/// ($v:ident) => {
|
||||
|
|
@ -106,7 +107,7 @@ fn token_at_offset_ignore_whitespace(file: &SyntaxNode, offset: TextSize) -> Opt
|
|||
/// };
|
||||
/// }
|
||||
///
|
||||
/// my_macro!(complete_me_here)
|
||||
/// my_macro!(complete_me_here);
|
||||
/// ```
|
||||
/// If we would expand the first thing we encounter only (which in fact this method used to do), we would
|
||||
/// be unable to complete here, because we would be walking directly into the void. So we instead try
|
||||
|
|
|
|||
|
|
@ -149,9 +149,9 @@ pub struct CompletionRelevance {
|
|||
/// This is set when the identifier being completed matches up with the name that is expected,
|
||||
/// like in a function argument.
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// fn f(spam: String) {}
|
||||
/// fn main {
|
||||
/// fn main() {
|
||||
/// let spam = 92;
|
||||
/// f($0) // name of local matches the name of param
|
||||
/// }
|
||||
|
|
@ -161,7 +161,7 @@ pub struct CompletionRelevance {
|
|||
pub type_match: Option<CompletionRelevanceTypeMatch>,
|
||||
/// Set for local variables.
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// fn foo(a: u32) {
|
||||
/// let b = 0;
|
||||
/// $0 // `a` and `b` are local
|
||||
|
|
@ -195,7 +195,7 @@ pub struct CompletionRelevanceTraitInfo {
|
|||
pub enum CompletionRelevanceTypeMatch {
|
||||
/// This is set in cases like these:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// enum Option<T> { Some(T), None }
|
||||
/// fn f(a: Option<u32>) {}
|
||||
/// fn main {
|
||||
|
|
@ -205,9 +205,9 @@ pub enum CompletionRelevanceTypeMatch {
|
|||
CouldUnify,
|
||||
/// This is set in cases where the type matches the expected type, like:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// fn f(spam: String) {}
|
||||
/// fn main {
|
||||
/// fn main() {
|
||||
/// let foo = String::new();
|
||||
/// f($0) // type of local matches the type of param
|
||||
/// }
|
||||
|
|
@ -221,7 +221,7 @@ pub enum CompletionRelevancePostfixMatch {
|
|||
NonExact,
|
||||
/// This is set in cases like these:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// (a > b).not$0
|
||||
/// ```
|
||||
///
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ impl CompletionFieldsToResolve {
|
|||
/// already present, it should give all possible variants for the identifier at
|
||||
/// the caret. In other words, for
|
||||
///
|
||||
/// ```no_run
|
||||
/// ```ignore
|
||||
/// fn f() {
|
||||
/// let foo = 92;
|
||||
/// let _ = bar$0
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ type DefaultedParam = Either<hir::TypeParam, hir::ConstParam>;
|
|||
/// block), you generally want to appropriately qualify the names, and sometimes
|
||||
/// you might want to substitute generic parameters as well:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// mod x {
|
||||
/// pub struct A<V>;
|
||||
/// pub trait T<U> { fn foo(&self, _: U) -> A<U>; }
|
||||
|
|
|
|||
|
|
@ -493,7 +493,7 @@ pub enum Snippet {
|
|||
Placeholder(TextRange),
|
||||
/// A group of placeholder snippets, e.g.
|
||||
///
|
||||
/// ```no_run
|
||||
/// ```ignore
|
||||
/// let ${0:new_var} = 4;
|
||||
/// fun(1, 2, 3, ${0:new_var});
|
||||
/// ```
|
||||
|
|
|
|||
|
|
@ -79,7 +79,9 @@ const USELESS_METHODS: &[&str] = &[
|
|||
/// the name, e.g. `a`, `a1`, `a2`, ...
|
||||
///
|
||||
/// # Examples
|
||||
/// ```rust
|
||||
///
|
||||
/// ```
|
||||
/// # use ide_db::syntax_helpers::suggest_name::NameGenerator;
|
||||
/// let mut generator = NameGenerator::new();
|
||||
/// assert_eq!(generator.suggest_name("a"), "a");
|
||||
/// assert_eq!(generator.suggest_name("a"), "a1");
|
||||
|
|
|
|||
|
|
@ -697,7 +697,7 @@ struct SeverityAttr {
|
|||
/// #[warn(non_snake_case)]
|
||||
/// mod foo {
|
||||
/// #[allow(nonstandard_style)]
|
||||
/// mod bar;
|
||||
/// mod bar {}
|
||||
/// }
|
||||
/// ```
|
||||
/// We want to not warn on non snake case inside `bar`. If we are traversing this for the first
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ use crate::ParseError;
|
|||
/// Consider
|
||||
///
|
||||
/// ```
|
||||
/// macro_rules! an_macro {
|
||||
/// ($x:expr + $y:expr) => ($y * $x)
|
||||
/// macro_rules! a_macro {
|
||||
/// ($x:expr, $y:expr) => ($y * $x)
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ impl Input {
|
|||
/// the *previous* token was joint, with mbe, you know whether the *current*
|
||||
/// one is joint. This API allows for styles of usage:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// // In text:
|
||||
/// tokens.was_joint(prev_joint);
|
||||
/// tokens.push(curr);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ pub use crate::{
|
|||
///
|
||||
/// That is, for something like
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// quick_check! {
|
||||
/// fn prop() {}
|
||||
/// }
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@ pub struct Output {
|
|||
/// 32-bit encoding of events. If LSB is zero, then that's an index into the
|
||||
/// error vector. Otherwise, it's one of the thee other variants, with data encoded as
|
||||
///
|
||||
/// |16 bit kind|8 bit n_input_tokens|4 bit tag|4 bit leftover|
|
||||
///
|
||||
/// ```text
|
||||
/// |16 bit kind|8 bit n_input_tokens|4 bit tag|4 bit leftover|
|
||||
/// ``````
|
||||
event: Vec<u32>,
|
||||
error: Vec<String>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ pub(crate) type Cause = String;
|
|||
/// A single-item queue that allows callers to request an operation to
|
||||
/// be performed later.
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// let queue = OpQueue::default();
|
||||
///
|
||||
/// // Request work to be done.
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ pub struct Config<T> {
|
|||
/// that specify level.
|
||||
pub chalk_filter: Option<String>,
|
||||
/// Filtering syntax, set in a shell:
|
||||
/// ```
|
||||
/// ```text
|
||||
/// env RA_PROFILE=* // dump everything
|
||||
/// env RA_PROFILE=foo|bar|baz // enabled only selected entries
|
||||
/// env RA_PROFILE=*@3>10 // dump everything, up to depth 3, if it takes more than 10
|
||||
|
|
@ -39,7 +39,7 @@ pub struct Config<T> {
|
|||
pub profile_filter: Option<String>,
|
||||
|
||||
/// Filtering syntax, set in a shell:
|
||||
/// ```
|
||||
/// ```text
|
||||
/// env RA_PROFILE_JSON=foo|bar|baz
|
||||
/// ```
|
||||
pub json_profile_filter: Option<String>,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
//!
|
||||
//! Usage:
|
||||
//!
|
||||
//! ```rust
|
||||
//! ```ignore
|
||||
//! # use tracing_subscriber::Registry;
|
||||
//! let layer = hprof::SpanTree::default();
|
||||
//! Registry::default().with(layer).init();
|
||||
//! ```
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
//!
|
||||
//! Usage:
|
||||
//!
|
||||
//! ```rust
|
||||
//! ```ignore
|
||||
//! # use tracing_subscriber::Registry;
|
||||
//! let layer = json::TimingLayer::new(std::io::stderr);
|
||||
//! Registry::default().with(layer).init();
|
||||
//! ```
|
||||
|
|
|
|||
|
|
@ -83,7 +83,8 @@ pub type RawMap<A> = hash_map::HashMap<TypeId, Box<A>, BuildHasherDefault<TypeId
|
|||
/// (Here using the [`AnyMap`] convenience alias; the first line could use
|
||||
/// <code>[anymap::Map][Map]::<[core::any::Any]>::new()</code> instead if desired.)
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// # use stdx::anymap;
|
||||
#[doc = "let mut data = anymap::AnyMap::new();"]
|
||||
/// assert_eq!(data.get(), None::<&i32>);
|
||||
/// ```
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ macro_rules! format_to_acc {
|
|||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```ignore
|
||||
/// impl_from!(Struct, Union, Enum for Adt);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ pub fn ancestors_at_offset(
|
|||
/// imprecise: if the cursor is strictly between two nodes of the desired type,
|
||||
/// as in
|
||||
///
|
||||
/// ```no_run
|
||||
/// ```ignore
|
||||
/// struct Foo {}|struct Bar;
|
||||
/// ```
|
||||
///
|
||||
|
|
|
|||
|
|
@ -72,9 +72,9 @@ impl IndentLevel {
|
|||
}
|
||||
|
||||
/// XXX: this intentionally doesn't change the indent of the very first token.
|
||||
/// Ie, in something like
|
||||
/// For example, in something like:
|
||||
/// ```
|
||||
/// fn foo() {
|
||||
/// fn foo() -> i32 {
|
||||
/// 92
|
||||
/// }
|
||||
/// ```
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
//! Ideally, we should use a proper "model selection" to directly compare
|
||||
//! quadratic and linear models, but that sounds rather complicated:
|
||||
//!
|
||||
//! https://stats.stackexchange.com/questions/21844/selecting-best-model-based-on-linear-quadratic-and-cubic-fit-of-data
|
||||
//! > https://stats.stackexchange.com/questions/21844/selecting-best-model-based-on-linear-quadratic-and-cubic-fit-of-data
|
||||
//!
|
||||
//! We might get false positives on a VM, but never false negatives. So, if the
|
||||
//! first round fails, we repeat the ordeal three more times and fail only if
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
//! Use this to test functionality local to one file.
|
||||
//!
|
||||
//! Simple Example:
|
||||
//! ```
|
||||
//!
|
||||
//! ```ignore
|
||||
//! r#"
|
||||
//! fn main() {
|
||||
//! println!("Hello World")
|
||||
|
|
@ -19,7 +20,8 @@
|
|||
//! which is also how to define multiple files in a single test fixture
|
||||
//!
|
||||
//! Example using two files in the same crate:
|
||||
//! ```
|
||||
//!
|
||||
//! ```ignore
|
||||
//! "
|
||||
//! //- /main.rs
|
||||
//! mod foo;
|
||||
|
|
@ -33,7 +35,8 @@
|
|||
//! ```
|
||||
//!
|
||||
//! Example using two crates with one file each, with one crate depending on the other:
|
||||
//! ```
|
||||
//!
|
||||
//! ```ignore
|
||||
//! r#"
|
||||
//! //- /main.rs crate:a deps:b
|
||||
//! fn main() {
|
||||
|
|
@ -51,7 +54,8 @@
|
|||
//! for the syntax.
|
||||
//!
|
||||
//! Example using some available metadata:
|
||||
//! ```
|
||||
//!
|
||||
//! ```ignore
|
||||
//! "
|
||||
//! //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo
|
||||
//! fn insert_source_code_here() {}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
//!
|
||||
//! The primary goal of this is to losslessly represent paths like
|
||||
//!
|
||||
//! ```
|
||||
//! ```ignore
|
||||
//! #[path = "./bar.rs"]
|
||||
//! mod foo;
|
||||
//! ```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue