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

rustc_resolve cleanups #125105

Merged
merged 4 commits into from
May 18, 2024
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
2 changes: 2 additions & 0 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use rustc_span::Span;

use std::cell::Cell;

use tracing::debug;

type Res = def::Res<NodeId>;

impl<'a, Id: Into<DefId>> ToNameBinding<'a>
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_hir::def_id::LocalDefId;
use rustc_span::hygiene::LocalExpnId;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;
use tracing::debug;

pub(crate) fn collect_definitions(
resolver: &mut Resolver<'_, '_>,
Expand Down
15 changes: 1 addition & 14 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{BytePos, Span, SyntaxContext};
use thin_vec::{thin_vec, ThinVec};
use tracing::debug;

use crate::errors::{
self, AddedMacroUse, ChangeImportBinding, ChangeImportBindingSuggestion, ConsiderAddingADerive,
Expand All @@ -43,9 +44,6 @@ use crate::{LexicalScopeBinding, NameBinding, NameBindingKind, PrivacyError, Vis
use crate::{ParentScope, PathResult, ResolutionError, Resolver, Scope, ScopeSet};
use crate::{Segment, UseError};

#[cfg(test)]
mod tests;

type Res = def::Res<ast::NodeId>;

/// A vector of spans and replacements, a message and applicability.
Expand Down Expand Up @@ -3026,14 +3024,3 @@ fn is_span_suitable_for_use_injection(s: Span) -> bool {
// import or other generated ones
!s.from_expansion()
}

/// Convert the given number into the corresponding ordinal
pub(crate) fn ordinalize(v: usize) -> String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this conflicts with #125042, but I think that one can use just the number too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #125042, the function is copied, not referenced (put aside whether it is good or not).

let suffix = match ((11..=13).contains(&(v % 100)), v % 10) {
(false, 1) => "st",
(false, 2) => "nd",
(false, 3) => "rd",
_ => "th",
};
format!("{v}{suffix}")
}
40 changes: 0 additions & 40 deletions compiler/rustc_resolve/src/diagnostics/tests.rs

This file was deleted.

1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/effective_visibilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_middle::middle::privacy::Level;
use rustc_middle::middle::privacy::{EffectiveVisibilities, EffectiveVisibility};
use rustc_middle::ty::Visibility;
use std::mem;
use tracing::info;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all of these additions from tracing in different files needed?

Copy link
Contributor Author

@nnethercote nnethercote May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The #[macro_use] extern crate tracing; gave us implicit import of all tracing macros. With that gone, we must do explicit imports, and tracing macros are used in lots of places.


#[derive(Clone, Copy)]
enum ParentId<'a> {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContex
use rustc_span::sym;
use rustc_span::symbol::{kw, Ident};
use rustc_span::Span;
use tracing::{debug, instrument};

use crate::errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
use crate::late::{ConstantHasGenerics, NoConstantGenericsReason, PathSource, Rib, RibKind};
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use rustc_span::hygiene::LocalExpnId;
use rustc_span::symbol::{kw, Ident, Symbol};
use rustc_span::Span;
use smallvec::SmallVec;
use tracing::debug;

use std::cell::Cell;
use std::mem;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use rustc_span::source_map::{respan, Spanned};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{BytePos, Span, SyntaxContext};
use smallvec::{smallvec, SmallVec};
use tracing::{debug, instrument, trace};

use std::assert_matches::debug_assert_matches;
use std::borrow::Cow;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use std::iter;
use std::ops::Deref;

use thin_vec::ThinVec;
use tracing::debug;

use super::NoConstantGenericsReason;

Expand Down
28 changes: 12 additions & 16 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@
//!
//! Type-relative name resolution (methods, fields, associated items) happens in `rustc_hir_analysis`.

// tidy-alphabetical-start
#![allow(internal_features)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::potential_query_instability)]
#![allow(rustc::untranslatable_diagnostic)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(extract_if)]
#![feature(if_let_guard)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(rustc_attrs)]
#![allow(rustdoc::private_intra_doc_links)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::potential_query_instability)]
#![allow(rustc::untranslatable_diagnostic)]
#![allow(internal_features)]

#[macro_use]
extern crate tracing;
#![feature(rustdoc_internals)]
// tidy-alphabetical-end

use errors::{
ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst, ParamKindInTyOfConstParam,
};
use rustc_arena::{DroplessArena, TypedArena};
use rustc_ast::expand::StrippedCfgItem;
use rustc_ast::node_id::NodeMap;
Expand Down Expand Up @@ -60,19 +55,21 @@ use rustc_session::lint::LintBuffer;
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};

use smallvec::{smallvec, SmallVec};
use std::cell::{Cell, RefCell};
use std::collections::BTreeSet;
use std::fmt;
use tracing::debug;

use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
use effective_visibilities::EffectiveVisibilitiesVisitor;
use errors::{
ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst, ParamKindInTyOfConstParam,
};
use imports::{Import, ImportData, ImportKind, NameResolution};
use late::{HasGenericParams, PathSource, PatternSource, UnnecessaryQualification};
use macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};

use crate::effective_visibilities::EffectiveVisibilitiesVisitor;

type Res = def::Res<NodeId>;

mod build_reduced_graph;
Expand Down Expand Up @@ -964,7 +961,6 @@ struct DeriveData {
has_derive_copy: bool,
}

