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
3 changes: 0 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3853,8 +3853,6 @@ dependencies = [
"icu_list",
"icu_locale",
"intl-memoizer",
"rustc_ast",
"rustc_ast_pretty",
"rustc_baked_icu_data",
"rustc_data_structures",
"rustc_macros",
Expand Down Expand Up @@ -4186,7 +4184,6 @@ dependencies = [
name = "rustc_lint_defs"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_data_structures",
"rustc_error_messages",
"rustc_hir_id",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,8 +1117,8 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara
dcx.emit_err(errors::OutOfOrderParams {
spans: spans.clone(),
sugg_span: span,
param_ord,
max_param,
param_ord: param_ord.to_string(),
max_param: max_param.to_string(),
ordered_params: &ordered_params,
});
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Errors emitted by ast_passes.

use rustc_abi::ExternAbi;
use rustc_ast::ParamKindOrd;
use rustc_errors::codes::*;
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
Expand Down Expand Up @@ -632,8 +631,8 @@ pub(crate) struct OutOfOrderParams<'a> {
applicability = "machine-applicable"
)]
pub sugg_span: Span,
pub param_ord: &'a ParamKindOrd,
pub max_param: &'a ParamKindOrd,
pub param_ord: String,
pub max_param: String,
pub ordered_params: &'a str,
}

Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_builtin_macros/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::env::VarError;
use rustc_ast::token::{self, LitKind};
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::{ExprKind, GenericArg, Mutability};
use rustc_ast_pretty::pprust;
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
use rustc_span::edit_distance::edit_distance;
use rustc_span::{Ident, Span, Symbol, kw, sym};
Expand Down Expand Up @@ -158,13 +159,13 @@ pub(crate) fn expand_env<'cx>(
cx.dcx().emit_err(errors::EnvNotDefined::CargoEnvVar {
span,
var: *symbol,
var_expr: &var_expr,
var_expr: pprust::expr_to_string(&var_expr),
})
} else {
cx.dcx().emit_err(errors::EnvNotDefined::CustomEnvVar {
span,
var: *symbol,
var_expr: &var_expr,
var_expr: pprust::expr_to_string(&var_expr),
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for EnvNotDefinedWithUserMessag
}

#[derive(Diagnostic)]
pub(crate) enum EnvNotDefined<'a> {
pub(crate) enum EnvNotDefined {
#[diag("environment variable `{$var}` not defined at compile time")]
#[help("`{$var}` may not be available for the current Cargo target")]
#[help(
Expand All @@ -563,7 +563,7 @@ pub(crate) enum EnvNotDefined<'a> {
#[primary_span]
span: Span,
var: Symbol,
var_expr: &'a rustc_ast::Expr,
var_expr: String,
},
#[diag("environment variable `{$var}` not defined at compile time")]
#[help("there is a similar Cargo environment variable: `{$suggested_var}`")]
Expand All @@ -579,7 +579,7 @@ pub(crate) enum EnvNotDefined<'a> {
#[primary_span]
span: Span,
var: Symbol,
var_expr: &'a rustc_ast::Expr,
var_expr: String,
},
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/intrinsic/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
return_error!(InvalidMonomorphization::FloatingPointVector {
span,
name,
f_ty: *f,
f_ty: f.name_str().to_string(),
in_ty
});
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use rustc_errors::{
Level, msg,
};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::LayoutError;
use rustc_middle::ty::{FloatTy, Ty};
use rustc_span::{Span, Symbol};

use crate::assert_module_sources::CguReuse;
Expand Down Expand Up @@ -748,7 +748,7 @@ pub enum InvalidMonomorphization<'tcx> {
#[primary_span]
span: Span,
name: Symbol,
f_ty: FloatTy,
f_ty: String,
in_ty: Ty<'tcx>,
},

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_error_messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ fluent-bundle = "0.16"
icu_list = { version = "2.0", default-features = false, features = ["alloc"] }
icu_locale = { version = "2.0", default-features = false }
intl-memoizer = "0.5.1"
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_baked_icu_data = { path = "../rustc_baked_icu_data" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_macros = { path = "../rustc_macros" }
Expand Down
47 changes: 0 additions & 47 deletions compiler/rustc_error_messages/src/diagnostic_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use std::num::ParseIntError;
use std::path::{Path, PathBuf};
use std::process::ExitStatus;

use rustc_ast as ast;
use rustc_ast_pretty::pprust;
use rustc_span::edition::Edition;

use crate::{DiagArgValue, IntoDiagArg};
Expand Down Expand Up @@ -69,7 +67,6 @@ macro_rules! into_diag_arg_for_number {
}

into_diag_arg_using_display!(
ast::ParamKindOrd,
std::io::Error,
Box<dyn std::error::Error>,
std::num::NonZero<u32>,
Expand Down Expand Up @@ -142,30 +139,6 @@ impl IntoDiagArg for PathBuf {
}
}

impl IntoDiagArg for ast::Expr {
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(pprust::expr_to_string(&self)))
}
}

impl IntoDiagArg for ast::Path {
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(pprust::path_to_string(&self)))
}
}

