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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -4026,7 +4026,6 @@ name = "rustc_expand"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr_ir",
"rustc_attr_parsing",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::node_id::NodeMap;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{self as ast, *};
use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
Expand DownExpand Up@@ -1231,7 +1231,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs,
target_span,
target,
OmitDoc::Lower,
|s| l.lower(s),
|lint_id, span, kind| {
self.delayed_lints.push(DelayedLint {
Expand Down
34 changes: 3 additions & 31 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,10 +46,6 @@ macro_rules! gate_multi {
}};
}

pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
PostExpansionVisitor { sess, features }.visit_attribute(attr)
}

struct PostExpansionVisitor<'a> {
sess: &'a Session,

Expand DownExpand Up@@ -152,33 +148,9 @@ impl<'a> PostExpansionVisitor<'a> {
}

impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_attribute(&mut self, attr: &ast::Attribute) {
// Check unstable flavors of the `#[doc]` attribute.
if attr.has_name(sym::doc) {
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($s:literal { $($name:ident => $feature:ident)* })*) => {
$($(if meta_item_inner.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
gate!(self, $feature, attr.span, msg);
})*)*
}}

gate_doc!(
"experimental" {
cfg => doc_cfg
auto_cfg => doc_cfg
masked => doc_masked
notable_trait => doc_notable_trait
}
"meant for internal use only" {
attribute => rustdoc_internals
keyword => rustdoc_internals
fake_variadic => rustdoc_internals
search_unbox => rustdoc_internals
}
);
}
}
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
// Checked in attribute parsers, do NOT add checks here
visit::walk_attribute(self, attr)
}

fn visit_item(&mut self, i: &'a ast::Item) {
Expand Down
102 changes: 63 additions & 39 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,10 +5,9 @@ use rustc_attr_ir::{
DocInline, HideOrShow,
};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, IndexEntry};
use rustc_errors::{Applicability, msg};
use rustc_errors::Applicability;
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::{INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES};
use rustc_session::diagnostics::feature_err;
use rustc_span::{Span, Symbol, edition, sym};

use super::prelude::{ALL_TARGETS, AllowedTargets};
Expand DownExpand Up@@ -526,19 +525,15 @@ impl DocParser {
}
macro_rules! no_args_and_crate_level {
($ident: ident) => {{
no_args_and_crate_level!($ident, |span| {});
}};
($ident: ident, |$span:ident| $extra_validation:block) => {{
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
let $span = path.span();
if !check_attr_crate_level(cx, $span) {
let span = path.span();
if !check_attr_crate_level(cx, span) {
return;
}
$extra_validation
self.attribute.$ident = Some($span);
self.attribute.$ident = Some(span);
}};
}
macro_rules! string_arg_and_crate_level {
Expand DownExpand Up@@ -569,6 +564,12 @@ impl DocParser {
self.attribute.$ident = Some((s, path.span()));
}};
}
macro_rules! gated {
($feature:ident $(,$notes:expr)*) => {
let stability = $crate::unstable!($feature $(, $notes)*);
cx.shared.cx.check_attribute_stability(&cx.attr_path, path.span(), stability);
};
}

