Use DiagnosticInfo for anchor failure
This gets rid of a lot of parameters, as well as fixing a diagnostic bug.
This commit is contained in:
parent
6e4ef54d79
commit
d4011e1270
@ -251,6 +251,7 @@ struct ResolutionInfo {
|
|||||||
extra_fragment: Option<String>,
|
extra_fragment: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
struct DiagnosticInfo<'a> {
|
struct DiagnosticInfo<'a> {
|
||||||
item: &'a Item,
|
item: &'a Item,
|
||||||
dox: &'a str,
|
dox: &'a str,
|
||||||
@ -949,19 +950,19 @@ impl LinkCollector<'_, '_> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let diag_info = DiagnosticInfo {
|
||||||
|
item,
|
||||||
|
dox,
|
||||||
|
ori_link: &ori_link.link,
|
||||||
|
link_range: ori_link.range.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
let link = ori_link.link.replace("`", "");
|
let link = ori_link.link.replace("`", "");
|
||||||
let no_backticks_range = range_between_backticks(&ori_link);
|
let no_backticks_range = range_between_backticks(&ori_link);
|
||||||
let parts = link.split('#').collect::<Vec<_>>();
|
let parts = link.split('#').collect::<Vec<_>>();
|
||||||
let (link, extra_fragment) = if parts.len() > 2 {
|
let (link, extra_fragment) = if parts.len() > 2 {
|
||||||
// A valid link can't have multiple #'s
|
// A valid link can't have multiple #'s
|
||||||
anchor_failure(
|
anchor_failure(self.cx, diag_info, AnchorFailure::MultipleAnchors);
|
||||||
self.cx,
|
|
||||||
&item,
|
|
||||||
&link,
|
|
||||||
dox,
|
|
||||||
ori_link.range,
|
|
||||||
AnchorFailure::MultipleAnchors,
|
|
||||||
);
|
|
||||||
return None;
|
return None;
|
||||||
} else if parts.len() == 2 {
|
} else if parts.len() == 2 {
|
||||||
if parts[0].trim().is_empty() {
|
if parts[0].trim().is_empty() {
|
||||||
@ -1092,12 +1093,6 @@ impl LinkCollector<'_, '_> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let diag_info = DiagnosticInfo {
|
|
||||||
item,
|
|
||||||
dox,
|
|
||||||
ori_link: &ori_link.link,
|
|
||||||
link_range: ori_link.range.clone(),
|
|
||||||
};
|
|
||||||
let (mut res, mut fragment) = self.resolve_with_disambiguator_cached(
|
let (mut res, mut fragment) = self.resolve_with_disambiguator_cached(
|
||||||
ResolutionInfo {
|
ResolutionInfo {
|
||||||
module_id,
|
module_id,
|
||||||
@ -1105,7 +1100,7 @@ impl LinkCollector<'_, '_> {
|
|||||||
path_str: path_str.to_owned(),
|
path_str: path_str.to_owned(),
|
||||||
extra_fragment,
|
extra_fragment,
|
||||||
},
|
},
|
||||||
diag_info,
|
diag_info.clone(), // this struct should really be Copy, but Range is not :(
|
||||||
matches!(ori_link.kind, LinkType::Reference | LinkType::Shortcut),
|
matches!(ori_link.kind, LinkType::Reference | LinkType::Shortcut),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@ -1123,10 +1118,7 @@ impl LinkCollector<'_, '_> {
|
|||||||
if fragment.is_some() {
|
if fragment.is_some() {
|
||||||
anchor_failure(
|
anchor_failure(
|
||||||
self.cx,
|
self.cx,
|
||||||
&item,
|
diag_info,
|
||||||
path_str,
|
|
||||||
dox,
|
|
||||||
ori_link.range,
|
|
||||||
AnchorFailure::RustdocAnchorConflict(prim),
|
AnchorFailure::RustdocAnchorConflict(prim),
|
||||||
);
|
);
|
||||||
return None;
|
return None;
|
||||||
@ -1360,14 +1352,7 @@ impl LinkCollector<'_, '_> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
Err(ErrorKind::AnchorFailure(msg)) => {
|
Err(ErrorKind::AnchorFailure(msg)) => {
|
||||||
anchor_failure(
|
anchor_failure(self.cx, diag, msg);
|
||||||
self.cx,
|
|
||||||
diag.item,
|
|
||||||
diag.ori_link,
|
|
||||||
diag.dox,
|
|
||||||
diag.link_range,
|
|
||||||
msg,
|
|
||||||
);
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1384,14 +1369,7 @@ impl LinkCollector<'_, '_> {
|
|||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
Err(ErrorKind::AnchorFailure(msg)) => {
|
Err(ErrorKind::AnchorFailure(msg)) => {
|
||||||
anchor_failure(
|
anchor_failure(self.cx, diag, msg);
|
||||||
self.cx,
|
|
||||||
diag.item,
|
|
||||||
diag.ori_link,
|
|
||||||
diag.dox,
|
|
||||||
diag.link_range,
|
|
||||||
msg,
|
|
||||||
);
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Err(ErrorKind::Resolve(box kind)) => Err(kind),
|
Err(ErrorKind::Resolve(box kind)) => Err(kind),
|
||||||
@ -1399,14 +1377,7 @@ impl LinkCollector<'_, '_> {
|
|||||||
value_ns: match self.resolve(path_str, ValueNS, base_node, extra_fragment) {
|
value_ns: match self.resolve(path_str, ValueNS, base_node, extra_fragment) {
|
||||||
Ok(res) => Ok(res),
|
Ok(res) => Ok(res),
|
||||||
Err(ErrorKind::AnchorFailure(msg)) => {
|
Err(ErrorKind::AnchorFailure(msg)) => {
|
||||||
anchor_failure(
|
anchor_failure(self.cx, diag, msg);
|
||||||
self.cx,
|
|
||||||
diag.item,
|
|
||||||
diag.ori_link,
|
|
||||||
diag.dox,
|
|
||||||
diag.link_range,
|
|
||||||
msg,
|
|
||||||
);
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Err(ErrorKind::Resolve(box kind)) => Err(kind),
|
Err(ErrorKind::Resolve(box kind)) => Err(kind),
|
||||||
@ -2004,10 +1975,7 @@ fn resolution_failure(
|
|||||||
/// Report an anchor failure.
|
/// Report an anchor failure.
|
||||||
fn anchor_failure(
|
fn anchor_failure(
|
||||||
cx: &DocContext<'_>,
|
cx: &DocContext<'_>,
|
||||||
item: &Item,
|
DiagnosticInfo { item, ori_link, dox, link_range }: DiagnosticInfo<'_>,
|
||||||
ori_link: &str,
|
|
||||||
dox: &str,
|
|
||||||
link_range: Range<usize>,
|
|
||||||
failure: AnchorFailure,
|
failure: AnchorFailure,
|
||||||
) {
|
) {
|
||||||
let msg = match failure {
|
let msg = match failure {
|
||||||
|
@ -43,3 +43,7 @@ pub fn enum_link() {}
|
|||||||
/// [u32#hello]
|
/// [u32#hello]
|
||||||
//~^ ERROR `u32#hello` contains an anchor
|
//~^ ERROR `u32#hello` contains an anchor
|
||||||
pub fn x() {}
|
pub fn x() {}
|
||||||
|
|
||||||
|
/// [prim@usize#x]
|
||||||
|
//~^ ERROR `prim@usize#x` contains an anchor
|
||||||
|
pub mod usize {}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
error: `Foo::f#hola` contains an anchor, but links to fields are already anchored
|
error: `prim@usize#x` contains an anchor, but links to builtin types are already anchored
|
||||||
--> $DIR/anchors.rs:25:15
|
--> $DIR/anchors.rs:47:6
|
||||||
|
|
|
|
||||||
LL | /// Or maybe [Foo::f#hola].
|
LL | /// [prim@usize#x]
|
||||||
| ^^^^^^^^^^^ contains invalid anchor
|
| ^^^^^^^^^^^^ contains invalid anchor
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/anchors.rs:1:9
|
--> $DIR/anchors.rs:1:9
|
||||||
@ -10,6 +10,12 @@ note: the lint level is defined here
|
|||||||
LL | #![deny(rustdoc::broken_intra_doc_links)]
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: `Foo::f#hola` contains an anchor, but links to fields are already anchored
|
||||||
|
--> $DIR/anchors.rs:25:15
|
||||||
|
|
|
||||||
|
LL | /// Or maybe [Foo::f#hola].
|
||||||
|
| ^^^^^^^^^^^ contains invalid anchor
|
||||||
|
|
||||||
error: `hello#people#!` contains multiple anchors
|
error: `hello#people#!` contains multiple anchors
|
||||||
--> $DIR/anchors.rs:31:28
|
--> $DIR/anchors.rs:31:28
|
||||||
|
|
|
|
||||||
@ -28,5 +34,5 @@ error: `u32#hello` contains an anchor, but links to builtin types are already an
|
|||||||
LL | /// [u32#hello]
|
LL | /// [u32#hello]
|
||||||
| ^^^^^^^^^ contains invalid anchor
|
| ^^^^^^^^^ contains invalid anchor
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user