Skip to content

Commit 0d53135

Browse files
committed
Auto merge of rust-lang#120715 - matthiaskrgr:rollup-sp1pp74, r=matthiaskrgr
Rollup of 12 pull requests Successful merges: - rust-lang#120520 (Some cleanups around diagnostic levels.) - rust-lang#120575 (Simplify codegen diagnostic handling) - rust-lang#120597 (Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved) - rust-lang#120602 (rustc_monomorphize: fix outdated comment in partition) - rust-lang#120609 (hir: Stop keeping prefixes for most of `use` list stems) - rust-lang#120631 (Emit a diagnostic for invalid target options) - rust-lang#120632 (For E0223, suggest associated functions that are similar to the path) - rust-lang#120670 (cleanup effect var handling) - rust-lang#120673 (rustc_metadata: fix typo) - rust-lang#120683 (miri: fix ICE with symbolic alignment check on extern static) - rust-lang#120690 (Remove b-naber from the compiler review rotation) - rust-lang#120713 (Make async closures test use async bound modifier) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4a2fe44 + d98a8a1 commit 0d53135

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+665
-370
lines changed

Diff for: compiler/rustc_ast_lowering/src/item.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
498498
}
499499
}
500500

501-
let res =
502-
self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
501+
let res = self.lower_import_res(id, path.span);
503502
let path = self.lower_use_path(res, &path, ParamMode::Explicit);
504503
hir::ItemKind::Use(path, hir::UseKind::Single)
505504
}
@@ -535,7 +534,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
535534
// for that we return the `{}` import (called the
536535
// `ListStem`).
537536

538-
let prefix = Path { segments, span: prefix.span.to(path.span), tokens: None };
537+
let span = prefix.span.to(path.span);
538+
let prefix = Path { segments, span, tokens: None };
539539

540540
// Add all the nested `PathListItem`s to the HIR.
541541
for &(ref use_tree, id) in trees {
@@ -569,9 +569,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
569569
});
570570
}
571571

572-
let res =
573-
self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
574-
let path = self.lower_use_path(res, &prefix, ParamMode::Explicit);
572+
let path = if trees.is_empty() && !prefix.segments.is_empty() {
573+
// For empty lists we need to lower the prefix so it is checked for things
574+
// like stability later.
575+
let res = self.lower_import_res(id, span);
576+
self.lower_use_path(res, &prefix, ParamMode::Explicit)
577+
} else {
578+
// For non-empty lists we can just drop all the data, the prefix is already
579+
// present in HIR as a part of nested imports.
580+
self.arena.alloc(hir::UsePath { res: smallvec![], segments: &[], span })
581+
};
575582
hir::ItemKind::Use(path, hir::UseKind::ListStem)
576583
}
577584
}

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
6464
use rustc_session::parse::{add_feature_diagnostics, feature_err};
6565
use rustc_span::symbol::{kw, sym, Ident, Symbol};
6666
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
67-
use smallvec::SmallVec;
67+
use smallvec::{smallvec, SmallVec};
6868
use std::collections::hash_map::Entry;
6969
use thin_vec::ThinVec;
7070

@@ -750,8 +750,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
750750
self.resolver.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
751751
}
752752