match path.word_sym() {
Some(sym::alias) => self.parse_alias(cx, path, args),
Expand All@@ -583,37 +584,60 @@ impl DocParser {
}
Some(sym::inline) => self.parse_inline(cx, path, args, DocInline::Inline),
Some(sym::no_inline) => self.parse_inline(cx, path, args, DocInline::NoInline),
Some(sym::masked) => no_args!(masked),
Some(sym::cfg) => self.parse_cfg(cx, args),
Some(sym::notable_trait) => no_args!(notable_trait),
Some(sym::keyword) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
),
Some(sym::attribute) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
),
Some(sym::fake_variadic) => no_args_and_not_crate_level!(fake_variadic),
Some(sym::search_unbox) => no_args_and_not_crate_level!(search_unbox),
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo, |span| {
if !cx.features().rustdoc_internals() {
feature_err(
cx.sess(),
sym::rustdoc_internals,
span,
msg!("the `#[doc(rust_logo)]` attribute is used for Rust branding"),
)
.emit();
Some(sym::masked) => {
gated!(doc_masked);
no_args!(masked)
}
Some(sym::cfg) => {
gated!(doc_cfg);
self.parse_cfg(cx, args)
}
Some(sym::notable_trait) => {
gated!(doc_notable_trait);
no_args!(notable_trait)
}
Some(sym::keyword) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
)
}
Some(sym::attribute) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
)
}
Some(sym::fake_variadic) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(fake_variadic)
}
Some(sym::search_unbox) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(search_unbox)
}
Some(sym::rust_logo) => {
// FIXME: Only feature gated at the crate level (!!)
if cx.target == Target::Crate {
gated!(
rustdoc_internals,
"the `#[doc(rust_logo)]` attribute is used for Rust branding"
);
}
}),
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
no_args_and_crate_level!(rust_logo)
}
Some(sym::auto_cfg) => {
gated!(doc_cfg);
self.parse_auto_cfg(cx, path, args)
}
Some(sym::test) => {
let Some(list) = args.as_list() else {
cx.emit_lint(
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -864,12 +864,6 @@ impl<'p, 'sess: 'p> DerefMut for SharedContext<'p, 'sess> {
}
}

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum OmitDoc {
Lower,
Skip,
}

#[derive(Copy, Clone, Debug)]
pub enum ShouldEmit {
/// The operations will emit errors, and lints, and errors are fatal.
Expand Down
31 changes: 14 additions & 17 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ use crate::context::{
use crate::diagnostics::ParsedDescription;
use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser};
use crate::synthetic::SyntheticAttrState;
use crate::{AttributeTemplate, OmitDoc, ShouldEmit};
use crate::{AttributeTemplate, ShouldEmit};

pub struct EmitAttribute(
pub Box<
Expand DownExpand Up@@ -161,7 +161,6 @@ impl<'sess> AttributeParser<'sess> {
attrs,
target_span,
target,
OmitDoc::Skip,
std::convert::identity,
|lint_id, span, kind| {
sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0)
Expand DownExpand Up@@ -310,14 +309,12 @@ impl<'sess> AttributeParser<'sess> {

/// Parse a list of attributes.
///
/// `target_span` is the span of the thing this list of attributes is applied to,
/// and when `omit_doc` is set, doc attributes are filtered out.
/// `target_span` is the span of the thing this list of attributes is applied to.
pub fn parse_attribute_list(
&mut self,
attrs: &[ast::Attribute],
target_span: Span,
target: Target,
omit_doc: OmitDoc,
lower_span: impl Copy + Fn(Span) -> Span,
mut emit_lint: impl FnMut(LintId, MultiSpan, EmitAttribute),
) -> Vec<Attribute> {
Expand All@@ -335,23 +332,23 @@ impl<'sess> AttributeParser<'sess> {
}
}

// Sometimes, for example for `#![doc = include_str!("readme.md")]`,
// doc still contains a non-literal. You might say, when we're lowering attributes
// that's expanded right? But no, sometimes, when parsing attributes on macros,
// we already use the lowering logic and these are still there. So, when `omit_doc`
// is set we *also* want to ignore these.
let is_doc_attribute = attr.has_name(sym::doc);
if omit_doc == OmitDoc::Skip && is_doc_attribute {
fn is_doc_non_lit_expr(attr: &ast::Attribute) -> bool {
if !attr.has_name(sym::doc) {
return false;
}
let ast::AttrKind::Normal(n) = &attr.kind else { return false };
let ast::AttrArgs::Eq { expr, .. } = &n.item.args else { return false };
!matches!(expr.kind, ast::ExprKind::Lit(_))
}

// FIXME accidentally allowed on Stable Rust
if target == Target::MacroCall && is_doc_non_lit_expr(attr) {
continue;
}

let attr_span = lower_span(attr.span);
match &attr.kind {
ast::AttrKind::DocComment(comment_kind, symbol) => {
if omit_doc == OmitDoc::Skip {
continue;
}

attributes.push(Attribute::Parsed(AttributeKind::DocComment {
style: attr.style,
kind: DocFragmentKind::Sugared(*comment_kind),
Expand DownExpand Up@@ -407,7 +404,7 @@ impl<'sess> AttributeParser<'sess> {
// bla
// blob
// a
if is_doc_attribute
if attr.has_name(sym::doc)
&& let ArgParser::NameValue(nv) = &args
// If not a string key/value, it should emit an error, but to make
// things simpler, it's handled in `DocParser` because it's simpler to
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,7 +116,7 @@ pub use attributes::cfg::{
};
pub use attributes::cfg_select::*;
pub use attributes::util::{is_builtin_attr, parse_version};
pub use context::{OmitDoc, ShouldEmit};
pub use context::ShouldEmit;
pub use diagnostics::ParsedDescription;
pub use interface::{AttributeParser, EmitAttribute};
pub use rustc_parse::parser::Recovery;
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_attr_parsing/src/stability.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,10 +53,24 @@ impl<'sess> AttributeParser<'sess> {
sym::prelude_import => ("the `prelude_import` attribute is for use by rustc only".to_string(), &[]),
sym::profiler_runtime => ("the `profiler_runtime` attribute is used to identify the `profiler_builtins` crate which contains the profiler runtime and will never be stable".to_string(), &[]),
sym::thread_local => ("the `thread_local` attribute is an experimental feature, and does not currently handle destructors".to_string(), &[]),
sym::rustdoc_internals => ("this subset of the `doc` attribute is meant for internal use only".to_string(), &[]),
sym::doc_notable_trait => ("the `doc(notable_trait)` attribute is experimental".to_string(), &[]),
sym::doc_cfg => ("the `doc(cfg)` and `doc(auto_cfg)` attributes are experimental".to_string(), &[]),
sym::doc_masked => ("the `doc(masked)` attribute is experimental".to_string(), &[]),
_ => (format!("the `{attr_path}` attribute is an experimental feature"), &[]),
};

let mut diag = feature_err(self.sess, gate_name, attr_path.span, explain);
// For unstable subsets of an attribute, point at that
let err_span = if matches!(
gate_name,
sym::rustdoc_internals | sym::doc_notable_trait | sym::doc_cfg | sym::doc_masked
) {
attr_span
} else {
attr_path.span
};

let mut diag = feature_err(self.sess, gate_name, err_span, explain);

// Remove the suggestion for `#![feature(staged_api)]` as these attributes are currently
// not usable outside std. If we do ever expose `#[stable]` etc under a different feature
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_expand/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@ doctest = false
[dependencies]
# tidy-alphabetical-start
rustc_ast = { path = "../rustc_ast" }
rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_expand/src/expand.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2245,15 +2245,13 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
attr
}

// Detect use of feature-gated or invalid attributes on macro invocations
// Run attributes through the attribute parser
// since they will not be detected after macro expansion.
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
use SyntheticAttr::*;
let features = self.cx.ecfg.features;
let mut attrs = attrs.iter().peekable();
let mut span: Option<Span> = None;
while let Some(attr) = attrs.next() {
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
validate_attr::check_attr(&self.cx.sess.psess, attr);
AttributeParser::parse_limited_all(
self.cx.sess,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -257,8 +257,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
sym::fundamental,
sym::may_dangle,

sym::rustc_never_type_options,

// ==========================================================================
// Internal attributes: Runtime related:
// ==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2468,7 +2468,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}

let lint_ambiguous = match probes[0].0.kind {
let lint_ambiguous = match child_candidate.kind {
TraitCandidate(_, lint) => lint,
_ => false,
};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ use std::mem;
use rustc_ast::visit::FnKind;
use rustc_ast::*;
use rustc_attr_parsing as attr;
use rustc_attr_parsing::{AttributeParser, OmitDoc, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, ShouldEmit};
use rustc_expand::expand::AstFragment;
use rustc_hir as hir;
use rustc_hir::Target;
Expand DownExpand Up@@ -187,7 +187,6 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
&i.attrs,
i.span,
Target::MacroDef,
OmitDoc::Skip,
std::convert::identity,
|_lint_id, _span, _kind| {
// FIXME(jdonszelmann): emit lints here properly
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Rollup of 7 pull requests by GuillaumeGomez · Pull Request #161990 · rust-lang/rust · GitHub
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -4026,7 +4026,6 @@ name = "rustc_expand"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr_ir",
"rustc_attr_parsing",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::node_id::NodeMap;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{self as ast, *};
use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
Expand DownExpand Up@@ -1231,7 +1231,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs,
target_span,
target,
OmitDoc::Lower,
|s| l.lower(s),
|lint_id, span, kind| {
self.delayed_lints.push(DelayedLint {
Expand Down
34 changes: 3 additions & 31 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,10 +46,6 @@ macro_rules! gate_multi {
}};
}

pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
PostExpansionVisitor { sess, features }.visit_attribute(attr)
}

struct PostExpansionVisitor<'a> {
sess: &'a Session,

Expand DownExpand Up@@ -152,33 +148,9 @@ impl<'a> PostExpansionVisitor<'a> {
}

impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_attribute(&mut self, attr: &ast::Attribute) {
// Check unstable flavors of the `#[doc]` attribute.
if attr.has_name(sym::doc) {
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($s:literal { $($name:ident => $feature:ident)* })*) => {
$($(if meta_item_inner.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
gate!(self, $feature, attr.span, msg);
})*)*
}}

gate_doc!(
"experimental" {
cfg => doc_cfg
auto_cfg => doc_cfg
masked => doc_masked
notable_trait => doc_notable_trait
}
"meant for internal use only" {
attribute => rustdoc_internals
keyword => rustdoc_internals
fake_variadic => rustdoc_internals
search_unbox => rustdoc_internals
}
);
}
}
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
// Checked in attribute parsers, do NOT add checks here
visit::walk_attribute(self, attr)
}

fn visit_item(&mut self, i: &'a ast::Item) {
Expand Down
102 changes: 63 additions & 39 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,10 +5,9 @@ use rustc_attr_ir::{
DocInline, HideOrShow,
};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, IndexEntry};
use rustc_errors::{Applicability, msg};
use rustc_errors::Applicability;
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::{INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES};
use rustc_session::diagnostics::feature_err;
use rustc_span::{Span, Symbol, edition, sym};

use super::prelude::{ALL_TARGETS, AllowedTargets};
Expand DownExpand Up@@ -526,19 +525,15 @@ impl DocParser {
}
macro_rules! no_args_and_crate_level {
($ident: ident) => {{
no_args_and_crate_level!($ident, |span| {});
}};
($ident: ident, |$span:ident| $extra_validation:block) => {{
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
let $span = path.span();
if !check_attr_crate_level(cx, $span) {
let span = path.span();
if !check_attr_crate_level(cx, span) {
return;
}
$extra_validation
self.attribute.$ident = Some($span);
self.attribute.$ident = Some(span);
}};
}
macro_rules! string_arg_and_crate_level {
Expand DownExpand Up@@ -569,6 +564,12 @@ impl DocParser {
self.attribute.$ident = Some((s, path.span()));
}};
}
macro_rules! gated {
($feature:ident $(,$notes:expr)*) => {
let stability = $crate::unstable!($feature $(, $notes)*);
cx.shared.cx.check_attribute_stability(&cx.attr_path, path.span(), stability);
};
}

match path.word_sym() {
Some(sym::alias) => self.parse_alias(cx, path, args),
Expand All@@ -583,37 +584,60 @@ impl DocParser {
}
Some(sym::inline) => self.parse_inline(cx, path, args, DocInline::Inline),
Some(sym::no_inline) => self.parse_inline(cx, path, args, DocInline::NoInline),
Some(sym::masked) => no_args!(masked),
Some(sym::cfg) => self.parse_cfg(cx, args),
Some(sym::notable_trait) => no_args!(notable_trait),
Some(sym::keyword) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
),
Some(sym::attribute) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
),
Some(sym::fake_variadic) => no_args_and_not_crate_level!(fake_variadic),
Some(sym::search_unbox) => no_args_and_not_crate_level!(search_unbox),
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo, |span| {
if !cx.features().rustdoc_internals() {
feature_err(
cx.sess(),
sym::rustdoc_internals,
span,
msg!("the `#[doc(rust_logo)]` attribute is used for Rust branding"),
)
.emit();
Some(sym::masked) => {
gated!(doc_masked);
no_args!(masked)
}
Some(sym::cfg) => {
gated!(doc_cfg);
self.parse_cfg(cx, args)
}
Some(sym::notable_trait) => {
gated!(doc_notable_trait);
no_args!(notable_trait)
}
Some(sym::keyword) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
)
}
Some(sym::attribute) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
)
}
Some(sym::fake_variadic) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(fake_variadic)
}
Some(sym::search_unbox) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(search_unbox)
}
Some(sym::rust_logo) => {
// FIXME: Only feature gated at the crate level (!!)
if cx.target == Target::Crate {
gated!(
rustdoc_internals,
"the `#[doc(rust_logo)]` attribute is used for Rust branding"
);
}
}),
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
no_args_and_crate_level!(rust_logo)
}
Some(sym::auto_cfg) => {
gated!(doc_cfg);
self.parse_auto_cfg(cx, path, args)
}
Some(sym::test) => {
let Some(list) = args.as_list() else {
cx.emit_lint(
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -864,12 +864,6 @@ impl<'p, 'sess: 'p> DerefMut for SharedContext<'p, 'sess> {
}
}

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum OmitDoc {
Lower,
Skip,
}

#[derive(Copy, Clone, Debug)]
pub enum ShouldEmit {
/// The operations will emit errors, and lints, and errors are fatal.
Expand Down
31 changes: 14 additions & 17 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ use crate::context::{
use crate::diagnostics::ParsedDescription;
use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser};
use crate::synthetic::SyntheticAttrState;
use crate::{AttributeTemplate, OmitDoc, ShouldEmit};
use crate::{AttributeTemplate, ShouldEmit};

pub struct EmitAttribute(
pub Box<
Expand DownExpand Up@@ -161,7 +161,6 @@ impl<'sess> AttributeParser<'sess> {
attrs,
target_span,
target,
OmitDoc::Skip,
std::convert::identity,
|lint_id, span, kind| {
sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0)
Expand DownExpand Up@@ -310,14 +309,12 @@ impl<'sess> AttributeParser<'sess> {

/// Parse a list of attributes.
///
/// `target_span` is the span of the thing this list of attributes is applied to,
/// and when `omit_doc` is set, doc attributes are filtered out.
/// `target_span` is the span of the thing this list of attributes is applied to.
pub fn parse_attribute_list(
&mut self,
attrs: &[ast::Attribute],
target_span: Span,
target: Target,
omit_doc: OmitDoc,
lower_span: impl Copy + Fn(Span) -> Span,
mut emit_lint: impl FnMut(LintId, MultiSpan, EmitAttribute),
) -> Vec<Attribute> {
Expand All@@ -335,23 +332,23 @@ impl<'sess> AttributeParser<'sess> {
}
}

// Sometimes, for example for `#![doc = include_str!("readme.md")]`,
// doc still contains a non-literal. You might say, when we're lowering attributes
// that's expanded right? But no, sometimes, when parsing attributes on macros,
// we already use the lowering logic and these are still there. So, when `omit_doc`
// is set we *also* want to ignore these.
let is_doc_attribute = attr.has_name(sym::doc);
if omit_doc == OmitDoc::Skip && is_doc_attribute {
fn is_doc_non_lit_expr(attr: &ast::Attribute) -> bool {
if !attr.has_name(sym::doc) {
return false;
}
let ast::AttrKind::Normal(n) = &attr.kind else { return false };
let ast::AttrArgs::Eq { expr, .. } = &n.item.args else { return false };
!matches!(expr.kind, ast::ExprKind::Lit(_))
}

// FIXME accidentally allowed on Stable Rust
if target == Target::MacroCall && is_doc_non_lit_expr(attr) {
continue;
}

let attr_span = lower_span(attr.span);
match &attr.kind {
ast::AttrKind::DocComment(comment_kind, symbol) => {
if omit_doc == OmitDoc::Skip {
continue;
}

attributes.push(Attribute::Parsed(AttributeKind::DocComment {
style: attr.style,
kind: DocFragmentKind::Sugared(*comment_kind),
Expand DownExpand Up@@ -407,7 +404,7 @@ impl<'sess> AttributeParser<'sess> {
// bla
// blob
// a
if is_doc_attribute
if attr.has_name(sym::doc)
&& let ArgParser::NameValue(nv) = &args
// If not a string key/value, it should emit an error, but to make
// things simpler, it's handled in `DocParser` because it's simpler to
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,7 +116,7 @@ pub use attributes::cfg::{
};
pub use attributes::cfg_select::*;
pub use attributes::util::{is_builtin_attr, parse_version};
pub use context::{OmitDoc, ShouldEmit};
pub use context::ShouldEmit;
pub use diagnostics::ParsedDescription;
pub use interface::{AttributeParser, EmitAttribute};
pub use rustc_parse::parser::Recovery;
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_attr_parsing/src/stability.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,10 +53,24 @@ impl<'sess> AttributeParser<'sess> {
sym::prelude_import => ("the `prelude_import` attribute is for use by rustc only".to_string(), &[]),
sym::profiler_runtime => ("the `profiler_runtime` attribute is used to identify the `profiler_builtins` crate which contains the profiler runtime and will never be stable".to_string(), &[]),
sym::thread_local => ("the `thread_local` attribute is an experimental feature, and does not currently handle destructors".to_string(), &[]),
sym::rustdoc_internals => ("this subset of the `doc` attribute is meant for internal use only".to_string(), &[]),
sym::doc_notable_trait => ("the `doc(notable_trait)` attribute is experimental".to_string(), &[]),
sym::doc_cfg => ("the `doc(cfg)` and `doc(auto_cfg)` attributes are experimental".to_string(), &[]),
sym::doc_masked => ("the `doc(masked)` attribute is experimental".to_string(), &[]),
_ => (format!("the `{attr_path}` attribute is an experimental feature"), &[]),
};

let mut diag = feature_err(self.sess, gate_name, attr_path.span, explain);
// For unstable subsets of an attribute, point at that
let err_span = if matches!(
gate_name,
sym::rustdoc_internals | sym::doc_notable_trait | sym::doc_cfg | sym::doc_masked
) {
attr_span
} else {
attr_path.span
};

let mut diag = feature_err(self.sess, gate_name, err_span, explain);

// Remove the suggestion for `#![feature(staged_api)]` as these attributes are currently
// not usable outside std. If we do ever expose `#[stable]` etc under a different feature
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_expand/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@ doctest = false
[dependencies]
# tidy-alphabetical-start
rustc_ast = { path = "../rustc_ast" }
rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_expand/src/expand.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2245,15 +2245,13 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
attr
}

// Detect use of feature-gated or invalid attributes on macro invocations
// Run attributes through the attribute parser
// since they will not be detected after macro expansion.
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
use SyntheticAttr::*;
let features = self.cx.ecfg.features;
let mut attrs = attrs.iter().peekable();
let mut span: Option<Span> = None;
while let Some(attr) = attrs.next() {
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
validate_attr::check_attr(&self.cx.sess.psess, attr);
AttributeParser::parse_limited_all(
self.cx.sess,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -257,8 +257,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
sym::fundamental,
sym::may_dangle,

sym::rustc_never_type_options,

// ==========================================================================
// Internal attributes: Runtime related:
// ==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2468,7 +2468,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}

let lint_ambiguous = match probes[0].0.kind {
let lint_ambiguous = match child_candidate.kind {
TraitCandidate(_, lint) => lint,
_ => false,
};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ use std::mem;
use rustc_ast::visit::FnKind;
use rustc_ast::*;
use rustc_attr_parsing as attr;
use rustc_attr_parsing::{AttributeParser, OmitDoc, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, ShouldEmit};
use rustc_expand::expand::AstFragment;
use rustc_hir as hir;
use rustc_hir::Target;
Expand DownExpand Up@@ -187,7 +187,6 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
&i.attrs,
i.span,
Target::MacroDef,
OmitDoc::Skip,
std::convert::identity,
|_lint_id, _span, _kind| {
// FIXME(jdonszelmann): emit lints here properly
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Rollup of 7 pull requests by GuillaumeGomez · Pull Request #161990 · rust-lang/rust · GitHub
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -4026,7 +4026,6 @@ name = "rustc_expand"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr_ir",
"rustc_attr_parsing",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::node_id::NodeMap;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{self as ast, *};
use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
Expand DownExpand Up@@ -1231,7 +1231,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs,
target_span,
target,
OmitDoc::Lower,
|s| l.lower(s),
|lint_id, span, kind| {
self.delayed_lints.push(DelayedLint {
Expand Down
34 changes: 3 additions & 31 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,10 +46,6 @@ macro_rules! gate_multi {
}};
}

pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
PostExpansionVisitor { sess, features }.visit_attribute(attr)
}

struct PostExpansionVisitor<'a> {
sess: &'a Session,

Expand DownExpand Up@@ -152,33 +148,9 @@ impl<'a> PostExpansionVisitor<'a> {
}

impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_attribute(&mut self, attr: &ast::Attribute) {
// Check unstable flavors of the `#[doc]` attribute.
if attr.has_name(sym::doc) {
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($s:literal { $($name:ident => $feature:ident)* })*) => {
$($(if meta_item_inner.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
gate!(self, $feature, attr.span, msg);
})*)*
}}

gate_doc!(
"experimental" {
cfg => doc_cfg
auto_cfg => doc_cfg
masked => doc_masked
notable_trait => doc_notable_trait
}
"meant for internal use only" {
attribute => rustdoc_internals
keyword => rustdoc_internals
fake_variadic => rustdoc_internals
search_unbox => rustdoc_internals
}
);
}
}
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
// Checked in attribute parsers, do NOT add checks here
visit::walk_attribute(self, attr)
}

fn visit_item(&mut self, i: &'a ast::Item) {
Expand Down
102 changes: 63 additions & 39 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,10 +5,9 @@ use rustc_attr_ir::{
DocInline, HideOrShow,
};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, IndexEntry};
use rustc_errors::{Applicability, msg};
use rustc_errors::Applicability;
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::{INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES};
use rustc_session::diagnostics::feature_err;
use rustc_span::{Span, Symbol, edition, sym};

use super::prelude::{ALL_TARGETS, AllowedTargets};
Expand DownExpand Up@@ -526,19 +525,15 @@ impl DocParser {
}
macro_rules! no_args_and_crate_level {
($ident: ident) => {{
no_args_and_crate_level!($ident, |span| {});
}};
($ident: ident, |$span:ident| $extra_validation:block) => {{
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
let $span = path.span();
if !check_attr_crate_level(cx, $span) {
let span = path.span();
if !check_attr_crate_level(cx, span) {
return;
}
$extra_validation
self.attribute.$ident = Some($span);
self.attribute.$ident = Some(span);
}};
}
macro_rules! string_arg_and_crate_level {
Expand DownExpand Up@@ -569,6 +564,12 @@ impl DocParser {
self.attribute.$ident = Some((s, path.span()));
}};
}
macro_rules! gated {
($feature:ident $(,$notes:expr)*) => {
let stability = $crate::unstable!($feature $(, $notes)*);
cx.shared.cx.check_attribute_stability(&cx.attr_path, path.span(), stability);
};
}

match path.word_sym() {
Some(sym::alias) => self.parse_alias(cx, path, args),
Expand All@@ -583,37 +584,60 @@ impl DocParser {
}
Some(sym::inline) => self.parse_inline(cx, path, args, DocInline::Inline),
Some(sym::no_inline) => self.parse_inline(cx, path, args, DocInline::NoInline),
Some(sym::masked) => no_args!(masked),
Some(sym::cfg) => self.parse_cfg(cx, args),
Some(sym::notable_trait) => no_args!(notable_trait),
Some(sym::keyword) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
),
Some(sym::attribute) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
),
Some(sym::fake_variadic) => no_args_and_not_crate_level!(fake_variadic),
Some(sym::search_unbox) => no_args_and_not_crate_level!(search_unbox),
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo, |span| {
if !cx.features().rustdoc_internals() {
feature_err(
cx.sess(),
sym::rustdoc_internals,
span,
msg!("the `#[doc(rust_logo)]` attribute is used for Rust branding"),
)
.emit();
Some(sym::masked) => {
gated!(doc_masked);
no_args!(masked)
}
Some(sym::cfg) => {
gated!(doc_cfg);
self.parse_cfg(cx, args)
}
Some(sym::notable_trait) => {
gated!(doc_notable_trait);
no_args!(notable_trait)
}
Some(sym::keyword) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
)
}
Some(sym::attribute) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
)
}
Some(sym::fake_variadic) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(fake_variadic)
}
Some(sym::search_unbox) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(search_unbox)
}
Some(sym::rust_logo) => {
// FIXME: Only feature gated at the crate level (!!)
if cx.target == Target::Crate {
gated!(
rustdoc_internals,
"the `#[doc(rust_logo)]` attribute is used for Rust branding"
);
}
}),
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
no_args_and_crate_level!(rust_logo)
}
Some(sym::auto_cfg) => {
gated!(doc_cfg);
self.parse_auto_cfg(cx, path, args)
}
Some(sym::test) => {
let Some(list) = args.as_list() else {
cx.emit_lint(
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -864,12 +864,6 @@ impl<'p, 'sess: 'p> DerefMut for SharedContext<'p, 'sess> {
}
}

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum OmitDoc {
Lower,
Skip,
}

#[derive(Copy, Clone, Debug)]
pub enum ShouldEmit {
/// The operations will emit errors, and lints, and errors are fatal.
Expand Down
31 changes: 14 additions & 17 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ use crate::context::{
use crate::diagnostics::ParsedDescription;
use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser};
use crate::synthetic::SyntheticAttrState;
use crate::{AttributeTemplate, OmitDoc, ShouldEmit};
use crate::{AttributeTemplate, ShouldEmit};

pub struct EmitAttribute(
pub Box<
Expand DownExpand Up@@ -161,7 +161,6 @@ impl<'sess> AttributeParser<'sess> {
attrs,
target_span,
target,
OmitDoc::Skip,
std::convert::identity,
|lint_id, span, kind| {
sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0)
Expand DownExpand Up@@ -310,14 +309,12 @@ impl<'sess> AttributeParser<'sess> {

/// Parse a list of attributes.
///
/// `target_span` is the span of the thing this list of attributes is applied to,
/// and when `omit_doc` is set, doc attributes are filtered out.
/// `target_span` is the span of the thing this list of attributes is applied to.
pub fn parse_attribute_list(
&mut self,
attrs: &[ast::Attribute],
target_span: Span,
target: Target,
omit_doc: OmitDoc,
lower_span: impl Copy + Fn(Span) -> Span,
mut emit_lint: impl FnMut(LintId, MultiSpan, EmitAttribute),
) -> Vec<Attribute> {
Expand All@@ -335,23 +332,23 @@ impl<'sess> AttributeParser<'sess> {
}
}

// Sometimes, for example for `#![doc = include_str!("readme.md")]`,
// doc still contains a non-literal. You might say, when we're lowering attributes
// that's expanded right? But no, sometimes, when parsing attributes on macros,
// we already use the lowering logic and these are still there. So, when `omit_doc`
// is set we *also* want to ignore these.
let is_doc_attribute = attr.has_name(sym::doc);
if omit_doc == OmitDoc::Skip && is_doc_attribute {
fn is_doc_non_lit_expr(attr: &ast::Attribute) -> bool {
if !attr.has_name(sym::doc) {
return false;
}
let ast::AttrKind::Normal(n) = &attr.kind else { return false };
let ast::AttrArgs::Eq { expr, .. } = &n.item.args else { return false };
!matches!(expr.kind, ast::ExprKind::Lit(_))
}

// FIXME accidentally allowed on Stable Rust
if target == Target::MacroCall && is_doc_non_lit_expr(attr) {
continue;
}

let attr_span = lower_span(attr.span);
match &attr.kind {
ast::AttrKind::DocComment(comment_kind, symbol) => {
if omit_doc == OmitDoc::Skip {
continue;
}

attributes.push(Attribute::Parsed(AttributeKind::DocComment {
style: attr.style,
kind: DocFragmentKind::Sugared(*comment_kind),
Expand DownExpand Up@@ -407,7 +404,7 @@ impl<'sess> AttributeParser<'sess> {
// bla
// blob
// a
if is_doc_attribute
if attr.has_name(sym::doc)
&& let ArgParser::NameValue(nv) = &args
// If not a string key/value, it should emit an error, but to make
// things simpler, it's handled in `DocParser` because it's simpler to
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,7 +116,7 @@ pub use attributes::cfg::{
};
pub use attributes::cfg_select::*;
pub use attributes::util::{is_builtin_attr, parse_version};
pub use context::{OmitDoc, ShouldEmit};
pub use context::ShouldEmit;
pub use diagnostics::ParsedDescription;
pub use interface::{AttributeParser, EmitAttribute};
pub use rustc_parse::parser::Recovery;
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_attr_parsing/src/stability.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,10 +53,24 @@ impl<'sess> AttributeParser<'sess> {
sym::prelude_import => ("the `prelude_import` attribute is for use by rustc only".to_string(), &[]),
sym::profiler_runtime => ("the `profiler_runtime` attribute is used to identify the `profiler_builtins` crate which contains the profiler runtime and will never be stable".to_string(), &[]),
sym::thread_local => ("the `thread_local` attribute is an experimental feature, and does not currently handle destructors".to_string(), &[]),
sym::rustdoc_internals => ("this subset of the `doc` attribute is meant for internal use only".to_string(), &[]),
sym::doc_notable_trait => ("the `doc(notable_trait)` attribute is experimental".to_string(), &[]),
sym::doc_cfg => ("the `doc(cfg)` and `doc(auto_cfg)` attributes are experimental".to_string(), &[]),
sym::doc_masked => ("the `doc(masked)` attribute is experimental".to_string(), &[]),
_ => (format!("the `{attr_path}` attribute is an experimental feature"), &[]),
};

let mut diag = feature_err(self.sess, gate_name, attr_path.span, explain);
// For unstable subsets of an attribute, point at that
let err_span = if matches!(
gate_name,
sym::rustdoc_internals | sym::doc_notable_trait | sym::doc_cfg | sym::doc_masked
) {
attr_span
} else {
attr_path.span
};

let mut diag = feature_err(self.sess, gate_name, err_span, explain);

// Remove the suggestion for `#![feature(staged_api)]` as these attributes are currently
// not usable outside std. If we do ever expose `#[stable]` etc under a different feature
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_expand/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@ doctest = false
[dependencies]
# tidy-alphabetical-start
rustc_ast = { path = "../rustc_ast" }
rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_expand/src/expand.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2245,15 +2245,13 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
attr
}

// Detect use of feature-gated or invalid attributes on macro invocations
// Run attributes through the attribute parser
// since they will not be detected after macro expansion.
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
use SyntheticAttr::*;
let features = self.cx.ecfg.features;
let mut attrs = attrs.iter().peekable();
let mut span: Option<Span> = None;
while let Some(attr) = attrs.next() {
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
validate_attr::check_attr(&self.cx.sess.psess, attr);
AttributeParser::parse_limited_all(
self.cx.sess,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -257,8 +257,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
sym::fundamental,
sym::may_dangle,

sym::rustc_never_type_options,

// ==========================================================================
// Internal attributes: Runtime related:
// ==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2468,7 +2468,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}

let lint_ambiguous = match probes[0].0.kind {
let lint_ambiguous = match child_candidate.kind {
TraitCandidate(_, lint) => lint,
_ => false,
};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ use std::mem;
use rustc_ast::visit::FnKind;
use rustc_ast::*;
use rustc_attr_parsing as attr;
use rustc_attr_parsing::{AttributeParser, OmitDoc, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, ShouldEmit};
use rustc_expand::expand::AstFragment;
use rustc_hir as hir;
use rustc_hir::Target;
Expand DownExpand Up@@ -187,7 +187,6 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
&i.attrs,
i.span,
Target::MacroDef,
OmitDoc::Skip,
std::convert::identity,
|_lint_id, _span, _kind| {
// FIXME(jdonszelmann): emit lints here properly
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Rollup of 7 pull requests by GuillaumeGomez · Pull Request #161990 · rust-lang/rust · GitHub
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -4026,7 +4026,6 @@ name = "rustc_expand"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr_ir",
"rustc_attr_parsing",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::node_id::NodeMap;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{self as ast, *};
use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
Expand DownExpand Up@@ -1231,7 +1231,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs,
target_span,
target,
OmitDoc::Lower,
|s| l.lower(s),
|lint_id, span, kind| {
self.delayed_lints.push(DelayedLint {
Expand Down
34 changes: 3 additions & 31 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,10 +46,6 @@ macro_rules! gate_multi {
}};
}

pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
PostExpansionVisitor { sess, features }.visit_attribute(attr)
}

struct PostExpansionVisitor<'a> {
sess: &'a Session,

Expand DownExpand Up@@ -152,33 +148,9 @@ impl<'a> PostExpansionVisitor<'a> {
}

impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_attribute(&mut self, attr: &ast::Attribute) {
// Check unstable flavors of the `#[doc]` attribute.
if attr.has_name(sym::doc) {
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($s:literal { $($name:ident => $feature:ident)* })*) => {
$($(if meta_item_inner.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
gate!(self, $feature, attr.span, msg);
})*)*
}}

gate_doc!(
"experimental" {
cfg => doc_cfg
auto_cfg => doc_cfg
masked => doc_masked
notable_trait => doc_notable_trait
}
"meant for internal use only" {
attribute => rustdoc_internals
keyword => rustdoc_internals
fake_variadic => rustdoc_internals
search_unbox => rustdoc_internals
}
);
}
}
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
// Checked in attribute parsers, do NOT add checks here
visit::walk_attribute(self, attr)
}

fn visit_item(&mut self, i: &'a ast::Item) {
Expand Down
102 changes: 63 additions & 39 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,10 +5,9 @@ use rustc_attr_ir::{
DocInline, HideOrShow,
};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, IndexEntry};
use rustc_errors::{Applicability, msg};
use rustc_errors::Applicability;
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::{INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES};
use rustc_session::diagnostics::feature_err;
use rustc_span::{Span, Symbol, edition, sym};

use super::prelude::{ALL_TARGETS, AllowedTargets};
Expand DownExpand Up@@ -526,19 +525,15 @@ impl DocParser {
}
macro_rules! no_args_and_crate_level {
($ident: ident) => {{
no_args_and_crate_level!($ident, |span| {});
}};
($ident: ident, |$span:ident| $extra_validation:block) => {{
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
let $span = path.span();
if !check_attr_crate_level(cx, $span) {
let span = path.span();
if !check_attr_crate_level(cx, span) {
return;
}
$extra_validation
self.attribute.$ident = Some($span);
self.attribute.$ident = Some(span);
}};
}
macro_rules! string_arg_and_crate_level {
Expand DownExpand Up@@ -569,6 +564,12 @@ impl DocParser {
self.attribute.$ident = Some((s, path.span()));
}};
}
macro_rules! gated {
($feature:ident $(,$notes:expr)*) => {
let stability = $crate::unstable!($feature $(, $notes)*);
cx.shared.cx.check_attribute_stability(&cx.attr_path, path.span(), stability);
};
}

match path.word_sym() {
Some(sym::alias) => self.parse_alias(cx, path, args),
Expand All@@ -583,37 +584,60 @@ impl DocParser {
}
Some(sym::inline) => self.parse_inline(cx, path, args, DocInline::Inline),
Some(sym::no_inline) => self.parse_inline(cx, path, args, DocInline::NoInline),
Some(sym::masked) => no_args!(masked),
Some(sym::cfg) => self.parse_cfg(cx, args),
Some(sym::notable_trait) => no_args!(notable_trait),
Some(sym::keyword) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
),
Some(sym::attribute) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
),
Some(sym::fake_variadic) => no_args_and_not_crate_level!(fake_variadic),
Some(sym::search_unbox) => no_args_and_not_crate_level!(search_unbox),
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo, |span| {
if !cx.features().rustdoc_internals() {
feature_err(
cx.sess(),
sym::rustdoc_internals,
span,
msg!("the `#[doc(rust_logo)]` attribute is used for Rust branding"),
)
.emit();
Some(sym::masked) => {
gated!(doc_masked);
no_args!(masked)
}
Some(sym::cfg) => {
gated!(doc_cfg);
self.parse_cfg(cx, args)
}
Some(sym::notable_trait) => {
gated!(doc_notable_trait);
no_args!(notable_trait)
}
Some(sym::keyword) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
)
}
Some(sym::attribute) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
)
}
Some(sym::fake_variadic) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(fake_variadic)
}
Some(sym::search_unbox) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(search_unbox)
}
Some(sym::rust_logo) => {
// FIXME: Only feature gated at the crate level (!!)
if cx.target == Target::Crate {
gated!(
rustdoc_internals,
"the `#[doc(rust_logo)]` attribute is used for Rust branding"
);
}
}),
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
no_args_and_crate_level!(rust_logo)
}
Some(sym::auto_cfg) => {
gated!(doc_cfg);
self.parse_auto_cfg(cx, path, args)
}
Some(sym::test) => {
let Some(list) = args.as_list() else {
cx.emit_lint(
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -864,12 +864,6 @@ impl<'p, 'sess: 'p> DerefMut for SharedContext<'p, 'sess> {
}
}

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum OmitDoc {
Lower,
Skip,
}

#[derive(Copy, Clone, Debug)]
pub enum ShouldEmit {
/// The operations will emit errors, and lints, and errors are fatal.
Expand Down
31 changes: 14 additions & 17 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ use crate::context::{
use crate::diagnostics::ParsedDescription;
use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser};
use crate::synthetic::SyntheticAttrState;
use crate::{AttributeTemplate, OmitDoc, ShouldEmit};
use crate::{AttributeTemplate, ShouldEmit};

pub struct EmitAttribute(
pub Box<
Expand DownExpand Up@@ -161,7 +161,6 @@ impl<'sess> AttributeParser<'sess> {
attrs,
target_span,
target,
OmitDoc::Skip,
std::convert::identity,
|lint_id, span, kind| {
sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0)
Expand DownExpand Up@@ -310,14 +309,12 @@ impl<'sess> AttributeParser<'sess> {

/// Parse a list of attributes.
///
/// `target_span` is the span of the thing this list of attributes is applied to,
/// and when `omit_doc` is set, doc attributes are filtered out.
/// `target_span` is the span of the thing this list of attributes is applied to.
pub fn parse_attribute_list(
&mut self,
attrs: &[ast::Attribute],
target_span: Span,
target: Target,
omit_doc: OmitDoc,
lower_span: impl Copy + Fn(Span) -> Span,
mut emit_lint: impl FnMut(LintId, MultiSpan, EmitAttribute),
) -> Vec<Attribute> {
Expand All@@ -335,23 +332,23 @@ impl<'sess> AttributeParser<'sess> {
}
}

// Sometimes, for example for `#![doc = include_str!("readme.md")]`,
// doc still contains a non-literal. You might say, when we're lowering attributes
// that's expanded right? But no, sometimes, when parsing attributes on macros,
// we already use the lowering logic and these are still there. So, when `omit_doc`
// is set we *also* want to ignore these.
let is_doc_attribute = attr.has_name(sym::doc);
if omit_doc == OmitDoc::Skip && is_doc_attribute {
fn is_doc_non_lit_expr(attr: &ast::Attribute) -> bool {
if !attr.has_name(sym::doc) {
return false;
}
let ast::AttrKind::Normal(n) = &attr.kind else { return false };
let ast::AttrArgs::Eq { expr, .. } = &n.item.args else { return false };
!matches!(expr.kind, ast::ExprKind::Lit(_))
}

// FIXME accidentally allowed on Stable Rust
if target == Target::MacroCall && is_doc_non_lit_expr(attr) {
continue;
}

let attr_span = lower_span(attr.span);
match &attr.kind {
ast::AttrKind::DocComment(comment_kind, symbol) => {
if omit_doc == OmitDoc::Skip {
continue;
}

attributes.push(Attribute::Parsed(AttributeKind::DocComment {
style: attr.style,
kind: DocFragmentKind::Sugared(*comment_kind),
Expand DownExpand Up@@ -407,7 +404,7 @@ impl<'sess> AttributeParser<'sess> {
// bla
// blob
// a
if is_doc_attribute
if attr.has_name(sym::doc)
&& let ArgParser::NameValue(nv) = &args
// If not a string key/value, it should emit an error, but to make
// things simpler, it's handled in `DocParser` because it's simpler to
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,7 +116,7 @@ pub use attributes::cfg::{
};
pub use attributes::cfg_select::*;
pub use attributes::util::{is_builtin_attr, parse_version};
pub use context::{OmitDoc, ShouldEmit};
pub use context::ShouldEmit;
pub use diagnostics::ParsedDescription;
pub use interface::{AttributeParser, EmitAttribute};
pub use rustc_parse::parser::Recovery;
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_attr_parsing/src/stability.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,10 +53,24 @@ impl<'sess> AttributeParser<'sess> {
sym::prelude_import => ("the `prelude_import` attribute is for use by rustc only".to_string(), &[]),
sym::profiler_runtime => ("the `profiler_runtime` attribute is used to identify the `profiler_builtins` crate which contains the profiler runtime and will never be stable".to_string(), &[]),
sym::thread_local => ("the `thread_local` attribute is an experimental feature, and does not currently handle destructors".to_string(), &[]),
sym::rustdoc_internals => ("this subset of the `doc` attribute is meant for internal use only".to_string(), &[]),
sym::doc_notable_trait => ("the `doc(notable_trait)` attribute is experimental".to_string(), &[]),
sym::doc_cfg => ("the `doc(cfg)` and `doc(auto_cfg)` attributes are experimental".to_string(), &[]),
sym::doc_masked => ("the `doc(masked)` attribute is experimental".to_string(), &[]),
_ => (format!("the `{attr_path}` attribute is an experimental feature"), &[]),
};

let mut diag = feature_err(self.sess, gate_name, attr_path.span, explain);
// For unstable subsets of an attribute, point at that
let err_span = if matches!(
gate_name,
sym::rustdoc_internals | sym::doc_notable_trait | sym::doc_cfg | sym::doc_masked
) {
attr_span
} else {
attr_path.span
};

let mut diag = feature_err(self.sess, gate_name, err_span, explain);

// Remove the suggestion for `#![feature(staged_api)]` as these attributes are currently
// not usable outside std. If we do ever expose `#[stable]` etc under a different feature
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_expand/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@ doctest = false
[dependencies]
# tidy-alphabetical-start
rustc_ast = { path = "../rustc_ast" }
rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_expand/src/expand.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2245,15 +2245,13 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
attr
}

// Detect use of feature-gated or invalid attributes on macro invocations
// Run attributes through the attribute parser
// since they will not be detected after macro expansion.
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
use SyntheticAttr::*;
let features = self.cx.ecfg.features;
let mut attrs = attrs.iter().peekable();
let mut span: Option<Span> = None;
while let Some(attr) = attrs.next() {
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
validate_attr::check_attr(&self.cx.sess.psess, attr);
AttributeParser::parse_limited_all(
self.cx.sess,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -257,8 +257,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
sym::fundamental,
sym::may_dangle,

sym::rustc_never_type_options,

// ==========================================================================
// Internal attributes: Runtime related:
// ==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2468,7 +2468,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}

let lint_ambiguous = match probes[0].0.kind {
let lint_ambiguous = match child_candidate.kind {
TraitCandidate(_, lint) => lint,
_ => false,
};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ use std::mem;
use rustc_ast::visit::FnKind;
use rustc_ast::*;
use rustc_attr_parsing as attr;
use rustc_attr_parsing::{AttributeParser, OmitDoc, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, ShouldEmit};
use rustc_expand::expand::AstFragment;
use rustc_hir as hir;
use rustc_hir::Target;
Expand DownExpand Up@@ -187,7 +187,6 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
&i.attrs,
i.span,
Target::MacroDef,
OmitDoc::Skip,
std::convert::identity,
|_lint_id, _span, _kind| {
// FIXME(jdonszelmann): emit lints here properly
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Rollup of 7 pull requests by GuillaumeGomez · Pull Request #161990 · rust-lang/rust · GitHub
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -4026,7 +4026,6 @@ name = "rustc_expand"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr_ir",
"rustc_attr_parsing",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::node_id::NodeMap;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{self as ast, *};
use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
Expand DownExpand Up@@ -1231,7 +1231,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs,
target_span,
target,
OmitDoc::Lower,
|s| l.lower(s),
|lint_id, span, kind| {
self.delayed_lints.push(DelayedLint {
Expand Down
34 changes: 3 additions & 31 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,10 +46,6 @@ macro_rules! gate_multi {
}};
}

pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
PostExpansionVisitor { sess, features }.visit_attribute(attr)
}

struct PostExpansionVisitor<'a> {
sess: &'a Session,

Expand DownExpand Up@@ -152,33 +148,9 @@ impl<'a> PostExpansionVisitor<'a> {
}

impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_attribute(&mut self, attr: &ast::Attribute) {
// Check unstable flavors of the `#[doc]` attribute.
if attr.has_name(sym::doc) {
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($s:literal { $($name:ident => $feature:ident)* })*) => {
$($(if meta_item_inner.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
gate!(self, $feature, attr.span, msg);
})*)*
}}

gate_doc!(
"experimental" {
cfg => doc_cfg
auto_cfg => doc_cfg
masked => doc_masked
notable_trait => doc_notable_trait
}
"meant for internal use only" {
attribute => rustdoc_internals
keyword => rustdoc_internals
fake_variadic => rustdoc_internals
search_unbox => rustdoc_internals
}
);
}
}
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
// Checked in attribute parsers, do NOT add checks here
visit::walk_attribute(self, attr)
}

fn visit_item(&mut self, i: &'a ast::Item) {
Expand Down
102 changes: 63 additions & 39 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,10 +5,9 @@ use rustc_attr_ir::{
DocInline, HideOrShow,
};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, IndexEntry};
use rustc_errors::{Applicability, msg};
use rustc_errors::Applicability;
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::{INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES};
use rustc_session::diagnostics::feature_err;
use rustc_span::{Span, Symbol, edition, sym};

use super::prelude::{ALL_TARGETS, AllowedTargets};
Expand DownExpand Up@@ -526,19 +525,15 @@ impl DocParser {
}
macro_rules! no_args_and_crate_level {
($ident: ident) => {{
no_args_and_crate_level!($ident, |span| {});
}};
($ident: ident, |$span:ident| $extra_validation:block) => {{
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
let $span = path.span();
if !check_attr_crate_level(cx, $span) {
let span = path.span();
if !check_attr_crate_level(cx, span) {
return;
}
$extra_validation
self.attribute.$ident = Some($span);
self.attribute.$ident = Some(span);
}};
}
macro_rules! string_arg_and_crate_level {
Expand DownExpand Up@@ -569,6 +564,12 @@ impl DocParser {
self.attribute.$ident = Some((s, path.span()));
}};
}
macro_rules! gated {
($feature:ident $(,$notes:expr)*) => {
let stability = $crate::unstable!($feature $(, $notes)*);
cx.shared.cx.check_attribute_stability(&cx.attr_path, path.span(), stability);
};
}

match path.word_sym() {
Some(sym::alias) => self.parse_alias(cx, path, args),
Expand All@@ -583,37 +584,60 @@ impl DocParser {
}
Some(sym::inline) => self.parse_inline(cx, path, args, DocInline::Inline),
Some(sym::no_inline) => self.parse_inline(cx, path, args, DocInline::NoInline),
Some(sym::masked) => no_args!(masked),
Some(sym::cfg) => self.parse_cfg(cx, args),
Some(sym::notable_trait) => no_args!(notable_trait),
Some(sym::keyword) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
),
Some(sym::attribute) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
),
Some(sym::fake_variadic) => no_args_and_not_crate_level!(fake_variadic),
Some(sym::search_unbox) => no_args_and_not_crate_level!(search_unbox),
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo, |span| {
if !cx.features().rustdoc_internals() {
feature_err(
cx.sess(),
sym::rustdoc_internals,
span,
msg!("the `#[doc(rust_logo)]` attribute is used for Rust branding"),
)
.emit();
Some(sym::masked) => {
gated!(doc_masked);
no_args!(masked)
}
Some(sym::cfg) => {
gated!(doc_cfg);
self.parse_cfg(cx, args)
}
Some(sym::notable_trait) => {
gated!(doc_notable_trait);
no_args!(notable_trait)
}
Some(sym::keyword) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
)
}
Some(sym::attribute) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
)
}
Some(sym::fake_variadic) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(fake_variadic)
}
Some(sym::search_unbox) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(search_unbox)
}
Some(sym::rust_logo) => {
// FIXME: Only feature gated at the crate level (!!)
if cx.target == Target::Crate {
gated!(
rustdoc_internals,
"the `#[doc(rust_logo)]` attribute is used for Rust branding"
);
}
}),
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
no_args_and_crate_level!(rust_logo)
}
Some(sym::auto_cfg) => {
gated!(doc_cfg);
self.parse_auto_cfg(cx, path, args)
}
Some(sym::test) => {
let Some(list) = args.as_list() else {
cx.emit_lint(
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -864,12 +864,6 @@ impl<'p, 'sess: 'p> DerefMut for SharedContext<'p, 'sess> {
}
}

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum OmitDoc {
Lower,
Skip,
}

#[derive(Copy, Clone, Debug)]
pub enum ShouldEmit {
/// The operations will emit errors, and lints, and errors are fatal.
Expand Down
31 changes: 14 additions & 17 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ use crate::context::{
use crate::diagnostics::ParsedDescription;
use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser};
use crate::synthetic::SyntheticAttrState;
use crate::{AttributeTemplate, OmitDoc, ShouldEmit};
use crate::{AttributeTemplate, ShouldEmit};

pub struct EmitAttribute(
pub Box<
Expand DownExpand Up@@ -161,7 +161,6 @@ impl<'sess> AttributeParser<'sess> {
attrs,
target_span,
target,
OmitDoc::Skip,
std::convert::identity,
|lint_id, span, kind| {
sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0)
Expand DownExpand Up@@ -310,14 +309,12 @@ impl<'sess> AttributeParser<'sess> {

/// Parse a list of attributes.
///
/// `target_span` is the span of the thing this list of attributes is applied to,
/// and when `omit_doc` is set, doc attributes are filtered out.
/// `target_span` is the span of the thing this list of attributes is applied to.
pub fn parse_attribute_list(
&mut self,
attrs: &[ast::Attribute],
target_span: Span,
target: Target,
omit_doc: OmitDoc,
lower_span: impl Copy + Fn(Span) -> Span,
mut emit_lint: impl FnMut(LintId, MultiSpan, EmitAttribute),
) -> Vec<Attribute> {
Expand All@@ -335,23 +332,23 @@ impl<'sess> AttributeParser<'sess> {
}
}

// Sometimes, for example for `#![doc = include_str!("readme.md")]`,
// doc still contains a non-literal. You might say, when we're lowering attributes
// that's expanded right? But no, sometimes, when parsing attributes on macros,
// we already use the lowering logic and these are still there. So, when `omit_doc`
// is set we *also* want to ignore these.
let is_doc_attribute = attr.has_name(sym::doc);
if omit_doc == OmitDoc::Skip && is_doc_attribute {
fn is_doc_non_lit_expr(attr: &ast::Attribute) -> bool {
if !attr.has_name(sym::doc) {
return false;
}
let ast::AttrKind::Normal(n) = &attr.kind else { return false };
let ast::AttrArgs::Eq { expr, .. } = &n.item.args else { return false };
!matches!(expr.kind, ast::ExprKind::Lit(_))
}

// FIXME accidentally allowed on Stable Rust
if target == Target::MacroCall && is_doc_non_lit_expr(attr) {
continue;
}

let attr_span = lower_span(attr.span);
match &attr.kind {
ast::AttrKind::DocComment(comment_kind, symbol) => {
if omit_doc == OmitDoc::Skip {
continue;
}

attributes.push(Attribute::Parsed(AttributeKind::DocComment {
style: attr.style,
kind: DocFragmentKind::Sugared(*comment_kind),
Expand DownExpand Up@@ -407,7 +404,7 @@ impl<'sess> AttributeParser<'sess> {
// bla
// blob
// a
if is_doc_attribute
if attr.has_name(sym::doc)
&& let ArgParser::NameValue(nv) = &args
// If not a string key/value, it should emit an error, but to make
// things simpler, it's handled in `DocParser` because it's simpler to
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,7 +116,7 @@ pub use attributes::cfg::{
};
pub use attributes::cfg_select::*;
pub use attributes::util::{is_builtin_attr, parse_version};
pub use context::{OmitDoc, ShouldEmit};
pub use context::ShouldEmit;
pub use diagnostics::ParsedDescription;
pub use interface::{AttributeParser, EmitAttribute};
pub use rustc_parse::parser::Recovery;
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_attr_parsing/src/stability.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,10 +53,24 @@ impl<'sess> AttributeParser<'sess> {
sym::prelude_import => ("the `prelude_import` attribute is for use by rustc only".to_string(), &[]),
sym::profiler_runtime => ("the `profiler_runtime` attribute is used to identify the `profiler_builtins` crate which contains the profiler runtime and will never be stable".to_string(), &[]),
sym::thread_local => ("the `thread_local` attribute is an experimental feature, and does not currently handle destructors".to_string(), &[]),
sym::rustdoc_internals => ("this subset of the `doc` attribute is meant for internal use only".to_string(), &[]),
sym::doc_notable_trait => ("the `doc(notable_trait)` attribute is experimental".to_string(), &[]),
sym::doc_cfg => ("the `doc(cfg)` and `doc(auto_cfg)` attributes are experimental".to_string(), &[]),
sym::doc_masked => ("the `doc(masked)` attribute is experimental".to_string(), &[]),
_ => (format!("the `{attr_path}` attribute is an experimental feature"), &[]),
};

let mut diag = feature_err(self.sess, gate_name, attr_path.span, explain);
// For unstable subsets of an attribute, point at that
let err_span = if matches!(
gate_name,
sym::rustdoc_internals | sym::doc_notable_trait | sym::doc_cfg | sym::doc_masked
) {
attr_span
} else {
attr_path.span
};

let mut diag = feature_err(self.sess, gate_name, err_span, explain);

// Remove the suggestion for `#![feature(staged_api)]` as these attributes are currently
// not usable outside std. If we do ever expose `#[stable]` etc under a different feature
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_expand/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@ doctest = false
[dependencies]
# tidy-alphabetical-start
rustc_ast = { path = "../rustc_ast" }
rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_expand/src/expand.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2245,15 +2245,13 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
attr
}

// Detect use of feature-gated or invalid attributes on macro invocations
// Run attributes through the attribute parser
// since they will not be detected after macro expansion.
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
use SyntheticAttr::*;
let features = self.cx.ecfg.features;
let mut attrs = attrs.iter().peekable();
let mut span: Option<Span> = None;
while let Some(attr) = attrs.next() {
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
validate_attr::check_attr(&self.cx.sess.psess, attr);
AttributeParser::parse_limited_all(
self.cx.sess,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -257,8 +257,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
sym::fundamental,
sym::may_dangle,

sym::rustc_never_type_options,

// ==========================================================================
// Internal attributes: Runtime related:
// ==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2468,7 +2468,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}

let lint_ambiguous = match probes[0].0.kind {
let lint_ambiguous = match child_candidate.kind {
TraitCandidate(_, lint) => lint,
_ => false,
};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ use std::mem;
use rustc_ast::visit::FnKind;
use rustc_ast::*;
use rustc_attr_parsing as attr;
use rustc_attr_parsing::{AttributeParser, OmitDoc, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, ShouldEmit};
use rustc_expand::expand::AstFragment;
use rustc_hir as hir;
use rustc_hir::Target;
Expand DownExpand Up@@ -187,7 +187,6 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
&i.attrs,
i.span,
Target::MacroDef,
OmitDoc::Skip,
std::convert::identity,
|_lint_id, _span, _kind| {
// FIXME(jdonszelmann): emit lints here properly
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Rollup of 7 pull requests by GuillaumeGomez · Pull Request #161990 · rust-lang/rust · GitHub
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -4026,7 +4026,6 @@ name = "rustc_expand"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr_ir",
"rustc_attr_parsing",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::node_id::NodeMap;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{self as ast, *};
use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
Expand DownExpand Up@@ -1231,7 +1231,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs,
target_span,
target,
OmitDoc::Lower,
|s| l.lower(s),
|lint_id, span, kind| {
self.delayed_lints.push(DelayedLint {
Expand Down
34 changes: 3 additions & 31 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,10 +46,6 @@ macro_rules! gate_multi {
}};
}

pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
PostExpansionVisitor { sess, features }.visit_attribute(attr)
}

struct PostExpansionVisitor<'a> {
sess: &'a Session,

Expand DownExpand Up@@ -152,33 +148,9 @@ impl<'a> PostExpansionVisitor<'a> {
}

impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_attribute(&mut self, attr: &ast::Attribute) {
// Check unstable flavors of the `#[doc]` attribute.
if attr.has_name(sym::doc) {
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($s:literal { $($name:ident => $feature:ident)* })*) => {
$($(if meta_item_inner.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
gate!(self, $feature, attr.span, msg);
})*)*
}}

gate_doc!(
"experimental" {
cfg => doc_cfg
auto_cfg => doc_cfg
masked => doc_masked
notable_trait => doc_notable_trait
}
"meant for internal use only" {
attribute => rustdoc_internals
keyword => rustdoc_internals
fake_variadic => rustdoc_internals
search_unbox => rustdoc_internals
}
);
}
}
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
// Checked in attribute parsers, do NOT add checks here
visit::walk_attribute(self, attr)
}

fn visit_item(&mut self, i: &'a ast::Item) {
Expand Down
102 changes: 63 additions & 39 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,10 +5,9 @@ use rustc_attr_ir::{
DocInline, HideOrShow,
};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, IndexEntry};
use rustc_errors::{Applicability, msg};
use rustc_errors::Applicability;
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::{INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES};
use rustc_session::diagnostics::feature_err;
use rustc_span::{Span, Symbol, edition, sym};

use super::prelude::{ALL_TARGETS, AllowedTargets};
Expand DownExpand Up@@ -526,19 +525,15 @@ impl DocParser {
}
macro_rules! no_args_and_crate_level {
($ident: ident) => {{
no_args_and_crate_level!($ident, |span| {});
}};
($ident: ident, |$span:ident| $extra_validation:block) => {{
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
let $span = path.span();
if !check_attr_crate_level(cx, $span) {
let span = path.span();
if !check_attr_crate_level(cx, span) {
return;
}
$extra_validation
self.attribute.$ident = Some($span);
self.attribute.$ident = Some(span);
}};
}
macro_rules! string_arg_and_crate_level {
Expand DownExpand Up@@ -569,6 +564,12 @@ impl DocParser {
self.attribute.$ident = Some((s, path.span()));
}};
}
macro_rules! gated {
($feature:ident $(,$notes:expr)*) => {
let stability = $crate::unstable!($feature $(, $notes)*);
cx.shared.cx.check_attribute_stability(&cx.attr_path, path.span(), stability);
};
}

match path.word_sym() {
Some(sym::alias) => self.parse_alias(cx, path, args),
Expand All@@ -583,37 +584,60 @@ impl DocParser {
}
Some(sym::inline) => self.parse_inline(cx, path, args, DocInline::Inline),
Some(sym::no_inline) => self.parse_inline(cx, path, args, DocInline::NoInline),
Some(sym::masked) => no_args!(masked),
Some(sym::cfg) => self.parse_cfg(cx, args),
Some(sym::notable_trait) => no_args!(notable_trait),
Some(sym::keyword) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
),
Some(sym::attribute) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
),
Some(sym::fake_variadic) => no_args_and_not_crate_level!(fake_variadic),
Some(sym::search_unbox) => no_args_and_not_crate_level!(search_unbox),
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo, |span| {
if !cx.features().rustdoc_internals() {
feature_err(
cx.sess(),
sym::rustdoc_internals,
span,
msg!("the `#[doc(rust_logo)]` attribute is used for Rust branding"),
)
.emit();
Some(sym::masked) => {
gated!(doc_masked);
no_args!(masked)
}
Some(sym::cfg) => {
gated!(doc_cfg);
self.parse_cfg(cx, args)
}
Some(sym::notable_trait) => {
gated!(doc_notable_trait);
no_args!(notable_trait)
}
Some(sym::keyword) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
)
}
Some(sym::attribute) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
)
}
Some(sym::fake_variadic) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(fake_variadic)
}
Some(sym::search_unbox) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(search_unbox)
}
Some(sym::rust_logo) => {
// FIXME: Only feature gated at the crate level (!!)
if cx.target == Target::Crate {
gated!(
rustdoc_internals,
"the `#[doc(rust_logo)]` attribute is used for Rust branding"
);
}
}),
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
no_args_and_crate_level!(rust_logo)
}
Some(sym::auto_cfg) => {
gated!(doc_cfg);
self.parse_auto_cfg(cx, path, args)
}
Some(sym::test) => {
let Some(list) = args.as_list() else {
cx.emit_lint(
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -864,12 +864,6 @@ impl<'p, 'sess: 'p> DerefMut for SharedContext<'p, 'sess> {
}
}

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum OmitDoc {
Lower,
Skip,
}

#[derive(Copy, Clone, Debug)]
pub enum ShouldEmit {
/// The operations will emit errors, and lints, and errors are fatal.
Expand Down
31 changes: 14 additions & 17 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ use crate::context::{
use crate::diagnostics::ParsedDescription;
use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser};
use crate::synthetic::SyntheticAttrState;
use crate::{AttributeTemplate, OmitDoc, ShouldEmit};
use crate::{AttributeTemplate, ShouldEmit};

pub struct EmitAttribute(
pub Box<
Expand DownExpand Up@@ -161,7 +161,6 @@ impl<'sess> AttributeParser<'sess> {
attrs,
target_span,
target,
OmitDoc::Skip,
std::convert::identity,
|lint_id, span, kind| {
sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0)
Expand DownExpand Up@@ -310,14 +309,12 @@ impl<'sess> AttributeParser<'sess> {

/// Parse a list of attributes.
///
/// `target_span` is the span of the thing this list of attributes is applied to,
/// and when `omit_doc` is set, doc attributes are filtered out.
/// `target_span` is the span of the thing this list of attributes is applied to.
pub fn parse_attribute_list(
&mut self,
attrs: &[ast::Attribute],
target_span: Span,
target: Target,
omit_doc: OmitDoc,
lower_span: impl Copy + Fn(Span) -> Span,
mut emit_lint: impl FnMut(LintId, MultiSpan, EmitAttribute),
) -> Vec<Attribute> {
Expand All@@ -335,23 +332,23 @@ impl<'sess> AttributeParser<'sess> {
}
}

// Sometimes, for example for `#![doc = include_str!("readme.md")]`,
// doc still contains a non-literal. You might say, when we're lowering attributes
// that's expanded right? But no, sometimes, when parsing attributes on macros,
// we already use the lowering logic and these are still there. So, when `omit_doc`
// is set we *also* want to ignore these.
let is_doc_attribute = attr.has_name(sym::doc);
if omit_doc == OmitDoc::Skip && is_doc_attribute {
fn is_doc_non_lit_expr(attr: &ast::Attribute) -> bool {
if !attr.has_name(sym::doc) {
return false;
}
let ast::AttrKind::Normal(n) = &attr.kind else { return false };
let ast::AttrArgs::Eq { expr, .. } = &n.item.args else { return false };
!matches!(expr.kind, ast::ExprKind::Lit(_))
}

// FIXME accidentally allowed on Stable Rust
if target == Target::MacroCall && is_doc_non_lit_expr(attr) {
continue;
}

let attr_span = lower_span(attr.span);
match &attr.kind {
ast::AttrKind::DocComment(comment_kind, symbol) => {
if omit_doc == OmitDoc::Skip {
continue;
}

attributes.push(Attribute::Parsed(AttributeKind::DocComment {
style: attr.style,
kind: DocFragmentKind::Sugared(*comment_kind),
Expand DownExpand Up@@ -407,7 +404,7 @@ impl<'sess> AttributeParser<'sess> {
// bla
// blob
// a
if is_doc_attribute
if attr.has_name(sym::doc)
&& let ArgParser::NameValue(nv) = &args
// If not a string key/value, it should emit an error, but to make
// things simpler, it's handled in `DocParser` because it's simpler to
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,7 +116,7 @@ pub use attributes::cfg::{
};
pub use attributes::cfg_select::*;
pub use attributes::util::{is_builtin_attr, parse_version};
pub use context::{OmitDoc, ShouldEmit};
pub use context::ShouldEmit;
pub use diagnostics::ParsedDescription;
pub use interface::{AttributeParser, EmitAttribute};
pub use rustc_parse::parser::Recovery;
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_attr_parsing/src/stability.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,10 +53,24 @@ impl<'sess> AttributeParser<'sess> {
sym::prelude_import => ("the `prelude_import` attribute is for use by rustc only".to_string(), &[]),
sym::profiler_runtime => ("the `profiler_runtime` attribute is used to identify the `profiler_builtins` crate which contains the profiler runtime and will never be stable".to_string(), &[]),
sym::thread_local => ("the `thread_local` attribute is an experimental feature, and does not currently handle destructors".to_string(), &[]),
sym::rustdoc_internals => ("this subset of the `doc` attribute is meant for internal use only".to_string(), &[]),
sym::doc_notable_trait => ("the `doc(notable_trait)` attribute is experimental".to_string(), &[]),
sym::doc_cfg => ("the `doc(cfg)` and `doc(auto_cfg)` attributes are experimental".to_string(), &[]),
sym::doc_masked => ("the `doc(masked)` attribute is experimental".to_string(), &[]),
_ => (format!("the `{attr_path}` attribute is an experimental feature"), &[]),
};

let mut diag = feature_err(self.sess, gate_name, attr_path.span, explain);
// For unstable subsets of an attribute, point at that
let err_span = if matches!(
gate_name,
sym::rustdoc_internals | sym::doc_notable_trait | sym::doc_cfg | sym::doc_masked
) {
attr_span
} else {
attr_path.span
};

let mut diag = feature_err(self.sess, gate_name, err_span, explain);

// Remove the suggestion for `#![feature(staged_api)]` as these attributes are currently
// not usable outside std. If we do ever expose `#[stable]` etc under a different feature
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_expand/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@ doctest = false
[dependencies]
# tidy-alphabetical-start
rustc_ast = { path = "../rustc_ast" }
rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_expand/src/expand.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2245,15 +2245,13 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
attr
}

// Detect use of feature-gated or invalid attributes on macro invocations
// Run attributes through the attribute parser
// since they will not be detected after macro expansion.
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
use SyntheticAttr::*;
let features = self.cx.ecfg.features;
let mut attrs = attrs.iter().peekable();
let mut span: Option<Span> = None;
while let Some(attr) = attrs.next() {
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
validate_attr::check_attr(&self.cx.sess.psess, attr);
AttributeParser::parse_limited_all(
self.cx.sess,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -257,8 +257,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
sym::fundamental,
sym::may_dangle,

sym::rustc_never_type_options,

// ==========================================================================
// Internal attributes: Runtime related:
// ==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2468,7 +2468,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}

let lint_ambiguous = match probes[0].0.kind {
let lint_ambiguous = match child_candidate.kind {
TraitCandidate(_, lint) => lint,
_ => false,
};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ use std::mem;
use rustc_ast::visit::FnKind;
use rustc_ast::*;
use rustc_attr_parsing as attr;
use rustc_attr_parsing::{AttributeParser, OmitDoc, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, ShouldEmit};
use rustc_expand::expand::AstFragment;
use rustc_hir as hir;
use rustc_hir::Target;
Expand DownExpand Up@@ -187,7 +187,6 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
&i.attrs,
i.span,
Target::MacroDef,
OmitDoc::Skip,
std::convert::identity,
|_lint_id, _span, _kind| {
// FIXME(jdonszelmann): emit lints here properly
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Rollup of 7 pull requests by GuillaumeGomez · Pull Request #161990 · rust-lang/rust · GitHub
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -4026,7 +4026,6 @@ name = "rustc_expand"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr_ir",
"rustc_attr_parsing",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::node_id::NodeMap;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{self as ast, *};
use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
Expand DownExpand Up@@ -1231,7 +1231,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs,
target_span,
target,
OmitDoc::Lower,
|s| l.lower(s),
|lint_id, span, kind| {
self.delayed_lints.push(DelayedLint {
Expand Down
34 changes: 3 additions & 31 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,10 +46,6 @@ macro_rules! gate_multi {
}};
}

pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
PostExpansionVisitor { sess, features }.visit_attribute(attr)
}

struct PostExpansionVisitor<'a> {
sess: &'a Session,

Expand DownExpand Up@@ -152,33 +148,9 @@ impl<'a> PostExpansionVisitor<'a> {
}

impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_attribute(&mut self, attr: &ast::Attribute) {
// Check unstable flavors of the `#[doc]` attribute.
if attr.has_name(sym::doc) {
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($s:literal { $($name:ident => $feature:ident)* })*) => {
$($(if meta_item_inner.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
gate!(self, $feature, attr.span, msg);
})*)*
}}

gate_doc!(
"experimental" {
cfg => doc_cfg
auto_cfg => doc_cfg
masked => doc_masked
notable_trait => doc_notable_trait
}
"meant for internal use only" {
attribute => rustdoc_internals
keyword => rustdoc_internals
fake_variadic => rustdoc_internals
search_unbox => rustdoc_internals
}
);
}
}
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
// Checked in attribute parsers, do NOT add checks here
visit::walk_attribute(self, attr)
}

fn visit_item(&mut self, i: &'a ast::Item) {
Expand Down
102 changes: 63 additions & 39 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,10 +5,9 @@ use rustc_attr_ir::{
DocInline, HideOrShow,
};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, IndexEntry};
use rustc_errors::{Applicability, msg};
use rustc_errors::Applicability;
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::{INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES};
use rustc_session::diagnostics::feature_err;
use rustc_span::{Span, Symbol, edition, sym};

use super::prelude::{ALL_TARGETS, AllowedTargets};
Expand DownExpand Up@@ -526,19 +525,15 @@ impl DocParser {
}
macro_rules! no_args_and_crate_level {
($ident: ident) => {{
no_args_and_crate_level!($ident, |span| {});
}};
($ident: ident, |$span:ident| $extra_validation:block) => {{
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
let $span = path.span();
if !check_attr_crate_level(cx, $span) {
let span = path.span();
if !check_attr_crate_level(cx, span) {
return;
}
$extra_validation
self.attribute.$ident = Some($span);
self.attribute.$ident = Some(span);
}};
}
macro_rules! string_arg_and_crate_level {
Expand DownExpand Up@@ -569,6 +564,12 @@ impl DocParser {
self.attribute.$ident = Some((s, path.span()));
}};
}
macro_rules! gated {
($feature:ident $(,$notes:expr)*) => {
let stability = $crate::unstable!($feature $(, $notes)*);
cx.shared.cx.check_attribute_stability(&cx.attr_path, path.span(), stability);
};
}

match path.word_sym() {
Some(sym::alias) => self.parse_alias(cx, path, args),
Expand All@@ -583,37 +584,60 @@ impl DocParser {
}
Some(sym::inline) => self.parse_inline(cx, path, args, DocInline::Inline),
Some(sym::no_inline) => self.parse_inline(cx, path, args, DocInline::NoInline),
Some(sym::masked) => no_args!(masked),
Some(sym::cfg) => self.parse_cfg(cx, args),
Some(sym::notable_trait) => no_args!(notable_trait),
Some(sym::keyword) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
),
Some(sym::attribute) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
),
Some(sym::fake_variadic) => no_args_and_not_crate_level!(fake_variadic),
Some(sym::search_unbox) => no_args_and_not_crate_level!(search_unbox),
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo, |span| {
if !cx.features().rustdoc_internals() {
feature_err(
cx.sess(),
sym::rustdoc_internals,
span,
msg!("the `#[doc(rust_logo)]` attribute is used for Rust branding"),
)
.emit();
Some(sym::masked) => {
gated!(doc_masked);
no_args!(masked)
}
Some(sym::cfg) => {
gated!(doc_cfg);
self.parse_cfg(cx, args)
}
Some(sym::notable_trait) => {
gated!(doc_notable_trait);
no_args!(notable_trait)
}
Some(sym::keyword) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
)
}
Some(sym::attribute) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
)
}
Some(sym::fake_variadic) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(fake_variadic)
}
Some(sym::search_unbox) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(search_unbox)
}
Some(sym::rust_logo) => {
// FIXME: Only feature gated at the crate level (!!)
if cx.target == Target::Crate {
gated!(
rustdoc_internals,
"the `#[doc(rust_logo)]` attribute is used for Rust branding"
);
}
}),
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
no_args_and_crate_level!(rust_logo)
}
Some(sym::auto_cfg) => {
gated!(doc_cfg);
self.parse_auto_cfg(cx, path, args)
}
Some(sym::test) => {
let Some(list) = args.as_list() else {
cx.emit_lint(
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -864,12 +864,6 @@ impl<'p, 'sess: 'p> DerefMut for SharedContext<'p, 'sess> {
}
}

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum OmitDoc {
Lower,
Skip,
}

#[derive(Copy, Clone, Debug)]
pub enum ShouldEmit {
/// The operations will emit errors, and lints, and errors are fatal.
Expand Down
31 changes: 14 additions & 17 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ use crate::context::{
use crate::diagnostics::ParsedDescription;
use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser};
use crate::synthetic::SyntheticAttrState;
use crate::{AttributeTemplate, OmitDoc, ShouldEmit};
use crate::{AttributeTemplate, ShouldEmit};

pub struct EmitAttribute(
pub Box<
Expand DownExpand Up@@ -161,7 +161,6 @@ impl<'sess> AttributeParser<'sess> {
attrs,
target_span,
target,
OmitDoc::Skip,
std::convert::identity,
|lint_id, span, kind| {
sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0)
Expand DownExpand Up@@ -310,14 +309,12 @@ impl<'sess> AttributeParser<'sess> {

/// Parse a list of attributes.
///
/// `target_span` is the span of the thing this list of attributes is applied to,
/// and when `omit_doc` is set, doc attributes are filtered out.
/// `target_span` is the span of the thing this list of attributes is applied to.
pub fn parse_attribute_list(
&mut self,
attrs: &[ast::Attribute],
target_span: Span,
target: Target,
omit_doc: OmitDoc,
lower_span: impl Copy + Fn(Span) -> Span,
mut emit_lint: impl FnMut(LintId, MultiSpan, EmitAttribute),
) -> Vec<Attribute> {
Expand All@@ -335,23 +332,23 @@ impl<'sess> AttributeParser<'sess> {
}
}

// Sometimes, for example for `#![doc = include_str!("readme.md")]`,
// doc still contains a non-literal. You might say, when we're lowering attributes
// that's expanded right? But no, sometimes, when parsing attributes on macros,
// we already use the lowering logic and these are still there. So, when `omit_doc`
// is set we *also* want to ignore these.
let is_doc_attribute = attr.has_name(sym::doc);
if omit_doc == OmitDoc::Skip && is_doc_attribute {
fn is_doc_non_lit_expr(attr: &ast::Attribute) -> bool {
if !attr.has_name(sym::doc) {
return false;
}
let ast::AttrKind::Normal(n) = &attr.kind else { return false };
let ast::AttrArgs::Eq { expr, .. } = &n.item.args else { return false };
!matches!(expr.kind, ast::ExprKind::Lit(_))
}

// FIXME accidentally allowed on Stable Rust
if target == Target::MacroCall && is_doc_non_lit_expr(attr) {
continue;
}

let attr_span = lower_span(attr.span);
match &attr.kind {
ast::AttrKind::DocComment(comment_kind, symbol) => {
if omit_doc == OmitDoc::Skip {
continue;
}

attributes.push(Attribute::Parsed(AttributeKind::DocComment {
style: attr.style,
kind: DocFragmentKind::Sugared(*comment_kind),
Expand DownExpand Up@@ -407,7 +404,7 @@ impl<'sess> AttributeParser<'sess> {
// bla
// blob
// a
if is_doc_attribute
if attr.has_name(sym::doc)
&& let ArgParser::NameValue(nv) = &args
// If not a string key/value, it should emit an error, but to make
// things simpler, it's handled in `DocParser` because it's simpler to
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,7 +116,7 @@ pub use attributes::cfg::{
};
pub use attributes::cfg_select::*;
pub use attributes::util::{is_builtin_attr, parse_version};
pub use context::{OmitDoc, ShouldEmit};
pub use context::ShouldEmit;
pub use diagnostics::ParsedDescription;
pub use interface::{AttributeParser, EmitAttribute};
pub use rustc_parse::parser::Recovery;
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_attr_parsing/src/stability.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,10 +53,24 @@ impl<'sess> AttributeParser<'sess> {
sym::prelude_import => ("the `prelude_import` attribute is for use by rustc only".to_string(), &[]),
sym::profiler_runtime => ("the `profiler_runtime` attribute is used to identify the `profiler_builtins` crate which contains the profiler runtime and will never be stable".to_string(), &[]),
sym::thread_local => ("the `thread_local` attribute is an experimental feature, and does not currently handle destructors".to_string(), &[]),
sym::rustdoc_internals => ("this subset of the `doc` attribute is meant for internal use only".to_string(), &[]),
sym::doc_notable_trait => ("the `doc(notable_trait)` attribute is experimental".to_string(), &[]),
sym::doc_cfg => ("the `doc(cfg)` and `doc(auto_cfg)` attributes are experimental".to_string(), &[]),
sym::doc_masked => ("the `doc(masked)` attribute is experimental".to_string(), &[]),
_ => (format!("the `{attr_path}` attribute is an experimental feature"), &[]),
};

let mut diag = feature_err(self.sess, gate_name, attr_path.span, explain);
// For unstable subsets of an attribute, point at that
let err_span = if matches!(
gate_name,
sym::rustdoc_internals | sym::doc_notable_trait | sym::doc_cfg | sym::doc_masked
) {
attr_span
} else {
attr_path.span
};

let mut diag = feature_err(self.sess, gate_name, err_span, explain);

// Remove the suggestion for `#![feature(staged_api)]` as these attributes are currently
// not usable outside std. If we do ever expose `#[stable]` etc under a different feature
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_expand/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@ doctest = false
[dependencies]
# tidy-alphabetical-start
rustc_ast = { path = "../rustc_ast" }
rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_expand/src/expand.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2245,15 +2245,13 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
attr
}

// Detect use of feature-gated or invalid attributes on macro invocations
// Run attributes through the attribute parser
// since they will not be detected after macro expansion.
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
use SyntheticAttr::*;
let features = self.cx.ecfg.features;
let mut attrs = attrs.iter().peekable();
let mut span: Option<Span> = None;
while let Some(attr) = attrs.next() {
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
validate_attr::check_attr(&self.cx.sess.psess, attr);
AttributeParser::parse_limited_all(
self.cx.sess,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -257,8 +257,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
sym::fundamental,
sym::may_dangle,

sym::rustc_never_type_options,

// ==========================================================================
// Internal attributes: Runtime related:
// ==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2468,7 +2468,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}

let lint_ambiguous = match probes[0].0.kind {
let lint_ambiguous = match child_candidate.kind {
TraitCandidate(_, lint) => lint,
_ => false,
};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ use std::mem;
use rustc_ast::visit::FnKind;
use rustc_ast::*;
use rustc_attr_parsing as attr;
use rustc_attr_parsing::{AttributeParser, OmitDoc, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, ShouldEmit};
use rustc_expand::expand::AstFragment;
use rustc_hir as hir;
use rustc_hir::Target;
Expand DownExpand Up@@ -187,7 +187,6 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
&i.attrs,
i.span,
Target::MacroDef,
OmitDoc::Skip,
std::convert::identity,
|_lint_id, _span, _kind| {
// FIXME(jdonszelmann): emit lints here properly
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Rollup of 7 pull requests by GuillaumeGomez · Pull Request #161990 · rust-lang/rust · GitHub
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -4026,7 +4026,6 @@ name = "rustc_expand"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr_ir",
"rustc_attr_parsing",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::node_id::NodeMap;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{self as ast, *};
use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
Expand DownExpand Up@@ -1231,7 +1231,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs,
target_span,
target,
OmitDoc::Lower,
|s| l.lower(s),
|lint_id, span, kind| {
self.delayed_lints.push(DelayedLint {
Expand Down
34 changes: 3 additions & 31 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,10 +46,6 @@ macro_rules! gate_multi {
}};
}

pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
PostExpansionVisitor { sess, features }.visit_attribute(attr)
}

struct PostExpansionVisitor<'a> {
sess: &'a Session,

Expand DownExpand Up@@ -152,33 +148,9 @@ impl<'a> PostExpansionVisitor<'a> {
}

impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_attribute(&mut self, attr: &ast::Attribute) {
// Check unstable flavors of the `#[doc]` attribute.
if attr.has_name(sym::doc) {
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($s:literal { $($name:ident => $feature:ident)* })*) => {
$($(if meta_item_inner.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
gate!(self, $feature, attr.span, msg);
})*)*
}}

gate_doc!(
"experimental" {
cfg => doc_cfg
auto_cfg => doc_cfg
masked => doc_masked
notable_trait => doc_notable_trait
}
"meant for internal use only" {
attribute => rustdoc_internals
keyword => rustdoc_internals
fake_variadic => rustdoc_internals
search_unbox => rustdoc_internals
}
);
}
}
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
// Checked in attribute parsers, do NOT add checks here
visit::walk_attribute(self, attr)
}

fn visit_item(&mut self, i: &'a ast::Item) {
Expand Down
102 changes: 63 additions & 39 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,10 +5,9 @@ use rustc_attr_ir::{
DocInline, HideOrShow,
};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, IndexEntry};
use rustc_errors::{Applicability, msg};
use rustc_errors::Applicability;
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::{INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES};
use rustc_session::diagnostics::feature_err;
use rustc_span::{Span, Symbol, edition, sym};

use super::prelude::{ALL_TARGETS, AllowedTargets};
Expand DownExpand Up@@ -526,19 +525,15 @@ impl DocParser {
}
macro_rules! no_args_and_crate_level {
($ident: ident) => {{
no_args_and_crate_level!($ident, |span| {});
}};
($ident: ident, |$span:ident| $extra_validation:block) => {{
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
let $span = path.span();
if !check_attr_crate_level(cx, $span) {
let span = path.span();
if !check_attr_crate_level(cx, span) {
return;
}
$extra_validation
self.attribute.$ident = Some($span);
self.attribute.$ident = Some(span);
}};
}
macro_rules! string_arg_and_crate_level {
Expand DownExpand Up@@ -569,6 +564,12 @@ impl DocParser {
self.attribute.$ident = Some((s, path.span()));
}};
}
macro_rules! gated {
($feature:ident $(,$notes:expr)*) => {
let stability = $crate::unstable!($feature $(, $notes)*);
cx.shared.cx.check_attribute_stability(&cx.attr_path, path.span(), stability);
};
}

match path.word_sym() {
Some(sym::alias) => self.parse_alias(cx, path, args),
Expand All@@ -583,37 +584,60 @@ impl DocParser {
}
Some(sym::inline) => self.parse_inline(cx, path, args, DocInline::Inline),
Some(sym::no_inline) => self.parse_inline(cx, path, args, DocInline::NoInline),
Some(sym::masked) => no_args!(masked),
Some(sym::cfg) => self.parse_cfg(cx, args),
Some(sym::notable_trait) => no_args!(notable_trait),
Some(sym::keyword) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
),
Some(sym::attribute) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
),
Some(sym::fake_variadic) => no_args_and_not_crate_level!(fake_variadic),
Some(sym::search_unbox) => no_args_and_not_crate_level!(search_unbox),
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo, |span| {
if !cx.features().rustdoc_internals() {
feature_err(
cx.sess(),
sym::rustdoc_internals,
span,
msg!("the `#[doc(rust_logo)]` attribute is used for Rust branding"),
)
.emit();
Some(sym::masked) => {
gated!(doc_masked);
no_args!(masked)
}
Some(sym::cfg) => {
gated!(doc_cfg);
self.parse_cfg(cx, args)
}
Some(sym::notable_trait) => {
gated!(doc_notable_trait);
no_args!(notable_trait)
}
Some(sym::keyword) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
)
}
Some(sym::attribute) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
)
}
Some(sym::fake_variadic) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(fake_variadic)
}
Some(sym::search_unbox) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(search_unbox)
}
Some(sym::rust_logo) => {
// FIXME: Only feature gated at the crate level (!!)
if cx.target == Target::Crate {
gated!(
rustdoc_internals,
"the `#[doc(rust_logo)]` attribute is used for Rust branding"
);
}
}),
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
no_args_and_crate_level!(rust_logo)
}
Some(sym::auto_cfg) => {
gated!(doc_cfg);
self.parse_auto_cfg(cx, path, args)
}
Some(sym::test) => {
let Some(list) = args.as_list() else {
cx.emit_lint(
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -864,12 +864,6 @@ impl<'p, 'sess: 'p> DerefMut for SharedContext<'p, 'sess> {
}
}

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum OmitDoc {
Lower,
Skip,
}

#[derive(Copy, Clone, Debug)]
pub enum ShouldEmit {
/// The operations will emit errors, and lints, and errors are fatal.
Expand Down
31 changes: 14 additions & 17 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ use crate::context::{
use crate::diagnostics::ParsedDescription;
use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser};
use crate::synthetic::SyntheticAttrState;
use crate::{AttributeTemplate, OmitDoc, ShouldEmit};
use crate::{AttributeTemplate, ShouldEmit};

pub struct EmitAttribute(
pub Box<
Expand DownExpand Up@@ -161,7 +161,6 @@ impl<'sess> AttributeParser<'sess> {
attrs,
target_span,
target,
OmitDoc::Skip,
std::convert::identity,
|lint_id, span, kind| {
sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0)
Expand DownExpand Up@@ -310,14 +309,12 @@ impl<'sess> AttributeParser<'sess> {

/// Parse a list of attributes.
///
/// `target_span` is the span of the thing this list of attributes is applied to,
/// and when `omit_doc` is set, doc attributes are filtered out.
/// `target_span` is the span of the thing this list of attributes is applied to.
pub fn parse_attribute_list(
&mut self,
attrs: &[ast::Attribute],
target_span: Span,
target: Target,
omit_doc: OmitDoc,
lower_span: impl Copy + Fn(Span) -> Span,
mut emit_lint: impl FnMut(LintId, MultiSpan, EmitAttribute),
) -> Vec<Attribute> {
Expand All@@ -335,23 +332,23 @@ impl<'sess> AttributeParser<'sess> {
}
}

// Sometimes, for example for `#![doc = include_str!("readme.md")]`,
// doc still contains a non-literal. You might say, when we're lowering attributes
// that's expanded right? But no, sometimes, when parsing attributes on macros,
// we already use the lowering logic and these are still there. So, when `omit_doc`
// is set we *also* want to ignore these.
let is_doc_attribute = attr.has_name(sym::doc);
if omit_doc == OmitDoc::Skip && is_doc_attribute {
fn is_doc_non_lit_expr(attr: &ast::Attribute) -> bool {
if !attr.has_name(sym::doc) {
return false;
}
let ast::AttrKind::Normal(n) = &attr.kind else { return false };
let ast::AttrArgs::Eq { expr, .. } = &n.item.args else { return false };
!matches!(expr.kind, ast::ExprKind::Lit(_))
}

// FIXME accidentally allowed on Stable Rust
if target == Target::MacroCall && is_doc_non_lit_expr(attr) {
continue;
}

let attr_span = lower_span(attr.span);
match &attr.kind {
ast::AttrKind::DocComment(comment_kind, symbol) => {
if omit_doc == OmitDoc::Skip {
continue;
}

attributes.push(Attribute::Parsed(AttributeKind::DocComment {
style: attr.style,
kind: DocFragmentKind::Sugared(*comment_kind),
Expand DownExpand Up@@ -407,7 +404,7 @@ impl<'sess> AttributeParser<'sess> {
// bla
// blob
// a
if is_doc_attribute
if attr.has_name(sym::doc)
&& let ArgParser::NameValue(nv) = &args
// If not a string key/value, it should emit an error, but to make
// things simpler, it's handled in `DocParser` because it's simpler to
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,7 +116,7 @@ pub use attributes::cfg::{
};
pub use attributes::cfg_select::*;
pub use attributes::util::{is_builtin_attr, parse_version};
pub use context::{OmitDoc, ShouldEmit};
pub use context::ShouldEmit;
pub use diagnostics::ParsedDescription;
pub use interface::{AttributeParser, EmitAttribute};
pub use rustc_parse::parser::Recovery;
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_attr_parsing/src/stability.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,10 +53,24 @@ impl<'sess> AttributeParser<'sess> {
sym::prelude_import => ("the `prelude_import` attribute is for use by rustc only".to_string(), &[]),
sym::profiler_runtime => ("the `profiler_runtime` attribute is used to identify the `profiler_builtins` crate which contains the profiler runtime and will never be stable".to_string(), &[]),
sym::thread_local => ("the `thread_local` attribute is an experimental feature, and does not currently handle destructors".to_string(), &[]),
sym::rustdoc_internals => ("this subset of the `doc` attribute is meant for internal use only".to_string(), &[]),
sym::doc_notable_trait => ("the `doc(notable_trait)` attribute is experimental".to_string(), &[]),
sym::doc_cfg => ("the `doc(cfg)` and `doc(auto_cfg)` attributes are experimental".to_string(), &[]),
sym::doc_masked => ("the `doc(masked)` attribute is experimental".to_string(), &[]),
_ => (format!("the `{attr_path}` attribute is an experimental feature"), &[]),
};

let mut diag = feature_err(self.sess, gate_name, attr_path.span, explain);
// For unstable subsets of an attribute, point at that
let err_span = if matches!(
gate_name,
sym::rustdoc_internals | sym::doc_notable_trait | sym::doc_cfg | sym::doc_masked
) {
attr_span
} else {
attr_path.span
};

let mut diag = feature_err(self.sess, gate_name, err_span, explain);

// Remove the suggestion for `#![feature(staged_api)]` as these attributes are currently
// not usable outside std. If we do ever expose `#[stable]` etc under a different feature
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_expand/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@ doctest = false
[dependencies]
# tidy-alphabetical-start
rustc_ast = { path = "../rustc_ast" }
rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_expand/src/expand.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2245,15 +2245,13 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
attr
}

// Detect use of feature-gated or invalid attributes on macro invocations
// Run attributes through the attribute parser
// since they will not be detected after macro expansion.
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
use SyntheticAttr::*;
let features = self.cx.ecfg.features;
let mut attrs = attrs.iter().peekable();
let mut span: Option<Span> = None;
while let Some(attr) = attrs.next() {
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
validate_attr::check_attr(&self.cx.sess.psess, attr);
AttributeParser::parse_limited_all(
self.cx.sess,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -257,8 +257,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
sym::fundamental,
sym::may_dangle,

sym::rustc_never_type_options,

// ==========================================================================
// Internal attributes: Runtime related:
// ==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2468,7 +2468,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}

let lint_ambiguous = match probes[0].0.kind {
let lint_ambiguous = match child_candidate.kind {
TraitCandidate(_, lint) => lint,
_ => false,
};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ use std::mem;
use rustc_ast::visit::FnKind;
use rustc_ast::*;
use rustc_attr_parsing as attr;
use rustc_attr_parsing::{AttributeParser, OmitDoc, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, ShouldEmit};
use rustc_expand::expand::AstFragment;
use rustc_hir as hir;
use rustc_hir::Target;
Expand DownExpand Up@@ -187,7 +187,6 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
&i.attrs,
i.span,
Target::MacroDef,
OmitDoc::Skip,
std::convert::identity,
|_lint_id, _span, _kind| {
// FIXME(jdonszelmann): emit lints here properly
Expand Down
Loading
Loading