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 11 pull requests #121789

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aca631f
Increase visibility of `join_path` and `split_paths`
tgross35 Jan 8, 2024
0de3677
Fix typo
joshtriplett Feb 11, 2024
75a4fa1
Suggest moving if non-found macro_rules! is defined later
chenyukang Feb 15, 2024
5d59d0c
have `String` use `SliceIndex` impls from `str`
pitaj Jan 24, 2024
11f9489
Changing some attributes to only_local.
surechen Feb 28, 2024
75e15f7
Deeply normalize obligations in refining_impl_trait
compiler-errors Feb 28, 2024
5512945
Implement unwind safety for Condvar
ecton Feb 28, 2024
3fbdec4
Add a comment about how `IntoDiagnostic` should be impl'd.
nnethercote Feb 27, 2024
199be46
Refactor `DiagCtxtInner::flush_delayed`.
nnethercote Feb 27, 2024
9dfe5ef
Fix typo in `rustc_passes/messages.ftl`
sisungo Feb 29, 2024
9c6a076
document potential memory leak in unbounded channel
ibraheemdev Feb 29, 2024
1850ba7
Remove unused diagnostic struct
mu001999 Feb 29, 2024
7c9fa95
fix typos
ibraheemdev Feb 29, 2024
da37c8f
Fix tests that are affected by this change
sisungo Feb 29, 2024
ad4c932
Restore the standard library review rotation to its former glory
Amanieu Feb 28, 2024
2978c98
Rollup merge of #119748 - tgross35:suggest-path-split, r=Amanieu
jhpratt Feb 29, 2024
7b29e65
Rollup merge of #120291 - pitaj:string-sliceindex, r=Amanieu
jhpratt Feb 29, 2024
032f19d
Rollup merge of #121130 - chenyukang:yukang-fix-121061-macro-later, r…
jhpratt Feb 29, 2024
cecc2a4
Rollup merge of #121723 - nnethercote:two-diagnostic-things, r=oli-obk
jhpratt Feb 29, 2024
4010270
Rollup merge of #121740 - surechen:change_attribute_to_local_20240228…
jhpratt Feb 29, 2024
d9becfb
Rollup merge of #121745 - compiler-errors:refining-impl-trait-deeply-…
jhpratt Feb 29, 2024
ccb2cb8
Rollup merge of #121748 - Amanieu:restore-libs-rotation, r=Amanieu
jhpratt Feb 29, 2024
f0e5863
Rollup merge of #121768 - ecton:condvar-unwindsafe, r=m-ou-se
jhpratt Feb 29, 2024
3b15e6b
Rollup merge of #121777 - sisungo:master, r=oli-obk
jhpratt Feb 29, 2024
e392b48
Rollup merge of #121778 - ibraheemdev:patch-19, r=RalfJung
jhpratt Feb 29, 2024
f8b3fbc
Rollup merge of #121779 - mu001999:clean, r=Nilstrieb
jhpratt Feb 29, 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
21 changes: 0 additions & 21 deletions compiler/rustc_builtin_macros/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,27 +136,6 @@ pub(crate) struct BenchSig {
pub(crate) span: Span,
}

#[derive(Diagnostic)]
#[diag(builtin_macros_test_arg_non_lifetime)]
pub(crate) struct TestArgNonLifetime {
#[primary_span]
pub(crate) span: Span,
}

#[derive(Diagnostic)]
#[diag(builtin_macros_should_panic)]
pub(crate) struct ShouldPanic {
#[primary_span]
pub(crate) span: Span,
}

#[derive(Diagnostic)]
#[diag(builtin_macros_test_args)]
pub(crate) struct TestArgs {
#[primary_span]
pub(crate) span: Span,
}