impl IntoDiagArg for ast::token::Token {
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
DiagArgValue::Str(pprust::token_to_string(&self))
}
}

impl IntoDiagArg for ast::token::TokenKind {
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
DiagArgValue::Str(pprust::token_kind_to_string(&self))
}
}

impl IntoDiagArg for std::ffi::CString {
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
Expand All @@ -178,28 +151,8 @@ impl IntoDiagArg for rustc_data_structures::small_c_str::SmallCStr {
}
}

impl IntoDiagArg for ast::Visibility {
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
let s = pprust::vis_to_string(&self);
let s = s.trim_end().to_string();
DiagArgValue::Str(Cow::Owned(s))
}
}

impl IntoDiagArg for Backtrace {
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
DiagArgValue::Str(Cow::from(self.to_string()))
}
}

impl IntoDiagArg for ast::util::parser::ExprPrecedence {
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
DiagArgValue::Number(self as i32)
}
}

impl IntoDiagArg for ast::FloatTy {
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
DiagArgValue::Str(Cow::Borrowed(self.name_str()))
}
}
5 changes: 2 additions & 3 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::borrow::Cow;

use rustc_ast::ast;
use rustc_errors::codes::*;
use rustc_hir::limit::Limit;
use rustc_macros::{Diagnostic, Subdiagnostic};
Expand Down Expand Up @@ -230,7 +229,7 @@ pub(crate) struct WrongFragmentKind<'a> {
#[primary_span]
pub span: Span,
pub kind: &'a str,
pub name: &'a ast::Path,
pub name: String,
}

#[derive(Diagnostic)]
Expand All @@ -249,7 +248,7 @@ pub(crate) struct IncompleteParse<'a> {
pub descr: String,
#[label("caused by the macro expansion here")]
pub label_span: Span,
pub macro_path: &'a ast::Path,
pub macro_path: String,
pub kind_name: &'a str,
#[note("macros cannot expand to match arms")]
pub expands_to_match_arm: bool,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
mac: &ast::MacCall,
span: Span,
) -> ErrorGuaranteed {
let guar =
self.cx.dcx().emit_err(WrongFragmentKind { span, kind: kind.name(), name: &mac.path });
let name = pprust::path_to_string(&mac.path);
let guar = self.cx.dcx().emit_err(WrongFragmentKind { span, kind: kind.name(), name });
self.cx.macro_error_and_trace_macros_diag();
guar
}
Expand Down Expand Up @@ -1218,7 +1218,7 @@ pub(crate) fn ensure_complete_parse<'a>(
span: def_site_span,
descr,
label_span: span,
macro_path,
macro_path: pprust::path_to_string(macro_path),
kind_name,
expands_to_match_arm,
add_semicolon,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
continue;
}

let (level, lint_id) = match Level::from_attr(attr) {
let (level, lint_id) = match Level::from_attr(attr.name(), || attr.id()) {
None => continue,
// This is the only lint level with a `LintExpectationId` that can be created from
// an attribute.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint_defs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2024"

[dependencies]
# tidy-alphabetical-start
rustc_ast = { path = "../rustc_ast" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_error_messages = { path = "../rustc_error_messages" }
rustc_hir_id = { path = "../rustc_hir_id" }
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::borrow::Cow;
use std::fmt::Display;

use rustc_ast::AttrId;
use rustc_ast::attr::AttributeExt;
use rustc_data_structures::fx::FxIndexSet;
use rustc_data_structures::stable_hasher::{
HashStable, HashStableContext, StableCompare, StableHasher, ToStableHashKey,
Expand All @@ -12,7 +10,7 @@ use rustc_hir_id::{HirId, ItemLocalId};
use rustc_macros::{Decodable, Encodable, HashStable};
use rustc_span::def_id::DefPathHash;
pub use rustc_span::edition::Edition;
use rustc_span::{Ident, Symbol, sym};
use rustc_span::{AttrId, Ident, Symbol, sym};
use serde::{Deserialize, Serialize};

pub use self::Level::*;
Expand Down Expand Up @@ -238,8 +236,11 @@ impl Level {
}

/// Converts an `Attribute` to a level.
pub fn from_attr(attr: &impl AttributeExt) -> Option<(Self, Option<LintExpectationId>)> {
attr.name().and_then(|name| Self::from_symbol(name, || Some(attr.id())))
pub fn from_attr(
attr_name: Option<Symbol>,
attr_id: impl Fn() -> AttrId,
) -> Option<(Self, Option<LintExpectationId>)> {
attr_name.and_then(|name| Self::from_symbol(name, || Some(attr_id())))
}

/// Converts a `Symbol` to a level.
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_mir_build/src/builder/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
break;
}

if self.tcx.hir_attrs(id).iter().any(|attr| Level::from_attr(attr).is_some()) {
if self
.tcx
.hir_attrs(id)
.iter()
.any(|attr| Level::from_attr(attr.name(), || attr.id()).is_some())
{
// This is a rare case. It's for a node path that doesn't reach the root due to an
// intervening lint level attribute. This result doesn't get cached.
return id;
Expand Down
Loading
Loading