Skip to content

Commit

Permalink
Auto merge of #129324 - GuillaumeGomez:rollup-fhf5ors, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - #129270 (Don't consider locals to shadow inner items' generics)
 - #129277 (Update annotate-snippets to 0.11)
 - #129308 (fix: simple typo in compiler directory)
 - #129309 (ctfe: make CompileTimeInterpCx type alias public)
 - #129314 (fix a broken link in `mir/mod.rs`)
 - #129318 (Remove unneeded conversion to `DefId` for `ExtraInfo`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 21, 2024
2 parents 5aea140 + 26cef0c commit 79c26da
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 111 deletions.
14 changes: 2 additions & 12 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ dependencies = [
"yansi-term",
]

[[package]]
name = "annotate-snippets"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d9b665789884a7e8fb06c84b295e923b03ca51edbb7d08f91a6a50322ecbfe6"
dependencies = [
"anstyle",
"unicode-width",
]

[[package]]
name = "annotate-snippets"
version = "0.11.4"
Expand Down Expand Up @@ -3642,7 +3632,7 @@ dependencies = [
name = "rustc_errors"
version = "0.0.0"
dependencies = [
"annotate-snippets 0.10.2",
"annotate-snippets 0.11.4",
"derive_setters",
"rustc_ast",
"rustc_ast_pretty",
Expand Down Expand Up @@ -3702,7 +3692,7 @@ dependencies = [
name = "rustc_fluent_macro"
version = "0.0.0"
dependencies = [
"annotate-snippets 0.10.2",
"annotate-snippets 0.11.4",
"fluent-bundle",
"fluent-syntax",
"proc-macro2",
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ const TINY_LINT_TERMINATOR_LIMIT: usize = 20;
/// power of two of interpreted terminators.
const PROGRESS_INDICATOR_START: usize = 4_000_000;

/// Extra machine state for CTFE, and the Machine instance
/// Extra machine state for CTFE, and the Machine instance.
//
// Should be public because out-of-tree rustc consumers need this
// if they want to interact with constant values.
pub struct CompileTimeMachine<'tcx> {
/// The number of terminators that have been evaluated.
///
Expand Down Expand Up @@ -160,7 +163,7 @@ impl<K: Hash + Eq, V> interpret::AllocMap<K, V> for FxIndexMap<K, V> {
}
}

pub(crate) type CompileTimeInterpCx<'tcx> = InterpCx<'tcx, CompileTimeMachine<'tcx>>;
pub type CompileTimeInterpCx<'tcx> = InterpCx<'tcx, CompileTimeMachine<'tcx>>;

#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum MemoryKind {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
# tidy-alphabetical-start
annotate-snippets = "0.10"
annotate-snippets = "0.11"
derive_setters = "0.1.6"
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
Expand Down
69 changes: 29 additions & 40 deletions compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! [annotate_snippets]: https://docs.rs/crate/annotate-snippets/
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};
use annotate_snippets::{Renderer, Snippet};
use rustc_data_structures::sync::Lrc;
use rustc_error_messages::FluentArgs;
use rustc_span::source_map::SourceMap;
Expand Down Expand Up @@ -83,15 +83,17 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
file.get_line(line.line_index - 1).map(|a| a.to_string()).unwrap_or_default()
}

/// Maps `diagnostic::Level` to `snippet::AnnotationType`
fn annotation_type_for_level(level: Level) -> AnnotationType {
/// Maps [`crate::Level`] to [`annotate_snippets::Level`]
fn annotation_level_for_level(level: Level) -> annotate_snippets::Level {
match level {
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => AnnotationType::Error,
Level::ForceWarning(_) | Level::Warning => AnnotationType::Warning,
Level::Note | Level::OnceNote => AnnotationType::Note,
Level::Help | Level::OnceHelp => AnnotationType::Help,
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => {
annotate_snippets::Level::Error
}
Level::ForceWarning(_) | Level::Warning => annotate_snippets::Level::Warning,
Level::Note | Level::OnceNote => annotate_snippets::Level::Note,
Level::Help | Level::OnceHelp => annotate_snippets::Level::Help,
// FIXME(#59346): Not sure how to map this level
Level::FailureNote => AnnotationType::Error,
Level::FailureNote => annotate_snippets::Level::Error,
Level::Allow => panic!("Should not call with Allow"),
Level::Expect(_) => panic!("Should not call with Expect"),
}
Expand Down Expand Up @@ -180,42 +182,29 @@ impl AnnotateSnippetEmitter {
})
.collect();
let code = code.map(|code| code.to_string());
let snippet = Snippet {
title: Some(Annotation {
label: Some(&message),
id: code.as_deref(),
annotation_type: annotation_type_for_level(*level),
}),
footer: vec![],
slices: annotated_files
.iter()
.map(|(file_name, source, line_index, annotations)| {
Slice {
source,
line_start: *line_index,
origin: Some(file_name),
// FIXME(#59346): Not really sure when `fold` should be true or false
fold: false,
annotations: annotations
.iter()
.map(|annotation| SourceAnnotation {
range: (
annotation.start_col.display,
annotation.end_col.display,
),
label: annotation.label.as_deref().unwrap_or_default(),
annotation_type: annotation_type_for_level(*level),
})
.collect(),
}
})
.collect(),
};

let snippets =
annotated_files.iter().map(|(file_name, source, line_index, annotations)| {
Snippet::source(source)
.line_start(*line_index)
.origin(file_name)
// FIXME(#59346): Not really sure when `fold` should be true or false
.fold(false)
.annotations(annotations.iter().map(|annotation| {
annotation_level_for_level(*level)
.span(annotation.start_col.display..annotation.end_col.display)
.label(annotation.label.as_deref().unwrap_or_default())
}))
});
let mut message = annotation_level_for_level(*level).title(&message).snippets(snippets);
if let Some(code) = code.as_deref() {
message = message.id(code)
}
// FIXME(#59346): Figure out if we can _always_ print to stderr or not.
// `emitter.rs` has the `Destination` enum that lists various possible output
// destinations.
let renderer = Renderer::plain().anonymized_line_numbers(self.ui_testing);
eprintln!("{}", renderer.render(snippet))
eprintln!("{}", renderer.render(message))
}
// FIXME(#59346): Is it ok to return None if there's no source_map?
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_fluent_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ proc-macro = true

[dependencies]
# tidy-alphabetical-start
annotate-snippets = "0.10"
annotate-snippets = "0.11"
fluent-bundle = "0.15.2"
fluent-syntax = "0.11"
proc-macro2 = "1"
Expand Down
30 changes: 9 additions & 21 deletions compiler/rustc_fluent_macro/src/fluent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
use std::fs::read_to_string;
use std::path::{Path, PathBuf};

use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};
use annotate_snippets::{Renderer, Snippet};
use fluent_bundle::{FluentBundle, FluentError, FluentResource};
use fluent_syntax::ast::{
Attribute, Entry, Expression, Identifier, InlineExpression, Message, Pattern, PatternElement,
Expand Down Expand Up @@ -154,27 +154,15 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
.unwrap()
.0;

let snippet = Snippet {
title: Some(Annotation {
label: Some(&err),
id: None,
annotation_type: AnnotationType::Error,
}),
footer: vec![],
slices: vec![Slice {
source: this.source(),
line_start,
origin: Some(&relative_ftl_path),
fold: true,
annotations: vec![SourceAnnotation {
label: "",
annotation_type: AnnotationType::Error,
range: (pos.start, pos.end - 1),
}],
}],
};
let message = annotate_snippets::Level::Error.title(&err).snippet(
Snippet::source(this.source())
.line_start(line_start)
.origin(&relative_ftl_path)
.fold(true)
.annotation(annotate_snippets::Level::Error.span(pos.start..pos.end - 1)),
);
let renderer = Renderer::plain();
eprintln!("{}\n", renderer.render(snippet));
eprintln!("{}\n", renderer.render(message));
}

