Skip to content

Rollup of 10 pull requests #120709

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

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
511bf6e
Add note to resolve error about generics from inside static/const
clubby789 Jan 13, 2024
2cfc817
Special case 'generic param from outer item' message for `Self`
clubby789 Jan 13, 2024
c367983
Suggest name value cfg when only value is used for check-cfg
chenyukang Jan 28, 2024
0213c87
limit the names_possiblilities to less than 3
chenyukang Jan 30, 2024
ca243e7
add testcase for more than 3 cfg names
chenyukang Jan 30, 2024
d34b0fa
Add test for method on unbounded type parameter receiver
estebank Jan 26, 2024
20b1c2a
Account for unbounded type param receiver in suggestions
estebank Jan 26, 2024
9ccc770
fix rebase
estebank Jan 30, 2024
5c41409
Account for non-overlapping unmet trait bounds in suggestion
estebank Jan 30, 2024
7331315
Remove `ffi_returns_twice` feature
clubby789 Jan 30, 2024
49d49eb
ast_lowering: Make sure all imports have non-empty resolution lists
petrochenkov Jan 30, 2024
3ff6796
hir: Make sure all `HirId`s have corresponding HIR `Node`s
petrochenkov Jan 20, 2024
e292423
hir: Remove `fn opt_hir_id` and `fn opt_span`
petrochenkov Jan 21, 2024
be77cf8
Use a `Vec` instead of a slice in `DeconstructedPat`
Nadrieril Jan 25, 2024
f65fe3b
Remove `pattern_arena` from `RustcMatchCheckCtxt`
Nadrieril Jan 25, 2024
be80c82
hir: Add some FIXMEs for future work
petrochenkov Jan 31, 2024
0e16885
Use deeply_normalize_with_skipped_universes in when processing type o…
compiler-errors Jan 30, 2024
7576b77
Do process_registered_region_obligations in a loop
compiler-errors Jan 30, 2024
7d1fda7
Normalize type outlives obligations in NLL
compiler-errors Jan 30, 2024
a371059
Don't hang when there's an infinite loop of outlives obligations
compiler-errors Feb 1, 2024
e951bcf
Normalize the whole PolyTypeOutlivesPredicate, more simplifications
compiler-errors Feb 2, 2024
9f58cf4
get rid of nontrivial_structural_match lint and custom_eq const qualif
RalfJung Jan 27, 2024
48abca7
show indirect_structural_match and pointer_structural_match in future…
RalfJung Jan 27, 2024
45d01b8
update the tracking issue for structural match violations
RalfJung Jan 27, 2024
e00df17
merge the accepted-structural-match tests into one
RalfJung Jan 28, 2024
f2eec89
unstably allow constants to refer to statics and read from immutable …
RalfJung Jan 5, 2024
189c957
validation: descend from consts into statics
RalfJung Jan 6, 2024
1461e12
detect consts that reference extern statics
RalfJung Jan 6, 2024
f695515
rebless after rebase
RalfJung Feb 5, 2024
262c7ad
Rollup merge of #119614 - RalfJung:const-refs-to-static, r=oli-obk
matthiaskrgr Feb 6, 2024
7dc7422
Rollup merge of #119939 - clubby789:static-const-generic-note, r=comp…
matthiaskrgr Feb 6, 2024
a22f60a
Rollup merge of #120206 - petrochenkov:somehir, r=compiler-errors
matthiaskrgr Feb 6, 2024
3d69c79
Rollup merge of #120331 - Nadrieril:no-arena, r=compiler-errors
matthiaskrgr Feb 6, 2024
bfc4e34
Rollup merge of #120396 - estebank:method-on-unbounded-type-param, r=…
matthiaskrgr Feb 6, 2024
308162a
Rollup merge of #120423 - RalfJung:indirect-structural-match, r=petro…
matthiaskrgr Feb 6, 2024
d8f5cb9
Rollup merge of #120435 - chenyukang:yukang-fix-120427-cfg-name, r=Ur…
matthiaskrgr Feb 6, 2024
6293990
Rollup merge of #120502 - clubby789:remove-ffi-returns-twice, r=compi…
matthiaskrgr Feb 6, 2024
a513920
Rollup merge of #120507 - estebank:issue-108428, r=davidtwco
matthiaskrgr Feb 6, 2024
d26cd5e
Rollup merge of #120513 - compiler-errors:normalize-regions-for-nll, …
matthiaskrgr Feb 6, 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
14 changes: 12 additions & 2 deletions compiler/rustc_resolve/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,27 @@ resolve_forward_declared_generic_param =
.label = defaulted generic parameters cannot be forward declared