753-
fn expect_full_res_from_use(&mut self, id: NodeId) -> impl Iterator<Item = Res<NodeId>> {
754-
self.resolver.get_import_res(id).present_items()
753+
fn lower_import_res(&mut self, id: NodeId, span: Span) -> SmallVec<[Res; 3]> {
754+
let res = self.resolver.get_import_res(id).present_items();
755+
let res: SmallVec<_> = res.map(|res| self.lower_res(res)).collect();
756+
if res.is_empty() {
757+
self.dcx().span_delayed_bug(span, "no resolution for an import");
758+
return smallvec![Res::Err];
759+
}
760+
res
755761
}
756762

757763
fn make_lang_item_qpath(&mut self, lang_item: hir::LangItem, span: Span) -> hir::QPath<'hir> {

Diff for: compiler/rustc_ast_lowering/src/path.rs

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
196196
p: &Path,
197197
param_mode: ParamMode,
198198
) -> &'hir hir::UsePath<'hir> {
199+
assert!((1..=3).contains(&res.len()));
199200
self.arena.alloc(hir::UsePath {
200201
res,
201202
segments: self.arena.alloc_from_iter(p.segments.iter().map(|segment| {

Diff for: compiler/rustc_codegen_llvm/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ codegen_llvm_invalid_minimum_alignment_not_power_of_two =
2828
codegen_llvm_invalid_minimum_alignment_too_large =
2929
invalid minimum global alignment: {$align} is too large
3030
31+
codegen_llvm_invalid_target_feature_prefix = target feature `{$feature}` must begin with a `+` or `-`"
32+
3133
codegen_llvm_load_bitcode = failed to load bitcode of module "{$name}"
3234
codegen_llvm_load_bitcode_with_llvm_err = failed to load bitcode of module "{$name}": {$llvm_err}
3335

Diff for: compiler/rustc_codegen_llvm/src/errors.rs

+6
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,9 @@ pub struct MismatchedDataLayout<'a> {
253253
pub llvm_target: &'a str,
254254
pub llvm_layout: &'a str,
255255
}
256+
257+
#[derive(Diagnostic)]
258+
#[diag(codegen_llvm_invalid_target_feature_prefix)]
259+
pub(crate) struct InvalidTargetFeaturePrefix<'a> {
260+
pub feature: &'a str,
261+
}

Diff for: compiler/rustc_codegen_llvm/src/llvm_util.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::back::write::create_informational_target_machine;
22
use crate::errors::{
3-
PossibleFeature, TargetFeatureDisableOrEnable, UnknownCTargetFeature,
4-
UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
3+
InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable,
4+
UnknownCTargetFeature, UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
55
};
66
use crate::llvm;
77
use libc::c_int;
@@ -511,7 +511,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
511511
sess.target
512512
.features
513513
.split(',')
514-
.filter(|v| !v.is_empty() && backend_feature_name(v).is_some())
514+
.filter(|v| !v.is_empty() && backend_feature_name(sess, v).is_some())
515515
.map(String::from),
516516
);
517517

@@ -535,7 +535,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
535535
}
536536
};
537537

538-
let feature = backend_feature_name(s)?;
538+
let feature = backend_feature_name(sess, s)?;
539539
// Warn against use of LLVM specific feature names and unstable features on the CLI.
540540
if diagnostics {
541541
let feature_state = supported_features.iter().find(|&&(v, _)| v == feature);
@@ -611,11 +611,11 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
611611
/// Returns a feature name for the given `+feature` or `-feature` string.
612612
///
613613
/// Only allows features that are backend specific (i.e. not [`RUSTC_SPECIFIC_FEATURES`].)
614-
fn backend_feature_name(s: &str) -> Option<&str> {
614+
fn backend_feature_name<'a>(sess: &Session, s: &'a str) -> Option<&'a str> {
615615
// features must start with a `+` or `-`.
616-
let feature = s.strip_prefix(&['+', '-'][..]).unwrap_or_else(|| {
617-
bug!("target feature `{}` must begin with a `+` or `-`", s);
618-
});
616+
let feature = s
617+
.strip_prefix(&['+', '-'][..])
618+
.unwrap_or_else(|| sess.dcx().emit_fatal(InvalidTargetFeaturePrefix { feature: s }));
619619
// Rustc-specific feature requests like `+crt-static` or `-crt-static`
620620
// are not passed down to LLVM.
621621
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {

Diff for: compiler/rustc_codegen_ssa/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,7 @@ impl Translate for SharedEmitter {
18101810
}
18111811

18121812
impl Emitter for SharedEmitter {
1813-
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
1813+
fn emit_diagnostic(&mut self, diag: rustc_errors::Diagnostic) {
18141814
let args: FxHashMap<DiagnosticArgName, DiagnosticArgValue> =
18151815
diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect();
18161816
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {

Diff for: compiler/rustc_const_eval/src/interpret/validity.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
993993
// Complain about any other kind of error -- those are bad because we'd like to
994994
// report them in a way that shows *where* in the value the issue lies.
995995
Err(err) => {
996-
bug!(
997-
"Unexpected Undefined Behavior error during validation: {}",
998-
self.format_error(err)
999-
);
996+
bug!("Unexpected error during validation: {}", self.format_error(err));
1000997
}
1001998
}
1002999
}

Diff for: compiler/rustc_error_messages/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl From<Cow<'static, str>> for DiagnosticMessage {
378378
}
379379
}
380380

381-
/// A workaround for "good path" ICEs when formatting types in disabled lints.
381+
/// A workaround for good_path_delayed_bug ICEs when formatting types in disabled lints.
382382
///
383383
/// Delays formatting until `.into(): DiagnosticMessage` is used.
384384
pub struct DelayDm<F>(pub F);

Diff for: compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ impl Translate for AnnotateSnippetEmitter {
4444

4545
impl Emitter for AnnotateSnippetEmitter {
4646
/// The entry point for the diagnostics generation
47-
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
47+
fn emit_diagnostic(&mut self, mut diag: Diagnostic) {
4848
let fluent_args = to_fluent_args(diag.args());
4949

50-
let mut children = diag.children.clone();
51-
let (mut primary_span, suggestions) = self.primary_span_formatted(diag, &fluent_args);
50+
let mut suggestions = diag.suggestions.unwrap_or(vec![]);
51+
self.primary_span_formatted(&mut diag.span, &mut suggestions, &fluent_args);
5252

5353
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
54-
&mut primary_span,
55-
&mut children,
54+
&mut diag.span,
55+
&mut diag.children,
5656
&diag.level,
5757
self.macro_backtrace,
5858
);
@@ -62,9 +62,9 @@ impl Emitter for AnnotateSnippetEmitter {
6262
&diag.messages,
6363
&fluent_args,
6464
&diag.code,
65-
&primary_span,
66-
&children,
67-
suggestions,
65+
&diag.span,
66+
&diag.children,
67+
&suggestions,
6868
);
6969
}
7070

@@ -85,7 +85,11 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
8585
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
8686
fn annotation_type_for_level(level: Level) -> AnnotationType {
8787
match level {
88-
Level::Bug | Level::DelayedBug(_) | Level::Fatal | Level::Error => AnnotationType::Error,
88+
Level::Bug
89+
| Level::Fatal
90+
| Level::Error
91+
| Level::DelayedBug
92+
| Level::GoodPathDelayedBug => AnnotationType::Error,
8993
Level::ForceWarning(_) | Level::Warning => AnnotationType::Warning,
9094
Level::Note | Level::OnceNote => AnnotationType::Note,
9195
Level::Help | Level::OnceHelp => AnnotationType::Help,

Diff for: compiler/rustc_errors/src/diagnostic.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::snippet::Style;
22
use crate::{
3-
CodeSuggestion, DelayedBugKind, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee,
4-
ErrCode, Level, MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart,
5-
SuggestionStyle,
3+
CodeSuggestion, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, ErrCode, Level,
4+
MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
65
};
76
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
87
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
@@ -235,19 +234,16 @@ impl Diagnostic {
235234

236235
pub fn is_error(&self) -> bool {
237236
match self.level {
238-
Level::Bug
239-
| Level::DelayedBug(DelayedBugKind::Normal)
240-
| Level::Fatal
241-
| Level::Error
242-
| Level::FailureNote => true,
237+
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => true,
243238

244-
Level::ForceWarning(_)
239+
Level::GoodPathDelayedBug
240+
| Level::ForceWarning(_)
245241
| Level::Warning
246-
| Level::DelayedBug(DelayedBugKind::GoodPath)
247242
| Level::Note
248243
| Level::OnceNote
249244
| Level::Help
250245
| Level::OnceHelp
246+
| Level::FailureNote
251247
| Level::Allow
252248
| Level::Expect(_) => false,
253249
}
@@ -306,11 +302,11 @@ impl Diagnostic {
306302
#[track_caller]
307303
pub fn downgrade_to_delayed_bug(&mut self) {
308304
assert!(
309-
self.is_error(),
305+
matches!(self.level, Level::Error | Level::DelayedBug),
310306
"downgrade_to_delayed_bug: cannot downgrade {:?} to DelayedBug: not an error",
311307
self.level
312308
);
313-
self.level = Level::DelayedBug(DelayedBugKind::Normal);
309+
self.level = Level::DelayedBug;
314310
}
315311

316312
/// Appends a labeled span to the diagnostic.

Diff for: compiler/rustc_errors/src/emitter.rs

+20-22
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub type DynEmitter = dyn Emitter + DynSend;
193193
/// Emitter trait for emitting errors.
194194
pub trait Emitter: Translate {
195195
/// Emit a structured diagnostic.
196-
fn emit_diagnostic(&mut self, diag: &Diagnostic);
196+
fn emit_diagnostic(&mut self, diag: Diagnostic);
197197

198198
/// Emit a notification that an artifact has been output.
199199
/// Currently only supported for the JSON format.
@@ -230,17 +230,17 @@ pub trait Emitter: Translate {
230230
///
231231
/// * If the current `Diagnostic` has only one visible `CodeSuggestion`,
232232
/// we format the `help` suggestion depending on the content of the
233-
/// substitutions. In that case, we return the modified span only.
233+
/// substitutions. In that case, we modify the span and clear the
234+
/// suggestions.
234235
///
235236
/// * If the current `Diagnostic` has multiple suggestions,
236-
/// we return the original `primary_span` and the original suggestions.
237-
fn primary_span_formatted<'a>(
237+
/// we leave `primary_span` and the suggestions untouched.
238+
fn primary_span_formatted(
238239
&mut self,
239-
diag: &'a Diagnostic,
240+
primary_span: &mut MultiSpan,
241+
suggestions: &mut Vec<CodeSuggestion>,
240242
fluent_args: &FluentArgs<'_>,
241-
) -> (MultiSpan, &'a [CodeSuggestion]) {
242-
let mut primary_span = diag.span.clone();
243-
let suggestions = diag.suggestions.as_deref().unwrap_or(&[]);
243+
) {
244244
if let Some((sugg, rest)) = suggestions.split_first() {
245245
let msg = self.translate_message(&sugg.msg, fluent_args).map_err(Report::new).unwrap();
246246
if rest.is_empty() &&
@@ -287,16 +287,15 @@ pub trait Emitter: Translate {
287287
primary_span.push_span_label(sugg.substitutions[0].parts[0].span, msg);
288288

289289
// We return only the modified primary_span
290-
(primary_span, &[])
290+
suggestions.clear();
291291
} else {
292292
// if there are multiple suggestions, print them all in full
293293
// to be consistent. We could try to figure out if we can
294294
// make one (or the first one) inline, but that would give
295295
// undue importance to a semi-random suggestion
296-
(primary_span, suggestions)
297296
}
298297
} else {
299-
(primary_span, suggestions)
298+
// do nothing
300299
}
301300
}
302301

@@ -518,16 +517,15 @@ impl Emitter for HumanEmitter {
518517
self.sm.as_ref()
519518
}
520519

521-
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
520+
fn emit_diagnostic(&mut self, mut diag: Diagnostic) {
522521
let fluent_args = to_fluent_args(diag.args());
523522

524-
let mut children = diag.children.clone();
525-
let (mut primary_span, suggestions) = self.primary_span_formatted(diag, &fluent_args);
526-
debug!("emit_diagnostic: suggestions={:?}", suggestions);
523+
let mut suggestions = diag.suggestions.unwrap_or(vec![]);
524+
self.primary_span_formatted(&mut diag.span, &mut suggestions, &fluent_args);
527525

528526
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
529-
&mut primary_span,
530-
&mut children,
527+
&mut diag.span,
528+
&mut diag.children,
531529
&diag.level,
532530
self.macro_backtrace,
533531
);
@@ -537,9 +535,9 @@ impl Emitter for HumanEmitter {
537535
&diag.messages,
538536
&fluent_args,
539537
&diag.code,
540-
&primary_span,
541-
&children,
542-
suggestions,
538+
&diag.span,
539+
&diag.children,
540+
&suggestions,
543541
self.track_diagnostics.then_some(&diag.emitted_at),
544542
);
545543
}
@@ -576,9 +574,8 @@ impl Emitter for SilentEmitter {
576574
None
577575
}
578576

579-
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
577+
fn emit_diagnostic(&mut self, mut diag: Diagnostic) {
580578
if diag.level == Level::Fatal {
581-
let mut diag = diag.clone();
582579
diag.note(self.fatal_note.clone());
583580
self.fatal_dcx.emit_diagnostic(diag);
584581
}
@@ -2116,6 +2113,7 @@ impl HumanEmitter {
21162113
}
21172114
if !self.short_message {
21182115
for child in children {
2116+
assert!(child.level.can_be_top_or_sub().1);
21192117
let span = &child.span;
21202118
if let Err(err) = self.emit_messages_default_inner(
21212119
span,

0 commit comments

Comments
 (0)