return failed(&crate_name);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ rustc_index::newtype_index! {
/// [CFG]: https://rustc-dev-guide.rust-lang.org/appendix/background.html#cfg
/// [data-flow analyses]:
/// https://rustc-dev-guide.rust-lang.org/appendix/background.html#what-is-a-dataflow-analysis
/// [`CriticalCallEdges`]: ../../rustc_const_eval/transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges
/// [`CriticalCallEdges`]: ../../rustc_mir_transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges
/// [guide-mir]: https://rustc-dev-guide.rust-lang.org/mir/
#[derive(HashStable)]
#[encodable]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.cfg.terminate(block, source_info, TerminatorKind::UnwindResume);
}

/// Sets up the drops for explict tail calls.
/// Sets up the drops for explicit tail calls.
///
/// Unlike other kinds of early exits, tail calls do not go through the drop tree.
/// Instead, all scheduled drops are immediately added to the CFG.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/dep_graph/serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl<D: Deps> EncoderState<D> {
/// Encodes a node that was promoted from the previous graph. It reads the information directly from
/// the previous dep graph for performance reasons.
///
/// This differs from `encode_node` where you have to explictly provide the relevant `NodeInfo`.
/// This differs from `encode_node` where you have to explicitly provide the relevant `NodeInfo`.
///
/// It expects all edges to already have a new dep node index assigned.
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2677,14 +2677,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
// We also can't shadow bindings from associated parent items.
for ns in [ValueNS, TypeNS] {
for parent_rib in self.ribs[ns].iter().rev() {
seen_bindings
.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));

