diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index 09ef6dc18814..e4a55bf39333 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -504,6 +504,16 @@ pub struct CfgInfo { pub value: Option<(Symbol, Span)>, } +impl CfgInfo { + pub fn span_for_name_and_value(&self) -> Span { + if let Some((_, value_span)) = self.value { + self.name_span.with_hi(value_span.hi()) + } else { + self.name_span + } + } +} + #[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] pub struct CfgHideShow { pub kind: HideOrShow, diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index 6cad4301b313..1413f7f56c96 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -47,7 +47,7 @@ fn is_simple_cfg(cfg: &CfgEntry) -> bool { } } -/// Whether the configuration consists of just `Cfg`, `Not` or `All`. +/// Returns `false` if is `Any`, otherwise returns `true`. fn is_all_cfg(cfg: &CfgEntry) -> bool { match cfg { CfgEntry::Bool(..) @@ -756,7 +756,6 @@ fn handle_auto_cfg_hide_show( tcx: TyCtxt<'_>, cfg_info: &mut CfgInfo, attr: &CfgHideShow, - attr_span: Span, new_show_attrs: &mut FxHashMap<(Symbol, Option), rustc_span::Span>, new_hide_attrs: &mut FxHashMap<(Symbol, Option), rustc_span::Span>, ) { @@ -764,16 +763,16 @@ fn handle_auto_cfg_hide_show( let simple = NameValueCfg::from(value); if attr.kind == HideOrShow::Show { if let Some(span) = new_hide_attrs.get(&(simple.name, simple.value)) { - show_hide_show_conflict_error(tcx, attr_span, *span); + show_hide_show_conflict_error(tcx, value.span_for_name_and_value(), *span); } else { - new_show_attrs.insert((simple.name, simple.value), attr_span); + new_show_attrs.insert((simple.name, simple.value), value.span_for_name_and_value()); } cfg_info.hidden_cfg.remove(&simple); } else { if let Some(span) = new_show_attrs.get(&(simple.name, simple.value)) { - show_hide_show_conflict_error(tcx, attr_span, *span); + show_hide_show_conflict_error(tcx, value.span_for_name_and_value(), *span); } else { - new_hide_attrs.insert((simple.name, simple.value), attr_span); + new_hide_attrs.insert((simple.name, simple.value), value.span_for_name_and_value()); } cfg_info.hidden_cfg.insert(simple); } @@ -871,12 +870,11 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator ) { return None; } - for (value, span) in &d.auto_cfg { + for (value, _) in &d.auto_cfg { handle_auto_cfg_hide_show( tcx, cfg_info, value, - *span, &mut new_show_attrs, &mut new_hide_attrs, ); diff --git a/tests/rustdoc-ui/cfg-hide-show-conflict.stderr b/tests/rustdoc-ui/cfg-hide-show-conflict.stderr index 384a9f1a0b1f..22231e82cd7b 100644 --- a/tests/rustdoc-ui/cfg-hide-show-conflict.stderr +++ b/tests/rustdoc-ui/cfg-hide-show-conflict.stderr @@ -1,14 +1,14 @@ error: same `cfg` was in `auto_cfg(hide(...))` and `auto_cfg(show(...))` on the same item - --> $DIR/cfg-hide-show-conflict.rs:3:8 + --> $DIR/cfg-hide-show-conflict.rs:3:31 | LL | #![doc(auto_cfg(show(windows, target_os = "linux")))] - | ^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ | note: first change was here - --> $DIR/cfg-hide-show-conflict.rs:2:8 + --> $DIR/cfg-hide-show-conflict.rs:2:22 | LL | #![doc(auto_cfg(hide(target_os = "linux")))] - | ^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error