Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use rustc_metadata::{
walk_native_lib_search_dirs,
};
use rustc_middle::bug;
use rustc_middle::lint::diag_lint_level;
use rustc_middle::lint::emit_lint_base;
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
use rustc_middle::middle::dependency_format::Linkage;
use rustc_middle::middle::exported_symbols::SymbolExportKind;
Expand Down Expand Up @@ -784,7 +784,7 @@ fn report_linker_output(sess: &Session, levels: CodegenLintLevels, stdout: &[u8]
}

let lint_msg = |msg| {
diag_lint_level(
emit_lint_base(
sess,
LINKER_MESSAGES,
levels.linker_messages,
Expand All @@ -793,7 +793,7 @@ fn report_linker_output(sess: &Session, levels: CodegenLintLevels, stdout: &[u8]
);
};
let lint_info = |msg| {
diag_lint_level(sess, LINKER_INFO, levels.linker_info, None, LinkerOutput { inner: msg });
emit_lint_base(sess, LINKER_INFO, levels.linker_info, None, LinkerOutput { inner: msg });
};

if !escaped_stderr.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ pub trait LintContext {
// set the span in their `decorate` function (preferably using set_span).
/// Emit a lint at the appropriate level, with an optional associated span.
///
/// [`diag_lint_level`]: rustc_middle::lint::diag_lint_level#decorate-signature
/// [`emit_lint_base`]: rustc_middle::lint::emit_lint_base#decorate-signature
#[track_caller]
fn opt_span_diag_lint<S: Into<MultiSpan>>(
&self,
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_index::IndexVec;
use rustc_middle::bug;
use rustc_middle::hir::nested_filter;
use rustc_middle::lint::{
LevelAndSource, LintExpectation, LintLevelSource, ShallowLintLevelMap, diag_lint_level,
LevelAndSource, LintExpectation, LintLevelSource, ShallowLintLevelMap, emit_lint_base,
reveal_actual_level,
};
use rustc_middle::query::Providers;
Expand Down Expand Up @@ -981,7 +981,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
if self.lint_added_lints {
let lint = builtin::UNKNOWN_LINTS;
let level = self.lint_level(builtin::UNKNOWN_LINTS);
diag_lint_level(
emit_lint_base(
self.sess,
lint,
level,
Expand All @@ -1008,7 +1008,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
decorator: impl for<'a> Diagnostic<'a, ()>,
) {
let level = self.lint_level(lint);
diag_lint_level(self.sess, lint, level, span, decorator)
emit_lint_base(self.sess, lint, level, span, decorator)
}

#[track_caller]
Expand All @@ -1019,13 +1019,13 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
decorator: impl for<'a> Diagnostic<'a, ()>,
) {
let level = self.lint_level(lint);
diag_lint_level(self.sess, lint, level, Some(span), decorator);
emit_lint_base(self.sess, lint, level, Some(span), decorator);
}

#[track_caller]
pub fn emit_lint(&self, lint: &'static Lint, decorator: impl for<'a> Diagnostic<'a, ()>) {
let level = self.lint_level(lint);
diag_lint_level(self.sess, lint, level, None, decorator);
emit_lint_base(self.sess, lint, level, None, decorator);
}
}

Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,8 @@ fn explain_lint_level_source(
///
/// - [`TyCtxt::emit_node_span_lint`]
/// - `LintContext::opt_span_lint`
///
/// This function will replace `lint_level` once all its callers have been replaced
/// with `diag_lint_level`.
#[track_caller]
pub fn diag_lint_level<'a, D: Diagnostic<'a, ()> + 'a>(
pub fn emit_lint_base<'a, D: Diagnostic<'a, ()> + 'a>(
sess: &'a Session,
lint: &'static Lint,
level: LevelAndSource,
Expand All @@ -314,7 +311,7 @@ pub fn diag_lint_level<'a, D: Diagnostic<'a, ()> + 'a>(
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
// the "real" work.
#[track_caller]
fn diag_lint_level_impl<'a>(
fn emit_lint_base_impl<'a>(
sess: &'a Session,
lint: &'static Lint,
level: LevelAndSource,
Expand Down Expand Up @@ -498,7 +495,7 @@ pub fn diag_lint_level<'a, D: Diagnostic<'a, ()> + 'a>(
explain_lint_level_source(sess, lint, level, src, &mut err);
err.emit();
}
diag_lint_level_impl(
emit_lint_base_impl(
sess,
lint,
level,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use crate::dep_graph::dep_node::make_metadata;
use crate::dep_graph::{DepGraph, DepKindVTable, DepNodeIndex};
use crate::ich::StableHashingContext;
use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarKind};
use crate::lint::diag_lint_level;
use crate::lint::emit_lint_base;
use crate::metadata::ModChild;
use crate::middle::codegen_fn_attrs::{CodegenFnAttrs, TargetFeature};
use crate::middle::resolve_bound_vars;
Expand Down Expand Up @@ -2539,7 +2539,7 @@ impl<'tcx> TyCtxt<'tcx> {
decorator: impl for<'a> Diagnostic<'a, ()>,
) {
let level = self.lint_level_at_node(lint, hir_id);
diag_lint_level(self.sess, lint, level, Some(span.into()), decorator)
emit_lint_base(self.sess, lint, level, Some(span.into()), decorator)
}

/// Find the appropriate span where `use` and outer attributes can be inserted at.
Expand Down Expand Up @@ -2582,7 +2582,7 @@ impl<'tcx> TyCtxt<'tcx> {
decorator: impl for<'a> Diagnostic<'a, ()>,
) {
let level = self.lint_level_at_node(lint, id);
diag_lint_level(self.sess, lint, level, None, decorator);
emit_lint_base(self.sess, lint, level, None, decorator);
}

pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate<'tcx>]> {
Expand Down
29 changes: 29 additions & 0 deletions tests/crashes/146965.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//@ known-bug: #146965
//@ compile-flags: --crate-type lib -C opt-level=3

fn conjure<T>() -> T {
panic!()
}

pub trait Ring {
type Element;
}
impl<T> Ring for T {
type Element = u16;
}

// Removing the : Ring bound makes it not ICE
fn map_coeff<T: Ring>(f: impl Fn(<T as Ring>::Element)) {
let c = conjure::<<T as Ring>::Element>();
f(c);
}

// Adding a : Ring bound makes it not ICE
fn gcd<T>() {
map_coeff::<T>(|_: u16| {});
}

// Removing the : Ring bound makes it not ICE
pub fn bivariate_factorization<T: Ring>() {
gcd::<T>();
}
21 changes: 21 additions & 0 deletions tests/crashes/150263.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ known-bug: #150263
//@ compile-flags: --crate-type lib -C opt-level=3

pub trait Scope {
type Timestamp;
}
impl<G> Scope for G {
type Timestamp = ();
}

pub fn create<G: Scope>() {
enter::<G>();
}

fn enter<G>() {
unary::<G>(|_: <G as Scope>::Timestamp| {});
}

fn unary<G: Scope>(constructor: impl FnOnce(G::Timestamp)) {
constructor(None.unwrap());
}
Loading