Skip to content

Commit 9a7f41d

Browse files
committed
Auto merge of rust-lang#129324 - GuillaumeGomez:rollup-fhf5ors, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - rust-lang#129270 (Don't consider locals to shadow inner items' generics) - rust-lang#129277 (Update annotate-snippets to 0.11) - rust-lang#129308 (fix: simple typo in compiler directory) - rust-lang#129309 (ctfe: make CompileTimeInterpCx type alias public) - rust-lang#129314 (fix a broken link in `mir/mod.rs`) - rust-lang#129318 (Remove unneeded conversion to `DefId` for `ExtraInfo`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4d5b3b1 + 26cef0c commit 9a7f41d

File tree

15 files changed

+92
-111
lines changed

15 files changed

+92
-111
lines changed

Cargo.lock

+2-12
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,6 @@ dependencies = [
9494
"yansi-term",
9595
]
9696

97-
[[package]]
98-
name = "annotate-snippets"
99-
version = "0.10.2"
100-
source = "registry+https://github.com/rust-lang/crates.io-index"
101-
checksum = "6d9b665789884a7e8fb06c84b295e923b03ca51edbb7d08f91a6a50322ecbfe6"
102-
dependencies = [
103-
"anstyle",
104-
"unicode-width",
105-
]
106-
10797
[[package]]
10898
name = "annotate-snippets"
10999
version = "0.11.4"
@@ -3642,7 +3632,7 @@ dependencies = [
36423632
name = "rustc_errors"
36433633
version = "0.0.0"
36443634
dependencies = [
3645-
"annotate-snippets 0.10.2",
3635+
"annotate-snippets 0.11.4",
36463636
"derive_setters",
36473637
"rustc_ast",
36483638
"rustc_ast_pretty",
@@ -3702,7 +3692,7 @@ dependencies = [
37023692
name = "rustc_fluent_macro"
37033693
version = "0.0.0"
37043694
dependencies = [
3705-
"annotate-snippets 0.10.2",
3695+
"annotate-snippets 0.11.4",
37063696
"fluent-bundle",
37073697
"fluent-syntax",
37083698
"proc-macro2",

compiler/rustc_const_eval/src/const_eval/machine.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ const TINY_LINT_TERMINATOR_LIMIT: usize = 20;
4040
/// power of two of interpreted terminators.
4141
const PROGRESS_INDICATOR_START: usize = 4_000_000;
4242

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

163-
pub(crate) type CompileTimeInterpCx<'tcx> = InterpCx<'tcx, CompileTimeMachine<'tcx>>;
166+
pub type CompileTimeInterpCx<'tcx> = InterpCx<'tcx, CompileTimeMachine<'tcx>>;
164167

165168
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
166169
pub enum MemoryKind {

compiler/rustc_errors/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
annotate-snippets = "0.10"
8+
annotate-snippets = "0.11"
99
derive_setters = "0.1.6"
1010
rustc_ast = { path = "../rustc_ast" }
1111
rustc_ast_pretty = { path = "../rustc_ast_pretty" }

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+29-40
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//!
66
//! [annotate_snippets]: https://docs.rs/crate/annotate-snippets/
77
8-
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};
8+
use annotate_snippets::{Renderer, Snippet};
99
use rustc_data_structures::sync::Lrc;
1010
use rustc_error_messages::FluentArgs;
1111
use rustc_span::source_map::SourceMap;
@@ -83,15 +83,17 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
8383
file.get_line(line.line_index - 1).map(|a| a.to_string()).unwrap_or_default()
8484
}
8585

86-
/// Maps `diagnostic::Level` to `snippet::AnnotationType`
87-
fn annotation_type_for_level(level: Level) -> AnnotationType {
86+
/// Maps [`crate::Level`] to [`annotate_snippets::Level`]
87+
fn annotation_level_for_level(level: Level) -> annotate_snippets::Level {
8888
match level {
89-
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => AnnotationType::Error,
90-
Level::ForceWarning(_) | Level::Warning => AnnotationType::Warning,
91-
Level::Note | Level::OnceNote => AnnotationType::Note,
92-
Level::Help | Level::OnceHelp => AnnotationType::Help,
89+
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => {
90+
annotate_snippets::Level::Error
91+
}
92+
Level::ForceWarning(_) | Level::Warning => annotate_snippets::Level::Warning,
93+
Level::Note | Level::OnceNote => annotate_snippets::Level::Note,
94+
Level::Help | Level::OnceHelp => annotate_snippets::Level::Help,
9395
// FIXME(#59346): Not sure how to map this level
94-
Level::FailureNote => AnnotationType::Error,
96+
Level::FailureNote => annotate_snippets::Level::Error,
9597
Level::Allow => panic!("Should not call with Allow"),
9698
Level::Expect(_) => panic!("Should not call with Expect"),
9799
}
@@ -180,42 +182,29 @@ impl AnnotateSnippetEmitter {
180182
})
181183
.collect();
182184
let code = code.map(|code| code.to_string());
183-
let snippet = Snippet {
184-
title: Some(Annotation {
185-
label: Some(&message),
186-
id: code.as_deref(),
187-
annotation_type: annotation_type_for_level(*level),
188-
}),
189-
footer: vec![],
190-
slices: annotated_files
191-
.iter()
192-
.map(|(file_name, source, line_index, annotations)| {
193-
Slice {
194-
source,
195-
line_start: *line_index,
196-
origin: Some(file_name),
197-
// FIXME(#59346): Not really sure when `fold` should be true or false
198-
fold: false,
199-
annotations: annotations
200-
.iter()
201-
.map(|annotation| SourceAnnotation {
202-
range: (
203-
annotation.start_col.display,
204-
annotation.end_col.display,
205-
),
206-
label: annotation.label.as_deref().unwrap_or_default(),
207-
annotation_type: annotation_type_for_level(*level),
208-
})
209-
.collect(),
210-
}
211-
})
212-
.collect(),
213-
};
185+
186+
let snippets =
187+
annotated_files.iter().map(|(file_name, source, line_index, annotations)| {
188+
Snippet::source(source)
189+
.line_start(*line_index)
190+
.origin(file_name)
191+
// FIXME(#59346): Not really sure when `fold` should be true or false
192+
.fold(false)
193+
.annotations(annotations.iter().map(|annotation| {
194+
annotation_level_for_level(*level)
195+
.span(annotation.start_col.display..annotation.end_col.display)
196+
.label(annotation.label.as_deref().unwrap_or_default())
197+
}))
198+
});
199+
let mut message = annotation_level_for_level(*level).title(&message).snippets(snippets);
200+
if let Some(code) = code.as_deref() {
201+
message = message.id(code)
202+
}
214203
// FIXME(#59346): Figure out if we can _always_ print to stderr or not.
215204
// `emitter.rs` has the `Destination` enum that lists various possible output
216205
// destinations.
217206
let renderer = Renderer::plain().anonymized_line_numbers(self.ui_testing);
218-
eprintln!("{}", renderer.render(snippet))
207+
eprintln!("{}", renderer.render(message))
219208
}
220209
// FIXME(#59346): Is it ok to return None if there's no source_map?
221210
}

compiler/rustc_fluent_macro/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ proc-macro = true
88

99
[dependencies]
1010
# tidy-alphabetical-start
11-
annotate-snippets = "0.10"
11+
annotate-snippets = "0.11"
1212
fluent-bundle = "0.15.2"
1313
fluent-syntax = "0.11"
1414
proc-macro2 = "1"

compiler/rustc_fluent_macro/src/fluent.rs

+9-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
22
use std::fs::read_to_string;
33
use std::path::{Path, PathBuf};
44

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

157-
let snippet = Snippet {
158-
title: Some(Annotation {
159-
label: Some(&err),
160-
id: None,
161-
annotation_type: AnnotationType::Error,
162-
}),
163-
footer: vec![],
164-
slices: vec![Slice {
165-
source: this.source(),
166-
line_start,
167-
origin: Some(&relative_ftl_path),
168-
fold: true,
169-
annotations: vec![SourceAnnotation {
170-
label: "",
171-
annotation_type: AnnotationType::Error,
172-
range: (pos.start, pos.end - 1),
173-
}],
174-
}],
175-
};
157+
let message = annotate_snippets::Level::Error.title(&err).snippet(
158+
Snippet::source(this.source())
159+
.line_start(line_start)
160+
.origin(&relative_ftl_path)
161+
.fold(true)
162+
.annotation(annotate_snippets::Level::Error.span(pos.start..pos.end - 1)),
163+
);
176164
let renderer = Renderer::plain();
177-
eprintln!("{}\n", renderer.render(snippet));
165+
eprintln!("{}\n", renderer.render(message));
178166
}
179167

180168
return failed(&crate_name);

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ rustc_index::newtype_index! {
13681368
/// [CFG]: https://rustc-dev-guide.rust-lang.org/appendix/background.html#cfg
13691369
/// [data-flow analyses]:
13701370
/// https://rustc-dev-guide.rust-lang.org/appendix/background.html#what-is-a-dataflow-analysis
1371-
/// [`CriticalCallEdges`]: ../../rustc_const_eval/transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges
1371+
/// [`CriticalCallEdges`]: ../../rustc_mir_transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges
13721372
/// [guide-mir]: https://rustc-dev-guide.rust-lang.org/mir/
13731373
#[derive(HashStable)]
13741374
#[encodable]

compiler/rustc_mir_build/src/build/scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
748748
self.cfg.terminate(block, source_info, TerminatorKind::UnwindResume);
749749
}
750750

751-
/// Sets up the drops for explict tail calls.
751+
/// Sets up the drops for explicit tail calls.
752752
///
753753
/// Unlike other kinds of early exits, tail calls do not go through the drop tree.
754754
/// Instead, all scheduled drops are immediately added to the CFG.

compiler/rustc_query_system/src/dep_graph/serialized.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<D: Deps> EncoderState<D> {
547547
/// Encodes a node that was promoted from the previous graph. It reads the information directly from
548548
/// the previous dep graph for performance reasons.
549549
///
550-
/// This differs from `encode_node` where you have to explictly provide the relevant `NodeInfo`.
550+
/// This differs from `encode_node` where you have to explicitly provide the relevant `NodeInfo`.
551551
///
552552
/// It expects all edges to already have a new dep node index assigned.
553553
#[inline]

compiler/rustc_resolve/src/late.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2677,14 +2677,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26772677
// We also can't shadow bindings from associated parent items.
26782678
for ns in [ValueNS, TypeNS] {
26792679
for parent_rib in self.ribs[ns].iter().rev() {
2680-
seen_bindings
2681-
.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
2682-
26832680
// Break at mod level, to account for nested items which are
26842681
// allowed to shadow generic param names.
26852682
if matches!(parent_rib.kind, RibKind::Module(..)) {
26862683
break;
26872684
}
2685+
2686+
seen_bindings
2687+
.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
26882688
}
26892689
}
26902690

src/librustdoc/clean/types.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel, StableS
1212
use rustc_const_eval::const_eval::is_unstable_const_fn;
1313
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1414
use rustc_hir::def::{CtorKind, DefKind, Res};
15-
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
15+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
1616
use rustc_hir::lang_items::LangItem;
1717
use rustc_hir::{BodyId, Mutability};
1818
use rustc_hir_analysis::check::intrinsic::intrinsic_operation_unsafety;
@@ -88,6 +88,11 @@ impl ItemId {
8888
}
8989
}
9090

91+
#[inline]
92+
pub(crate) fn as_local_def_id(self) -> Option<LocalDefId> {
93+
self.as_def_id().and_then(|id| id.as_local())
94+
}
95+
9196
#[inline]
9297
pub(crate) fn krate(self) -> CrateNum {
9398
match self {

src/librustdoc/doctest/rust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'a, 'tcx> HirCollector<'a, 'tcx> {
136136
self.enable_per_target_ignores,
137137
Some(&crate::html::markdown::ExtraInfo::new(
138138
self.tcx,
139-
def_id.to_def_id(),
139+
def_id,
140140
span_of_fragments(&attrs.doc_strings).unwrap_or(sp),
141141
)),
142142
);

src/librustdoc/html/markdown.rs

+20-24
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use pulldown_cmark::{
4040
};
4141
use rustc_data_structures::fx::FxHashMap;
4242
use rustc_errors::{Diag, DiagMessage};
43-
use rustc_hir::def_id::DefId;
43+
use rustc_hir::def_id::LocalDefId;
4444
use rustc_middle::ty::TyCtxt;
4545
pub(crate) use rustc_resolve::rustdoc::main_body_opts;
4646
use rustc_resolve::rustdoc::may_be_doc_link;
@@ -818,45 +818,41 @@ pub(crate) fn find_codes<T: doctest::DocTestVisitor>(
818818
}
819819

820820
pub(crate) struct ExtraInfo<'tcx> {
821-
def_id: DefId,
821+
def_id: LocalDefId,
822822
sp: Span,
823823
tcx: TyCtxt<'tcx>,
824824
}
825825

826826
impl<'tcx> ExtraInfo<'tcx> {
827-
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: DefId, sp: Span) -> ExtraInfo<'tcx> {
827+
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId, sp: Span) -> ExtraInfo<'tcx> {
828828
ExtraInfo { def_id, sp, tcx }
829829
}
830830

