Skip to content

Commit 2b24fdd

Browse files
committed
propagate default
1 parent a737217 commit 2b24fdd

File tree

13 files changed

+54
-44
lines changed

13 files changed

+54
-44
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,11 +1961,11 @@ pub struct MacroDef {
19611961
/// `true` if macro was defined with `macro_rules`.
19621962
pub macro_rules: bool,
19631963

1964-
pub eii_macro_for: Option<EiiMacroFor>,
1964+
pub eii_macro_for: Option<EIIMacroFor>,
19651965
}
19661966

19671967
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
1968-
pub struct EiiMacroFor {
1968+
pub struct EIIMacroFor {
19691969
pub extern_item_path: Path,
19701970
pub impl_unsafe: bool,
19711971
}
@@ -3605,6 +3605,7 @@ pub struct EIIImpl {
36053605
pub impl_safety: Safety,
36063606
pub span: Span,
36073607
pub inner_span: Span,
3608+
pub is_default: bool,
36083609
}
36093610

36103611
#[derive(Clone, Encodable, Decodable, Debug)]

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ fn walk_mac<T: MutVisitor>(vis: &mut T, mac: &mut MacCall) {
751751

752752
fn walk_macro_def<T: MutVisitor>(vis: &mut T, macro_def: &mut MacroDef) {
753753
let MacroDef { body, macro_rules: _, eii_macro_for } = macro_def;
754-
if let Some(EiiMacroFor { extern_item_path, impl_unsafe: _ }) = eii_macro_for {
754+
if let Some(EIIMacroFor { extern_item_path, impl_unsafe: _ }) = eii_macro_for {
755755
vis.visit_path(extern_item_path);
756756
}
757757
visit_delim_args(vis, body);

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl WalkItemKind for ItemKind {
479479
ItemKind::MacroDef(ident, ts) => {
480480
try_visit!(visitor.visit_ident(ident));
481481
try_visit!(visitor.visit_mac_def(ts, id));
482-
if let Some(EiiMacroFor { extern_item_path, impl_unsafe: _ }) = &ts.eii_macro_for {
482+
if let Some(EIIMacroFor { extern_item_path, impl_unsafe: _ }) = &ts.eii_macro_for {
483483
try_visit!(visitor.visit_path(extern_item_path, id));
484484
}
485485
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use super::{
2323
AstOwner, FnDeclKind, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode,
2424
ResolverAstLoweringExt,
2525
};
26-
use crate::GenericArgsMode;
2726

2827
pub(super) struct ItemLowerer<'a, 'hir> {
2928
pub(super) tcx: TyCtxt<'hir>,
@@ -156,7 +155,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
156155
match i {
157156
ItemKind::Fn(box Fn { eii_impl, .. }) => {
158157
let mut eii_impls = ThinVec::new();
159-
for EIIImpl { node_id, eii_macro_path, impl_safety, span, inner_span } in eii_impl {
158+
for EIIImpl {
159+
node_id,
160+
eii_macro_path,
161+
impl_safety,
162+
span,
163+
inner_span,
164+
is_default,
165+
} in eii_impl
166+
{
160167
let did = self.lower_path_simple_eii(*node_id, eii_macro_path);
161168
eii_impls.push(rustc_attr_parsing::EIIImpl {
162169
eii_macro: did,
@@ -165,12 +172,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
165172
impl_marked_unsafe: self
166173
.lower_safety(*impl_safety, hir::Safety::Safe)
167174
.is_unsafe(),
175+
is_default: *is_default,
168176
})
169177
}
170178

171179
vec![hir::Attribute::Parsed(AttributeKind::EiiImpl(eii_impls))]
172180
}
173-
ItemKind::MacroDef(_, MacroDef { eii_macro_for: Some(EiiMacroFor { extern_item_path, impl_unsafe }), .. }) => {
181+
ItemKind::MacroDef(
182+
_,
183+
MacroDef {
184+
eii_macro_for: Some(EIIMacroFor { extern_item_path, impl_unsafe }), ..
185+
},
186+
) => {
174187
vec![hir::Attribute::Parsed(AttributeKind::EiiMacroFor {
175188
eii_extern_item: self.lower_path_simple_eii(id, extern_item_path),
176189
impl_unsafe: *impl_unsafe,
@@ -720,7 +733,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
720733
)
721734
});
722735

723-
724736
// Unmarked safety in unsafe block defaults to unsafe.
725737
let header = self.lower_fn_header(sig.header, hir::Safety::Unsafe, attrs);
726738

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ impl<'a> State<'a> {
678678
}
679679

680680
fn print_fn_full(&mut self, vis: &ast::Visibility, attrs: &[ast::Attribute], func: &ast::Fn) {
681-
let ast::Fn { defaultness, ident, generics, sig, contract, body, define_opaque, eii_impl } = func;
681+
let ast::Fn { defaultness, ident, generics, sig, contract, body, define_opaque, eii_impl } =
682+
func;
682683
self.print_define_opaques(define_opaque.as_deref());
683684

684685
for EIIImpl { eii_macro_path, impl_safety, .. } in eii_impl {

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub struct EIIImpl {
145145
pub impl_marked_unsafe: bool,
146146
pub span: Span,
147147
pub inner_span: Span,
148+
pub is_default: bool,
148149
}
149150

150151
/// Represent parsed, *built in*, inert attributes.

compiler/rustc_builtin_macros/src/eii.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_ast::{DUMMY_NODE_ID, EIIImpl, EiiMacroFor, ItemKind, ast};
1+
use rustc_ast::{DUMMY_NODE_ID, EIIImpl, EIIMacroFor, ItemKind, ast};
22
use rustc_ast_pretty::pprust::path_to_string;
33
use rustc_expand::base::{Annotatable, ExtCtxt};
44
use rustc_span::{Span, kw};
@@ -50,7 +50,7 @@ pub(crate) fn eii_macro_for(
5050
false
5151
};
5252

53-
d.eii_macro_for = Some(EiiMacroFor { extern_item_path, impl_unsafe });
53+
d.eii_macro_for = Some(EIIMacroFor { extern_item_path, impl_unsafe });
5454

5555
// Return the original item and the new methods.
5656
vec![item]
@@ -94,8 +94,8 @@ pub(crate) fn eii_macro(
9494
eii_macro_path: meta_item.path.clone(),
9595
impl_safety: meta_item.unsafety,
9696
span,
97-
inner_span: meta_item.span,
98-
is_default: false,
97+
inner_span: meta_item.path.span,
98+
is_default,
9999
});
100100

101101
vec![item]

compiler/rustc_hir_analysis/src/check/compare_eii.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@ use std::borrow::Cow;
22
use std::iter;
33

44
use rustc_data_structures::fx::FxIndexSet;
5-
use rustc_errors::{
6-
Applicability, E0050, E0053, E0053, E0053, struct_span_code_err, struct_span_code_err,
7-
struct_span_code_err,
8-
};
5+
use rustc_errors::{Applicability, E0050, E0053, struct_span_code_err};
96
use rustc_hir::def_id::{DefId, LocalDefId};
10-
use rustc_hir::{
11-
self as hir, self as hir, self as hir, FnSig, HirId, HirId, HirId, ItemKind, ItemKind, ItemKind,
12-
};
7+
use rustc_hir::{self as hir, FnSig, HirId, ItemKind};
8+
use rustc_infer::infer::canonical::ir::TypingMode;
139
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
1410
use rustc_infer::traits::{ObligationCause, ObligationCauseCode};
1511
use rustc_middle::ty;
1612
use rustc_middle::ty::TyCtxt;
17-
use rustc_middle::ty::error::{ExpectedFound, TypeError, TypeError, TypeError};
18-
use rustc_span::{ErrorGuaranteed, Ident, Span};
13+
use rustc_middle::ty::error::{ExpectedFound, TypeError};
14+
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
1915
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2016
use rustc_trait_selection::regions::InferCtxtRegionExt;
2117
use rustc_trait_selection::traits::ObligationCtxt;
22-
use rustc_type_ir::TypingMode;
2318
use tracing::{debug, instrument};
2419

2520
use super::potentially_plural_count;
@@ -150,9 +145,9 @@ fn compare_number_of_method_arguments<'tcx>(
150145
}
151146
})
152147
})
153-
.or_else(|| tcx.hir().span_if_local(declaration));
148+
.or_else(|| tcx.hir_span_if_local(declaration));
154149

155-
let (external_impl_sig, _, _) = &tcx.hir().expect_item(external_impl).expect_fn();
150+
let (_, external_impl_sig, _, _) = &tcx.hir_expect_item(external_impl).expect_fn();
156151
let pos = external_impl_number_args.saturating_sub(1);
157152
let impl_span = external_impl_sig
158153
.decl
@@ -326,7 +321,7 @@ fn report_eii_mismatch<'tcx>(
326321
if declaration_sig.inputs().len() == *i {
327322
// Suggestion to change output type. We do not suggest in `async` functions
328323
// to avoid complex logic or incorrect output.
329-
if let ItemKind::Fn { sig, .. } = &tcx.hir().expect_item(external_impl_did).kind
324+
if let ItemKind::Fn { sig, .. } = &tcx.hir_expect_item(external_impl_did).kind
330325
&& !sig.header.asyncness.is_async()
331326
{
332327
let msg = "change the output type to match the declaration";
@@ -381,12 +376,9 @@ fn extract_spans_for_error_reporting<'tcx>(
381376
) -> (Span, Option<Span>, Ident) {
382377
let tcx = infcx.tcx;
383378
let (mut external_impl_args, external_impl_name) = {
384-
let item = tcx.hir().expect_item(external_impl);
385-
let (sig, _, _) = item.expect_fn();
386-
(
387-
sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span())),
388-
item.ident,
389-
)
379+
let item = tcx.hir_expect_item(external_impl);
380+
let (ident, sig, _, _) = item.expect_fn();
381+
(sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span())), ident)
390382
};
391383

392384
let declaration_args = declaration.as_local().map(|def_id| {
@@ -403,7 +395,7 @@ fn extract_spans_for_error_reporting<'tcx>(
403395
declaration_args.and_then(|mut args| args.nth(i)),
404396
external_impl_name,
405397
),
406-
_ => (cause.span, tcx.hir().span_if_local(declaration), external_impl_name),
398+
_ => (cause.span, tcx.hir_span_if_local(declaration), external_impl_name),
407399
}
408400
}
409401

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc_trait_selection::traits::{
4040
use tracing::{debug, instrument};
4141
use {rustc_ast as ast, rustc_hir as hir};
4242

43-
use super::compare_eii::{compare_eii_function_types, compare_eii_predicate_entailment};
43+
use super::compare_eii::compare_eii_function_types;
4444
use crate::autoderef::Autoderef;
4545
use crate::collect::CollectItemTypesVisitor;
4646
use crate::constrained_generic_params::{Parameter, identify_constrained_generic_params};

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18441844
fn encode_info_for_macro(&mut self, def_id: LocalDefId) {
18451845
let tcx = self.tcx;
18461846

1847-
let hir::ItemKind::Macro(_, macro_def, _) = tcx.hir_expect_item(def_id).kind else { bug!() };
1847+
let hir::ItemKind::Macro(_, macro_def, _) = tcx.hir_expect_item(def_id).kind else {
1848+
bug!()
1849+
};
18481850
self.tables.is_macro_rules.set(def_id.local_def_index, macro_def.macro_rules);
18491851
record!(self.tables.macro_definition[def_id.to_def_id()] <- &*macro_def.body);
18501852
}

compiler/rustc_parse/src/parser/item.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,9 +2198,10 @@ impl<'a> Parser<'a> {
21982198
};
21992199

22002200
self.psess.gated_spans.gate(sym::decl_macro, lo.to(self.prev_token.span));
2201-
Ok(
2202-
ItemKind::MacroDef(ident, ast::MacroDef { body, macro_rules: false, eii_macro_for: None }),
2203-
)
2201+
Ok(ItemKind::MacroDef(
2202+
ident,
2203+
ast::MacroDef { body, macro_rules: false, eii_macro_for: None },
2204+
))
22042205
}
22052206

22062207
/// Is this a possibly malformed start of a `macro_rules! foo` item definition?
@@ -2247,9 +2248,10 @@ impl<'a> Parser<'a> {
22472248
self.eat_semi_for_macro_if_needed(&body);
22482249
self.complain_if_pub_macro(vis, true);
22492250

2250-
Ok(
2251-
ItemKind::MacroDef(ident, ast::MacroDef { body, macro_rules: true, eii_macro_for: None }),
2252-
)
2251+
Ok(ItemKind::MacroDef(
2252+
ident,
2253+
ast::MacroDef { body, macro_rules: true, eii_macro_for: None },
2254+
))
22532255
}
22542256

22552257
/// Item macro invocations or `macro_rules!` definitions need inherited visibility.

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
484484
_target_span: Span,
485485
target: Target,
486486
) {
487-
for EIIImpl { span, inner_span, eii_macro, impl_marked_unsafe } in impls {
487+
for EIIImpl { span, inner_span, eii_macro, impl_marked_unsafe, is_default: _ } in impls {
488488
match target {
489489
Target::Fn => {}
490490
_ => {

compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,6 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
10611061
};
10621062
debug!("(resolving function) entering function");
10631063

1064-
10651064
if let FnKind::Fn(_, _, f) = fn_kind {
10661065
for EIIImpl { node_id, eii_macro_path, .. } in &f.eii_impl {
10671066
self.smart_resolve_path(*node_id, &None, &eii_macro_path, PathSource::Macro);
@@ -2846,7 +2845,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28462845
self.parent_scope.macro_rules = self.r.macro_rules_scopes[&def_id];
28472846
}
28482847

2849-
if let Some(EiiMacroFor { extern_item_path, impl_unsafe: _ }) =
2848+
if let Some(EIIMacroFor { extern_item_path, impl_unsafe: _ }) =
28502849
&macro_def.eii_macro_for
28512850
{
28522851
self.smart_resolve_path(

0 commit comments

Comments
 (0)