resolve_generic_params_from_outer_item =
can't use generic parameters from outer item
.label = use of generic parameter from outer item
can't use {$is_self ->
[true] `Self`
*[false] generic parameters
} from outer item
.label = use of {$is_self ->
[true] `Self`
*[false] generic parameter
} from outer item
.refer_to_type_directly = refer to the type directly here instead
.suggestion = try introducing a local generic parameter here

resolve_generic_params_from_outer_item_const = a `const` is a separate item from the item that contains it

resolve_generic_params_from_outer_item_const_param = const parameter from outer item

resolve_generic_params_from_outer_item_self_ty_alias = `Self` type implicitly declared here, by this `impl`

resolve_generic_params_from_outer_item_self_ty_param = can't use `Self` here

resolve_generic_params_from_outer_item_static = a `static` is a separate item from the item that contains it

resolve_generic_params_from_outer_item_ty_param = type parameter from outer item


Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
resolution_error: ResolutionError<'a>,
) -> DiagnosticBuilder<'_> {
match resolution_error {
ResolutionError::GenericParamsFromOuterItem(outer_res, has_generic_params) => {
ResolutionError::GenericParamsFromOuterItem(outer_res, has_generic_params, def_kind) => {
use errs::GenericParamsFromOuterItemLabel as Label;
let static_or_const = match def_kind {
DefKind::Static(_) => Some(errs::GenericParamsFromOuterItemStaticOrConst::Static),
DefKind::Const => Some(errs::GenericParamsFromOuterItemStaticOrConst::Const),
_ => None,
};
let is_self = matches!(outer_res, Res::SelfTyParam { .. } | Res::SelfTyAlias { .. });
let mut err = errs::GenericParamsFromOuterItem {
span,
label: None,
refer_to_type_directly: None,
sugg: None,
static_or_const,
is_self,
};

let sm = self.tcx.sess.source_map();
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_resolve/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ pub(crate) struct GenericParamsFromOuterItem {
pub(crate) refer_to_type_directly: Option<Span>,
#[subdiagnostic]
pub(crate) sugg: Option<GenericParamsFromOuterItemSugg>,
#[subdiagnostic]
pub(crate) static_or_const: Option<GenericParamsFromOuterItemStaticOrConst>,
pub(crate) is_self: bool,
}

#[derive(Subdiagnostic)]
pub(crate) enum GenericParamsFromOuterItemStaticOrConst {
#[note(resolve_generic_params_from_outer_item_static)]
Static,
#[note(resolve_generic_params_from_outer_item_const)]
Const,
}

#[derive(Subdiagnostic)]
Expand Down
30 changes: 20 additions & 10 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use rustc_span::symbol::{kw, Ident};
use rustc_span::Span;

use crate::errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
use crate::late::{
ConstantHasGenerics, HasGenericParams, NoConstantGenericsReason, PathSource, Rib, RibKind,
};
use crate::late::{ConstantHasGenerics, NoConstantGenericsReason, PathSource, Rib, RibKind};
use crate::macros::{sub_namespace_match, MacroRulesScope};
use crate::BindingKey;
use crate::{errors, AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, Determinacy, Finalize};
Expand Down Expand Up @@ -1090,7 +1088,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
| RibKind::ForwardGenericParamBan => {
// Nothing to do. Continue.
}
RibKind::Item(_) | RibKind::AssocItem => {
RibKind::Item(..) | RibKind::AssocItem => {
// This was an attempt to access an upvar inside a
// named function item. This is not allowed, so we
// report an error.
Expand Down Expand Up @@ -1155,7 +1153,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => {
for rib in ribs {
let has_generic_params: HasGenericParams = match rib.kind {
let (has_generic_params, def_kind) = match rib.kind {
RibKind::Normal
| RibKind::FnOrCoroutine
| RibKind::Module(..)
Expand Down Expand Up @@ -1213,7 +1211,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}

// This was an attempt to use a type parameter outside its scope.
RibKind::Item(has_generic_params) => has_generic_params,
RibKind::Item(has_generic_params, def_kind) => {
(has_generic_params, def_kind)
}
RibKind::ConstParamTy => {
if let Some(span) = finalize {
self.report_error(
Expand All @@ -1231,15 +1231,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
if let Some(span) = finalize {
self.report_error(
span,
ResolutionError::GenericParamsFromOuterItem(res, has_generic_params),
ResolutionError::GenericParamsFromOuterItem(
res,
has_generic_params,
def_kind,
),
);
}
return Res::Err;
}
}
Res::Def(DefKind::ConstParam, _) => {
for rib in ribs {
let has_generic_params = match rib.kind {
let (has_generic_params, def_kind) = match rib.kind {
RibKind::Normal
| RibKind::FnOrCoroutine
| RibKind::Module(..)
Expand Down Expand Up @@ -1276,7 +1280,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
continue;
}

RibKind::Item(has_generic_params) => has_generic_params,
RibKind::Item(has_generic_params, def_kind) => {
(has_generic_params, def_kind)
}
RibKind::ConstParamTy => {
if let Some(span) = finalize {
self.report_error(
Expand All @@ -1295,7 +1301,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
if let Some(span) = finalize {
self.report_error(
span,
ResolutionError::GenericParamsFromOuterItem(res, has_generic_params),
ResolutionError::GenericParamsFromOuterItem(
res,
has_generic_params,
def_kind,
),
);
}
return Res::Err;
Expand Down
46 changes: 26 additions & 20 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub(crate) enum RibKind<'a> {
FnOrCoroutine,

/// We passed through an item scope. Disallow upvars.
Item(HasGenericParams),
Item(HasGenericParams, DefKind),

/// We're in a constant item. Can't refer to dynamic stuff.
///
Expand Down Expand Up @@ -225,7 +225,7 @@ impl RibKind<'_> {
| RibKind::MacroDefinition(_)
| RibKind::ConstParamTy
| RibKind::InlineAsmSym => false,
RibKind::AssocItem | RibKind::Item(_) | RibKind::ForwardGenericParamBan => true,
RibKind::AssocItem | RibKind::Item(..) | RibKind::ForwardGenericParamBan => true,
}
}

Expand Down Expand Up @@ -869,11 +869,12 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
}
fn visit_foreign_item(&mut self, foreign_item: &'ast ForeignItem) {
self.resolve_doc_links(&foreign_item.attrs, MaybeExported::Ok(foreign_item.id));
let def_kind = self.r.local_def_kind(foreign_item.id);
match foreign_item.kind {
ForeignItemKind::TyAlias(box TyAlias { ref generics, .. }) => {
self.with_generic_param_rib(
&generics.params,
RibKind::Item(HasGenericParams::Yes(generics.span)),
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
LifetimeRibKind::Generics {
binder: foreign_item.id,
kind: LifetimeBinderKind::Item,
Expand All @@ -885,7 +886,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
ForeignItemKind::Fn(box Fn { ref generics, .. }) => {
self.with_generic_param_rib(
&generics.params,
RibKind::Item(HasGenericParams::Yes(generics.span)),
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
LifetimeRibKind::Generics {
binder: foreign_item.id,
kind: LifetimeBinderKind::Function,
Expand All @@ -895,7 +896,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
);
}
ForeignItemKind::Static(..) => {
self.with_static_rib(|this| {
self.with_static_rib(def_kind, |this| {
visit::walk_foreign_item(this, foreign_item);
});
}
Expand Down Expand Up @@ -2266,10 +2267,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {

fn resolve_adt(&mut self, item: &'ast Item, generics: &'ast Generics) {
debug!("resolve_adt");
let kind = self.r.local_def_kind(item.id);
self.with_current_self_item(item, |this| {
this.with_generic_param_rib(
&generics.params,
RibKind::Item(HasGenericParams::Yes(generics.span)),
RibKind::Item(HasGenericParams::Yes(generics.span), kind),
LifetimeRibKind::Generics {
binder: item.id,
kind: LifetimeBinderKind::Item,
Expand Down Expand Up @@ -2343,11 +2345,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
let name = item.ident.name;
debug!("(resolving item) resolving {} ({:?})", name, item.kind);

let def_kind = self.r.local_def_kind(item.id);
match item.kind {
ItemKind::TyAlias(box TyAlias { ref generics, .. }) => {
self.with_generic_param_rib(
&generics.params,
RibKind::Item(HasGenericParams::Yes(generics.span)),
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
LifetimeRibKind::Generics {
binder: item.id,
kind: LifetimeBinderKind::Item,
Expand All @@ -2360,7 +2363,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
ItemKind::Fn(box Fn { ref generics, .. }) => {
self.with_generic_param_rib(
&generics.params,
RibKind::Item(HasGenericParams::Yes(generics.span)),
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
LifetimeRibKind::Generics {
binder: item.id,
kind: LifetimeBinderKind::Function,
Expand Down Expand Up @@ -2399,7 +2402,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
// Create a new rib for the trait-wide type parameters.
self.with_generic_param_rib(
&generics.params,
RibKind::Item(HasGenericParams::Yes(generics.span)),
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
LifetimeRibKind::Generics {
binder: item.id,
kind: LifetimeBinderKind::Item,
Expand All @@ -2420,7 +2423,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
// Create a new rib for the trait-wide type parameters.
self.with_generic_param_rib(
&generics.params,
RibKind::Item(HasGenericParams::Yes(generics.span)),
RibKind::Item(HasGenericParams::Yes(generics.span), def_kind),
LifetimeRibKind::Generics {
binder: item.id,
kind: LifetimeBinderKind::Item,
Expand Down Expand Up @@ -2454,7 +2457,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}

ItemKind::Static(box ast::StaticItem { ref ty, ref expr, .. }) => {
self.with_static_rib(|this| {
self.with_static_rib(def_kind, |this| {
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| {
this.visit_ty(ty);
});
Expand All @@ -2469,11 +2472,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
ItemKind::Const(box ast::ConstItem { ref generics, ref ty, ref expr, .. }) => {
self.with_generic_param_rib(
&generics.params,
RibKind::Item(if self.r.tcx.features().generic_const_items {
HasGenericParams::Yes(generics.span)
} else {
HasGenericParams::No
}),
RibKind::Item(
if self.r.tcx.features().generic_const_items {
HasGenericParams::Yes(generics.span)
} else {
HasGenericParams::No
},
def_kind,
),
LifetimeRibKind::Generics {
binder: item.id,
kind: LifetimeBinderKind::ConstItem,
Expand Down Expand Up @@ -2558,7 +2564,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
let mut add_bindings_for_ns = |ns| {
let parent_rib = self.ribs[ns]
.iter()
.rfind(|r| matches!(r.kind, RibKind::Item(_)))
.rfind(|r| matches!(r.kind, RibKind::Item(..)))
.expect("associated item outside of an item");
seen_bindings.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
};
Expand Down Expand Up @@ -2693,8 +2699,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
self.label_ribs.pop();
}

fn with_static_rib(&mut self, f: impl FnOnce(&mut Self)) {
let kind = RibKind::Item(HasGenericParams::No);
fn with_static_rib(&mut self, def_kind: DefKind, f: impl FnOnce(&mut Self)) {
let kind = RibKind::Item(HasGenericParams::No, def_kind);
self.with_rib(ValueNS, kind, |this| this.with_rib(TypeNS, kind, f))
}

Expand Down Expand Up @@ -2875,7 +2881,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
// If applicable, create a rib for the type parameters.
self.with_generic_param_rib(
&generics.params,
RibKind::Item(HasGenericParams::Yes(generics.span)),
RibKind::Item(HasGenericParams::Yes(generics.span), self.r.local_def_kind(item_id)),
LifetimeRibKind::Generics {
span: generics.span,
binder: item_id,
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ struct BindingError {
#[derive(Debug)]
enum ResolutionError<'a> {
/// Error E0401: can't use type or const parameters from outer item.
GenericParamsFromOuterItem(Res, HasGenericParams),
GenericParamsFromOuterItem(Res, HasGenericParams, DefKind),
/// Error E0403: the name is already used for a type or const parameter in this generic
/// parameter list.
NameAlreadyUsedInParameterList(Symbol, Span),
Expand Down Expand Up @@ -1217,6 +1217,10 @@ impl<'tcx> Resolver<'_, 'tcx> {
self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`"))
}

fn local_def_kind(&self, node: NodeId) -> DefKind {
self.tcx.def_kind(self.local_def_id(node))
}

/// Adds a definition with a parent definition.
fn create_def(
&mut self,
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/error-codes/E0401.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LL | fn baz<U,
LL | (y: T) {
| ^ use of generic parameter from outer item

error[E0401]: can't use generic parameters from outer item
error[E0401]: can't use `Self` from outer item
--> $DIR/E0401.rs:24:25
|
LL | impl<T> Iterator for A<T> {
Expand All @@ -29,7 +29,7 @@ LL | impl<T> Iterator for A<T> {
LL | fn helper(sel: &Self) -> u8 {
| ^^^^
| |
| use of generic parameter from outer item
| use of `Self` from outer item
| refer to the type directly here instead

error[E0283]: type annotations needed
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/inner-static-type-parameter.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LL | fn foo<T>() {
| - type parameter from outer item
LL | static a: Bar<T> = Bar::What;
| ^ use of generic parameter from outer item
|
= note: a `static` is a separate item from the item that contains it

error[E0392]: type parameter `T` is never used
--> $DIR/inner-static-type-parameter.rs:3:10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LL | fn outer<T: Tr>() { // outer function
| - type parameter from outer item
LL | const K: u32 = T::C;
| ^^^^ use of generic parameter from outer item
|
= note: a `const` is a separate item from the item that contains it

error[E0401]: can't use generic parameters from outer item
--> $DIR/generic-params-from-outer-item-in-const-item.rs:19:24
Expand All @@ -14,6 +16,8 @@ LL | impl<T> Tr for T { // outer impl block
LL | const C: u32 = {
LL | const I: u32 = T::C;
| ^^^^ use of generic parameter from outer item
|
= note: a `const` is a separate item from the item that contains it

error[E0401]: can't use generic parameters from outer item
--> $DIR/generic-params-from-outer-item-in-const-item.rs:27:20
Expand All @@ -22,6 +26,8 @@ LL | struct S<T: Tr>(U32<{ // outer struct
| - type parameter from outer item
LL | const _: u32 = T::C;
| ^^^^ use of generic parameter from outer item
|
= note: a `const` is a separate item from the item that contains it

error: aborting due to 3 previous errors

Expand Down
Loading