Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #109824

Merged
merged 29 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e981738
Fix rustdoc intra-doc link invalid ambiguity error message
GuillaumeGomez Mar 13, 2023
e193950
Special case `ambiguity_error` if all candidates have the same "kind"
GuillaumeGomez Mar 14, 2023
c78ebab
Add regression tests for #108653
GuillaumeGomez Mar 3, 2023
95926b2
Rename description of primitive from "builtin type" into "primitive t…
GuillaumeGomez Mar 24, 2023
ec43cb3
Update UI tests for primitive type ambiguity error renaming
GuillaumeGomez Mar 24, 2023
537fdbd
Strenghten disambiguation in `ambiguity_error` and improve documentation
GuillaumeGomez Mar 24, 2023
415a3ca
Put back `is_derive_trait_collision` check
GuillaumeGomez Mar 24, 2023
f995003
Fix subslice capture in closure
clubby789 Mar 27, 2023
f40aa59
Rename doc(primitive) into rustc_doc_primitive
GuillaumeGomez Mar 21, 2023
3ef8d2d
Update tests for rustc_doc_primitive
GuillaumeGomez Mar 21, 2023
364e961
Replace doc(primitive) with rustc_doc_primitive
GuillaumeGomez Mar 21, 2023
48f7148
Update documentation for rustc_doc_primitive
GuillaumeGomez Mar 21, 2023
fa2824a
Add test to ensure doc(primitive) is not recognized anymore
GuillaumeGomez Mar 21, 2023
bcf8a8b
Improve code
GuillaumeGomez Mar 30, 2023
f6035fb
Update doc(primitive) in rustc_resolve
GuillaumeGomez Mar 30, 2023
f249832
Use std::fs::read_to_file in fluent_messages macro
est31 Mar 31, 2023
97fb15d
Don't emit the OS error in a note
est31 Mar 31, 2023
f049d5d
Remove an unnecessary use of `with_session_globals`.
nnethercote Mar 31, 2023
4e63ab6
Improve `with_source_map`.
nnethercote Mar 31, 2023
aab9e32
Update browser-ui-test version to 0.14.6
GuillaumeGomez Mar 31, 2023
efad057
Add tests to check that collapsed content is expanded when jumping to it
GuillaumeGomez Mar 31, 2023
54ef3a4
rustdoc-search: update docs for comma in `?` help popover
notriddle Mar 31, 2023
8fe5b56
Rollup merge of #109104 - GuillaumeGomez:fix-invalid-suggestion-ambig…
GuillaumeGomez Mar 31, 2023
6c93c63
Rollup merge of #109443 - GuillaumeGomez:doc-primitive-hard-error, r=…
GuillaumeGomez Mar 31, 2023
45fcb6f
Rollup merge of #109680 - clubby789:array-subslice-2229, r=davidtwco
GuillaumeGomez Mar 31, 2023
bd4e3f3
Rollup merge of #109798 - est31:ftl_test_note, r=davidtwco
GuillaumeGomez Mar 31, 2023
d732934
Rollup merge of #109805 - nnethercote:source_map-cleanups, r=bjorn3
GuillaumeGomez Mar 31, 2023
32842e8
Rollup merge of #109818 - GuillaumeGomez:test-collapsed-item, r=notri…
GuillaumeGomez Mar 31, 2023
083c128
Rollup merge of #109820 - notriddle:notriddle/help-comma, r=camelid
GuillaumeGomez Mar 31, 2023
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
10 changes: 7 additions & 3 deletions compiler/rustc_expand/src/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl base::BangProcMacro for BangProcMacro {
) -> Result<TokenStream, ErrorGuaranteed> {
let _timer =
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
recorder.record_arg_with_span(ecx.expansion_descr(), span);
recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span);
});

let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
Expand Down Expand Up @@ -85,7 +85,7 @@ impl base::AttrProcMacro for AttrProcMacro {
) -> Result<TokenStream, ErrorGuaranteed> {
let _timer =
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
recorder.record_arg_with_span(ecx.expansion_descr(), span);
recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span);
});