// Break at mod level, to account for nested items which are
// allowed to shadow generic param names.
if matches!(parent_rib.kind, RibKind::Module(..)) {
break;
}

seen_bindings
.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel, StableS
use rustc_const_eval::const_eval::is_unstable_const_fn;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::lang_items::LangItem;
use rustc_hir::{BodyId, Mutability};
use rustc_hir_analysis::check::intrinsic::intrinsic_operation_unsafety;
Expand Down Expand Up @@ -88,6 +88,11 @@ impl ItemId {
}
}

#[inline]
pub(crate) fn as_local_def_id(self) -> Option<LocalDefId> {
self.as_def_id().and_then(|id| id.as_local())
}

#[inline]
pub(crate) fn krate(self) -> CrateNum {
match self {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctest/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'a, 'tcx> HirCollector<'a, 'tcx> {
self.enable_per_target_ignores,
Some(&crate::html::markdown::ExtraInfo::new(
self.tcx,
def_id.to_def_id(),
def_id,
span_of_fragments(&attrs.doc_strings).unwrap_or(sp),
)),
);
Expand Down
44 changes: 20 additions & 24 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use pulldown_cmark::{
};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Diag, DiagMessage};
use rustc_hir::def_id::DefId;
use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::TyCtxt;
pub(crate) use rustc_resolve::rustdoc::main_body_opts;
use rustc_resolve::rustdoc::may_be_doc_link;
Expand Down Expand Up @@ -818,45 +818,41 @@ pub(crate) fn find_codes<T: doctest::DocTestVisitor>(
}

pub(crate) struct ExtraInfo<'tcx> {
def_id: DefId,
def_id: LocalDefId,
sp: Span,
tcx: TyCtxt<'tcx>,
}

impl<'tcx> ExtraInfo<'tcx> {
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: DefId, sp: Span) -> ExtraInfo<'tcx> {
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId, sp: Span) -> ExtraInfo<'tcx> {
ExtraInfo { def_id, sp, tcx }
}

fn error_invalid_codeblock_attr(&self, msg: impl Into<DiagMessage>) {
if let Some(def_id) = self.def_id.as_local() {
self.tcx.node_span_lint(
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
self.tcx.local_def_id_to_hir_id(def_id),
self.sp,
|lint| {
lint.primary_message(msg);
},
);
}
self.tcx.node_span_lint(
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
self.tcx.local_def_id_to_hir_id(self.def_id),
self.sp,
|lint| {
lint.primary_message(msg);
},
);
}

fn error_invalid_codeblock_attr_with_help(
&self,
msg: impl Into<DiagMessage>,
f: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
) {
if let Some(def_id) = self.def_id.as_local() {
self.tcx.node_span_lint(
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
self.tcx.local_def_id_to_hir_id(def_id),
self.sp,
|lint| {
lint.primary_message(msg);
f(lint);
},
);
}
self.tcx.node_span_lint(
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
self.tcx.local_def_id_to_hir_id(self.def_id),
self.sp,
|lint| {
lint.primary_message(msg);
f(lint);
},
);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/librustdoc/passes/lint/check_code_block_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ use crate::core::DocContext;
use crate::html::markdown::{self, RustCodeBlock};

pub(crate) fn visit_item(cx: &DocContext<'_>, item: &clean::Item) {
if let Some(dox) = &item.opt_doc_value() {
if let Some(def_id) = item.item_id.as_local_def_id()
&& let Some(dox) = &item.opt_doc_value()
{
let sp = item.attr_span(cx.tcx);
let extra = crate::html::markdown::ExtraInfo::new(cx.tcx, item.item_id.expect_def_id(), sp);
let extra = crate::html::markdown::ExtraInfo::new(cx.tcx, def_id, sp);
for code_block in markdown::rust_code_blocks(dox, &extra) {
check_rust_syntax(cx, item, dox, code_block);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/resolve/local-shadows-inner-generic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ check-pass

#![allow(non_camel_case_types)]

pub fn main() {
let a = 1;
struct Foo<a> { field: a, };
}

0 comments on commit 79c26da

Please sign in to comment.