Use multipart suggestion for code wrapping

Another one of those "good grief, I just submitted it and NOW I think of it" moments.
This commit is contained in:
Michael Howell 2022-02-01 23:27:07 -07:00
parent 0db9e40670
commit 76b5b27d88
4 changed files with 50 additions and 52 deletions

View File

@ -220,7 +220,7 @@ fn visit_item(&mut self, item: &Item) {
// and we don't try to detect stuff `<like this>` because that's not valid Rust.
if let Some(Some(generics_start)) = (is_open_tag
&& dox[..range.end].ends_with(">"))
.then(|| extract_path_backwards(&dox, range.start))
.then(|| extract_path_backwards(&dox, range.start))
{
let generics_sp = match super::source_span_for_markdown_range(
tcx,
@ -231,22 +231,15 @@ fn visit_item(&mut self, item: &Item) {
Some(sp) => sp,
None => item.attr_span(tcx),
};
if let Ok(generics_snippet) =
tcx.sess.source_map().span_to_snippet(generics_sp)
{
// short form is chosen here because ``Vec<i32>`` would be confusing.
diag.span_suggestion_short(
generics_sp,
"try marking as source code with `backticks`",
format!("`{}`", generics_snippet),
Applicability::MaybeIncorrect,
);
} else {
diag.span_help(
generics_sp,
"try marking as source code with `backticks`",
);
}
// multipart form is chosen here because ``Vec<i32>`` would be confusing.
diag.multipart_suggestion(
"try marking as source code",
vec![
(generics_sp.shrink_to_lo(), String::from("`")),
(generics_sp.shrink_to_hi(), String::from("`")),
],
Applicability::MaybeIncorrect,
);
}
diag.emit()
});

View File

@ -4,35 +4,29 @@
/// This `Vec<i32>` thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `Vec<i32>`
pub struct Generic;
/// This `vec::Vec<i32>` thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `vec::Vec<i32>`
pub struct GenericPath;
/// This `i32<i32>` thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `i32<i32>`
pub struct PathsCanContainTrailingNumbers;
/// This `Vec::<i32>` thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `Vec::<i32>`
pub struct Turbofish;
/// This [link](https://rust-lang.org)`::<i32>` thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `::<i32>`
pub struct BareTurbofish;
/// This <span>`Vec::<i32>`</span> thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `Vec::<i32>`
pub struct Nested;

View File

@ -4,35 +4,29 @@
/// This Vec<i32> thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `Vec<i32>`
pub struct Generic;
/// This vec::Vec<i32> thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `vec::Vec<i32>`
pub struct GenericPath;
/// This i32<i32> thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `i32<i32>`
pub struct PathsCanContainTrailingNumbers;
/// This Vec::<i32> thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `Vec::<i32>`
pub struct Turbofish;
/// This [link](https://rust-lang.org)::<i32> thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `::<i32>`
pub struct BareTurbofish;
/// This <span>Vec::<i32></span> thing!
//~^ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
//~|SUGGESTION `Vec::<i32>`
pub struct Nested;

View File

@ -2,55 +2,72 @@ error: unclosed HTML tag `i32`
--> $DIR/html-as-generics.rs:4:13
|
LL | /// This Vec<i32> thing!
| ---^^^^^
| |
| help: try marking as source code with `backticks`
| ^^^^^
|
note: the lint level is defined here
--> $DIR/html-as-generics.rs:2:9
|
LL | #![deny(rustdoc::invalid_html_tags)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: try marking as source code
|
LL | /// This `Vec<i32>` thing!
| + +
error: unclosed HTML tag `i32`
--> $DIR/html-as-generics.rs:10:18
--> $DIR/html-as-generics.rs:9:18
|
LL | /// This vec::Vec<i32> thing!
| --------^^^^^
| |
| help: try marking as source code with `backticks`
| ^^^^^
|
help: try marking as source code
|
LL | /// This `vec::Vec<i32>` thing!
| + +
error: unclosed HTML tag `i32`
--> $DIR/html-as-generics.rs:16:13
--> $DIR/html-as-generics.rs:14:13
|
LL | /// This i32<i32> thing!
| ---^^^^^
| |
| help: try marking as source code with `backticks`
| ^^^^^
|
help: try marking as source code
|
LL | /// This `i32<i32>` thing!
| + +
error: unclosed HTML tag `i32`
--> $DIR/html-as-generics.rs:22:15
--> $DIR/html-as-generics.rs:19:15
|
LL | /// This Vec::<i32> thing!
| -----^^^^^
| |
| help: try marking as source code with `backticks`
| ^^^^^
|
help: try marking as source code
|
LL | /// This `Vec::<i32>` thing!
| + +
error: unclosed HTML tag `i32`
--> $DIR/html-as-generics.rs:28:41
--> $DIR/html-as-generics.rs:24:41
|
LL | /// This [link](https://rust-lang.org)::<i32> thing!
| --^^^^^
| |
| help: try marking as source code with `backticks`
| ^^^^^
|
help: try marking as source code
|
LL | /// This [link](https://rust-lang.org)`::<i32>` thing!
| + +
error: unclosed HTML tag `i32`
--> $DIR/html-as-generics.rs:34:21
--> $DIR/html-as-generics.rs:29:21
|
LL | /// This <span>Vec::<i32></span> thing!
| -----^^^^^
| |
| help: try marking as source code with `backticks`
| ^^^^^
|
help: try marking as source code
|
LL | /// This <span>`Vec::<i32>`</span> thing!
| + +
error: aborting due to 6 previous errors