#[derive(Clone)]
struct MacroData {
ext: Lrc<SyntaxExtension>,
rule_spans: Vec<(usize, Span)>,
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
UNUSED_MACRO_RULES,
node_id,
rule_span,
format!(
"{} rule of macro `{}` is never used",
crate::diagnostics::ordinalize(arm_i + 1),
ident.name
),
format!("rule #{} of macro `{}` is never used", arm_i + 1, ident.name),
);
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::{InnerSpan, Span, DUMMY_SP};
use std::mem;
use std::ops::Range;
use tracing::{debug, trace};

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum DocFragmentKind {
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules-compile-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ macro_rules! num {
// Some nested use
(two_) => { foo(compile_error!("foo")); };
(three) => { 3 };
(four) => { 4 }; //~ ERROR: rule of macro
(four) => { 4 }; //~ ERROR: rule #5 of macro
}
const _NUM: u8 = num!(one) + num!(three);

// compile_error not used as a macro invocation
macro_rules! num2 {
(one) => { 1 };
// Only identifier present
(two) => { fn compile_error() {} }; //~ ERROR: rule of macro
(two) => { fn compile_error() {} }; //~ ERROR: rule #2 of macro
// Only identifier and bang present
(two_) => { compile_error! }; //~ ERROR: rule of macro
(two_) => { compile_error! }; //~ ERROR: rule #3 of macro
(three) => { 3 };
}
const _NUM2: u8 = num2!(one) + num2!(three);
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules-compile-error.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: 5th rule of macro `num` is never used
error: rule #5 of macro `num` is never used
--> $DIR/unused-macro-rules-compile-error.rs:12:5
|
LL | (four) => { 4 };
Expand All @@ -10,13 +10,13 @@ note: the lint level is defined here
LL | #![deny(unused_macro_rules)]
| ^^^^^^^^^^^^^^^^^^

error: 3rd rule of macro `num2` is never used
error: rule #3 of macro `num2` is never used
--> $DIR/unused-macro-rules-compile-error.rs:22:5
|
LL | (two_) => { compile_error! };
| ^^^^^^

error: 2nd rule of macro `num2` is never used
error: rule #2 of macro `num2` is never used
--> $DIR/unused-macro-rules-compile-error.rs:20:5
|
LL | (two) => { fn compile_error() {} };
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules-decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Most simple case
macro num {
(one) => { 1 },
(two) => { 2 }, //~ ERROR: 2nd rule of macro
(two) => { 2 }, //~ ERROR: rule #2 of macro
(three) => { 3 },
(four) => { 4 }, //~ ERROR: 4th rule of macro
(four) => { 4 }, //~ ERROR: rule #4 of macro
}
const _NUM: u8 = num!(one) + num!(three);

Expand All @@ -28,7 +28,7 @@ macro num_rec {
(two) => {
num_rec!(one) + num_rec!(one)
},
(three) => { //~ ERROR: 3rd rule of macro
(three) => { //~ ERROR: rule #3 of macro
num_rec!(one) + num_rec!(two)
},
(four) => {
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules-decl.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: 4th rule of macro `num` is never used
error: rule #4 of macro `num` is never used
--> $DIR/unused-macro-rules-decl.rs:11:5
|
LL | (four) => { 4 },
Expand All @@ -10,13 +10,13 @@ note: the lint level is defined here
LL | #![deny(unused_macro_rules)]
| ^^^^^^^^^^^^^^^^^^

error: 2nd rule of macro `num` is never used
error: rule #2 of macro `num` is never used
--> $DIR/unused-macro-rules-decl.rs:9:5
|
LL | (two) => { 2 },
| ^^^^^

error: 3rd rule of macro `num_rec` is never used
error: rule #3 of macro `num_rec` is never used
--> $DIR/unused-macro-rules-decl.rs:31:5
|
LL | (three) => {
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// Most simple case
macro_rules! num {
(one) => { 1 };
(two) => { 2 }; //~ ERROR: 2nd rule of macro
(two) => { 2 }; //~ ERROR: rule #2 of macro
(three) => { 3 };
(four) => { 4 }; //~ ERROR: 4th rule of macro
(four) => { 4 }; //~ ERROR: rule #4 of macro
}
const _NUM: u8 = num!(one) + num!(three);

Expand All @@ -27,7 +27,7 @@ macro_rules! num_rec {
(two) => {
num_rec!(one) + num_rec!(one)
};
(three) => { //~ ERROR: 3rd rule of macro
(three) => { //~ ERROR: rule #3 of macro
num_rec!(one) + num_rec!(two)
};
(four) => { num_rec!(two) + num_rec!(two) };
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/unused/unused-macro-rules.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: 4th rule of macro `num` is never used
error: rule #4 of macro `num` is never used
--> $DIR/unused-macro-rules.rs:10:5
|
LL | (four) => { 4 };
Expand All @@ -10,13 +10,13 @@ note: the lint level is defined here
LL | #![deny(unused_macro_rules)]
| ^^^^^^^^^^^^^^^^^^

error: 2nd rule of macro `num` is never used
error: rule #2 of macro `num` is never used
--> $DIR/unused-macro-rules.rs:8:5
|
LL | (two) => { 2 };
| ^^^^^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future note: we should emit a single error for all of the unused rules in a single macro.

error: 3rd rule of macro `num_rec` is never used
error: rule #3 of macro `num_rec` is never used
--> $DIR/unused-macro-rules.rs:30:5
|
LL | (three) => {
Expand Down
Loading