831831
fn error_invalid_codeblock_attr(&self, msg: impl Into<DiagMessage>) {
832-
if let Some(def_id) = self.def_id.as_local() {
833-
self.tcx.node_span_lint(
834-
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
835-
self.tcx.local_def_id_to_hir_id(def_id),
836-
self.sp,
837-
|lint| {
838-
lint.primary_message(msg);
839-
},
840-
);
841-
}
832+
self.tcx.node_span_lint(
833+
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
834+
self.tcx.local_def_id_to_hir_id(self.def_id),
835+
self.sp,
836+
|lint| {
837+
lint.primary_message(msg);
838+
},
839+
);
842840
}
843841

844842
fn error_invalid_codeblock_attr_with_help(
845843
&self,
846844
msg: impl Into<DiagMessage>,
847845
f: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
848846
) {
849-
if let Some(def_id) = self.def_id.as_local() {
850-
self.tcx.node_span_lint(
851-
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
852-
self.tcx.local_def_id_to_hir_id(def_id),
853-
self.sp,
854-
|lint| {
855-
lint.primary_message(msg);
856-
f(lint);
857-
},
858-
);
859-
}
847+
self.tcx.node_span_lint(
848+
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
849+
self.tcx.local_def_id_to_hir_id(self.def_id),
850+
self.sp,
851+
|lint| {
852+
lint.primary_message(msg);
853+
f(lint);
854+
},
855+
);
860856
}
861857
}
862858

src/librustdoc/passes/lint/check_code_block_syntax.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ use crate::core::DocContext;
1616
use crate::html::markdown::{self, RustCodeBlock};
1717

1818
pub(crate) fn visit_item(cx: &DocContext<'_>, item: &clean::Item) {
19-
if let Some(dox) = &item.opt_doc_value() {
19+
if let Some(def_id) = item.item_id.as_local_def_id()
20+
&& let Some(dox) = &item.opt_doc_value()
21+
{
2022
let sp = item.attr_span(cx.tcx);
21-
let extra = crate::html::markdown::ExtraInfo::new(cx.tcx, item.item_id.expect_def_id(), sp);
23+
let extra = crate::html::markdown::ExtraInfo::new(cx.tcx, def_id, sp);
2224
for code_block in markdown::rust_code_blocks(dox, &extra) {
2325
check_rust_syntax(cx, item, dox, code_block);
2426
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ check-pass
2+
3+
#![allow(non_camel_case_types)]
4+
5+
pub fn main() {
6+
let a = 1;
7+
struct Foo<a> { field: a, };
8+
}

0 commit comments

Comments
 (0)