let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
Expand Down Expand Up @@ -134,7 +134,11 @@ impl MultiItemModifier for DeriveProcMacro {
let stream = {
let _timer =
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
recorder.record_arg_with_span(ecx.expansion_descr(), span);
recorder.record_arg_with_span(
ecx.sess.source_map(),
ecx.expansion_descr(),
span,
);
});
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
let strategy = exec_strategy(ecx);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ declare_features! (
(active, rustc_allow_const_fn_unstable, "1.49.0", Some(69399), None),
/// Allows using compiler's own crates.
(active, rustc_private, "1.0.0", Some(27812), None),
/// Allows using internal rustdoc features like `doc(primitive)` or `doc(keyword)`.
/// Allows using internal rustdoc features like `doc(keyword)`.
(active, rustdoc_internals, "1.58.0", Some(90418), None),
/// Allows using the `rustdoc::missing_doc_code_examples` lint
(active, rustdoc_missing_doc_code_examples, "1.31.0", Some(101730), None),
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
definition of a trait, it's currently in experimental form and should be changed before \
being exposed outside of the std"
),
rustc_attr!(
rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing,
r#"`rustc_doc_primitive` is a rustc internal attribute"#,
),

// ==========================================================================
// Internal attributes, Testing:
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1893,14 +1893,13 @@ fn restrict_capture_precision(

for (i, proj) in place.projections.iter().enumerate() {
match proj.kind {
ProjectionKind::Index => {
// Arrays are completely captured, so we drop Index projections
ProjectionKind::Index | ProjectionKind::Subslice => {
// Arrays are completely captured, so we drop Index and Subslice projections
truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, i);
return (place, curr_mode);
}
ProjectionKind::Deref => {}
ProjectionKind::Field(..) => {} // ignore
ProjectionKind::Subslice => {} // We never capture this
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
override_queries: config.override_queries,
};

rustc_span::with_source_map(compiler.sess.parse_sess.clone_source_map(), move || {
rustc_span::set_source_map(compiler.sess.parse_sess.clone_source_map(), move || {
let r = {
let _sess_abort_error = OnDrop(|| {
compiler.sess.finish_diagnostics(registry);
Expand Down
23 changes: 9 additions & 14 deletions compiler/rustc_macros/src/diagnostics/fluent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use proc_macro2::TokenStream;
use quote::quote;
use std::{
collections::{HashMap, HashSet},
fs::File,
io::Read,
fs::read_to_string,
path::{Path, PathBuf},
};
use syn::{parse_macro_input, Ident, LitStr};
Expand Down Expand Up @@ -95,22 +94,18 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok

// As this macro also outputs an `include_str!` for this file, the macro will always be
// re-executed when the file changes.
let mut resource_file = match File::open(absolute_ftl_path) {
Ok(resource_file) => resource_file,
let resource_contents = match read_to_string(absolute_ftl_path) {
Ok(resource_contents) => resource_contents,
Err(e) => {
Diagnostic::spanned(resource_span, Level::Error, "could not open Fluent resource")
.note(e.to_string())
.emit();
Diagnostic::spanned(
resource_span,
Level::Error,
format!("could not open Fluent resource: {}", e.to_string()),
)
.emit();
return failed(&crate_name);
}
};
let mut resource_contents = String::new();
if let Err(e) = resource_file.read_to_string(&mut resource_contents) {
Diagnostic::spanned(resource_span, Level::Error, "could not read Fluent resource")
.note(e.to_string())
.emit();
return failed(&crate_name);
}
let mut bad = false;
for esc in ["\\n", "\\\"", "\\'"] {
for _ in resource_contents.matches(esc) {
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ passes_doc_test_unknown =
passes_doc_test_takes_list =
`#[doc(test(...)]` takes a list of attributes

passes_doc_primitive =
`doc(primitive)` should never have been stable

passes_doc_cfg_hide_takes_list =
`#[doc(cfg_hide(...)]` takes a list of attributes

Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,17 +1109,6 @@ impl CheckAttrVisitor<'_> {
}
}

sym::primitive => {
if !self.tcx.features().rustdoc_internals {
self.tcx.emit_spanned_lint(
INVALID_DOC_ATTRIBUTES,
hir_id,
i_meta.span,
errors::DocPrimitive,
);
}
}

_ => {
let path = rustc_ast_pretty::pprust::path_to_string(&i_meta.path);
if i_meta.has_name(sym::spotlight) {
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,6 @@ pub struct DocTestTakesList;
#[diag(passes_doc_cfg_hide_takes_list)]
pub struct DocCfgHideTakesList;

#[derive(LintDiagnostic)]
#[diag(passes_doc_primitive)]
pub struct DocPrimitive;

#[derive(LintDiagnostic)]
#[diag(passes_doc_test_unknown_any)]
pub struct DocTestUnknownAny {
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_resolve/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,14 @@ pub fn inner_docs(attrs: &[ast::Attribute]) -> bool {
attrs.iter().find(|a| a.doc_str().is_some()).map_or(true, |a| a.style == ast::AttrStyle::Inner)
}

/// Has `#[doc(primitive)]` or `#[doc(keyword)]`.
/// Has `#[rustc_doc_primitive]` or `#[doc(keyword)]`.
pub fn has_primitive_or_keyword_docs(attrs: &[ast::Attribute]) -> bool {
for attr in attrs {
if attr.has_name(sym::doc) && let Some(items) = attr.meta_item_list() {
if attr.has_name(sym::rustc_doc_primitive) {
return true;
} else if attr.has_name(sym::doc) && let Some(items) = attr.meta_item_list() {
for item in items {
if item.has_name(sym::primitive) || item.has_name(sym::keyword) {
if item.has_name(sym::keyword) {
return true;
}
}
Expand Down
23 changes: 13 additions & 10 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ pub struct SessionGlobals {
symbol_interner: symbol::Interner,
span_interner: Lock<span_encoding::SpanInterner>,
hygiene_data: Lock<hygiene::HygieneData>,

/// A reference to the source map in the `Session`. It's an `Option`
/// because it can't be initialized until `Session` is created, which
/// happens after `SessionGlobals`. `set_source_map` does the
/// initialization.
///
/// This field should only be used in places where the `Session` is truly
/// not available, such as `<Span as Debug>::fmt`.
source_map: Lock<Option<Lrc<SourceMap>>>,
}

Expand Down Expand Up @@ -1013,16 +1021,9 @@ impl<D: Decoder> Decodable<D> for Span {
}
}

/// Calls the provided closure, using the provided `SourceMap` to format
/// any spans that are debug-printed during the closure's execution.
///
/// Normally, the global `TyCtxt` is used to retrieve the `SourceMap`
/// (see `rustc_interface::callbacks::span_debug1`). However, some parts
/// of the compiler (e.g. `rustc_parse`) may debug-print `Span`s before
/// a `TyCtxt` is available. In this case, we fall back to
/// the `SourceMap` provided to this function. If that is not available,
/// we fall back to printing the raw `Span` field values.
pub fn with_source_map<T, F: FnOnce() -> T>(source_map: Lrc<SourceMap>, f: F) -> T {
/// Insert `source_map` into the session globals for the duration of the
/// closure's execution.
pub fn set_source_map<T, F: FnOnce() -> T>(source_map: Lrc<SourceMap>, f: F) -> T {
with_session_globals(|session_globals| {
*session_globals.source_map.borrow_mut() = Some(source_map);
});
Expand All @@ -1041,6 +1042,8 @@ pub fn with_source_map<T, F: FnOnce() -> T>(source_map: Lrc<SourceMap>, f: F) ->

impl fmt::Debug for Span {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Use the global `SourceMap` to print the span. If that's not
// available, fall back to printing the raw values.
with_session_globals(|session_globals| {
if let Some(source_map) = &*session_globals.source_map.borrow() {
write!(f, "{} ({:?})", source_map.span_to_diagnostic_string(*self), self.ctxt())
Expand Down
16 changes: 5 additions & 11 deletions compiler/rustc_span/src/profiling.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::source_map::SourceMap;

use std::borrow::Borrow;

use rustc_data_structures::profiling::EventArgRecorder;
Expand All @@ -11,25 +13,17 @@ pub trait SpannedEventArgRecorder {
///
/// Note: when self-profiling with costly event arguments, at least one argument
/// needs to be recorded. A panic will be triggered if that doesn't happen.
fn record_arg_with_span<A>(&mut self, event_arg: A, span: crate::Span)
fn record_arg_with_span<A>(&mut self, source_map: &SourceMap, event_arg: A, span: crate::Span)
where
A: Borrow<str> + Into<String>;
}

impl SpannedEventArgRecorder for EventArgRecorder<'_> {
fn record_arg_with_span<A>(&mut self, event_arg: A, span: crate::Span)
fn record_arg_with_span<A>(&mut self, source_map: &SourceMap, event_arg: A, span: crate::Span)
where
A: Borrow<str> + Into<String>,
{
self.record_arg(event_arg);

let span_arg = crate::with_session_globals(|session_globals| {
if let Some(source_map) = &*session_globals.source_map.borrow() {
source_map.span_to_embeddable_string(span)
} else {
format!("{span:?}")
}
});
self.record_arg(span_arg);
self.record_arg(source_map.span_to_embeddable_string(span));
}
}
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,7 @@ symbols! {
rustc_diagnostic_macros,
rustc_dirty,
rustc_do_not_const_check,
rustc_doc_primitive,
rustc_dummy,
rustc_dump_env_program_clauses,
rustc_dump_program_clauses,
Expand Down
Loading