clone less
This commit is contained in:
parent
49112241e9
commit
1ba97cb1cc
4 changed files with 76 additions and 82 deletions
|
@ -880,7 +880,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
||||||
(pair, r)
|
(pair, r)
|
||||||
})
|
})
|
||||||
.unzip();
|
.unzip();
|
||||||
self.record_late_bound_vars(hir_id, binders.clone());
|
self.record_late_bound_vars(hir_id, binders);
|
||||||
// Even if there are no lifetimes defined here, we still wrap it in a binder
|
// Even if there are no lifetimes defined here, we still wrap it in a binder
|
||||||
// scope. If there happens to be a nested poly trait ref (an error), that
|
// scope. If there happens to be a nested poly trait ref (an error), that
|
||||||
// will be `Concatenating` anyways, so we don't have to worry about the depth
|
// will be `Concatenating` anyways, so we don't have to worry about the depth
|
||||||
|
|
|
@ -856,7 +856,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
PatKind::InlineConstant { ref subpattern, .. } => {
|
PatKind::InlineConstant { ref subpattern, .. } => {
|
||||||
self.visit_primary_bindings(subpattern, pattern_user_ty.clone(), f)
|
self.visit_primary_bindings(subpattern, pattern_user_ty, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
PatKind::Leaf { ref subpatterns } => {
|
PatKind::Leaf { ref subpatterns } => {
|
||||||
|
|
|
@ -1750,7 +1750,7 @@ pub(crate) fn markdown_links<'md, R>(
|
||||||
}
|
}
|
||||||
// do not actually include braces in the span
|
// do not actually include braces in the span
|
||||||
let range = (open_brace + 1)..close_brace;
|
let range = (open_brace + 1)..close_brace;
|
||||||
MarkdownLinkRange::Destination(range.clone())
|
MarkdownLinkRange::Destination(range)
|
||||||
};
|
};
|
||||||
|
|
||||||
let span_for_offset_forward = |span: Range<usize>, open: u8, close: u8| {
|
let span_for_offset_forward = |span: Range<usize>, open: u8, close: u8| {
|
||||||
|
@ -1786,7 +1786,7 @@ pub(crate) fn markdown_links<'md, R>(
|
||||||
}
|
}
|
||||||
// do not actually include braces in the span
|
// do not actually include braces in the span
|
||||||
let range = (open_brace + 1)..close_brace;
|
let range = (open_brace + 1)..close_brace;
|
||||||
MarkdownLinkRange::Destination(range.clone())
|
MarkdownLinkRange::Destination(range)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut broken_link_callback = |link: BrokenLink<'md>| Some((link.reference, "".into()));
|
let mut broken_link_callback = |link: BrokenLink<'md>| Some((link.reference, "".into()));
|
||||||
|
|
|
@ -25,91 +25,85 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
|
||||||
Some(sp) => sp,
|
Some(sp) => sp,
|
||||||
None => item.attr_span(tcx),
|
None => item.attr_span(tcx),
|
||||||
};
|
};
|
||||||
tcx.struct_span_lint_hir(
|
tcx.struct_span_lint_hir(crate::lint::INVALID_HTML_TAGS, hir_id, sp, msg, |lint| {
|
||||||
crate::lint::INVALID_HTML_TAGS,
|
use rustc_lint_defs::Applicability;
|
||||||
hir_id,
|
// If a tag looks like `<this>`, it might actually be a generic.
|
||||||
sp,
|
// We don't try to detect stuff `<like, this>` because that's not valid HTML,
|
||||||
msg.to_string(),
|
// and we don't try to detect stuff `<like this>` because that's not valid Rust.
|
||||||
|lint| {
|
let mut generics_end = range.end;
|
||||||
use rustc_lint_defs::Applicability;
|
if let Some(Some(mut generics_start)) = (is_open_tag
|
||||||
// If a tag looks like `<this>`, it might actually be a generic.
|
&& dox[..generics_end].ends_with('>'))
|
||||||
// We don't try to detect stuff `<like, this>` because that's not valid HTML,
|
.then(|| extract_path_backwards(&dox, range.start))
|
||||||
// and we don't try to detect stuff `<like this>` because that's not valid Rust.
|
{
|
||||||
let mut generics_end = range.end;
|
while generics_start != 0
|
||||||
if let Some(Some(mut generics_start)) = (is_open_tag
|
&& generics_end < dox.len()
|
||||||
&& dox[..generics_end].ends_with('>'))
|
&& dox.as_bytes()[generics_start - 1] == b'<'
|
||||||
.then(|| extract_path_backwards(&dox, range.start))
|
&& dox.as_bytes()[generics_end] == b'>'
|
||||||
{
|
{
|
||||||
while generics_start != 0
|
generics_end += 1;
|
||||||
&& generics_end < dox.len()
|
generics_start -= 1;
|
||||||
&& dox.as_bytes()[generics_start - 1] == b'<'
|
if let Some(new_start) = extract_path_backwards(&dox, generics_start) {
|
||||||
&& dox.as_bytes()[generics_end] == b'>'
|
generics_start = new_start;
|
||||||
{
|
|
||||||
generics_end += 1;
|
|
||||||
generics_start -= 1;
|
|
||||||
if let Some(new_start) = extract_path_backwards(&dox, generics_start) {
|
|
||||||
generics_start = new_start;
|
|
||||||
}
|
|
||||||
if let Some(new_end) = extract_path_forward(&dox, generics_end) {
|
|
||||||
generics_end = new_end;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if let Some(new_end) = extract_path_forward(&dox, generics_end) {
|
if let Some(new_end) = extract_path_forward(&dox, generics_end) {
|
||||||
generics_end = new_end;
|
generics_end = new_end;
|
||||||
}
|
}
|
||||||
let generics_sp = match source_span_for_markdown_range(
|
|
||||||
tcx,
|
|
||||||
&dox,
|
|
||||||
&(generics_start..generics_end),
|
|
||||||
&item.attrs.doc_strings,
|
|
||||||
) {
|
|
||||||
Some(sp) => sp,
|
|
||||||
None => item.attr_span(tcx),
|
|
||||||
};
|
|
||||||
// Sometimes, we only extract part of a path. For example, consider this:
|
|
||||||
//
|
|
||||||
// <[u32] as IntoIter<u32>>::Item
|
|
||||||
// ^^^^^ unclosed HTML tag `u32`
|
|
||||||
//
|
|
||||||
// We don't have any code for parsing fully-qualified trait paths.
|
|
||||||
// In theory, we could add it, but doing it correctly would require
|
|
||||||
// parsing the entire path grammar, which is problematic because of
|
|
||||||
// overlap between the path grammar and Markdown.
|
|
||||||
//
|
|
||||||
// The example above shows that ambiguity. Is `[u32]` intended to be an
|
|
||||||
// intra-doc link to the u32 primitive, or is it intended to be a slice?
|
|
||||||
//
|
|
||||||
// If the below conditional were removed, we would suggest this, which is
|
|
||||||
// not what the user probably wants.
|
|
||||||
//
|
|
||||||
// <[u32] as `IntoIter<u32>`>::Item
|
|
||||||
//
|
|
||||||
// We know that the user actually wants to wrap the whole thing in a code
|
|
||||||
// block, but the only reason we know that is because `u32` does not, in
|
|
||||||
// fact, implement IntoIter. If the example looks like this:
|
|
||||||
//
|
|
||||||
// <[Vec<i32>] as IntoIter<i32>::Item
|
|
||||||
//
|
|
||||||
// The ideal fix would be significantly different.
|
|
||||||
if (generics_start > 0 && dox.as_bytes()[generics_start - 1] == b'<')
|
|
||||||
|| (generics_end < dox.len() && dox.as_bytes()[generics_end] == b'>')
|
|
||||||
{
|
|
||||||
return lint;
|
|
||||||
}
|
|
||||||
// multipart form is chosen here because ``Vec<i32>`` would be confusing.
|
|
||||||
lint.multipart_suggestion(
|
|
||||||
"try marking as source code",
|
|
||||||
vec![
|
|
||||||
(generics_sp.shrink_to_lo(), String::from("`")),
|
|
||||||
(generics_sp.shrink_to_hi(), String::from("`")),
|
|
||||||
],
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
if let Some(new_end) = extract_path_forward(&dox, generics_end) {
|
||||||
|
generics_end = new_end;
|
||||||
|
}
|
||||||
|
let generics_sp = match source_span_for_markdown_range(
|
||||||
|
tcx,
|
||||||
|
&dox,
|
||||||
|
&(generics_start..generics_end),
|
||||||
|
&item.attrs.doc_strings,
|
||||||
|
) {
|
||||||
|
Some(sp) => sp,
|
||||||
|
None => item.attr_span(tcx),
|
||||||
|
};
|
||||||
|
// Sometimes, we only extract part of a path. For example, consider this:
|
||||||
|
//
|
||||||
|
// <[u32] as IntoIter<u32>>::Item
|
||||||
|
// ^^^^^ unclosed HTML tag `u32`
|
||||||
|
//
|
||||||
|
// We don't have any code for parsing fully-qualified trait paths.
|
||||||
|
// In theory, we could add it, but doing it correctly would require
|
||||||
|
// parsing the entire path grammar, which is problematic because of
|
||||||
|
// overlap between the path grammar and Markdown.
|
||||||
|
//
|
||||||
|
// The example above shows that ambiguity. Is `[u32]` intended to be an
|
||||||
|
// intra-doc link to the u32 primitive, or is it intended to be a slice?
|
||||||
|
//
|
||||||
|
// If the below conditional were removed, we would suggest this, which is
|
||||||
|
// not what the user probably wants.
|
||||||
|
//
|
||||||
|
// <[u32] as `IntoIter<u32>`>::Item
|
||||||
|
//
|
||||||
|
// We know that the user actually wants to wrap the whole thing in a code
|
||||||
|
// block, but the only reason we know that is because `u32` does not, in
|
||||||
|
// fact, implement IntoIter. If the example looks like this:
|
||||||
|
//
|
||||||
|
// <[Vec<i32>] as IntoIter<i32>::Item
|
||||||
|
//
|
||||||
|
// The ideal fix would be significantly different.
|
||||||
|
if (generics_start > 0 && dox.as_bytes()[generics_start - 1] == b'<')
|
||||||
|
|| (generics_end < dox.len() && dox.as_bytes()[generics_end] == b'>')
|
||||||
|
{
|
||||||
|
return lint;
|
||||||
|
}
|
||||||
|
// multipart form is chosen here because ``Vec<i32>`` would be confusing.
|
||||||
|
lint.multipart_suggestion(
|
||||||
|
"try marking as source code",
|
||||||
|
vec![
|
||||||
|
(generics_sp.shrink_to_lo(), String::from("`")),
|
||||||
|
(generics_sp.shrink_to_hi(), String::from("`")),
|
||||||
|
],
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
lint
|
lint
|
||||||
},
|
});
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut tags = Vec::new();
|
let mut tags = Vec::new();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue