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 9 pull requests #129331

Merged
merged 18 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c864238
Update annotate-snippets to 0.11
Xiretza Aug 19, 2024
78d0e08
Don't consider RibKind::Module's bindings when checking generics shad…
compiler-errors Aug 19, 2024
dfea11d
Stabilize `iter::repeat_n`
scottmcm Aug 20, 2024
df019a9
skip updating when external binding is existed
bvanjoi Aug 16, 2024
2575196
fix: simple typo in compiler directory
c8ef Aug 20, 2024
38af7b0
ctfe: make CompileTimeInterpCx type alias public
RalfJung Aug 20, 2024
df568af
fix link in mir/mod
kyoto7250 Aug 20, 2024
83fce47
Remove unneeded conversion to `DefId` for `ExtraInfo`
GuillaumeGomez Aug 20, 2024
ef25fbd
lint on tail expr drop order change in Edition 2024
dingxiangfei2009 Aug 4, 2024
552b5c7
Rollup merge of #128662 - dingxiangfei2009:lint-tail-expr-drop-order,…
matthiaskrgr Aug 20, 2024
2e58d62
Rollup merge of #128932 - bvanjoi:issue-128813, r=petrochenkov
matthiaskrgr Aug 20, 2024
d502b1c
Rollup merge of #129270 - compiler-errors:inner-generics-shadowing, r…
matthiaskrgr Aug 20, 2024
43a1ca5
Rollup merge of #129277 - Xiretza:update-annotate-snippets, r=fee1-dead
matthiaskrgr Aug 20, 2024
aced570
Rollup merge of #129294 - scottmcm:stabilize-repeat-n, r=Noratrieb
matthiaskrgr Aug 20, 2024
ef9fba2
Rollup merge of #129308 - c8ef:typo, r=jieyouxu
matthiaskrgr Aug 20, 2024
b1f19ca
Rollup merge of #129309 - RalfJung:CompileTimeInterpCx, r=compiler-er…
matthiaskrgr Aug 20, 2024
71df480
Rollup merge of #129314 - kyoto7250:fix_link_in_mir_mod, r=compiler-e…
matthiaskrgr Aug 20, 2024
f631287
Rollup merge of #129318 - GuillaumeGomez:rm-unneeded-defid-conversion…
matthiaskrgr Aug 20, 2024
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
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
3 changes: 3 additions & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ lint_suspicious_double_ref_clone =
lint_suspicious_double_ref_deref =
using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type

lint_tail_expr_drop_order = these values and local bindings have significant drop implementation that will have a different drop order from that of Edition 2021
.label = these values have significant drop implementation and will observe changes in drop order under Edition 2024

lint_trailing_semi_macro = trailing semicolon in macro used in expression position
.note1 = macro invocations at the end of a block are treated as expressions
.note2 = to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mod ptr_nulls;
mod redundant_semicolon;
mod reference_casting;
mod shadowed_into_iter;
mod tail_expr_drop_order;
mod traits;
mod types;
mod unit_bindings;
Expand Down Expand Up @@ -115,6 +116,7 @@ use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use shadowed_into_iter::ShadowedIntoIter;
pub use shadowed_into_iter::{ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER};
use tail_expr_drop_order::TailExprDropOrder;
use traits::*;
use types::*;
use unit_bindings::*;
Expand Down Expand Up @@ -238,6 +240,7 @@ late_lint_methods!(
AsyncFnInTrait: AsyncFnInTrait,
NonLocalDefinitions: NonLocalDefinitions::default(),
ImplTraitOvercaptures: ImplTraitOvercaptures,
TailExprDropOrder: TailExprDropOrder,
]
]
);
Expand Down
Loading
Loading