Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ impl AttributeExt for Attribute {
}
}

fn deprecation_note(&self) -> Option<Symbol> {
fn deprecation_note(&self) -> Option<Ident> {
match &self.kind {
AttrKind::Normal(normal) if normal.item.path == sym::deprecated => {
let meta = &normal.item;

// #[deprecated = "..."]
if let Some(s) = meta.value_str() {
return Some(s);
return Some(Ident { name: s, span: meta.span() });
}

// #[deprecated(note = "...")]
Expand All @@ -252,7 +252,7 @@ impl AttributeExt for Attribute {
&& mi.path == sym::note
&& let Some(s) = mi.value_str()
{
return Some(s);
return Some(Ident { name: s, span: mi.span });
}
}
}
Expand Down Expand Up @@ -905,7 +905,7 @@ pub trait AttributeExt: Debug {
/// Returns the deprecation note if this is deprecation attribute.
/// * `#[deprecated = "note"]` returns `Some("note")`.
/// * `#[deprecated(note = "note", ...)]` returns `Some("note")`.
fn deprecation_note(&self) -> Option<Symbol>;
fn deprecation_note(&self) -> Option<Ident>;

fn is_proc_macro_attr(&self) -> bool {
[sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive]
Expand Down
22 changes: 14 additions & 8 deletions compiler/rustc_attr_parsing/src/attributes/deprecation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ fn get<S: Stage>(
name: Symbol,
param_span: Span,
arg: &ArgParser,
item: &Option<Symbol>,
) -> Option<Symbol> {
item: Option<Symbol>,
) -> Option<Ident> {
if item.is_some() {
cx.duplicate_key(param_span, name);
return None;
}
if let Some(v) = arg.name_value() {
if let Some(value_str) = v.value_as_str() {
if let Some(value_str) = v.value_as_ident() {
Some(value_str)
} else {
cx.expected_string_literal(v.value_span, Some(&v.value_as_lit()));
Expand Down Expand Up @@ -72,7 +72,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
let features = cx.features();

let mut since = None;
let mut note = None;
let mut note: Option<Ident> = None;
let mut suggestion = None;

let is_rustc = features.staged_api();
Expand All @@ -92,10 +92,16 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {

match ident_name {
Some(name @ sym::since) => {
since = Some(get(cx, name, param.span(), param.args(), &since)?);
since = Some(get(cx, name, param.span(), param.args(), since)?.name);
}
Some(name @ sym::note) => {
note = Some(get(cx, name, param.span(), param.args(), &note)?);
note = Some(get(
cx,
name,
param.span(),
param.args(),
note.map(|ident| ident.name),
)?);
}
Some(name @ sym::suggestion) => {
if !features.deprecated_suggestion() {
Expand All @@ -107,7 +113,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
}

suggestion =
Some(get(cx, name, param.span(), param.args(), &suggestion)?);
Some(get(cx, name, param.span(), param.args(), suggestion)?.name);
}
_ => {
cx.expected_specific_argument(
Expand All @@ -124,7 +130,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
}
}
ArgParser::NameValue(v) => {
let Some(value) = v.value_as_str() else {
let Some(value) = v.value_as_ident() else {
cx.expected_string_literal(v.value_span, Some(v.value_as_lit()));
return None;
};
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_attr_parsing/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ impl NameValueParser {
self.value_as_lit().kind.str()
}

/// If the value is a string literal, it will return its value associated with its span (an
/// `Ident` in short).
pub fn value_as_ident(&self) -> Option<Ident> {
let meta_item = self.value_as_lit();
meta_item.kind.str().map(|name| Ident { name, span: meta_item.span })
}

pub fn args_span(&self) -> Span {
self.eq_span.to(self.value_span)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/attrs/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub enum IntType {
pub struct Deprecation {
pub since: DeprecatedSince,
/// The note to issue a reason.
pub note: Option<Symbol>,
pub note: Option<Ident>,
/// A text snippet used to completely replace any use of the deprecated item in an expression.
///
/// This is currently unstable.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ impl AttributeExt for Attribute {
}

#[inline]
fn deprecation_note(&self) -> Option<Symbol> {
fn deprecation_note(&self) -> Option<Ident> {
match &self {
Attribute::Parsed(AttributeKind::Deprecation { deprecation, .. }) => deprecation.note,
_ => None,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub fn early_report_macro_deprecation(
let diag = BuiltinLintDiag::DeprecatedMacro {
suggestion: depr.suggestion,
suggestion_span: span,
note: depr.note,
note: depr.note.map(|ident| ident.name),
path,
since_kind: deprecated_since_kind(is_in_effect, depr.since),
};
Expand Down Expand Up @@ -228,7 +228,7 @@ fn late_report_deprecation(
}),
kind: def_kind.to_owned(),
path: def_path,
note: depr.note,
note: depr.note.map(|ident| ident.name),
since_kind: deprecated_since_kind(is_in_effect, depr.since),
};
tcx.emit_node_span_lint(lint, hir_id, method_span, diag);
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_resolve::rustdoc::{
use rustc_session::Session;
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{Symbol, kw, sym};
use rustc_span::{DUMMY_SP, FileName, Loc, RemapPathScopeComponents};
use rustc_span::{DUMMY_SP, FileName, Ident, Loc, RemapPathScopeComponents};
use tracing::{debug, trace};
use {rustc_ast as ast, rustc_hir as hir};

Expand Down Expand Up @@ -418,7 +418,7 @@ impl Item {
{
Some(Deprecation {
since: DeprecatedSince::Unspecified,
note: Some(note),
note: Some(Ident { name: note, span: DUMMY_SP }),
suggestion: None,
})
} else {
Expand Down Expand Up @@ -455,7 +455,7 @@ impl Item {
.attrs
.other_attrs
.iter()
.filter_map(|attr| attr.deprecation_note().map(|_| attr.span()));
.filter_map(|attr| attr.deprecation_note().map(|note| note.span));

span_of_fragments(&self.attrs.doc_strings)
.into_iter()
Expand Down
12 changes: 6 additions & 6 deletions tests/rustdoc-ui/intra-doc/deprecated.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unresolved link to `TypeAlias::hoge`
--> $DIR/deprecated.rs:3:1
--> $DIR/deprecated.rs:3:16
|
LL | #[deprecated = "[broken cross-reference](TypeAlias::hoge)"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the link appears in this line:

Expand All @@ -16,10 +16,10 @@ LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: unresolved link to `TypeAlias::hoge`
--> $DIR/deprecated.rs:6:1
--> $DIR/deprecated.rs:6:38
|
LL | #[deprecated(since = "0.0.0", note = "[broken cross-reference](TypeAlias::hoge)")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the link appears in this line:

Expand All @@ -28,10 +28,10 @@ LL | #[deprecated(since = "0.0.0", note = "[broken cross-reference](TypeAlias::h
= note: no item named `TypeAlias` in scope

error: unresolved link to `TypeAlias::hoge`
--> $DIR/deprecated.rs:9:1
--> $DIR/deprecated.rs:9:21
|
LL | #[deprecated(note = "[broken cross-reference](TypeAlias::hoge)", since = "0.0.0")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the link appears in this line:

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/unpretty/deprecated-attr.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ use ::std::prelude::rust_2015::*;
struct PlainDeprecated;

#[attr = Deprecation {deprecation: Deprecation {since: Unspecified,
note: "here's why this is deprecated"}}]
note: here's why this is deprecated#0}}]
struct DirectNote;

#[attr = Deprecation {deprecation: Deprecation {since: Unspecified,
note: "here's why this is deprecated"}}]
note: here's why this is deprecated#0}}]
struct ExplicitNote;

#[attr = Deprecation {deprecation: Deprecation {since: NonStandard("1.2.3"),
note: "here's why this is deprecated"}}]
note: here's why this is deprecated#0}}]
struct SinceAndNote;

#[attr = Deprecation {deprecation: Deprecation {since: NonStandard("1.2.3"),
note: "here's why this is deprecated"}}]
note: here's why this is deprecated#0}}]
struct FlippedOrder;

fn f() {
Expand Down
Loading