#[derive(Diagnostic)]
#[diag(builtin_macros_alloc_must_statics)]
pub(crate) struct AllocMustStatics {
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError {

/// Trait implemented by error types. This is rarely implemented manually. Instead, use
/// `#[derive(Diagnostic)]` -- see [rustc_macros::Diagnostic].
///
/// When implemented manually, it should be generic over the emission
/// guarantee, i.e.:
/// ```ignore (fragment)
/// impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for Foo { ... }
/// ```
/// rather than being specific:
/// ```ignore (fragment)
/// impl<'a> IntoDiagnostic<'a> for Bar { ... } // the default type param is `ErrorGuaranteed`
/// impl<'a> IntoDiagnostic<'a, ()> for Baz { ... }
/// ```
/// There are two reasons for this.
/// - A diagnostic like `Foo` *could* be emitted at any level -- `level` is
/// passed in to `into_diagnostic` from outside. Even if in practice it is
/// always emitted at a single level, we let the diagnostic creation/emission
/// site determine the level (by using `create_err`, `emit_warn`, etc.)
/// rather than the `IntoDiagnostic` impl.
/// - Derived impls are always generic, and it's good for the hand-written
/// impls to be consistent with them.
#[rustc_diagnostic_item = "IntoDiagnostic"]
pub trait IntoDiagnostic<'a, G: EmissionGuarantee = ErrorGuaranteed> {
/// Write out as a diagnostic out of `DiagCtxt`.
Expand Down
42 changes: 21 additions & 21 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,14 +1498,26 @@ impl DiagCtxtInner {
let bugs: Vec<_> =
std::mem::take(&mut self.delayed_bugs).into_iter().map(|(b, _)| b).collect();

// If backtraces are enabled, also print the query stack
let backtrace = std::env::var_os("RUST_BACKTRACE").map_or(true, |x| &x != "0");
for (i, bug) in bugs.into_iter().enumerate() {
if let Some(file) = self.ice_file.as_ref()
&& let Ok(mut out) = std::fs::File::options().create(true).append(true).open(file)
{
let _ = write!(
&mut out,
let decorate = backtrace || self.ice_file.is_none();
let mut out = self
.ice_file
.as_ref()
.and_then(|file| std::fs::File::options().create(true).append(true).open(file).ok());

// Put the overall explanation before the `DelayedBug`s, to frame them
// better (e.g. separate warnings from them). Also, use notes, which
// don't count as errors, to avoid possibly triggering
// `-Ztreat-err-as-bug`, which we don't want.
let note1 = "no errors encountered even though delayed bugs were created";
let note2 = "those delayed bugs will now be shown as internal compiler errors";
self.emit_diagnostic(DiagInner::new(Note, note1));
self.emit_diagnostic(DiagInner::new(Note, note2));

for bug in bugs {
if let Some(out) = &mut out {
_ = write!(
out,
"delayed bug: {}\n{}\n",
bug.inner
.messages
Expand All @@ -1516,21 +1528,9 @@ impl DiagCtxtInner {
);
}

if i == 0 {
// Put the overall explanation before the `DelayedBug`s, to
// frame them better (e.g. separate warnings from them). Also,
// make it a note so it doesn't count as an error, because that
// could trigger `-Ztreat-err-as-bug`, which we don't want.
let note1 = "no errors encountered even though delayed bugs were created";
let note2 = "those delayed bugs will now be shown as internal compiler errors";
self.emit_diagnostic(DiagInner::new(Note, note1));
self.emit_diagnostic(DiagInner::new(Note, note2));
}

let mut bug =
if backtrace || self.ice_file.is_none() { bug.decorate(self) } else { bug.inner };
let mut bug = if decorate { bug.decorate(self) } else { bug.inner };

// "Undelay" the delayed bugs (into plain `Bug`s).
// "Undelay" the delayed bugs into plain bugs.
if bug.level != DelayedBug {
// NOTE(eddyb) not panicking here because we're already producing
// an ICE, and the more information the merrier.
Expand Down
63 changes: 45 additions & 18 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,56 +555,80 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),
gated!(
rustc_allow_const_fn_unstable, Normal,
template!(Word, List: "feat1, feat2, ..."), DuplicatesOk,
template!(Word, List: "feat1, feat2, ..."), DuplicatesOk, @only_local: true,
"rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
),
gated!(
allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
"allow_internal_unsafe side-steps the unsafe_code lint",
@only_local: true, "allow_internal_unsafe side-steps the unsafe_code lint",
),
rustc_attr!(
rustc_allowed_through_unstable_modules, Normal, template!(Word),
WarnFollowing, @only_local: true,
"rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
through unstable paths"
),
rustc_attr!(rustc_allowed_through_unstable_modules, Normal, template!(Word), WarnFollowing,
"rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
through unstable paths"),

// ==========================================================================
// Internal attributes: Type system related:
// ==========================================================================

gated!(fundamental, Normal, template!(Word), WarnFollowing, experimental!(fundamental)),
gated!(
may_dangle, Normal, template!(Word), WarnFollowing, dropck_eyepatch,
may_dangle, Normal, template!(Word), WarnFollowing,
@only_local: true, dropck_eyepatch,
"`may_dangle` has unstable semantics and may be removed in the future",
),

// ==========================================================================
// Internal attributes: Runtime related:
// ==========================================================================

rustc_attr!(rustc_allocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
rustc_attr!(rustc_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
rustc_attr!(rustc_reallocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
rustc_attr!(rustc_deallocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
rustc_attr!(rustc_allocator_zeroed, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
rustc_attr!(
rustc_allocator, Normal, template!(Word), WarnFollowing,
@only_local: true, IMPL_DETAIL
),
rustc_attr!(
rustc_nounwind, Normal, template!(Word), WarnFollowing,
@only_local: true, IMPL_DETAIL
),
rustc_attr!(
rustc_reallocator, Normal, template!(Word), WarnFollowing,
@only_local: true, IMPL_DETAIL
),
rustc_attr!(
rustc_deallocator, Normal, template!(Word), WarnFollowing,
@only_local: true, IMPL_DETAIL
),
rustc_attr!(
rustc_allocator_zeroed, Normal, template!(Word), WarnFollowing,
@only_local: true, IMPL_DETAIL
),
gated!(
default_lib_allocator, Normal, template!(Word), WarnFollowing,
@only_local: true, allocator_internals, experimental!(default_lib_allocator),
),
gated!(
default_lib_allocator, Normal, template!(Word), WarnFollowing, allocator_internals,
experimental!(default_lib_allocator),
needs_allocator, Normal, template!(Word), WarnFollowing,
@only_local: true, allocator_internals, experimental!(needs_allocator),
),
gated!(
needs_allocator, Normal, template!(Word), WarnFollowing, allocator_internals,
experimental!(needs_allocator),
panic_runtime, Normal, template!(Word), WarnFollowing,
@only_local: true, experimental!(panic_runtime)
),
gated!(panic_runtime, Normal, template!(Word), WarnFollowing, experimental!(panic_runtime)),
gated!(
needs_panic_runtime, Normal, template!(Word), WarnFollowing,
experimental!(needs_panic_runtime)
@only_local: true, experimental!(needs_panic_runtime)
),
gated!(
compiler_builtins, Normal, template!(Word), WarnFollowing,
@only_local: true,
"the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
which contains compiler-rt intrinsics and will never be stable",
),
gated!(
profiler_runtime, Normal, template!(Word), WarnFollowing,
@only_local: true,
"the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
which contains the profiler runtime and will never be stable",
),
Expand All @@ -630,7 +654,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
template!(Word, List: "name, /*opt*/ attributes(name1, name2, ...)"), ErrorFollowing,
IMPL_DETAIL,
),
rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
rustc_attr!(
rustc_proc_macro_decls, Normal, template!(Word), WarnFollowing,
@only_local: true, INTERNAL_UNSTABLE
),
rustc_attr!(
rustc_macro_transparency, Normal,
template!(NameValueStr: "transparent|semitransparent|opaque"), ErrorFollowing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
// 1. Project the RPITIT projections from the trait to the opaques on the impl,
// which means that they don't need to be mapped manually.
//
// 2. Project any other projections that show up in the bound. That makes sure that
// we don't consider `tests/ui/async-await/in-trait/async-associated-types.rs`
// to be refining.
let (trait_bounds, impl_bounds) =
ocx.normalize(&ObligationCause::dummy(), param_env, (trait_bounds, impl_bounds));
// 2. Deeply normalize any other projections that show up in the bound. That makes sure
// that we don't consider `tests/ui/async-await/in-trait/async-associated-types.rs`
// or `tests/ui/impl-trait/in-trait/refine-normalize.rs` to be refining.
let Ok((trait_bounds, impl_bounds)) =
ocx.deeply_normalize(&ObligationCause::dummy(), param_env, (trait_bounds, impl_bounds))
else {
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)");
return;
};

// Since we've normalized things, we need to resolve regions, since we'll
// possibly have introduced region vars during projection. We don't expect
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,13 +1004,6 @@ pub(crate) struct StaticSpecialize {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_missing_tilde_const)]
pub(crate) struct MissingTildeConst {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
pub(crate) enum DropImplPolarity {
#[diag(hir_analysis_drop_impl_negative)]
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,14 +557,6 @@ pub(crate) struct CatchAfterTry {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(parse_gen_fn)]
#[help]
pub(crate) struct GenFn {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(parse_comma_after_base_struct)]
#[note]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ passes_doc_attr_not_crate_level =
`#![doc({$attr_name} = "...")]` isn't allowed as a crate-level attribute

passes_doc_cfg_hide_takes_list =
`#[doc(cfg_hide(...)]` takes a list of attributes
`#[doc(cfg_hide(...))]` takes a list of attributes

passes_doc_expect_str =
doc {$attr_name} attribute expects a string: #[doc({$attr_name} = "a")]
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_resolve/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ resolve_consider_declaring_with_pub =
resolve_consider_marking_as_pub =
consider marking `{$ident}` as `pub` in the imported module

resolve_consider_move_macro_position =
consider moving the definition of `{$ident}` before this call


resolve_const_not_member_of_trait =
const `{$const_}` is not a member of trait `{$trait_}`
.label = not a member of trait `{$trait_}`
Expand Down Expand Up @@ -186,6 +190,9 @@ resolve_lowercase_self =
attempt to use a non-constant value in a constant
.suggestion = try using `Self`

resolve_macro_defined_later =
a macro with the same name exists, but it appears later at here

resolve_macro_expected_found =
expected {$expected}, found {$found} `{$macro_path}`

Expand Down
23 changes: 22 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ use rustc_span::{BytePos, Span, SyntaxContext};
use thin_vec::{thin_vec, ThinVec};

use crate::errors::{AddedMacroUse, ChangeImportBinding, ChangeImportBindingSuggestion};
use crate::errors::{ConsiderAddingADerive, ExplicitUnsafeTraits, MaybeMissingMacroRulesName};
use crate::errors::{
ConsiderAddingADerive, ExplicitUnsafeTraits, MacroDefinedLater, MacroSuggMovePosition,
MaybeMissingMacroRulesName,
};
use crate::imports::{Import, ImportKind};
use crate::late::{PatternSource, Rib};
use crate::{errors as errs, BindingKey};
Expand Down Expand Up @@ -1456,6 +1459,24 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
return;
}

let unused_macro = self.unused_macros.iter().find_map(|(def_id, (_, unused_ident))| {
if unused_ident.name == ident.name {
Some((def_id.clone(), unused_ident.clone()))
} else {
None
}
});

if let Some((def_id, unused_ident)) = unused_macro {
let scope = self.local_macro_def_scopes[&def_id];
let parent_nearest = parent_scope.module.nearest_parent_mod();
if Some(parent_nearest) == scope.opt_def_id() {
err.subdiagnostic(self.dcx(), MacroDefinedLater { span: unused_ident.span });
err.subdiagnostic(self.dcx(), MacroSuggMovePosition { span: ident.span, ident });
return;
}
}

if self.macro_names.contains(&ident.normalize_to_macros_2_0()) {
err.subdiagnostic(self.dcx(), AddedMacroUse);
return;
Expand Down
Loading
Loading